Example usage for javax.swing.event TreeModelEvent TreeModelEvent

List of usage examples for javax.swing.event TreeModelEvent TreeModelEvent

Introduction

In this page you can find the example usage for javax.swing.event TreeModelEvent TreeModelEvent.

Prototype

public TreeModelEvent(Object source, TreePath path) 

Source Link

Document

Used to create an event when the node structure has changed in some way, identifying the path to the root of the modified subtree as a TreePath object.

Usage

From source file:com.haulmont.cuba.desktop.gui.data.TreeModelAdapter.java

public TreeModelAdapter(HierarchicalDatasource datasource, CaptionMode captionMode, String captionProperty,
        boolean autoRefresh) {

    this.datasource = datasource;
    this.captionMode = captionMode;

    setCaptionProperty(captionProperty);

    this.autoRefresh = autoRefresh;

    this.metadataTools = AppBeans.get(MetadataTools.NAME);

    collectionChangeListener = e -> {
        switch (e.getOperation()) {
        case CLEAR:
        case REFRESH:
        case ADD:
        case REMOVE:
            Object[] path = { getRoot() };
            for (TreeModelListener listener : treeModelListeners) {
                TreeModelEvent ev = new TreeModelEvent(this, path);
                listener.treeStructureChanged(ev);
            }//from   w  w w.  j ava 2s.  co  m
            break;

        case UPDATE:
            for (Object item : e.getItems()) {
                TreePath treePath = getTreePath(item);
                for (TreeModelListener listener : treeModelListeners) {
                    TreeModelEvent ev = new TreeModelEvent(this, treePath.getPath());
                    listener.treeNodesChanged(ev);
                }
            }
            break;
        }
    };
    //noinspection unchecked
    datasource.addCollectionChangeListener(
            new WeakCollectionChangeListener(datasource, collectionChangeListener));
}

From source file:gov.nij.er.ui.RecordTreeModel.java

/**
 * Update the model with data and notify listeners
 *//*from w w  w  .  j a  va2  s .co m*/
public void updateModel() {
    root = new DefaultMutableTreeNode(ROOT_NODE_LABEL);
    if (records != null) {
        Collections.sort(records, recordSorter);
        for (RecordWrapper record : records) {

            DefaultMutableTreeNode node = new RecordTreeNode(record);
            root.add(node);
        }
        LOG.debug("Initializing tree model with new records");
        for (TreeModelListener l : listeners) {
            l.treeStructureChanged(new TreeModelEvent(this, new Object[] { root, }));
        }
    }
}

From source file:com.igormaznitsa.mindmap.model.MindMap.java

private void fireModelChanged() {
    final Topic rootTopic = this.root;
    final TreeModelEvent evt = new TreeModelEvent(this,
            rootTopic == null ? (Topic[]) null : rootTopic.getPath());
    for (final TreeModelListener l : this.treeListeners) {
        l.treeStructureChanged(evt);/* w  ww  .ja v  a 2 s.  co m*/
    }
}

From source file:com.igormaznitsa.mindmap.model.MindMap.java

private void fireTopicChanged(@Nullable final Topic topic) {
    final TreeModelEvent evt = new TreeModelEvent(this, topic == null ? null : topic.getPath());
    for (final TreeModelListener l : this.treeListeners) {
        l.treeNodesChanged(evt);//from w  w w  . j av a  2  s  .c o m
    }
}

From source file:gov.nij.er.ui.RawDataFilteredTreeModel.java

/**
 * Refresh the model to recognize new data, and notify any listeners
 *//*from ww  w.  ja  v  a2s.co  m*/
public void updateModel() {
    LOG.debug("Updating model, isFiltered=" + isFiltered);
    for (TreeModelListener l : listeners) {
        l.treeStructureChanged(new TreeModelEvent(this, new Object[] { getRoot(), }));
    }
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

@Override
public void modelChanged() {
    delegate.modelChanged();//from w  w  w . j  ava2 s.co  m
    fireEvent(EventType.STRUCTURE_CHANGED, new TreeModelEvent(this, ((ITreeNode) getRoot()).getPathToRoot()));
}

From source file:GenealogyExample.java

/**
 * The only event raised by this model is TreeStructureChanged with the root
 * as path, i.e. the whole tree has changed.
 *///from w  ww  .j av a2s .c o  m
protected void fireTreeStructureChanged(Person oldRoot) {
    int len = treeModelListeners.size();
    TreeModelEvent e = new TreeModelEvent(this, new Object[] { oldRoot });
    for (int i = 0; i < len; i++) {
        ((TreeModelListener) treeModelListeners.elementAt(i)).treeStructureChanged(e);
    }
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

@Override
public int replaceChild(ITreeNode parent, ITreeNode oldChild, ITreeNode newChild) {
    int oldIndex = getIndexOfChild(parent, oldChild);

    delegate.replaceChild(parent, oldChild, newChild);

    final int newIndex = getIndexOfChild(parent, newChild);

    if (oldIndex != -1) {
        // old child was visible
        if (newIndex != -1) {
            // new child is visible as well
            fireEvent(EventType.STRUCTURE_CHANGED, new TreeModelEvent(this, parent.getPathToRoot()));
        } else {//  w  w w  .j ava2 s . c om
            // new child is hidden => REMOVE EVENT
            fireEvent(EventType.REMOVED, new TreeModelEvent(this, parent.getPathToRoot(),
                    new int[] { oldIndex }, new Object[] { oldChild }));
        }
    } else if (newIndex != -1) {
        // old (replaced) node was hidden
        if (newIndex != -1) { // new node is visible => ADD event
            fireEvent(EventType.ADDED, new TreeModelEvent(this, parent.getPathToRoot(), new int[] { newIndex },
                    new Object[] { newChild }));
        }
    }
    return oldIndex;
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

@Override
public void valueForPathChanged(TreePath path, Object newValue) {
    delegate.valueForPathChanged(path, newValue);

    final ITreeNode changedNode = (ITreeNode) path.getLastPathComponent();

    if (isPathToRootVisible(changedNode)) {
        fireEvent(EventType.CHANGED, new TreeModelEvent(this, changedNode.getPathToRoot()));
    }/*from w w w .  j  av  a2s . c o  m*/
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

@Override
public void nodeValueChanged(ITreeNode jobNode) {
    delegate.nodeValueChanged(jobNode);/* w w  w.j a va  2  s.c  o  m*/

    if (isPathToRootVisible(jobNode)) {
        fireEvent(EventType.CHANGED, new TreeModelEvent(this, jobNode.getPathToRoot()));
    }
}