LOG.error("No tree found!");
return;
}
UITreeOld tree = (UITreeOld) component;
TreeState treeState = tree.getState();
DefaultMutableTreeNode marker = treeState.getMarker();
String command = actionEvent.getComponent().getId();
if (LOG.isDebugEnabled()) {
LOG.debug("marker " + marker);
LOG.debug("lastMarker " + treeState.getLastMarker());
LOG.debug("root " + tree.getValue());
LOG.debug("command " + command);
LOG.debug("lastCommand " + treeState.getLastCommand());
}
if (marker != null) {
boolean isRoot = tree.getValue().equals(marker);
if (UITreeOld.COMMAND_NEW.equals(command)) {
treeState.commandNew(create(facesContext));
} else if (UITreeOld.COMMAND_DELETE.equals(command)) {
if (!isRoot) {
marker.removeFromParent();
}
treeState.setLastMarker(null);
treeState.setLastCommand(null);
} else if (UITreeOld.COMMAND_CUT.equals(command)) {
if (!isRoot) {
treeState.setLastMarker(marker);
treeState.setLastCommand(command);
}
} else if (UITreeOld.COMMAND_COPY.equals(command)) {
treeState.setLastMarker(marker);
treeState.setLastCommand(command);
} else if (UITreeOld.COMMAND_PASTE.equals(command)) {
if (treeState.getLastMarker() != null) {
if (UITreeOld.COMMAND_CUT.equals(treeState.getLastCommand())) {
marker.insert(treeState.getLastMarker(), 0);
} else if (UITreeOld.COMMAND_COPY.equals(treeState.getLastCommand())) {
marker.insert(copy(treeState.getLastMarker()), 0);
}
treeState.setLastMarker(null);
treeState.setLastCommand(null);
}
} else if (UITreeOld.COMMAND_MOVE_UP.equals(command)) {
if (!isRoot) {
MutableTreeNode node = marker;
MutableTreeNode parent = (MutableTreeNode) node.getParent();
int index = parent.getIndex(node);
index = Math.max(index - 1, 0);
parent.insert(node, index);
}
treeState.setLastMarker(null);
treeState.setLastCommand(null);
} else if (UITreeOld.COMMAND_MOVE_DOWN.equals(command)) {
if (!isRoot) {
MutableTreeNode node = marker;
MutableTreeNode parent = (MutableTreeNode) node.getParent();
int index = parent.getIndex(node);
index = Math.min(index + 1, parent.getChildCount() - 1);
parent.insert(node, index);
}
treeState.setLastMarker(null);
treeState.setLastCommand(null);
}
}
}