private MasterDetailsComponent.MyNode addFacetNode(final Facet facet, final MasterDetailsComponent.MyNode moduleNode) { final MasterDetailsComponent.MyNode existing = findFacetNode(facet, moduleNode); if (existing != null) return existing; final FacetConfigurable facetConfigurable = getOrCreateConfigurable(facet); final MasterDetailsComponent.MyNode facetNode = new MasterDetailsComponent.MyNode(facetConfigurable); myNodes.put(facet, facetNode); MasterDetailsComponent.MyNode parent = moduleNode; final Facet underlyingFacet = facet.getUnderlyingFacet(); if (underlyingFacet != null) { parent = myNodes.get(underlyingFacet); LOG.assertTrue(parent != null); } myStructureConfigurable.addNode(facetNode, parent); return facetNode; }
@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 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; }
public ActionCallback selectOrderEntry(@Nonnull final Module module, @Nullable final OrderEntry orderEntry) { Place p = new Place(); p.putPath(ProjectStructureConfigurable.CATEGORY, this); Runnable r = null; final MasterDetailsComponent.MyNode node = findModuleNode(module); if (node != null) { p.putPath(TREE_OBJECT, module); p.putPath(ModuleEditor.SELECTED_EDITOR_NAME, ClasspathEditor.NAME); r = new Runnable() { @Override public void run() { if (orderEntry != null) { ModuleEditor moduleEditor = ((ModuleConfigurable)node.getConfigurable()).getModuleEditor(); ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME); if (editor instanceof ClasspathEditor) { ((ClasspathEditor)editor).selectOrderEntry(orderEntry); } } } }; } final ActionCallback result = ProjectStructureConfigurable.getInstance(myProject).navigateTo(p, true); return r != null ? result.doWhenDone(r) : result; }
public boolean addSdkNode(final Sdk sdk, final boolean selectInTree) { if (!myUiDisposed) { myContext.getDaemonAnalyzer().queueUpdate(new SdkProjectStructureElement(myContext, sdk)); MyNode newSdkNode = new MyNode(new SdkConfigurable((SdkImpl)sdk, mySdksTreeModel, TREE_UPDATER, myHistory, myProject)); final MyNode groupNode = MasterDetailsComponent.findNodeByObject(myRoot, sdk.getSdkType()); if (groupNode != null) { addNode(newSdkNode, groupNode); } else { final MyNode sdkGroupNode = createSdkGroupNode((SdkType)sdk.getSdkType()); addNode(sdkGroupNode, myRoot); addNode(newSdkNode, sdkGroupNode); } if (selectInTree) { selectNodeInTree(newSdkNode); } return true; } return false; }
public boolean addFacetsNodes(final Module module, final MasterDetailsComponent.MyNode moduleNode) { boolean facetsExist = false; getFacetConfigurator().addFacetInfos(module); final FacetModel facetModel = getFacetConfigurator().getFacetModel(module); for (Facet facet : facetModel.getSortedFacets()) { addFacetNode(facet, moduleNode); facetsExist = true; } return facetsExist; }
private void addFacetNode(Facet facet) { MasterDetailsComponent.MyNode moduleNode = myStructureConfigurable.findModuleNode(facet.getModule()); if (moduleNode == null) return; addFacetNode(facet, moduleNode); final FacetStructureConfigurable facetStructureConfigurable = FacetStructureConfigurable.getInstance(myStructureConfigurable.getProject()); final MasterDetailsComponent.MyNode facetTypeNode = facetStructureConfigurable.getOrCreateFacetTypeNode(facet.getType()); LOG.assertTrue(facetTypeNode != null, "Cannot found node for " + facet.getType()); facetStructureConfigurable.addFacetNodes(facetTypeNode, Collections.singletonList(facet), this); }
public boolean addJdkNode(final Sdk jdk, final boolean selectInTree) { if (!myUiDisposed) { myContext.getDaemonAnalyzer().queueUpdate(new SdkProjectStructureElement(myContext, jdk)); addNode(new MyNode(new JdkConfigurable((ProjectJdkImpl)jdk, myJdksTreeModel, TREE_UPDATER, myHistory, myProject)), myRoot); if (selectInTree) { selectNodeInTree(MasterDetailsComponent.findNodeByObject(myRoot, jdk)); } return true; } return false; }
@Override public void actionPerformed(AnActionEvent e) { Library library = createLibrary(myType, myLibrariesConfigurable.getTree(), myProject, myLibrariesConfigurable.getModelProvider().getModifiableModel()); if (library == null) return; final BaseLibrariesConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library); final DefaultMutableTreeNode libraryNode = MasterDetailsComponent.findNodeByObject((TreeNode)rootConfigurable.getTree().getModel().getRoot(), library); rootConfigurable.selectNodeInTree(libraryNode); LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject, true); }
public void apply(@Nullable MasterDetailsComponent configurable, boolean addedOnly) throws ConfigurationException { String[] errorString = new String[1]; if (!canApply(errorString, configurable, addedOnly)) { throw new ConfigurationException(errorString[0]); } DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() { @Override public void run() { doApply(); } }); myModified = false; }
private void addFacetNode(Facet facet) { MasterDetailsComponent.MyNode moduleNode = myStructureConfigurable.findModuleNode(facet.getModule()); if (moduleNode == null) return; addFacetNode(facet, moduleNode); final FacetStructureConfigurable facetStructureConfigurable = FacetStructureConfigurable.getInstance(myStructureConfigurable.getProject()); final MasterDetailsComponent.MyNode facetTypeNode = facetStructureConfigurable.getOrCreateFacetTypeNode(facet.getType()); LOG.assertTrue(facetTypeNode != null, "Cannot found node for " + facet.getType()); facetStructureConfigurable.addFacetNode(facetTypeNode, facet, this); }
@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; }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myContext.reset(); myProjectSdksModel.reset(); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); } finally { token.finish(); } }
@Override public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) { if(myProjectStructureDialog == null) { return ActionCallback.REJECTED; } final Configurable toSelect = (Configurable)place.getPath(CATEGORY); if (mySelectedConfigurable != toSelect) { if (mySelectedConfigurable instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)mySelectedConfigurable).onStructureUnselected(); } removeSelected(); if (toSelect != null) { myProjectStructureDialog.select(toSelect); } setSelectedConfigurable(toSelect); if (toSelect instanceof MasterDetailsComponent) { final MasterDetailsComponent masterDetails = (MasterDetailsComponent)toSelect; masterDetails.setHistory(myHistory); } if (toSelect instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)toSelect).onStructureSelected(); } } final ActionCallback result = new ActionCallback(); Place.goFurther(toSelect, place, requestFocus).notifyWhenDone(result); if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) { myHistory.pushQueryPlace(); } return result; }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myWasUiDisposed = false; myContext.reset(); myProjectJdksModel.reset(myProject); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); if (myUiState.proportion > 0) { mySplitter.setProportion(myUiState.proportion); } } finally { token.finish(); } }
@Override public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) { final Configurable toSelect = (Configurable)place.getPath(CATEGORY); JComponent detailsContent = myDetails.getTargetComponent(); if (mySelectedConfigurable != toSelect) { if (mySelectedConfigurable instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)mySelectedConfigurable).onStructureUnselected(); } saveSideProportion(); removeSelected(); if (toSelect != null) { detailsContent = toSelect.createComponent(); myDetails.setContent(detailsContent); } mySelectedConfigurable = toSelect; if (mySelectedConfigurable != null) { myUiState.lastEditedConfigurable = mySelectedConfigurable.getDisplayName(); } if (toSelect instanceof MasterDetailsComponent) { final MasterDetailsComponent masterDetails = (MasterDetailsComponent)toSelect; if (myUiState.sideProportion > 0) { masterDetails.getSplitter().setProportion(myUiState.sideProportion); } masterDetails.setHistory(myHistory); } if (toSelect instanceof DetailsComponent.Facade) { ((DetailsComponent.Facade)toSelect).getDetailsComponent().setBannerMinHeight(myToolbarComponent.getPreferredSize().height); } if (toSelect instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)toSelect).onStructureSelected(); } } if (detailsContent != null) { JComponent toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(detailsContent); if (toFocus == null) { toFocus = detailsContent; } if (requestFocus) { myToFocus = toFocus; UIUtil.requestFocus(toFocus); } } final ActionCallback result = new ActionCallback(); Place.goFurther(toSelect, place, requestFocus).notifyWhenDone(result); myDetails.revalidate(); myDetails.repaint(); if (toSelect != null) { mySidePanel.select(createPlaceFor(toSelect)); } if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) { myHistory.pushQueryPlace(); } return result; }
private void saveSideProportion() { if (mySelectedConfigurable instanceof MasterDetailsComponent) { myUiState.sideProportion = ((MasterDetailsComponent)mySelectedConfigurable).getSplitter().getProportion(); } }
public boolean addModuleNodeChildren(Module module, MasterDetailsComponent.MyNode moduleNode, Runnable treeNodeNameUpdater) { return false; }
public Collection<AnAction> createAddActions(final NullableComputable<MasterDetailsComponent.MyNode> selectedNodeRetriever, final Runnable treeNodeNameUpdater, final Project project, final MasterDetailsComponent.MyNode root) { return Collections.emptyList(); }
public void addRootNodes(final MasterDetailsComponent.MyNode parent, final Project project, final Runnable treeUpdater) { }
@Nullable public Comparator<MasterDetailsComponent.MyNode> getNodeComparator() { return null; }
@Override public void customizeCellRenderer(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 namedConfigurable = node.getConfigurable(); if (namedConfigurable == null) { return; } final String displayName = node.getDisplayName(); final Icon icon = namedConfigurable.getIcon(expanded); setIcon(icon); setToolTipText(null); setFont(UIUtil.getTreeFont()); SimpleTextAttributes textAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES; if (node.isDisplayInBold()) { textAttributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; } else if (namedConfigurable instanceof ProjectStructureElementConfigurable) { final ProjectStructureElement projectStructureElement = ((ProjectStructureElementConfigurable)namedConfigurable).getProjectStructureElement(); if (projectStructureElement != null) { final ProjectStructureDaemonAnalyzer daemonAnalyzer = myContext.getDaemonAnalyzer(); final ProjectStructureProblemsHolderImpl problemsHolder = daemonAnalyzer.getProblemsHolder(projectStructureElement); if (problemsHolder != null && problemsHolder.containsProblems()) { final boolean isUnused = problemsHolder.containsProblems(ProjectStructureProblemType.Severity.UNUSED); final boolean haveWarnings = problemsHolder.containsProblems(ProjectStructureProblemType.Severity.WARNING); final boolean haveErrors = problemsHolder.containsProblems(ProjectStructureProblemType.Severity.ERROR); Color foreground = isUnused ? UIUtil.getInactiveTextColor() : null; final int style = haveWarnings || haveErrors ? SimpleTextAttributes.STYLE_WAVED : -1; final Color waveColor = haveErrors ? JBColor.RED : haveWarnings ? JBColor.GRAY : null; textAttributes = textAttributes.derive(style, foreground, null, waveColor); setToolTipText(problemsHolder.composeTooltipMessage()); } append(displayName, textAttributes); String description = projectStructureElement.getDescription(); if (description != null) { append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES, false); } return; } } append(displayName, textAttributes); } }
public void apply(@Nullable MasterDetailsComponent configurable) throws ConfigurationException { apply(configurable, false); }
private boolean canApply(String[] errorString, @Nullable MasterDetailsComponent rootConfigurable, boolean addedOnly) throws ConfigurationException { LinkedHashMap<Sdk, Sdk> sdks = new LinkedHashMap<Sdk, Sdk>(myProjectSdks); if (addedOnly) { Sdk[] allJdks = ProjectJdkTable.getInstance().getAllJdks(); for (Sdk jdk : allJdks) { sdks.remove(jdk); } } ArrayList<String> allNames = new ArrayList<String>(); Sdk itemWithError = null; for (Sdk currItem : sdks.values()) { String currName = currItem.getName(); if (currName.isEmpty()) { itemWithError = currItem; errorString[0] = ProjectBundle.message("sdk.list.name.required.error"); break; } if (allNames.contains(currName)) { itemWithError = currItem; errorString[0] = ProjectBundle.message("sdk.list.unique.name.required.error"); break; } final SdkAdditionalData sdkAdditionalData = currItem.getSdkAdditionalData(); if (sdkAdditionalData instanceof ValidatableSdkAdditionalData) { try { ((ValidatableSdkAdditionalData)sdkAdditionalData).checkValid(this); } catch (ConfigurationException e) { if (rootConfigurable != null) { final Object projectJdk = rootConfigurable.getSelectedObject(); if (!(projectJdk instanceof Sdk) || !Comparing.strEqual(((Sdk)projectJdk).getName(), currName)) { //do not leave current item with current name rootConfigurable.selectNodeInTree(currName); } } throw new ConfigurationException(ProjectBundle.message("sdk.configuration.exception", currName) + " " + e.getMessage()); } } allNames.add(currName); } if (itemWithError == null) return true; if (rootConfigurable != null) { rootConfigurable.selectNodeInTree(itemWithError.getName()); } return false; }
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background HeavyProcessLatch.INSTANCE.processStarted(); try { myWasUiDisposed = false; myContext.reset(); myProjectJdksModel.reset(myProject); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); if (myUiState.proportion > 0) { mySplitter.setProportion(myUiState.proportion); } } finally { HeavyProcessLatch.INSTANCE.processFinished(); } }
private boolean canApply(String[] errorString, @Nullable MasterDetailsComponent rootConfigurable, boolean addedOnly) throws ConfigurationException { LinkedHashMap<Sdk, Sdk> sdks = new LinkedHashMap<Sdk, Sdk>(myProjectSdks); if (addedOnly) { Sdk[] allJdks = ProjectJdkTable.getInstance().getAllJdks(); for (Sdk jdk : allJdks) { sdks.remove(jdk); } } ArrayList<String> allNames = new ArrayList<String>(); Sdk itemWithError = null; for (Sdk currItem : sdks.values()) { String currName = currItem.getName(); if (currName.isEmpty()) { itemWithError = currItem; errorString[0] = ProjectBundle.message("sdk.list.name.required.error"); break; } if (allNames.contains(currName)) { itemWithError = currItem; errorString[0] = ProjectBundle.message("sdk.list.unique.name.required.error"); break; } final SdkAdditionalData sdkAdditionalData = currItem.getSdkAdditionalData(); if (sdkAdditionalData instanceof ValidatableSdkAdditionalData) { try { ((ValidatableSdkAdditionalData) sdkAdditionalData).checkValid(this); } catch (ConfigurationException e) { if (rootConfigurable != null) { final Object projectJdk = rootConfigurable.getSelectedObject(); if (!(projectJdk instanceof Sdk) || !Comparing.strEqual(((Sdk)projectJdk).getName(), currName)) { //do not leave current item with current name rootConfigurable.selectNodeInTree(currName); } } throw new ConfigurationException(ProjectBundle.message("sdk.configuration.exception", currName) + " " + e.getMessage()); } } allNames.add(currName); } if (itemWithError == null) return true; if (rootConfigurable != null) { rootConfigurable.selectNodeInTree(itemWithError.getName()); } return false; }