use of com.revolsys.swing.tree.BaseTreeNode in project com.revolsys.open by revolsys.
the class MenuSourceAction method actionDo.
@SuppressWarnings("unchecked")
private void actionDo() {
Object item = MenuFactory.getMenuSource();
if (item instanceof BaseTreeNode) {
final BaseTreeNode node = (BaseTreeNode) item;
item = node.getUserObject();
}
this.action.accept(item);
}
use of com.revolsys.swing.tree.BaseTreeNode in project com.revolsys.open by revolsys.
the class TreeTransferHandler method exportDone.
@Override
protected void exportDone(final JComponent component, final Transferable transferable, final int action) {
if (isDndMoveAction(action)) {
try {
final Object data = transferable.getTransferData(TreePathListTransferable.FLAVOR);
if (data instanceof TreePathListTransferable) {
final TreePathListTransferable pathTransferable = (TreePathListTransferable) data;
final Collection<TreePath> paths = pathTransferable.getPaths();
for (final TreePath path : paths) {
final TreePath parentPath = path.getParentPath();
final Object parent = parentPath.getLastPathComponent();
if (parent instanceof BaseTreeNode) {
final BaseTreeNode parentNode = (BaseTreeNode) parent;
if (pathTransferable.isMoved(path)) {
parentNode.removeChild(path);
}
}
}
pathTransferable.reset();
}
} catch (final Throwable e) {
Logs.error(this, "Cannot export data", e);
}
}
}
use of com.revolsys.swing.tree.BaseTreeNode in project com.revolsys.open by revolsys.
the class TreeTransferHandler method importData.
@Override
public boolean importData(final TransferSupport support) {
final Component component = support.getComponent();
if (component instanceof JTree) {
final JTree.DropLocation loc = (JTree.DropLocation) support.getDropLocation();
final TreePath path = loc.getPath();
final int index = loc.getChildIndex();
if (path != null) {
try {
final Object pathItem = path.getLastPathComponent();
if (pathItem instanceof BaseTreeNode) {
final BaseTreeNode node = (BaseTreeNode) pathItem;
return node.dndImportData(support, index);
}
} catch (final Exception e) {
Logs.error(this, "Cannot import data", e);
return false;
}
}
}
return false;
}
use of com.revolsys.swing.tree.BaseTreeNode in project com.revolsys.open by revolsys.
the class LazyLoadTreeNode method removeNode.
public final void removeNode(final int index) {
final List<BaseTreeNode> children = this.children;
if (isLoaded()) {
if (index > 0 && index < children.size()) {
final BaseTreeNode node = children.remove(index);
nodeRemoved(index, node);
}
}
}
use of com.revolsys.swing.tree.BaseTreeNode in project com.revolsys.open by revolsys.
the class LazyLoadTreeNode method setChildren.
private void setChildren(final int updateIndex, final List<BaseTreeNode> newNodes) {
if (updateIndex == this.updateIndicies.get()) {
if (newNodes.size() == 1) {
this.loaded = !(newNodes.get(0) instanceof LoadingTreeNode);
} else {
this.loaded = true;
}
final List<BaseTreeNode> oldNodes = this.children;
for (int i = 0; i < oldNodes.size(); ) {
final BaseTreeNode oldNode = oldNodes.get(i);
if (newNodes.contains(oldNode)) {
i++;
} else {
oldNodes.remove(i);
nodeRemoved(i, oldNode);
oldNode.setParent(null);
}
}
for (int i = 0; i < newNodes.size(); ) {
final BaseTreeNode oldNode;
if (i < oldNodes.size()) {
oldNode = oldNodes.get(i);
} else {
oldNode = null;
}
final BaseTreeNode newNode = newNodes.get(i);
if (!newNode.equals(oldNode)) {
newNode.setParent(this);
oldNodes.add(i, newNode);
nodesInserted(i);
}
i++;
}
}
}
Aggregations