001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.selection;
017:
018: import java.util.List;
019: import java.util.Vector;
020:
021: import org.columba.api.command.ICommandReference;
022: import org.columba.api.selection.ISelectionHandler;
023: import org.columba.api.selection.ISelectionListener;
024: import org.columba.api.selection.SelectionChangedEvent;
025:
026: /**
027: * Handles the selection of a component identified with an id.
028: * <p>
029: * We need the id for the {@link SelectionManager}which keeps a map of
030: * selection handlers.
031: * <p>
032: *
033: *
034: * @author fdietz, tstich
035: */
036: public abstract class SelectionHandler implements ISelectionHandler {
037: /**
038: * id of component for later identification
039: */
040: protected String id;
041:
042: /**
043: * list of selection listeners
044: */
045: protected List selectionListener;
046:
047: /**
048: * Default constructor
049: *
050: * @param id
051: * id of component
052: */
053: public SelectionHandler(String id) {
054: this .id = id;
055:
056: selectionListener = new Vector();
057: }
058:
059: /**
060: * Get id of component.
061: *
062: * @return String id of component
063: */
064: public String getId() {
065: return id;
066: }
067:
068: /**
069: * Add selection listener.
070: *
071: * @param l
072: * selectionlistener
073: */
074: public void addSelectionListener(ISelectionListener l) {
075: selectionListener.add(l);
076: }
077:
078: /**
079: * Fire a selection has changed event.
080: * <p>
081: * Notify all listeners for a change.
082: *
083: * @param e
084: * change event
085: */
086: protected void fireSelectionChanged(SelectionChangedEvent e) {
087: for (int i = 0; i < selectionListener.size(); i++) {
088: ((ISelectionListener) selectionListener.get(i))
089: .selectionChanged(e);
090: }
091: }
092:
093: /**
094: * @see org.columba.api.selection.ISelectionHandler#getSelection()
095: */
096: public abstract ICommandReference getSelection();
097:
098: /**
099: * @see org.columba.api.selection.ISelectionHandler#setSelection(org.columba.api.command.ICommandReference)
100: */
101: public abstract void setSelection(ICommandReference selection);
102:
103: /**
104: * @param command
105: */
106: public void removeSelectionListener(ISelectionListener l) {
107: selectionListener.remove(l);
108: }
109: }
|