@Nullable private static MasterDetailsComponent.MyNode findFacetNode(final Facet facet, final MasterDetailsComponent.MyNode moduleNode) { for (int i = 0; i < moduleNode.getChildCount(); i++) { final TreeNode node = moduleNode.getChildAt(i); if (node instanceof MasterDetailsComponent.MyNode) { final MasterDetailsComponent.MyNode configNode = (MasterDetailsComponent.MyNode)node; final NamedConfigurable config = configNode.getConfigurable(); if (config instanceof FacetConfigurable) { final Facet existingFacet = ((FacetConfigurable)config).getEditableObject(); if (existingFacet != null && existingFacet.equals(facet)) { return configNode; } } } } return null; }
@Override public void performFix() { final LibraryTable.ModifiableModel libraryTable = myContext.getModifiableLibraryTable(myLibrary.getTable()); if (libraryTable instanceof LibrariesModifiableModel) { for (String invalidRoot : myInvalidUrls) { final ExistingLibraryEditor libraryEditor = ((LibrariesModifiableModel)libraryTable).getLibraryEditor(myLibrary); libraryEditor.removeRoot(invalidRoot, myType); } myContext.getDaemonAnalyzer().queueUpdate(LibraryProjectStructureElement.this); final ProjectStructureConfigurable structureConfigurable = ProjectStructureConfigurable.getInstance(myContext.getProject()); navigate().doWhenDone(new Runnable() { @Override public void run() { final NamedConfigurable configurable = structureConfigurable.getConfigurableFor(myLibrary).getSelectedConfigurable(); if (configurable instanceof LibraryConfigurable) { ((LibraryConfigurable)configurable).updateComponent(); } } }); } }
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MasterDetailsComponent.MyNode) { final MasterDetailsComponent.MyNode node = (MasterDetailsComponent.MyNode)value; final NamedConfigurable configurable = node.getConfigurable(); if (configurable != null) { final Icon icon = configurable.getIcon(expanded); final boolean showSeparator = configurable instanceof FrameworkDetectionConfigurable; final JComponent component = configureComponent(node.getDisplayName(), null, icon, icon, selected, showSeparator, null, -1); myTextLabel.setOpaque(selected); return component; } } return myRendererComponent; }
@Override public void apply() throws ConfigurationException { final Ref<ConfigurationException> exceptionRef = Ref.create(); try { ProjectJdksConfigurable.super.apply(); boolean modifiedJdks = false; for (int i = 0; i < myRoot.getChildCount(); i++) { final NamedConfigurable configurable = ((MyNode)myRoot.getChildAt(i)).getConfigurable(); if (configurable.isModified()) { configurable.apply(); modifiedJdks = true; } } if (myProjectJdksModel.isModified() || modifiedJdks) { myProjectJdksModel.apply(ProjectJdksConfigurable.this); } myProjectJdksModel.setProjectSdk(getSelectedJdk()); } catch (ConfigurationException e) { exceptionRef.set(e); } if (!exceptionRef.isNull()) { throw exceptionRef.get(); } }
@Override public void actionPerformed(AnActionEvent e) { String name = UniqueNameGenerator.generateUniqueName(myServerType.getPresentableName(), new Condition<String>() { @Override public boolean value(String s) { for (NamedConfigurable<RemoteServer<?>> configurable : getConfiguredServers()) { if (configurable.getDisplayName().equals(s)) { return false; } } return true; } }); MyNode node = addServerNode(myServersManager.createServer(myServerType, name), true); selectNodeInTree(node); }
public MyRemoveAction() { super(new Condition<Object[]>() { @Override public boolean value(final Object[] objects) { Object[] editableObjects = ContainerUtil.mapNotNull(objects, new Function<Object, Object>() { @Override public Object fun(Object object) { if (object instanceof MyNode) { final NamedConfigurable namedConfigurable = ((MyNode)object).getConfigurable(); if (namedConfigurable != null) { return namedConfigurable.getEditableObject(); } } return null; } }, new Object[0]); return editableObjects.length == objects.length && canBeRemoved(editableObjects); } }); }
@Override public int compare(final MyNode o1, final MyNode o2) { final NamedConfigurable configurable1 = o1.getConfigurable(); final NamedConfigurable configurable2 = o2.getConfigurable(); if (configurable1.getClass() == configurable2.getClass()) { return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()); } final Object editableObject1 = configurable1.getEditableObject(); final Object editableObject2 = configurable2.getEditableObject(); if (editableObject2 instanceof Module && editableObject1 instanceof ModuleGroup) return -1; if (editableObject1 instanceof Module && editableObject2 instanceof ModuleGroup) return 1; if (editableObject2 instanceof Module && editableObject1 instanceof String) return 1; if (editableObject1 instanceof Module && editableObject2 instanceof String) return -1; if (editableObject2 instanceof ModuleGroup && editableObject1 instanceof String) return 1; if (editableObject1 instanceof ModuleGroup && editableObject2 instanceof String) return -1; return 0; }
@Override public void apply() throws ConfigurationException { boolean modifiedSdks = false; for (int i = 0; i < myRoot.getChildCount(); i++) { final TreeNode groupNode = myRoot.getChildAt(i); for (int k = 0; k < groupNode.getChildCount(); k++) { final MyNode sdkNode = (MyNode)groupNode.getChildAt(k); final NamedConfigurable configurable = sdkNode.getConfigurable(); if (configurable.isModified()) { configurable.apply(); modifiedSdks = true; } } } if (mySdksTreeModel.isModified() || modifiedSdks) mySdksTreeModel.apply(this); }
@Nullable public ProjectStructureElement getSelectedElement() { final TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null && selectionPath.getLastPathComponent() instanceof MyNode) { MyNode node = (MyNode)selectionPath.getLastPathComponent(); final NamedConfigurable configurable = node.getConfigurable(); if (configurable instanceof ProjectStructureElementConfigurable) { return ((ProjectStructureElementConfigurable)configurable).getProjectStructureElement(); } } return null; }
@NotNull private MultiMap<RemoveConfigurableHandler, MyNode> groupNodes(List<MyNode> nodes) { List<? extends RemoveConfigurableHandler<?>> handlers = getRemoveHandlers(); MultiMap<RemoveConfigurableHandler, MyNode> grouped = new LinkedMultiMap<RemoveConfigurableHandler, MyNode>(); for (MyNode node : nodes) { final NamedConfigurable<?> configurable = node.getConfigurable(); if (configurable == null) continue; RemoveConfigurableHandler handler = findHandler(handlers, configurable.getClass()); if (handler == null) continue; grouped.putValue(handler, node); } return grouped; }
private static RemoveConfigurableHandler<?> findHandler(List<? extends RemoveConfigurableHandler<?>> handlers, Class<? extends NamedConfigurable> configurableClass) { for (RemoveConfigurableHandler<?> handler : handlers) { if (handler.getConfigurableClass().isAssignableFrom(configurableClass)) { return handler; } } return null; }
private List<LibraryConfigurable> getLibraryConfigurables() { //todo[nik] improve List<LibraryConfigurable> libraryConfigurables = new ArrayList<LibraryConfigurable>(); for (int i = 0; i < myRoot.getChildCount(); i++) { final TreeNode node = myRoot.getChildAt(i); if (node instanceof MyNode) { final NamedConfigurable configurable = ((MyNode)node).getConfigurable(); if (configurable instanceof LibraryConfigurable) { libraryConfigurables.add((LibraryConfigurable)configurable); } } } return libraryConfigurables; }
@Override protected void updateSelection(@Nullable NamedConfigurable configurable) { boolean selectionChanged = !Comparing.equal(myCurrentConfigurable, configurable); if (myCurrentConfigurable instanceof LibraryConfigurable && selectionChanged) { ((LibraryConfigurable)myCurrentConfigurable).onUnselected(); } super.updateSelection(configurable); if (myCurrentConfigurable instanceof LibraryConfigurable && selectionChanged) { ((LibraryConfigurable)myCurrentConfigurable).onSelected(); } }
@Override protected Comparator<MyNode> getNodeComparator() { return new Comparator<MyNode>() { @Override public int compare(MyNode node1, MyNode node2) { final NamedConfigurable c1 = node1.getConfigurable(); final NamedConfigurable c2 = node2.getConfigurable(); if (c1 instanceof FrameworkDetectionConfigurable && !(c2 instanceof FrameworkDetectionConfigurable)) return 1; if (!(c1 instanceof FrameworkDetectionConfigurable) && c2 instanceof FrameworkDetectionConfigurable) return -1; return StringUtil.naturalCompare(node1.getDisplayName(), node2.getDisplayName()); } }; }
public boolean updateMultiSelection(final List<NamedConfigurable> selectedConfigurables, final DetailsComponent detailsComponent) { FacetType selectedFacetType = null; List<FacetEditor> facetEditors = new ArrayList<FacetEditor>(); for (NamedConfigurable selectedConfigurable : selectedConfigurables) { if (selectedConfigurable instanceof FacetConfigurable) { FacetConfigurable facetConfigurable = (FacetConfigurable)selectedConfigurable; FacetType facetType = facetConfigurable.getEditableObject().getType(); if (selectedFacetType != null && selectedFacetType != facetType) { return false; } selectedFacetType = facetType; facetEditors.add(facetConfigurable.getEditor()); } } if (facetEditors.size() <= 1 || selectedFacetType == null) { return false; } FacetEditor[] selectedEditors = facetEditors.toArray(new FacetEditor[facetEditors.size()]); MultipleFacetSettingsEditor editor = selectedFacetType.createMultipleConfigurationsEditor(myProject, selectedEditors); if (editor == null) { return false; } setSelectedNode(null); myCurrentMultipleSettingsEditor = editor; detailsComponent.setText(ProjectBundle.message("multiple.facets.banner.0.1.facets", selectedEditors.length, selectedFacetType.getPresentableName())); detailsComponent.setContent(editor.createComponent()); return true; }
@Override protected void updateSelection(@Nullable final NamedConfigurable configurable) { disposeMultipleSettingsEditor(); if (configurable instanceof FacetTypeConfigurable) { ((FacetTypeConfigurable)configurable).updateComponent(); } super.updateSelection(configurable); }
@Override public void actionPerformed(final AnActionEvent e) { NamedConfigurable selected = getSelectedConfigurable(); if (selected instanceof FacetConfigurable) { ProjectStructureConfigurable.getInstance(myProject).select(((FacetConfigurable)selected).getEditableObject(), true); } }
private void updateName() { final TreePath path = myTree.getSelectionPath(); if (path != null) { final NamedConfigurable configurable = ((MyNode)path.getLastPathComponent()).getConfigurable(); if (configurable != null && configurable instanceof JdkConfigurable) { configurable.updateName(); } } }
@Override public void apply() throws ConfigurationException { boolean modifiedJdks = false; for (int i = 0; i < myRoot.getChildCount(); i++) { final NamedConfigurable configurable = ((MyNode)myRoot.getChildAt(i)).getConfigurable(); if (configurable.isModified()) { configurable.apply(); modifiedJdks = true; } } if (myJdksTreeModel.isModified() || modifiedJdks) myJdksTreeModel.apply(this); myJdksTreeModel.setProjectSdk(ProjectRootManager.getInstance(myProject).getProjectSdk()); }
private MyNode addArtifactNode(final Artifact artifact) { final NamedConfigurable<Artifact> configurable; if (artifact instanceof InvalidArtifact) { configurable = new InvalidArtifactConfigurable((InvalidArtifact)artifact, myPackagingEditorContext, TREE_UPDATER); } else { configurable = new ArtifactConfigurable(artifact, myPackagingEditorContext, TREE_UPDATER); } final MyNode node = new MyNode(configurable); addNode(node, myRoot); return node; }
@Override protected void processRemovedItems() { final Set<Sdk> jdks = new HashSet<Sdk>(); for(int i = 0; i < myRoot.getChildCount(); i++){ final DefaultMutableTreeNode node = (DefaultMutableTreeNode)myRoot.getChildAt(i); final NamedConfigurable namedConfigurable = (NamedConfigurable)node.getUserObject(); jdks.add(((JdkConfigurable)namedConfigurable).getEditableObject()); } final HashMap<Sdk, Sdk> sdks = new HashMap<Sdk, Sdk>(myProjectJdksModel.getProjectSdks()); for (Sdk sdk : sdks.values()) { if (!jdks.contains(sdk)) { myProjectJdksModel.removeSdk(sdk); } } }
@Override public void apply() throws ConfigurationException { super.apply(); Set<RemoteServer<?>> servers = new HashSet<RemoteServer<?>>(getServers()); for (NamedConfigurable<RemoteServer<?>> configurable : getConfiguredServers()) { RemoteServer<?> server = configurable.getEditableObject(); server.setName(configurable.getDisplayName()); if (!servers.contains(server)) { myServersManager.addServer(server); } } }
private List<NamedConfigurable<RemoteServer<?>>> getConfiguredServers() { List<NamedConfigurable<RemoteServer<?>>> configurables = new ArrayList<NamedConfigurable<RemoteServer<?>>>(); for (int i = 0; i < myRoot.getChildCount(); i++) { MyNode node = (MyNode)myRoot.getChildAt(i); configurables.add((NamedConfigurable<RemoteServer<?>>)node.getConfigurable()); } return configurables; }
private boolean removeFromModel(final TreePath selectionPath) { final Object last = selectionPath.getLastPathComponent(); if (!(last instanceof MyNode)) return false; final MyNode node = (MyNode)last; final NamedConfigurable configurable = node.getConfigurable(); if (configurable == null) return false; final Object editableObject = configurable.getEditableObject(); return removeObject(editableObject); }
@Override protected void updateSelection(@Nullable NamedConfigurable configurable) { boolean selectionChanged = !Comparing.equal(myCurrentConfigurable, configurable); if (myCurrentConfigurable != null && selectionChanged) { ((LibraryConfigurable)myCurrentConfigurable).onUnselected(); } super.updateSelection(configurable); if (myCurrentConfigurable != null && selectionChanged) { ((LibraryConfigurable)myCurrentConfigurable).onSelected(); } }
@Override protected Comparator<MyNode> getNodeComparator() { return new Comparator<MyNode>() { @Override public int compare(MyNode node1, MyNode node2) { final NamedConfigurable c1 = node1.getConfigurable(); final NamedConfigurable c2 = node2.getConfigurable(); if (c1 instanceof FrameworkDetectionConfigurable && !(c2 instanceof FrameworkDetectionConfigurable)) return 1; if (!(c1 instanceof FrameworkDetectionConfigurable) && c2 instanceof FrameworkDetectionConfigurable) return -1; return node1.getDisplayName().compareToIgnoreCase(node2.getDisplayName()); } }; }
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MasterDetailsComponent.MyNode) { final MasterDetailsComponent.MyNode node = (MasterDetailsComponent.MyNode)value; final NamedConfigurable configurable = node.getConfigurable(); if (configurable != null) { final Icon icon = configurable.getIcon(expanded); final boolean showSeparator = configurable instanceof FrameworkDetectionConfigurable; int width = -1; if (showSeparator && tree.isVisible()) { final int treeWidth = tree.getVisibleRect().width; if (treeWidth > 0) { width = treeWidth; } } final JComponent component = configureComponent(node.getDisplayName(), null, icon, icon, selected, showSeparator, null, width); myTextLabel.setOpaque(selected); return component; } } return myRendererComponent; }