private void remove() { final SimpleNode[] nodes = myTree.getSelectedNodesIfUniform(); for (final SimpleNode node : nodes) { if (node instanceof FileSetNode) { final OfbizFileSet fileSet = ((FileSetNode) node).mySet; if (fileSet.getFiles().isEmpty()) { myBuffer.remove(fileSet); return; } final int result = Messages.showYesNoDialog( myPanel, String.format("Remove File Set '%s' ?", fileSet.getName()), "Confirm removal", Messages.getQuestionIcon()); if (result == DialogWrapper.OK_EXIT_CODE) { if (fileSet.isAutodetected()) { fileSet.setRemoved(true); myBuffer.add(fileSet); } else { myBuffer.remove(fileSet); } } } else if (node instanceof ConfigFileNode) { final VirtualFilePointer filePointer = ((ConfigFileNode) node).myFilePointer; final OfbizFileSet fileSet = ((FileSetNode) node.getParent()).mySet; fileSet.removeFile(filePointer); } } }
private void selectFileSet(final OfbizFileSet fileSet) { myTree.select( myBuilder, new SimpleNodeVisitor() { public boolean accept(final SimpleNode simpleNode) { if (simpleNode instanceof FileSetNode) { if (((FileSetNode) simpleNode).mySet.equals(fileSet)) { return true; } } return false; } }, false); }
@Nullable private FileSetNode getCurrentFileSetNode() { final SimpleNode selectedNode = myTree.getSelectedNode(); if (selectedNode == null) { return null; } if (selectedNode instanceof FileSetNode) { return (FileSetNode) selectedNode; } else if (selectedNode.getParent() instanceof FileSetNode) { return (FileSetNode) selectedNode.getParent(); } else { final SimpleNode parent = selectedNode.getParent(); if (parent != null && parent.getParent() instanceof FileSetNode) { return (FileSetNode) selectedNode.getParent().getParent(); } } return null; }
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); }
public ComponentFileSetConfigurationTab( @NotNull final OfbizFacetConfiguration strutsFacetConfiguration, @NotNull final FacetEditorContext facetEditorContext) { originalConfiguration = strutsFacetConfiguration; module = facetEditorContext.getModule(); myConfigsSercher = new OfbizComponentConfigsSearcher(module); // init tree final SimpleTreeStructure structure = new SimpleTreeStructure() { public Object getRootElement() { return myRootNode; } }; myTree.setRootVisible(false); myTree.setShowsRootHandles(true); // show expand/collapse handles myBuilder = new SimpleTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), structure, null); myBuilder.initRoot(); final DumbService dumbService = DumbService.getInstance(facetEditorContext.getProject()); myTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { final OfbizFileSet fileSet = getCurrentFileSet(); myEditButton.setEnabled(fileSet != null && !dumbService.isDumb()); myRemoveButton.setEnabled(fileSet != null); } }); myAddSetButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { final OfbizFileSet fileSet = new OfbizFileSet( OfbizFileSet.getUniqueId(myBuffer), OfbizFileSet.getUniqueName("My Component Fileset", myBuffer), originalConfiguration) { public boolean isNew() { return true; } }; final FileSetEditor editor = new FileSetEditor(myPanel, fileSet, facetEditorContext, myConfigsSercher); editor.show(); if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) { final OfbizFileSet editedFileSet = editor.getEditedFileSet(); Disposer.register(strutsFacetConfiguration, editedFileSet); myBuffer.add(editedFileSet); myModified = true; myBuilder.updateFromRoot(); selectFileSet(fileSet); } myTree.requestFocus(); } }); myEditButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { final OfbizFileSet fileSet = getCurrentFileSet(); if (fileSet != null) { final FileSetEditor editor = new FileSetEditor(myPanel, fileSet, facetEditorContext, myConfigsSercher); editor.show(); if (editor.getExitCode() == DialogWrapper.OK_EXIT_CODE) { myModified = true; myBuffer.remove(fileSet); final OfbizFileSet edited = editor.getEditedFileSet(); Disposer.register(strutsFacetConfiguration, edited); myBuffer.add(edited); edited.setAutodetected(false); myBuilder.updateFromRoot(); selectFileSet(edited); } myTree.requestFocus(); } } }); myRemoveButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { remove(); myModified = true; myBuilder.updateFromRoot(); myTree.requestFocus(); } }); dumbService.makeDumbAware(myAddSetButton, this); dumbService.makeDumbAware(myEditButton, this); }