@Override public void actionPerformed(AnActionEvent e) { final PackagingElementNode<?> node = myLayoutTreeComponent.getSelection().getNodeIfSingle(); if (node == null) return; final CompositePackagingElementNode parent = node.getParentNode(); if (parent == null) return; final PackagingElement<?> element = node.getElementIfSingle(); final CompositePackagingElement<?> parentElement = parent.getElementIfSingle(); if (parentElement == null || element == null) return; if (!myLayoutTreeComponent.checkCanModifyChildren(parentElement, parent, Arrays.asList(node))) return; final List<PackagingElement<?>> toSelect = new ArrayList<PackagingElement<?>>(); myLayoutTreeComponent.editLayout( new Runnable() { public void run() { final int index = parentElement.getChildren().indexOf(element); final PackagingElement<?> moved = parentElement.moveChild(index, myDirection); if (moved != null) { toSelect.add(moved); } } }); if (!toSelect.isEmpty()) { myLayoutTreeComponent.updateAndSelect(parent, toSelect); } }
private boolean isEnabled() { if (myLayoutTreeComponent.isSortElements()) { return false; } final PackagingElementNode<?> node = myLayoutTreeComponent.getSelection().getNodeIfSingle(); if (node == null) { return false; } final CompositePackagingElementNode parent = node.getParentNode(); if (parent == null) return false; final PackagingElement<?> element = node.getElementIfSingle(); final CompositePackagingElement<?> parentElement = parent.getElementIfSingle(); if (parentElement == null || element == null) return false; final List<PackagingElement<?>> children = parentElement.getChildren(); final int index = children.indexOf(element); return index != -1 && 0 <= index + myDirection && index + myDirection < children.size(); }
private static CompositePackagingElement<?> getOrCreateModifiableParent( CompositePackagingElement<?> parentElement, PackagingElementNode<?> node) { PackagingElementNode<?> current = node; List<String> dirNames = new ArrayList<String>(); while (current != null && !(current instanceof ArtifactRootNode)) { final PackagingElement<?> packagingElement = current.getFirstElement(); if (!(packagingElement instanceof DirectoryPackagingElement)) { return parentElement; } dirNames.add(((DirectoryPackagingElement) packagingElement).getDirectoryName()); current = current.getParentNode(); } if (current == null) return parentElement; final PackagingElement<?> rootElement = current.getElementIfSingle(); if (!(rootElement instanceof CompositePackagingElement<?>)) return parentElement; Collections.reverse(dirNames); String path = StringUtil.join(dirNames, "/"); return PackagingElementFactory.getInstance() .getOrCreateDirectory((CompositePackagingElement<?>) rootElement, path); }