1 11 12 package org.eclipse.jface.internal.provisional.action; 13 14 import org.eclipse.core.runtime.ListenerList; 15 import org.eclipse.jface.action.ToolBarManager; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.ToolBar; 21 22 34 public class ToolBarManager2 extends ToolBarManager implements IToolBarManager2 { 35 36 40 private transient ListenerList listenerList = null; 41 42 46 public ToolBarManager2() { 47 super(); 48 } 49 50 58 public ToolBarManager2(int style) { 59 super(style); 60 } 61 62 70 public ToolBarManager2(ToolBar toolbar) { 71 super(toolbar); 72 } 73 74 77 public Control createControl2(Composite parent) { 78 return createControl(parent); 79 } 80 81 84 public Control getControl2() { 85 return getControl(); 86 } 87 88 91 public int getItemCount() { 92 ToolBar toolBar = getControl(); 93 if (toolBar == null || toolBar.isDisposed()) { 94 return 0; 95 } 96 return toolBar.getItemCount(); 97 } 98 99 102 public void addPropertyChangeListener(IPropertyChangeListener listener) { 103 if (listenerList == null) { 104 listenerList = new ListenerList(ListenerList.IDENTITY); 105 } 106 107 listenerList.add(listener); 108 } 109 110 113 public void removePropertyChangeListener(IPropertyChangeListener listener) { 114 if (listenerList != null) { 115 listenerList.remove(listener); 116 117 if (listenerList.isEmpty()) { 118 listenerList = null; 119 } 120 } 121 } 122 123 129 protected final Object [] getListeners() { 130 final ListenerList list = listenerList; 131 if (list == null) { 132 return new Object [0]; 133 } 134 135 return list.getListeners(); 136 } 137 138 142 private void firePropertyChange(final PropertyChangeEvent event) { 143 final Object [] list = getListeners(); 144 for (int i = 0; i < list.length; ++i) { 145 ((IPropertyChangeListener) list[i]).propertyChange(event); 146 } 147 } 148 149 155 private void firePropertyChange(final String propertyName, 156 final Object oldValue, final Object newValue) { 157 if (listenerList != null) { 158 firePropertyChange(new PropertyChangeEvent(this, propertyName, 159 oldValue, newValue)); 160 } 161 } 162 163 166 protected void relayout(ToolBar layoutBar, int oldCount, int newCount) { 167 super.relayout(layoutBar, oldCount, newCount); 168 firePropertyChange(PROP_LAYOUT, new Integer (oldCount), new Integer (newCount)); 169 } 170 } 171 | Popular Tags |