Esempio n. 1
0
    /**
     * Called when an event is to be posed to the member.
     *
     * @param event Event to post.
     * @return true if event should be propogated, false if it should be cancelled.
     */
    public boolean eventPosted(EventObject event) {
      ElementTreeModel model = (ElementTreeModel) _tree.getModel();
      // XXX This crap needs cleaning up. Type switching is lazy...
      if (event instanceof PropertyChangeEvent) {
        // The project node has changed.
        model.fireNodeChanged((ACSElement) event.getSource());
      } else if (event instanceof NewElementEvent && model != null) {
        ACSElement element = ((NewElementEvent) event).getNewElement();
        model.fireNodeAdded(element);
        TreePath path = new TreePath(model.getPathToRoot(element));
        _selections.setSelectionPath(path);
        _tree.scrollPathToVisible(path);
      } else {
        ACSProjectElement project = null;
        if (event instanceof ProjectSelectedEvent) {
          ProjectSelectedEvent e = (ProjectSelectedEvent) event;
          project = e.getSelectedProject();
        }

        if (project == null) {
          // The project has been closed.
          // XXX this needs to be tested against
          // different version of Swing...
          _tree.setModel(null);
          _tree.setSelectionModel(null);
          // Send an empty selection event to notify others that
          // nothing is selected.
          ElementSelectionEvent.createEvent(getContext(), null);
        } else {
          _tree.setModel(new ElementTreeModel(project));
          _selections = new ElementTreeSelectionModel();
          _selections.addTreeSelectionListener(new SelectionForwarder());
          _tree.setSelectionModel(_selections);
        }
      }
      return true;
    }
Esempio n. 2
0
 public void valueChanged(TreeSelectionEvent e) {
   getContext()
       .getEventBus()
       .postEvent(
           ElementSelectionEvent.createEvent(getContext(), _selections.getSelectedElements()));
 }