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.Hashtable;
019:
020: import org.columba.api.command.ICommandReference;
021: import org.columba.api.selection.ISelectionHandler;
022: import org.columba.api.selection.ISelectionListener;
023: import org.columba.api.selection.ISelectionManager;
024:
025: /**
026: * Manages selection handling of a complete frame which can have many different
027: * components with a selection model.
028: * <p>
029: * It additionally wraps almost all methods of {@link SelectionHandler}. So,
030: * there's no need to directly access {@link SelectionHandler}.
031: * <p>
032: * The <code>org.columba.core.gui.frame</code> package makes highly use of
033: * this class to manage all its selection stuff.
034: * <p>
035: * SelectionHandler has an id <code>String</code> as attribute. This makes it
036: * easy to indentify the SelectionHandler.
037: *
038: * @see org.columba.core.selection.SelectionHandler
039: * @see org.columba.api.gui.frame.IFrameMediator
040: *
041: * @author fdietz, tstich
042: */
043: public class SelectionManager implements ISelectionManager {
044: /**
045: * Map for storing all selection handlers
046: *
047: */
048: private Hashtable selectionHandler;
049:
050: /**
051: * default constructor
052: */
053: public SelectionManager() {
054: // init Map
055: selectionHandler = new Hashtable();
056: }
057:
058: /**
059: * Add selection handler
060: *
061: * @param handler
062: */
063: public void addSelectionHandler(ISelectionHandler handler) {
064: selectionHandler.put(handler.getId(), handler);
065: }
066:
067: /**
068: * @see org.columba.api.selection.ISelectionManager#registerSelectionListener(java.lang.String, org.columba.api.selection.ISelectionListener)
069: */
070: public void registerSelectionListener(String id,
071: ISelectionListener l) {
072: SelectionHandler h = ((SelectionHandler) selectionHandler
073: .get(id));
074:
075: h.addSelectionListener(l);
076: }
077:
078: /**
079: * @see org.columba.api.selection.ISelectionManager#removeSelectionListener(java.lang.String, org.columba.api.selection.ISelectionListener)
080: */
081: public void removeSelectionListener(String id, ISelectionListener l) {
082: SelectionHandler h = ((SelectionHandler) selectionHandler
083: .get(id));
084:
085: h.removeSelectionListener(l);
086: }
087:
088: /**
089: * @see org.columba.api.selection.ISelectionManager#setSelection(java.lang.String, org.columba.api.command.ICommandReference)
090: */
091: public void setSelection(String id, ICommandReference selection) {
092: ((ISelectionHandler) selectionHandler.get(id))
093: .setSelection(selection);
094: }
095:
096: /**
097: * @see org.columba.api.selection.ISelectionManager#getSelection(java.lang.String)
098: */
099: public ICommandReference getSelection(String id) {
100: return ((ISelectionHandler) selectionHandler.get(id))
101: .getSelection();
102: }
103:
104: /**
105: * @see org.columba.api.selection.ISelectionManager#getHandler(java.lang.String)
106: */
107: public ISelectionHandler getHandler(String id) {
108: return (ISelectionHandler) selectionHandler.get(id);
109: }
110: }
|