p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / editor / SimpleSelectionProvider.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.editor;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.runtime.ListenerList;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionChangedListener;
16 import org.eclipse.jface.viewers.ISelectionProvider;
17 import org.eclipse.jface.viewers.SelectionChangedEvent;
18
19 /**
20 * @author p.ciardelli
21 * @created 16.05.2008
22 * @version 1.0
23 */
24 public class SimpleSelectionProvider implements ISelectionProvider {
25 private static final Logger logger = Logger
26 .getLogger(SimpleSelectionProvider.class);
27
28 private ListenerList listeners = new ListenerList();
29 private ISelection selection;
30
31 public void addSelectionChangedListener(
32 ISelectionChangedListener listener) {
33 listeners.add(listener);
34 }
35
36 public ISelection getSelection() {
37 if (selection != null)
38 return selection;
39 return null;
40 }
41
42 public void removeSelectionChangedListener(
43 ISelectionChangedListener listener) {
44 listeners.remove(listener);
45 }
46
47 public void setSelection(ISelection selection) {
48 this.selection = selection;
49 fireSelectionChanged();
50 }
51
52 private void fireSelectionChanged() {
53
54 SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
55
56 for (Object listener : listeners.getListeners()) {
57 if (listener instanceof ISelectionChangedListener) {
58 ((ISelectionChangedListener)listener).selectionChanged(event);
59 }
60 }
61 }
62
63 }