001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.tree;
014:
015: import javax.swing.event.TreeSelectionEvent;
016: import javax.swing.tree.DefaultTreeSelectionModel;
017: import javax.swing.tree.TreePath;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021:
022: /**
023: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
024: */
025: public class SDefaultTreeSelectionModel extends
026: DefaultTreeSelectionModel implements STreeSelectionModel {
027:
028: /**
029: * indicates if we should fire event immediately when they arise, or if we
030: * should collect them for a later delivery
031: */
032: private boolean delayEvents = false;
033:
034: /**
035: * got a delayed Event?
036: */
037: protected final ArrayList delayedEvents = new ArrayList();
038:
039: public SDefaultTreeSelectionModel() {
040: super ();
041: }
042:
043: public boolean getDelayEvents() {
044: return delayEvents;
045: }
046:
047: public void setDelayEvents(boolean b) {
048: delayEvents = b;
049: }
050:
051: /**
052: * fire event with isValueIsAdjusting true
053: */
054: public void fireDelayedIntermediateEvents() {
055: }
056:
057: public void fireDelayedFinalEvents() {
058: for (Iterator iter = delayedEvents.iterator(); iter.hasNext();) {
059: TreeSelectionEvent e = (TreeSelectionEvent) iter.next();
060:
061: fireValueChanged(e);
062: }
063: delayedEvents.clear();
064: }
065:
066: protected void fireValueChanged(TreeSelectionEvent e) {
067: if (delayEvents) {
068: delayedEvents.add(e);
069: } else {
070: super .fireValueChanged(e);
071: }
072: }
073:
074: /**
075: * Unique shared instance. No selection possible.
076: */
077: public static final SDefaultTreeSelectionModel NO_SELECTION_MODEL = new SDefaultTreeSelectionModel() {
078: /**
079: * A null implementation that selects nothing
080: */
081: public void setSelectionPaths(TreePath[] pPaths) {
082: }
083:
084: /**
085: * A null implementation that adds nothing
086: */
087: public void addSelectionPaths(TreePath[] paths) {
088: }
089:
090: /**
091: * A null implementation that removes nothing
092: */
093: public void removeSelectionPaths(TreePath[] paths) {
094: }
095:
096: // don't fire events, because there should be not state change
097: protected void fireValueChanged(TreeSelectionEvent e) {
098: }
099:
100: };
101:
102: }
|