public void selectNode(@NotNull String parentPath, @NotNull PackagingElement<?> element) { final PackagingElementNode<?> parent = myTree.findCompositeNodeByPath(parentPath); if (parent == null) return; for (SimpleNode node : parent.getChildren()) { if (node instanceof PackagingElementNode) { final List<? extends PackagingElement<?>> elements = ((PackagingElementNode<?>)node).getPackagingElements(); for (PackagingElement<?> packagingElement : elements) { if (packagingElement.isEqualTo(element)) { myBuilder.select(node); return; } } } } }
public LayoutTreeSelection(@NotNull LayoutTree tree) { final TreePath[] paths = tree.getSelectionPaths(); if (paths == null) { return; } for (TreePath path : paths) { final SimpleNode node = tree.getNodeFor(path); if (node instanceof PackagingElementNode) { final PackagingElementNode<?> elementNode = (PackagingElementNode<?>)node; mySelectedNodes.add(elementNode); myNode2Path.put(elementNode, path); for (PackagingElement<?> element : elementNode.getPackagingElements()) { mySelectedElements.add(element); myElement2Node.put(element, elementNode); } } } }
@Override protected SimpleNode[] buildChildren() { if (myConfigurable != null) { myConfigurableToNodeMap.put(myConfigurable, this); } if (myComposite == null) { return NO_CHILDREN; } Configurable[] configurables = myComposite.getConfigurables(); if (configurables == null || configurables.length == 0) { return NO_CHILDREN; } SimpleNode[] result = new SimpleNode[configurables.length]; for (int i = 0; i < configurables.length; i++) { result[i] = new MyNode(this, configurables[i], myLevel + 1); if (myConfigurable != null) { myFilter.myContext.registerKid(myConfigurable, configurables[i]); } } return result; }
@Override public boolean shouldBeShowing(SimpleNode node) { if (myFiltered != null) { Configurable configurable = getConfigurable(node); if (configurable != null) { if (!myFiltered.contains(configurable)) { if (myHits != null) { Set<Configurable> configurables = myHits.getNameFullHits(); while (node != null) { if (configurable != null) { if (configurables.contains(configurable)) { return true; } } node = node.getParent(); configurable = getConfigurable(node); } } return false; } } } return true; }
@Override @NotNull protected DomCollectionChildDescription[] getDomCollectionChildDescriptions(final AnActionEvent e) { final DomModelTreeView view = getTreeView(e); SimpleNode node = view.getTree().getSelectedNode(); if (node instanceof BaseDomElementNode) { List<DomCollectionChildDescription> consolidated = ((BaseDomElementNode)node).getConsolidatedChildrenDescriptions(); if (consolidated.size() > 0) { return consolidated.toArray(new DomCollectionChildDescription[consolidated.size()]); } } final DomElementsGroupNode groupNode = getDomElementsGroupNode(view); return groupNode == null ? DomCollectionChildDescription.EMPTY_ARRAY : new DomCollectionChildDescription[]{groupNode.getChildDescription()}; }
@Override public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) { final SimpleNode selectedNode = treeView.getTree().getSelectedNode(); if (selectedNode instanceof BaseDomElementNode) { if (selectedNode instanceof DomFileElementNode) { e.getPresentation().setVisible(false); return; } final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement(); final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove", Messages.getQuestionIcon()); if (ret == Messages.OK) { new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) { @Override protected void run(@NotNull final Result result) throws Throwable { domElement.undefine(); } }.execute(); } } }
@Override @Nullable public Object getData(String dataId) { if (DATA_KEY.is(dataId)) { return this; } final SimpleNode simpleNode = getTree().getSelectedNode(); if (simpleNode instanceof AbstractDomElementNode) { final DomElement domElement = ((AbstractDomElementNode)simpleNode).getDomElement(); if (domElement != null && domElement.isValid()) { if (CommonDataKeys.NAVIGATABLE.is(dataId)) { final XmlElement tag = domElement.getXmlElement(); if (tag instanceof Navigatable) { return tag; } } } } return null; }
@Override public SimpleNode[] getChildren() { if (!isDirectory) { return NO_CHILDREN; } List<TfvcItem> children; try { children = treeContext.getChildItems(path); } catch (TfsException e) { return new SimpleNode[]{new TfsErrorTreeNode(this, e.getMessage())}; } final List<TfsTreeNode> result = new ArrayList<TfsTreeNode>(virtualChildren); for (final TfvcItem childItem : children) { result.add(new TfsTreeNode(this, childItem.getPath(), childItem.isFolder(), false)); } return result.toArray(new SimpleNode[result.size()]); }
@NotNull private List<SimpleNode> getChildren(@NotNull QueryFolder folder) { List<SimpleNode> result = ContainerUtil.newArrayList(); for (QueryItem item : folder.getItems()) { SimpleNode child; if (item instanceof QueryDefinition) { child = new SavedQueryDefinitionNode(myQueriesTreeContext, (QueryDefinition)item); } else if (item instanceof QueryFolder) { child = new SavedQueryFolderNode(myQueriesTreeContext, (QueryFolder)item); } else { throw new IllegalArgumentException("Unknown query item " + item); } result.add(child); } return result; }
@NotNull protected DomCollectionChildDescription[] getDomCollectionChildDescriptions(final AnActionEvent e) { final DomModelTreeView view = getTreeView(e); SimpleNode node = view.getTree().getSelectedNode(); if (node instanceof BaseDomElementNode) { List<DomCollectionChildDescription> consolidated = ((BaseDomElementNode)node).getConsolidatedChildrenDescriptions(); if (consolidated.size() > 0) { return consolidated.toArray(new DomCollectionChildDescription[consolidated.size()]); } } final DomElementsGroupNode groupNode = getDomElementsGroupNode(view); return groupNode == null ? DomCollectionChildDescription.EMPTY_ARRAY : new DomCollectionChildDescription[]{groupNode.getChildDescription()}; }
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) { final SimpleNode selectedNode = treeView.getTree().getSelectedNode(); if (selectedNode instanceof BaseDomElementNode) { if (selectedNode instanceof DomFileElementNode) { e.getPresentation().setVisible(false); return; } final DomElement domElement = ((BaseDomElementNode)selectedNode).getDomElement(); final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode) + "?", ApplicationBundle.message("action.remove"), Messages.getQuestionIcon()); if (ret == 0) { new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) { protected void run(final Result result) throws Throwable { domElement.undefine(); } }.execute(); } } }
@Nullable public Object getData(String dataId) { if (DomModelTreeView.DATA_KEY.is(dataId)) { return this; } final SimpleNode simpleNode = getTree().getSelectedNode(); if (simpleNode instanceof AbstractDomElementNode) { final DomElement domElement = ((AbstractDomElementNode)simpleNode).getDomElement(); if (domElement != null && domElement.isValid()) { if (PlatformDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { final XmlElement tag = domElement.getXmlElement(); if (tag instanceof Navigatable) { return new Navigatable[] { (Navigatable)tag }; } } } } return null; }
@Override public void retrieveChildren() { retrievingChildren = true; DescribeResult describeResult; try { describeResult = client.describeObject(versionUrl, sObjectDescription.getName()); } catch (Exception e) { logger.error(ERROR_MESSAGE + getName(), e); describeResult = null; } if (describeResult == null) { this.children = new SimpleNode[] { new ExplorerErrorNode(this, ERROR_MESSAGE + getName()) }; } else { this.children = getChildrenFromJSONObject(describeResult); } retrievingChildren = false; }
private void setupMetadataPanel(Project project, SimpleToolWindowPanel metadataPanel) { RestClientService restClientService = ServiceManager.getService(project, RestClientService.class); SimpleNode metadataRootNode = new MetadataExplorerRootNode(project, restClientService, "Metadata"); SimpleTree metadataTree = new SimpleTree(); SimpleTreeBuilder metadataTreeBuilder = new SimpleTreeBuilder(metadataTree, (DefaultTreeModel)metadataTree.getModel(), new ExplorerTreeStructure(metadataRootNode), null); Disposer.register(project, metadataTreeBuilder); metadataTree.addTreeExpansionListener(new ExplorerTreeExpansionListener(metadataTreeBuilder)); metadataTree.setCellRenderer(new ExplorerCellRenderer()); ActionToolbar toolbar = createToolbar(metadataRootNode, metadataTreeBuilder); toolbar.setTargetComponent(metadataPanel); metadataPanel.setToolbar(toolbar.getComponent()); metadataPanel.setContent(ScrollPaneFactory.createScrollPane(metadataTree)); metadataTree.setShowsRootHandles(true); }
private void setupToolingMetadataPanel(Project project, SimpleToolWindowPanel toolingMetadataPanel) { ToolingRestClientService toolingRestClientService = ServiceManager.getService(project, ToolingRestClientService.class); SimpleNode toolingMetadataRootNode = new MetadataExplorerRootNode(project, toolingRestClientService, " Tooling Metadata"); SimpleTree toolingMetadataTree = new SimpleTree(); SimpleTreeBuilder toolingMetadataTreeBuilder = new SimpleTreeBuilder(toolingMetadataTree, (DefaultTreeModel)toolingMetadataTree.getModel(), new ExplorerTreeStructure(toolingMetadataRootNode), null); Disposer.register(project, toolingMetadataTreeBuilder); toolingMetadataTree.addTreeExpansionListener(new ExplorerTreeExpansionListener(toolingMetadataTreeBuilder)); toolingMetadataTree.setCellRenderer(new ExplorerCellRenderer()); ActionToolbar toolbar = createToolbar(toolingMetadataRootNode, toolingMetadataTreeBuilder); toolbar.setTargetComponent(toolingMetadataPanel); toolingMetadataPanel.setToolbar(toolbar.getComponent()); toolingMetadataPanel.setContent(ScrollPaneFactory.createScrollPane(toolingMetadataTree)); toolingMetadataTree.setShowsRootHandles(true); }
@Override public void retrieveChildren() { List<SimpleNode> children = new ArrayList<SimpleNode>(jsonArray.length()); for (int i=0; i<jsonArray.length(); i++) { Object object = jsonArray.get(i); String name = getName().substring(0, getName().length()-1) + " " + i; SimpleNode child; if (object instanceof JSONArray) { child = new ExplorerJSONArrayNode(this, (JSONArray)object, name); } else if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject)object; if (jsonObject.keySet().contains("name")) { name = jsonObject.getString("name"); } child = new ExplorerJSONObjectNode(this, (JSONObject)object, name); } else { child = new ExplorerLeafNode(this, name, object.toString()); } children.add(child); } this.children = children.toArray(new SimpleNode[children.size()]); }
protected SimpleNode[] getChildrenFromJSONObject(JSONObject jsonObject) { List<SimpleNode> children = new ArrayList<SimpleNode>(jsonObject.keySet().size()); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String name = (String)iterator.next(); Object object = jsonObject.get(name); SimpleNode child; if (object instanceof JSONArray) { child = new ExplorerJSONArrayNode(this, (JSONArray)object, name); } else if (object instanceof JSONObject) { child = new ExplorerJSONObjectNode(this, (JSONObject)object, name); } else { child = new ExplorerLeafNode(this, name, object.toString()); } children.add(child); } return children.toArray(new SimpleNode[children.size()]); }
public void selectNode(@Nonnull String parentPath, @Nonnull PackagingElement<?> element) { final PackagingElementNode<?> parent = myTree.findCompositeNodeByPath(parentPath); if (parent == null) return; for (SimpleNode node : parent.getChildren()) { if (node instanceof PackagingElementNode) { final List<? extends PackagingElement<?>> elements = ((PackagingElementNode<?>)node).getPackagingElements(); for (PackagingElement<?> packagingElement : elements) { if (packagingElement.isEqualTo(element)) { myBuilder.select(node); return; } } } } }
public LayoutTreeSelection(@Nonnull LayoutTree tree) { final TreePath[] paths = tree.getSelectionPaths(); if (paths == null) { return; } for (TreePath path : paths) { final SimpleNode node = tree.getNodeFor(path); if (node instanceof PackagingElementNode) { final PackagingElementNode<?> elementNode = (PackagingElementNode<?>)node; mySelectedNodes.add(elementNode); myNode2Path.put(elementNode, path); for (PackagingElement<?> element : elementNode.getPackagingElements()) { mySelectedElements.add(element); myElement2Node.put(element, elementNode); } } } }
@Override @Nullable public Object getData(@NotNull Key<?> dataId) { if (DomModelTreeView.DATA_KEY == dataId) { return this; } final SimpleNode simpleNode = getTree().getSelectedNode(); if (simpleNode instanceof AbstractDomElementNode) { final DomElement domElement = ((AbstractDomElementNode)simpleNode).getDomElement(); if (domElement != null && domElement.isValid()) { if (PlatformDataKeys.NAVIGATABLE_ARRAY == dataId) { final XmlElement tag = domElement.getXmlElement(); if (tag instanceof Navigatable) { return new Navigatable[] { (Navigatable)tag }; } } } } return null; }
void updateUpTo(SimpleNode node) { SimpleNode each = node; while (each != null) { updateFrom(each); each = each.getParent(); } }
static <T extends SimpleNode> List<T> getSelectedNodes(SimpleTree tree, Class<T> nodeClass) { final List<T> filtered = new ArrayList<>(); for (SimpleNode node : getSelectedNodes(tree)) { if ((nodeClass != null) && (!nodeClass.isInstance(node))) { filtered.clear(); break; } //noinspection unchecked filtered.add((T) node); } return filtered; }
private static List<SimpleNode> getSelectedNodes(SimpleTree tree) { List<SimpleNode> nodes = new ArrayList<>(); TreePath[] treePaths = tree.getSelectionPaths(); if (treePaths != null) { for (TreePath treePath : treePaths) { nodes.add(tree.getNodeFor(treePath)); } } return nodes; }
@Override public boolean isVisible() { if (getDisplayKind() == DisplayKind.ALWAYS) return true; for (SimpleNode each : getChildren()) { if (((SeedStackSimpleNode) each).isVisible()) return true; } return false; }
@Override protected SimpleNode[] buildChildren() { List<? extends SeedStackSimpleNode> children = doGetChildren(); if (children.isEmpty()) return NO_CHILDREN; List<SeedStackSimpleNode> result = new ArrayList<>(); for (SeedStackSimpleNode each : children) { if (each.isVisible()) result.add(each); } return result.toArray(new SeedStackSimpleNode[result.size()]); }
public ErrorLevel getChildrenErrorLevel() { ErrorLevel result = ErrorLevel.NONE; for (SimpleNode each : getChildren()) { ErrorLevel eachLevel = ((SeedStackSimpleNode) each).getTotalErrorLevel(); if (eachLevel.compareTo(result) > 0) result = eachLevel; } return result; }
@Override protected void configureUiHelper(TreeUIHelper helper) { final Convertor<TreePath, String> convertor = new Convertor<TreePath, String>() { @Override public String convert(final TreePath path) { final SimpleNode node = getNodeFor(path); if (node instanceof PackagingElementNode) { return ((PackagingElementNode<?>)node).getElementPresentation().getSearchName(); } return ""; } }; new TreeSpeedSearch(this, convertor, true); }
@Nullable public PackagingElement<?> getElementByPath(TreePath path) { final SimpleNode node = getNodeFor(path); if (node instanceof PackagingElementNode) { final List<? extends PackagingElement<?>> elements = ((PackagingElementNode<?>)node).getPackagingElements(); if (!elements.isEmpty()) { return elements.get(0); } } return null; }
@TestOnly public void selectNode(@NotNull String parentPath, @NotNull String nodeName) { final PackagingElementNode<?> parent = myTree.findCompositeNodeByPath(parentPath); if (parent == null) return; for (SimpleNode node : parent.getChildren()) { if (node instanceof PackagingElementNode) { if (nodeName.equals(((PackagingElementNode)node).getElementPresentation().getSearchName())) { myBuilder.select(node); return; } } } }
private static boolean pathContains(TreePath path, PackagingElementNode<?> node, LayoutTree tree) { while (path != null) { final SimpleNode pathNode = tree.getNodeFor(path); if (pathNode == node) { return true; } path = path.getParentPath(); } return false; }
@Override protected SimpleNode[] buildChildren() { List<PackagingElementNode<?>> children = new ArrayList<PackagingElementNode<?>>(); for (CompositePackagingElement<?> element : getPackagingElements()) { PackagingTreeNodeFactory.addNodes(element.getChildren(), this, element, myContext, mySubstitutionParameters, getNodeSource(element), children, myArtifactType, new HashSet<PackagingElement<?>>()); } return children.isEmpty() ? NO_CHILDREN : children.toArray(new SimpleNode[children.size()]); }
@Nullable public CompositePackagingElementNode findCompositeChild(@NotNull String name) { final SimpleNode[] children = getChildren(); for (SimpleNode child : children) { if (child instanceof CompositePackagingElementNode) { final CompositePackagingElementNode composite = (CompositePackagingElementNode)child; if (name.equals(composite.getFirstElement().getName())) { return composite; } } } return null; }
public List<PackagingElementNode<?>> getNodesByPath(List<PackagingElement<?>> pathToPlace) { List<PackagingElementNode<?>> result = new ArrayList<PackagingElementNode<?>>(); PackagingElementNode<?> current = this; int i = 0; result.add(current); while (current != null && i < pathToPlace.size()) { final SimpleNode[] children = current.getCached(); if (children == null) { break; } PackagingElementNode<?> next = null; final PackagingElement<?> element = pathToPlace.get(i); search: for (SimpleNode child : children) { if (child instanceof PackagingElementNode<?>) { PackagingElementNode<?> childNode = (PackagingElementNode<?>)child; for (PackagingElement<?> childElement : childNode.getPackagingElements()) { if (childElement.isEqualTo(element)) { next = childNode; break search; } } for (PackagingNodeSource nodeSource : childNode.getNodeSources()) { if (nodeSource.getSourceElement().isEqualTo(element)) { next = current; break search; } } } } current = next; if (current != null) { result.add(current); } i++; } return result; }
@Override protected SimpleNode[] buildChildren() { final PackagingSourceItemsProvider[] providers = PackagingSourceItemsProvider.EP_NAME.getExtensions(); PackagingSourceItemFilter[] filters = PackagingSourceItemFilter.EP_NAME.getExtensions(); List<SimpleNode> children = new ArrayList<SimpleNode>(); for (PackagingSourceItemsProvider provider : providers) { final Collection<? extends PackagingSourceItem> items = provider.getSourceItems(myContext, myArtifact, getSourceItem()); for (PackagingSourceItem item : items) { if (myArtifact.getArtifactType().isSuitableItem(item) && isAvailable(item, myContext, filters)) { children.add(new SourceItemNode(myContext, this, item, myArtifactEditor)); } } } return children.isEmpty() ? NO_CHILDREN : children.toArray(new SimpleNode[children.size()]); }
@Override public int getWeight() { if (getDelegate() instanceof SimpleNode) { return ((SimpleNode)getDelegate()).getWeight(); } return super.getWeight(); }
@Override public boolean isAlwaysShowPlus() { if (myDelegate instanceof SimpleNode) { return ((SimpleNode)myDelegate).isAlwaysShowPlus(); } return super.isAlwaysShowPlus(); }