1 11 package org.eclipse.debug.internal.ui.viewers.model.provisional; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.ListenerList; 17 import org.eclipse.core.runtime.SafeRunner; 18 import org.eclipse.jface.util.IPropertyChangeListener; 19 import org.eclipse.jface.util.PropertyChangeEvent; 20 import org.eclipse.jface.util.SafeRunnable; 21 22 29 public class PresentationContext implements IPresentationContext { 30 31 private String fId; 32 private ListenerList fListeners = new ListenerList(); 33 private Map fProperties = new HashMap (); 34 35 40 public PresentationContext(String id) { 41 fId = id; 42 } 43 44 47 public String [] getColumns() { 48 return (String []) getProperty(IPresentationContext.PROPERTY_COLUMNS); 49 } 50 51 58 protected void firePropertyChange(String property, Object oldValue, Object newValue) { 59 if (!fListeners.isEmpty()) { 60 final PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue); 61 Object [] listeners = fListeners.getListeners(); 62 for (int i = 0; i < listeners.length; i++) { 63 final IPropertyChangeListener listener = (IPropertyChangeListener) listeners[i]; 64 SafeRunner.run(new SafeRunnable() { 65 public void run() throws Exception { 66 listener.propertyChange(event); 67 } 68 }); 69 } 70 } 71 } 72 73 78 public void setColumns(String [] ids) { 79 setProperty(IPresentationContext.PROPERTY_COLUMNS, ids); 80 } 81 82 83 86 public void dispose() { 87 fListeners.clear(); 88 fProperties.clear(); 89 } 90 91 94 public void addPropertyChangeListener(IPropertyChangeListener listener) { 95 fListeners.add(listener); 96 } 97 98 101 public void removePropertyChangeListener(IPropertyChangeListener listener) { 102 fListeners.remove(listener); 103 } 104 105 108 public String getId() { 109 return fId; 110 } 111 112 115 public Object getProperty(String property) { 116 synchronized (fProperties) { 117 return fProperties.get(property); 118 } 119 } 120 121 124 public void setProperty(String property, Object value) { 125 synchronized (fProperties) { 126 Object oldValue = fProperties.get(property); 127 if (!isEqual(oldValue, value)) { 128 fProperties.put(property, value); 129 firePropertyChange(property, oldValue, value); 130 } 131 } 132 } 133 134 private boolean isEqual(Object a, Object b) { 135 if (a == null) { 136 return b == null; 137 } 138 return a.equals(b); 139 } 140 141 142 } 143 | Popular Tags |