@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(); }