@Override @Nullable public Object getParentElement(Object element) { if (element instanceof AntBuildTarget) { if (element instanceof MetaTarget) { return ((MetaTarget)element).getBuildFile(); } return ((AntBuildTarget)element).getModel().getBuildFile(); } if (element instanceof AntBuildFile) { return myRoot; } return null; }
private static void addGroupOfTargets(final AntBuildFile buildFile, final AntBuildTarget[] targets, final Set<String> addedTargetNames, final DefaultActionGroup group) { final DefaultActionGroup subgroup = new DefaultActionGroup(); for (final AntBuildTarget target : targets) { final String displayName = target.getName(); if (addedTargetNames.contains(displayName)) { continue; } addedTargetNames.add(displayName); final String[] targetsToRun = (target instanceof MetaTarget) ? ((MetaTarget)target).getTargetNames() : new String[]{displayName}; subgroup.add(getOrCreateAction(buildFile, displayName, targetsToRun, target.getNotEmptyDescription(), ((AntBuildTargetBase)target).getActionId())); } if (subgroup.getChildrenCount() > 0) { group.add(subgroup); } }
private static String[] getTargetNamesFromPaths(TreePath[] paths) { final List<String> targets = new ArrayList<String>(); for (final TreePath path : paths) { final Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); if (!(userObject instanceof AntTargetNodeDescriptor)) { continue; } final AntBuildTarget target = ((AntTargetNodeDescriptor)userObject).getTarget(); if (target instanceof MetaTarget) { ContainerUtil.addAll(targets, ((MetaTarget)target).getTargetNames()); } else { targets.add(target.getName()); } } return ArrayUtil.toStringArray(targets); }
public void setSelected(AnActionEvent event, boolean state) { final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); if (state) { final AntBuildFileBase buildFile = (AntBuildFileBase)((myTarget instanceof MetaTarget) ? ((MetaTarget)myTarget).getBuildFile() : myTarget.getModel().getBuildFile()); antConfiguration.setTargetForEvent(buildFile, myTarget.getName(), myExecutionEvent); } else { antConfiguration.clearTargetForEvent(myExecutionEvent); } myBuilder.queueUpdate(); }
private void doAction() { final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return; } try { // try to remove build file if (paths.length == 1) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)paths[0].getLastPathComponent(); if (node.getUserObject() instanceof AntBuildFileNodeDescriptor) { final AntBuildFileNodeDescriptor descriptor = (AntBuildFileNodeDescriptor)node.getUserObject(); if (descriptor.getBuildFile().equals(getCurrentBuildFile())) { removeBuildFile(); return; } } } // try to remove meta targets final AntBuildTarget[] targets = getTargetObjectsFromPaths(paths); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); for (final AntBuildTarget buildTarget : targets) { if (buildTarget instanceof MetaTarget) { for (final ExecutionEvent event : antConfiguration.getEventsForTarget(buildTarget)) { if (event instanceof ExecuteCompositeTargetEvent) { antConfiguration.clearTargetForEvent(event); } } } } } finally { myBuilder.queueUpdate(); myTree.repaint(); } }