示例#1
0
 private void fireStructureChangedEvent(TreeModelEvent e) {
   TreeModelListener[] listeners =
       listenerList.toArray(new TreeModelListener[listenerList.size()]);
   for (TreeModelListener listener : listeners) {
     listener.treeStructureChanged(e);
   }
 }
        @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);
                  }
                });
          }
        }
  /**
   * 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);
        }
      }
    }
  }
示例#4
0
 private void fireNodesInsertedEvent(TreeModelEvent e) {
   TreeModelListener[] listeners =
       listenerList.toArray(new TreeModelListener[listenerList.size()]);
   for (TreeModelListener listener : listeners) {
     listener.treeNodesInserted(e);
   }
 }
 @Override
 public void entryAdded(Entry newEntry, Folder parent) {
   TreeModelEvent e = makeChangeEvent(newEntry);
   for (TreeModelListener l : listeners.getListeners(TreeModelListener.class)) {
     l.treeNodesInserted(e);
   }
 }
 private void fireTreeStructureChanged(final Object oldRoot) {
   treeModelListeners.size();
   final TreeModelEvent e = new TreeModelEvent(this, new Object[] {oldRoot});
   for (final TreeModelListener tml : treeModelListeners) {
     tml.treeStructureChanged(e);
   }
 }
 @Override
 public void entryChanged(Entry entry) {
   TreeModelEvent e = makeChangeEvent(entry);
   for (TreeModelListener l : listeners.getListeners(TreeModelListener.class)) {
     l.treeNodesChanged(e);
   }
 }
示例#8
0
  @Test
  public void testReplace() {
    final AnalysesModel model = new AnalysesModel();
    final MCMCPresentation inco1 = new MCMCPresentation(d_wrapper, "inco1");
    final MCMCPresentation inco2 = new MCMCPresentation(d_wrapper, "inco2");

    model.add(ModelType.Inconsistency, inco1);
    JUnitUtil.assertAllAndOnly(
        model.getModels(ModelType.Inconsistency), Collections.singleton(inco1));

    TreeModelListener listener = EasyMock.createStrictMock(TreeModelListener.class);

    TreeModelEvent event1a =
        new TreeModelEvent(
            model,
            new Object[] {model.getRoot(), ModelType.Inconsistency},
            new int[] {0},
            new Object[] {inco2});
    listener.treeNodesChanged(TreeModelEventMatcher.eqTreeModelEvent(event1a));

    EasyMock.replay(listener);
    model.addTreeModelListener(listener);
    model.replace(ModelType.Inconsistency, inco1, inco2);
    EasyMock.verify(listener);

    JUnitUtil.assertAllAndOnly(
        model.getModels(ModelType.Inconsistency), Collections.singleton(inco2));
  }
    protected void deleteCurrent() {
      int num_logs_deleted = 0;
      Set<Group> groups_changed = new HashSet<>();

      for (TreePath tp : display.logTree.getSelectionPaths()) {
        if (tp.getPathCount() == 3) {
          Group group = (Group) tp.getPath()[1];
          LogReference reference = (LogReference) tp.getLastPathComponent();

          Debug.warn("deleting {%s} from {%s}", reference, group);
          group.remove(reference);

          ++num_logs_deleted;
          groups_changed.add(group);
        } else {
          Debug.warn("cannot delete {%s}", tp.getLastPathComponent());
        }
      }

      for (Group group : groups_changed) {
        TreeModelEvent removeEvent = new TreeModelEvent(this, new Object[] {this, group});

        for (TreeModelListener listener : listeners) listener.treeStructureChanged(removeEvent);
      }

      ToolMessage.displayAndPrint("deleted %d logs", num_logs_deleted);
    }
  /**
   * Hides nodes from the tree that do not match <code>text</code>.
   *
   * @param text search text
   */
  public void filterByText(String text) {
    text = normalize(text);
    if (text == null || text.length() == 0) {
      visibleNodes = null;
    } else {
      visibleNodes = new HashSet<Object>();
      String[] keywords = text.split(" ");
      for (int i = 0; i < keywords.length; i++) {
        SortedMap<String, List<Object>> nodeListByKey = getMatches(text);
        if (i == 0) {
          for (List<Object> nodes : nodeListByKey.values()) {
            visibleNodes.addAll(nodes);
          }
        } else {
          Set<Object> allNew = new HashSet<Object>();
          for (List<Object> nodes : nodeListByKey.values()) {
            allNew.addAll(nodes);
          }
          visibleNodes.retainAll(allNew);
        }
      }
      ensureParentsVisible();
    }

    TreeModelEvent event = new TreeModelEvent(this, new Object[] {model.getRoot()});
    for (TreeModelListener listener : listeners) {
      listener.treeStructureChanged(event);
    }
  }
 public final void update() {
   this.list = swf.getAS3Packs();
   TreeModelEvent event = new TreeModelEvent(this, new TreePath(root));
   for (TreeModelListener listener : listeners) {
     listener.treeStructureChanged(event);
   }
 }
    protected void treeReSorted() {
      Debug.event("LogModel tree resorted");

      TreeModelEvent tme = new TreeModelEvent(this, new Object[] {this});
      for (TreeModelListener l : listeners) {
        l.treeStructureChanged(tme);
      }
    }
    protected void showReferenceAdded(LogReference reference) {
      Debug.event("LogModel reference added");

      TreeModelEvent tme = new TreeModelEvent(this, new Object[] {this, reference.container});
      for (TreeModelListener l : listeners) {
        l.treeStructureChanged(tme);
      }
    }
 public void fireTreeStructureChanged(TreePath path) {
   TreeModelEvent event = new TreeModelEvent(this, path);
   synchronized (listeners) {
     for (TreeModelListener listener : listeners) {
       listener.treeStructureChanged(event);
     }
   }
 }
示例#15
0
 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);
   }
 }
    protected void showGroupAdded(Group group) {
      // TreeModelEvent tme = new TreeModelEvent(this, new Object[]{root},
      // new int[]{AllGroups.allGroups.indexOf(group)},
      // new Object[]{group});
      Debug.event("LogModel group added");

      TreeModelEvent changed = new TreeModelEvent(this, new Object[] {this});
      for (TreeModelListener listener : listeners) listener.treeStructureChanged(changed);
    }
 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);
     }
   }
 }
    public void treeStructureChanged(TreeModelEvent event) {
      if (!isVisible(event.getTreePath().getLastPathComponent())) {
        return;
      }

      for (TreeModelListener listener : listeners) {
        listener.treeStructureChanged(event);
      }
    }
示例#19
0
 public void addChild(
     TreeNavigatorNode parent, TreeNavigatorNode child, TreeNavigatorNode previousSibling) {
   // int i = parent.getChildCount();
   int p = parent.addChild(child, previousSibling);
   TreeModelEvent tme =
       new TreeModelEvent(this, parent.getTreePath(), new int[] {p}, new Object[] {child});
   for (TreeModelListener l : listeners) {
     l.treeNodesInserted(tme);
   }
 }
示例#20
0
 private void fireTreeNodesChanged(
     final TreePath parentPath, final int[] indices, final Object[] children) {
   TreeModelEvent event = new TreeModelEvent(this, parentPath, indices, children);
   Iterator iterator = listeners.iterator();
   TreeModelListener listener = null;
   while (iterator.hasNext()) {
     listener = (TreeModelListener) iterator.next();
     listener.treeNodesChanged(event);
   }
 }
示例#21
0
 private void fireTreeNodeInserted(EntityCategory category, int idx) {
   for (TreeModelListener l : d_listeners) {
     l.treeNodesInserted(
         new TreeModelEvent(
             this,
             new Object[] {d_root, category},
             new int[] {idx},
             new Object[] {d_domain.getCategoryContents(category).get(idx)}));
   }
 }
    public void treeNodesInserted(TreeModelEvent event) {
      if (!isVisible(event.getTreePath().getLastPathComponent())) {
        return;
      }

      event = refactorEvent(event);
      for (TreeModelListener listener : listeners) {
        listener.treeNodesInserted(event);
      }
    }
示例#23
0
 /**
  * Notifies the tree that the given node has been added.
  *
  * @param tree
  * @param node
  */
 public void nodeInserted(AbstractTree tree, TreeNode parent, TreeNode node) {
   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.treeNodesInserted(e);
     }
   }
 }
 public void fireTreeInsert(TreePath path, int childIndex, Object child) {
   Object[] children = {child};
   //        int childIndex = this.getIndexOfChild(path.getLastPathComponent(), child);
   int[] indicies = {childIndex};
   TreeModelEvent event = new TreeModelEvent(this, path, indicies, children);
   synchronized (listeners) {
     for (TreeModelListener listener : listeners) {
       listener.treeNodesInserted(event);
     }
   }
 }
示例#25
0
 protected void fireNodeChanged(TreeNavigatorNode node) {
   TreePath pathToParent;
   if (node.getParent() == null) {
     pathToParent = new TreePath(getRoot());
   } else {
     pathToParent = node.getParent().getTreePath();
   }
   int[] c = new int[] {getIndexOfChild(pathToParent.getLastPathComponent(), node)};
   TreeModelEvent tme = new TreeModelEvent(this, pathToParent, c, new Object[] {node});
   for (TreeModelListener l : listeners) {
     l.treeNodesChanged(tme);
   }
 }
示例#26
0
  /**
   * Send an event to the listeners instructing that the largescale structure of nodes has changed.
   *
   * @param evt The event to be sent
   */
  private void fireTreeStructureChanged(TreeModelEvent evt) {
    Iterator itr = listeners.iterator();
    TreeModelListener l;

    while (itr.hasNext()) {
      l = (TreeModelListener) itr.next();
      try {
        l.treeStructureChanged(evt);
      } catch (Exception e) {
        I18nManager intl_mgr = I18nManager.getManager();
        String msg = intl_mgr.getString(STRUCTURE_CHANGE_ERR_PROP) + l;

        errorReporter.errorReport(msg, e);
      }
    }
  }
示例#27
0
  /**
   * 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);
      }
    }
  }
 @Override
 public void folderRefreshed(Folder folder) {
   TreeModelEvent e = makeChangeEvent(folder);
   final RepositoryTreeUtil treeUtil = new RepositoryTreeUtil();
   if (parentTree != null) {
     treeUtil.saveExpansionState(parentTree);
   }
   for (TreeModelListener l : listeners.getListeners(TreeModelListener.class)) {
     l.treeStructureChanged(e);
   }
   treeUtil.locateExpandedEntries();
   if (parentTree != null) {
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             treeUtil.restoreExpansionState(parentTree);
           }
         });
   }
 }
示例#29
0
 /**
  * Notifies the tree that the children of given node have been changed.
  *
  * @param tree
  * @param node
  */
 public void nodeChildrenChanged(AbstractTree tree, TreeNode node) {
   TreeModelEvent event = new TreeModelEvent(this, pathFromNode(tree, node));
   for (TreeModelListener l : listeners) {
     l.treeStructureChanged(event);
   }
 }
示例#30
0
  @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);
  }