KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > PresentationContext


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.viewers;
12
13 import org.eclipse.core.runtime.ListenerList;
14 import org.eclipse.core.runtime.SafeRunner;
15 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18 import org.eclipse.jface.util.SafeRunnable;
19 import org.eclipse.ui.IWorkbenchPart;
20
21 /**
22  * Presentation context.
23  * <p>
24  * Clients may instantiate and subclass this class.
25  * </p>
26  * @since 3.2
27  */

28 public class PresentationContext implements IPresentationContext {
29     
30     private IWorkbenchPart fPart;
31     private String JavaDoc[] fColumns;
32     private ListenerList fListeners = new ListenerList();
33     
34     /**
35      * Constructs a presentation context for the given part.
36      *
37      * @param part workbench part
38      */

39     public PresentationContext(IWorkbenchPart part) {
40         fPart = part;
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.debug.ui.viewers.IPresentationContext#getPart()
45      */

46     public IWorkbenchPart getPart() {
47         return fPart;
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext#getColumns()
52      */

53     public String JavaDoc[] getColumns() {
54         return fColumns;
55     }
56     
57     /**
58      * Fires a property change event to all registered listeners
59      *
60      * @param property property name
61      * @param oldValue old value or <code>null</code>
62      * @param newValue new value or <code>null</code>
63      */

64     protected void firePropertyChange(String JavaDoc property, Object JavaDoc oldValue, Object JavaDoc newValue) {
65         if (!fListeners.isEmpty()) {
66             final PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue);
67             Object JavaDoc[] listeners = fListeners.getListeners();
68             for (int i = 0; i < listeners.length; i++) {
69                 final IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i];
70                 SafeRunner.run(new SafeRunnable() {
71                     public void run() throws Exception JavaDoc {
72                         listener.propertyChange(event);
73                     }
74                 });
75             }
76         }
77     }
78     
79     /**
80      * Sets the visible column ids.
81      *
82      * @param ids column identifiers
83      */

84     protected void setColumns(String JavaDoc[] ids) {
85         String JavaDoc[] oldValue = fColumns;
86         fColumns = ids;
87         firePropertyChange(IPresentationContext.PROPERTY_COLUMNS, oldValue, ids);
88     }
89     
90     /**
91      * Disposes this presentation context.
92      */

93     protected void dispose() {
94         fListeners.clear();
95         fPart = null;
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
100      */

101     public void addPropertyChangeListener(IPropertyChangeListener listener) {
102         fListeners.add(listener);
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
107      */

108     public void removePropertyChangeListener(IPropertyChangeListener listener) {
109         fListeners.remove(listener);
110     }
111
112 }
113
Popular Tags