protected DomModelTreeView( DomElement rootElement, DomManager manager, SimpleTreeStructure treeStructure) { myDomManager = manager; myRootElement = rootElement; myTree = new SimpleTree(new DefaultTreeModel(new DefaultMutableTreeNode())); myTree.setRootVisible(isRootVisible()); myTree.setShowsRootHandles(true); myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); ToolTipManager.sharedInstance().registerComponent(myTree); TreeUtil.installActions(myTree); myBuilder = new AbstractTreeBuilder( myTree, (DefaultTreeModel) myTree.getModel(), treeStructure, WeightBasedComparator.INSTANCE, false); Disposer.register(this, myBuilder); myBuilder.setNodeDescriptorComparator(null); myBuilder.initRootNode(); add(myTree, BorderLayout.CENTER); myTree.addTreeExpansionListener( new TreeExpansionListener() { @Override public void treeExpanded(TreeExpansionEvent event) { final SimpleNode simpleNode = myTree.getNodeFor(event.getPath()); if (simpleNode instanceof AbstractDomElementNode) { ((AbstractDomElementNode) simpleNode).setExpanded(true); } } @Override public void treeCollapsed(TreeExpansionEvent event) { final SimpleNode simpleNode = myTree.getNodeFor(event.getPath()); if (simpleNode instanceof AbstractDomElementNode) { ((AbstractDomElementNode) simpleNode).setExpanded(false); simpleNode.update(); } } }); myDomManager.addDomEventListener( new DomChangeAdapter() { @Override protected void elementChanged(DomElement element) { if (element.isValid()) { queueUpdate(DomUtil.getFile(element).getVirtualFile()); } else if (element instanceof DomFileElement) { final XmlFile xmlFile = ((DomFileElement) element).getFile(); queueUpdate(xmlFile.getVirtualFile()); } } }, this); final Project project = myDomManager.getProject(); DomElementAnnotationsManager.getInstance(project) .addHighlightingListener( new DomElementAnnotationsManager.DomHighlightingListener() { @Override public void highlightingFinished(@NotNull DomFileElement element) { if (element.isValid()) { queueUpdate(DomUtil.getFile(element).getVirtualFile()); } } }, this); myTree.setPopupGroup(getPopupActions(), DOM_MODEL_TREE_VIEW_POPUP); }
protected final Project getProject() { return myDomManager.getProject(); }