* @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 RefreshDisplayEvent && model != null) {
_tree.validate();
}
else if(event instanceof NewElementEvent &&
(event instanceof NewProjectEvent == false) &&
model != null) {
ACSElement element = ((NewElementEvent)event).getNewElement();
model.fireNodeAdded(element);
TreePath path = new TreePath(model.getPathToRoot(element));
_selections.setSelectionPath(path);
_tree.scrollPathToVisible(path);
}
else if(event instanceof DeleteElementEvent && model != null) {
ACSElement element = ((DeleteElementEvent)event).getDeletedElement();
model.fireNodeDeleted(element);
_tree.updateUI();
}
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 {
boolean updateModel = false;
TreeModel testModel = _tree.getModel();
// Set the model if's not an ElementTreeModel
if (testModel instanceof ElementTreeModel) {
ElementTreeModel etm = (ElementTreeModel) testModel;
ACSProjectElement currentProject =
(ACSProjectElement) etm.getRoot();
// Set the model if the project is wrong
if (currentProject != project) {
updateModel = true;
}
} else {
updateModel = true;
}
// Should we update the tree model
if (updateModel) {
_tree.setModel(new ElementTreeModel(project));
_tree.getModel().addTreeModelListener(
new ChangeHandler());
_selections = new ElementTreeSelectionModel();
_selections.addTreeSelectionListener(