/** * Notifies all registered TreeModelListeners of a change. * * @param event The TreeModelEvent to notify the listeners with. * @param action The action that is being reported. */ private void notifyTreeModelListeners(TreeModelEvent tme, int action) { if (treeModelListeners != null) { TreeModelListener o; Iterator iterator; // Notify each listener. iterator = treeModelListeners.values().iterator(); while (iterator.hasNext()) { o = ((TreeModelListener) ((WeakReference) iterator.next()).get()); switch (action) { case NODES_CHANGED: ((TreeModelListener) o).treeNodesChanged(tme); break; case NODES_INSERTED: ((TreeModelListener) o).treeNodesInserted(tme); break; case NODES_REMOVED: ((TreeModelListener) o).treeNodesRemoved(tme); break; case STRUCTURE_CHANGED: ((TreeModelListener) o).treeStructureChanged(tme); } } } }
@Override public void entryRemoved(Entry removedEntry, Folder parent, int index) { TreePath path = getPathTo(parent); TreeModelEvent e = new TreeModelEvent( RepositoryTreeModel.this, path, new int[] {index}, new Object[] {removedEntry}); boolean pathSaved = false; final RepositoryTreeUtil treeUtil = new RepositoryTreeUtil(); if (parentTree != null) { pathSaved = createPostRemoveEventSelectionPath(removedEntry, parent, index, path, treeUtil); } for (TreeModelListener l : listeners.getListeners(TreeModelListener.class)) { l.treeNodesRemoved(e); } if (parentTree != null && pathSaved) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { treeUtil.restoreSelectionPath(parentTree); } }); } }
public void removeChild(TreeNavigatorNode parent, TreeNavigatorNode child) { int i = getIndexOfChild(parent, child); parent.removeChild(child); TreeModelEvent tme = new TreeModelEvent(this, parent.getTreePath(), new int[] {i}, new Object[] {child}); for (TreeModelListener l : listeners) { l.treeNodesRemoved(tme); } }
public void fireTreeNodesRemoved(TreePath parentPath, int childIndex, Object child) { TreeModelEvent event = new TreeModelEvent(this, parentPath, new int[] {childIndex}, new Object[] {child}); synchronized (listeners) { for (TreeModelListener listener : listeners) { listener.treeNodesRemoved(event); } } }
/** * Notifies the tree that the given node will be removed. This method must be called <b>before</b> * the node is actually deleted. * * @param tree * @param node */ public void nodeDeleted(AbstractTree tree, TreeNode node) { TreeNode parent = (TreeNode) getParent(tree, node); if (parent != null) { int index = parent.getChildren().indexOf(node); if (index != -1) { TreeModelEvent e = new TreeModelEvent( this, pathFromNode(tree, parent), new int[] {index}, new Object[] {node}); for (TreeModelListener l : listeners) { l.treeNodesRemoved(e); } } } }
/** * Send an event to the listeners instructing that some nodes have been removed. * * @param evt The event to be sent */ private void fireTreeNodesRemoved(TreeModelEvent evt) { Iterator itr = listeners.iterator(); TreeModelListener l; while (itr.hasNext()) { l = (TreeModelListener) itr.next(); try { l.treeNodesRemoved(evt); } catch (Exception e) { I18nManager intl_mgr = I18nManager.getManager(); String msg = intl_mgr.getString(NODE_REMOVE_ERR_PROP) + l; errorReporter.errorReport(msg, e); } } }
@Test public void testListeners() { final AnalysesModel model = new AnalysesModel(); final MCMCPresentation inco1 = new MCMCPresentation(d_wrapper, "inco1"); final MCMCPresentation cons1 = new MCMCPresentation(d_wrapper, "cons1"); final MCMCPresentation splt1 = new MCMCPresentation(d_wrapper, "splt1"); final MCMCPresentation splt2 = new MCMCPresentation(d_wrapper, "splt2"); TreeModelListener listener = EasyMock.createStrictMock(TreeModelListener.class); TreeModelEvent event1a = new TreeModelEvent( model, new Object[] {model.getRoot()}, new int[] {0}, new Object[] {ModelType.Inconsistency}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event1a)); TreeModelEvent event1b = new TreeModelEvent( model, new Object[] {model.getRoot(), ModelType.Inconsistency}, new int[] {0}, new Object[] {inco1}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event1b)); TreeModelEvent event2a = new TreeModelEvent( model, new Object[] {model.getRoot()}, new int[] {0}, new Object[] {ModelType.Consistency}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event2a)); TreeModelEvent event2b = new TreeModelEvent( model, new Object[] {model.getRoot(), ModelType.Consistency}, new int[] {0}, new Object[] {cons1}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event2b)); TreeModelEvent event3a = new TreeModelEvent( model, new Object[] {model.getRoot()}, new int[] {2}, new Object[] {ModelType.NodeSplit}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event3a)); TreeModelEvent event3b = new TreeModelEvent( model, new Object[] {model.getRoot(), ModelType.NodeSplit}, new int[] {0}, new Object[] {splt2}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event3b)); TreeModelEvent event4 = new TreeModelEvent( model, new Object[] {model.getRoot(), ModelType.NodeSplit}, new int[] {0}, new Object[] {splt1}); listener.treeNodesInserted(TreeModelEventMatcher.eqTreeModelEvent(event4)); TreeModelEvent event5 = new TreeModelEvent( model, new Object[] {model.getRoot()}, new int[] {0, 1, 2}, new Object[] {ModelType.Consistency, ModelType.Inconsistency, ModelType.NodeSplit}); listener.treeNodesRemoved(TreeModelEventMatcher.eqTreeModelEvent(event5)); EasyMock.replay(listener); model.addTreeModelListener(listener); model.add(ModelType.Inconsistency, inco1); model.add(ModelType.Consistency, cons1); model.add(ModelType.NodeSplit, splt2); model.add(ModelType.NodeSplit, splt1); model.clear(); model.removeTreeModelListener(listener); model.add(ModelType.Inconsistency, inco1); EasyMock.verify(listener); }
private void fireDelete(TreeModelEvent event) { for (TreeModelListener l : listeners.getListeners(TreeModelListener.class)) { l.treeNodesRemoved(event); } }
private void fireTreeNodeRemoved(EntityCategory category, int idx) { for (TreeModelListener l : d_listeners) { l.treeNodesRemoved( new TreeModelEvent(this, new Object[] {d_root, category}, new int[] {idx}, null)); } }
public void fireNodeRemoved(Object source, TreePath expandedPath) { TreeModelListener[] listeners = getTreeModelListeners(); for (TreeModelListener listener : listeners) { listener.treeNodesRemoved(new TreeModelEvent(source, expandedPath)); } }