KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > selection > SelectionHandler


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.selection;
17
18 import java.util.List JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import org.columba.api.command.ICommandReference;
22 import org.columba.api.selection.ISelectionHandler;
23 import org.columba.api.selection.ISelectionListener;
24 import org.columba.api.selection.SelectionChangedEvent;
25
26 /**
27  * Handles the selection of a component identified with an id.
28  * <p>
29  * We need the id for the {@link SelectionManager}which keeps a map of
30  * selection handlers.
31  * <p>
32  *
33  *
34  * @author fdietz, tstich
35  */

36 public abstract class SelectionHandler implements ISelectionHandler {
37     /**
38      * id of component for later identification
39      */

40     protected String JavaDoc id;
41
42     /**
43      * list of selection listeners
44      */

45     protected List JavaDoc selectionListener;
46
47     /**
48      * Default constructor
49      *
50      * @param id
51      * id of component
52      */

53     public SelectionHandler(String JavaDoc id) {
54         this.id = id;
55
56         selectionListener = new Vector JavaDoc();
57     }
58
59     /**
60      * Get id of component.
61      *
62      * @return String id of component
63      */

64     public String JavaDoc getId() {
65         return id;
66     }
67
68     /**
69      * Add selection listener.
70      *
71      * @param l
72      * selectionlistener
73      */

74     public void addSelectionListener(ISelectionListener l) {
75         selectionListener.add(l);
76     }
77
78     /**
79      * Fire a selection has changed event.
80      * <p>
81      * Notify all listeners for a change.
82      *
83      * @param e
84      * change event
85      */

86     protected void fireSelectionChanged(SelectionChangedEvent e) {
87         for ( int i=0; i<selectionListener.size(); i++) {
88             ((ISelectionListener)selectionListener.get(i)).selectionChanged(e);
89         }
90     }
91
92     /**
93      * @see org.columba.api.selection.ISelectionHandler#getSelection()
94      */

95     public abstract ICommandReference getSelection();
96
97     /**
98      * @see org.columba.api.selection.ISelectionHandler#setSelection(org.columba.api.command.ICommandReference)
99      */

100     public abstract void setSelection(ICommandReference selection);
101
102     /**
103      * @param command
104      */

105     public void removeSelectionListener(ISelectionListener l) {
106         selectionListener.remove(l);
107     }
108 }
Popular Tags