Search in sources :

Example 1 with BaseTreeNode

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);
}
Also used : BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode)

Example 2 with BaseTreeNode

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);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode)

Example 3 with BaseTreeNode

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;
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 4 with BaseTreeNode

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);
        }
    }
}
Also used : BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode)

Example 5 with BaseTreeNode

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++;
        }
    }
}
Also used : BaseTreeNode(com.revolsys.swing.tree.BaseTreeNode)

Aggregations

BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)27 LayerGroup (com.revolsys.swing.map.layer.LayerGroup)5 ArrayList (java.util.ArrayList)5 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)4 Layer (com.revolsys.swing.map.layer.Layer)4 TreePath (javax.swing.tree.TreePath)4 Component (java.awt.Component)3 Path (java.nio.file.Path)3 JComponent (javax.swing.JComponent)3 RecordStore (com.revolsys.record.schema.RecordStore)2 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)2 BaseTree (com.revolsys.swing.tree.BaseTree)2 JTree (javax.swing.JTree)2 PathName (com.revolsys.io.PathName)1 FileConnectionManager (com.revolsys.io.file.FileConnectionManager)1 RecordStoreConnectionManager (com.revolsys.record.io.RecordStoreConnectionManager)1 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)1 TabbedPane (com.revolsys.swing.TabbedPane)1 DnDTabbedPane (com.revolsys.swing.component.DnDTabbedPane)1 Project (com.revolsys.swing.map.layer.Project)1