Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 123257 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/action/ToolBarManager.java (-97 / +1 lines)
Lines 13-21 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
14
import java.util.Iterator;
15
15
16
import org.eclipse.core.runtime.ListenerList;
17
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.accessibility.ACC;
17
import org.eclipse.swt.accessibility.ACC;
21
import org.eclipse.swt.accessibility.AccessibleAdapter;
18
import org.eclipse.swt.accessibility.AccessibleAdapter;
Lines 36-42 Link Here
36
 * </p>
33
 * </p>
37
 */
34
 */
38
public class ToolBarManager extends ContributionManager implements
35
public class ToolBarManager extends ContributionManager implements
39
		IToolBarManager2 {
36
		IToolBarManager {
40
37
41
	/**
38
	/**
42
	 * The tool bar items style; <code>SWT.NONE</code> by default.
39
	 * The tool bar items style; <code>SWT.NONE</code> by default.
Lines 57-68 Link Here
57
	private MenuManager contextMenuManager = null;
54
	private MenuManager contextMenuManager = null;
58
55
59
	/**
56
	/**
60
	 * A collection of objects listening to changes to this manager. This
61
	 * collection is <code>null</code> if there are no listeners.
62
	 */
63
	private transient ListenerList listenerList = null;
64
	
65
	/**
66
	 * Creates a new tool bar manager with the default SWT button style. Use the
57
	 * Creates a new tool bar manager with the default SWT button style. Use the
67
	 * <code>createControl</code> method to create the tool bar control.
58
	 * <code>createControl</code> method to create the tool bar control.
68
	 */
59
	 */
Lines 191-197 Link Here
191
	protected void relayout(ToolBar layoutBar, int oldCount, int newCount) {
182
	protected void relayout(ToolBar layoutBar, int oldCount, int newCount) {
192
		if ((oldCount == 0) != (newCount == 0))
183
		if ((oldCount == 0) != (newCount == 0))
193
			layoutBar.getParent().layout();
184
			layoutBar.getParent().layout();
194
		firePropertyChange(PROP_LAYOUT, new Integer(oldCount), new Integer(newCount));
195
	}
185
	}
196
186
197
	/**
187
	/**
Lines 406-495 Link Here
406
		}
396
		}
407
	}
397
	}
408
398
409
	/* (non-Javadoc)
410
	 * @see org.eclipse.jface.action.IToolBarManager2#createControl2(org.eclipse.swt.widgets.Composite)
411
	 */
412
	public Control createControl2(Composite parent) {
413
		return createControl(parent);
414
	}
415
416
	/* (non-Javadoc)
417
	 * @see org.eclipse.jface.action.IToolBarManager2#getControl2()
418
	 */
419
	public Control getControl2() {
420
		return getControl();
421
	}
422
423
	/* (non-Javadoc)
424
	 * @see org.eclipse.jface.action.IToolBarManager2#getItemCount()
425
	 */
426
	public int getItemCount() {
427
		if (!toolBarExist())
428
			return 0;
429
		return toolBar.getItemCount();
430
	}
431
432
	/* (non-Javadoc)
433
	 * @see org.eclipse.jface.action.IToolBarManager2#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
434
	 */
435
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
436
		if (listenerList == null) {
437
			listenerList = new ListenerList(ListenerList.IDENTITY);
438
		}
439
440
		listenerList.add(listener);
441
	}
442
443
	/* (non-Javadoc)
444
	 * @see org.eclipse.jface.action.IToolBarManager2#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
445
	 */
446
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
447
		if (listenerList != null) {
448
			listenerList.remove(listener);
449
450
			if (listenerList.isEmpty()) {
451
				listenerList = null;
452
			}
453
		}
454
	}
455
	
456
	/*
457
	 * Returns the listeners attached to this event manager.
458
	 * The listeners currently attached; may be empty, but never
459
	 * null.
460
	 */
461
	protected final Object[] getListeners() {
462
		final ListenerList list = listenerList;
463
		if (list == null) {
464
			return new Object[0];
465
		}
466
467
		return list.getListeners();
468
	}
469
470
	/*
471
	 * Notifies any property change listeners that a property has changed. Only
472
	 * listeners registered at the time this method is called are notified.
473
	 */
474
	private void firePropertyChange(final PropertyChangeEvent event) {
475
		final Object[] list = getListeners();
476
		for (int i = 0; i < list.length; ++i) {
477
			((IPropertyChangeListener) list[i]).propertyChange(event);
478
		}
479
	}
480
481
	/*
482
	 * Notifies any property change listeners that a property has changed. Only
483
	 * listeners registered at the time this method is called are notified. This
484
	 * method avoids creating an event object if there are no listeners
485
	 * registered, but calls firePropertyChange(PropertyChangeEvent) if there are.
486
	 */
487
	private void firePropertyChange(final String propertyName,
488
			final Object oldValue, final Object newValue) {
489
		if (listenerList != null) {
490
			firePropertyChange(new PropertyChangeEvent(this, propertyName,
491
					oldValue, newValue));
492
		}
493
	}
494
495
}
399
}
(-)src/org/eclipse/jface/action/ToolBarContributionItem.java (-1 / +1 lines)
Lines 43-49 Link Here
43
 * 
43
 * 
44
 * @since 3.0
44
 * @since 3.0
45
 */
45
 */
46
public class ToolBarContributionItem extends ContributionItem implements IToolBarContributionItem {
46
public class ToolBarContributionItem extends ContributionItem {
47
47
48
    /**
48
    /**
49
     * A constant used by <code>setMinimumItemsToShow</code> and <code>getMinimumItemsToShow</code>
49
     * A constant used by <code>setMinimumItemsToShow</code> and <code>getMinimumItemsToShow</code>
(-)src/org/eclipse/jface/action/ICoolBarManager.java (-144 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2006 IBM Corporation and others.
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jface.action;
11
package org.eclipse.jface.action;
12
12
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Control;
15
import org.eclipse.swt.widgets.CoolBar;
13
import org.eclipse.swt.widgets.CoolBar;
16
14
17
/**
15
/**
Lines 52-93 Link Here
52
     * @see ToolBarContributionItem
50
     * @see ToolBarContributionItem
53
     */
51
     */
54
    public void add(IToolBarManager toolBarManager);
52
    public void add(IToolBarManager toolBarManager);
55
    
56
    /**
57
     * Creates and returns this manager's cool bar control. Does not create a
58
     * new control if one already exists.
59
     * 
60
	 * <p>
61
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
62
	 * part of a work in progress. There is a guarantee neither that this API will
63
	 * work nor that it will remain the same. Please do not use this API without
64
	 * consulting with the Platform/UI team.
65
	 * </p>
66
     * 
67
     * @param parent
68
     *            the parent control
69
     * @return the cool bar control
70
	 * @since 3.2
71
     */
72
    public CoolBar createControl(Composite parent);
73
74
    /**
75
     * Creates and returns this manager's control. Does not create a
76
     * new control if one already exists.
77
     * 
78
	 * <p>
79
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
80
	 * part of a work in progress. There is a guarantee neither that this API will
81
	 * work nor that it will remain the same. Please do not use this API without
82
	 * consulting with the Platform/UI team.
83
	 * </p>
84
     * 
85
     * @param parent
86
     *            the parent control
87
     * @return the control
88
	 * @since 3.2
89
     */
90
    public Control createControl2(Composite parent);
91
53
92
    /**
54
    /**
93
     * Returns the context menu manager used by this cool bar manager. This
55
     * Returns the context menu manager used by this cool bar manager. This
Lines 100-135 Link Here
100
    public IMenuManager getContextMenuManager();
62
    public IMenuManager getContextMenuManager();
101
63
102
    /**
64
    /**
103
     * Returns the cool bar control for this manager.
104
     * 
105
	 * <p>
106
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
107
	 * part of a work in progress. There is a guarantee neither that this API will
108
	 * work nor that it will remain the same. Please do not use this API without
109
	 * consulting with the Platform/UI team.
110
	 * </p>
111
     * 
112
     * @return the cool bar control, or <code>null</code> if none
113
	 * @since 3.2
114
     */
115
    public CoolBar getControl();
116
    
117
    /**
118
     * Returns the bar control for this manager.
119
     * 
120
	 * <p>
121
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
122
	 * part of a work in progress. There is a guarantee neither that this API will
123
	 * work nor that it will remain the same. Please do not use this API without
124
	 * consulting with the Platform/UI team.
125
	 * </p>
126
     *  
127
     * @return the bar control, or <code>null</code> if none
128
	 * @since 3.2
129
     */
130
    public Control getControl2();
131
132
    /**
133
     * Returns whether the layout of the underlying cool bar widget is locked.
65
     * Returns whether the layout of the underlying cool bar widget is locked.
134
     * 
66
     * 
135
     * @return <code>true</code> if cool bar layout is locked, <code>false</code>
67
     * @return <code>true</code> if cool bar layout is locked, <code>false</code>
Lines 155-228 Link Here
155
    public void setContextMenuManager(IMenuManager menuManager);
87
    public void setContextMenuManager(IMenuManager menuManager);
156
88
157
    /**
89
    /**
158
     * Synchronizes the visual order of the cool items in the control with this
159
     * manager's internal data structures. This method should be called before
160
     * requesting the order of the contribution items to ensure that the order
161
     * is accurate.
162
     * <p>
163
     * Note that <code>update()</code> and <code>refresh()</code> are
164
     * converses: <code>update()</code> changes the visual order to match the
165
     * internal structures, and <code>refresh</code> changes the internal
166
     * structures to match the visual order.
167
     * </p>
168
     * 
169
	 * <p>
170
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
171
	 * part of a work in progress. There is a guarantee neither that this API will
172
	 * work nor that it will remain the same. Please do not use this API without
173
	 * consulting with the Platform/UI team.
174
	 * </p>
175
     * 
176
	 * @since 3.2
177
     */
178
    public void refresh();
179
    
180
    /**
181
	 * Disposes the resources for this manager.
182
     * 
183
	 * <p>
184
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
185
	 * part of a work in progress. There is a guarantee neither that this API will
186
	 * work nor that it will remain the same. Please do not use this API without
187
	 * consulting with the Platform/UI team.
188
	 * </p>
189
     * 
190
     * @since 3.2 
191
     */
192
    public void dispose();
193
194
    /**
195
     * Restores the canonical order of this cool bar manager. The canonical
196
     * order is the order in which the contribution items where added.
197
     * 
198
	 * <p>
199
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
200
	 * part of a work in progress. There is a guarantee neither that this API will
201
	 * work nor that it will remain the same. Please do not use this API without
202
	 * consulting with the Platform/UI team.
203
	 * </p>
204
     * 
205
	 * @since 3.2     
206
	 */
207
    public void resetItemOrder();
208
209
    /**
210
     * Replaces the current items with the given items.
211
     * Forces an update.
212
     * 
213
	 * <p>
214
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
215
	 * part of a work in progress. There is a guarantee neither that this API will
216
	 * work nor that it will remain the same. Please do not use this API without
217
	 * consulting with the Platform/UI team.
218
	 * </p>
219
     * 
220
     * @param newItems the items with which to replace the current items
221
     * @since 3.2
222
	 */
223
    public void setItems(IContributionItem[] newItems);
224
	
225
    /**
226
     * Locks or unlocks the layout of the underlying cool bar widget. Once the
90
     * Locks or unlocks the layout of the underlying cool bar widget. Once the
227
     * cool bar is locked, cool items cannot be repositioned by the user.
91
     * cool bar is locked, cool items cannot be repositioned by the user.
228
     * <p>
92
     * <p>
Lines 230-242 Link Here
230
     * cool bar is locked.
94
     * cool bar is locked.
231
     * </p>
95
     * </p>
232
     * 
96
     * 
233
	 * <p>
234
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
235
	 * part of a work in progress. There is a guarantee neither that this API will
236
	 * work nor that it will remain the same. Please do not use this API without
237
	 * consulting with the Platform/UI team.
238
	 * </p>
239
     *  
240
     * @param value
97
     * @param value
241
     *            <code>true</code> to lock the cool bar, <code>false</code>
98
     *            <code>true</code> to lock the cool bar, <code>false</code>
242
     *            to unlock
99
     *            to unlock
(-)src/org/eclipse/jface/action/CoolBarManager.java (-37 lines)
Lines 245-270 Link Here
245
        }
245
        }
246
        return coolBar;
246
        return coolBar;
247
    }
247
    }
248
    
249
    /**
250
     * Creates and returns this manager's cool bar control. Does not create a
251
     * new control if one already exists.
252
     * 
253
	 * <p>
254
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
255
	 * part of a work in progress. There is a guarantee neither that this API will
256
	 * work nor that it will remain the same. Please do not use this API without
257
	 * consulting with the Platform/UI team.
258
	 * </p>
259
     * 
260
     * @param parent
261
     *            the parent control
262
     * @return the cool bar control
263
	 * @since 3.2
264
     */
265
    public Control createControl2(Composite parent) {
266
        return createControl(parent);
267
    }
268
248
269
    /**
249
    /**
270
     * Disposes of this cool bar manager and frees all allocated SWT resources.
250
     * Disposes of this cool bar manager and frees all allocated SWT resources.
Lines 402-424 Link Here
402
    public CoolBar getControl() {
382
    public CoolBar getControl() {
403
        return coolBar;
383
        return coolBar;
404
    }
384
    }
405
    
406
    /**
407
     * Returns the control for this manager.
408
     * 
409
	 * <p>
410
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
411
	 * part of a work in progress. There is a guarantee neither that this API will
412
	 * work nor that it will remain the same. Please do not use this API without
413
	 * consulting with the Platform/UI team.
414
	 * </p>
415
     * 
416
     * @return the control, or <code>null</code> if none
417
	 * @since 3.2
418
     */
419
    public Control getControl2() {
420
        return coolBar;
421
    }
422
385
423
    /**
386
    /**
424
     * Returns an array list of all the contribution items in the manager.
387
     * Returns an array list of all the contribution items in the manager.
(-)src/org/eclipse/jface/action/SubCoolBarManager.java (-73 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2006 IBM Corporation and others.
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-19 Link Here
11
package org.eclipse.jface.action;
11
package org.eclipse.jface.action;
12
12
13
import org.eclipse.jface.util.Assert;
13
import org.eclipse.jface.util.Assert;
14
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.swt.widgets.CoolBar;
17
14
18
/**
15
/**
19
 * A <code>SubCoolBarManager</code> monitors the additional and removal of 
16
 * A <code>SubCoolBarManager</code> monitors the additional and removal of 
Lines 45-82 Link Here
45
        super.add(new ToolBarContributionItem(toolBarManager));
42
        super.add(new ToolBarContributionItem(toolBarManager));
46
    }
43
    }
47
44
48
    /*
49
     *  (non-Javadoc)
50
     * @see org.eclipse.jface.action.ICoolBarManager#createControl(org.eclipse.swt.widgets.Composite)
51
     */
52
    public CoolBar createControl(Composite parent) {
53
        return null;
54
    }
55
    
56
    /*
57
     *  (non-Javadoc)
58
     * @see org.eclipse.jface.action.ICoolBarManager#createControl2(org.eclipse.swt.widgets.Composite)
59
     */
60
    public Control createControl2(Composite parent) {
61
        return createControl(parent);
62
    }
63
64
    /*
65
     *  (non-Javadoc)
66
     * @see org.eclipse.jface.action.ICoolBarManager#getControl()
67
     */
68
    public CoolBar getControl() {
69
        return null;
70
    }
71
    
72
    /*
73
     *  (non-Javadoc)
74
     * @see org.eclipse.jface.action.ICoolBarManager#getControl2()
75
     */
76
    public Control getControl2() {
77
        return null;
78
    }
79
    
80
    /* (non-Javadoc)
45
    /* (non-Javadoc)
81
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
46
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
82
     */
47
     */
Lines 117-138 Link Here
117
        return null;
82
        return null;
118
    }
83
    }
119
84
120
    /*
121
     *  (non-Javadoc)
122
     * @see org.eclipse.jface.action.ICoolBarManager#refresh()
123
     */
124
    public void refresh() {
125
        // do nothing
126
    }
127
128
    /*
129
     *  (non-Javadoc)
130
     * @see org.eclipse.jface.action.ICoolBarManager#resetItemOrder()
131
     */
132
    public void resetItemOrder() {
133
        // do nothing
134
    }
135
    
136
    /* (non-Javadoc)
85
    /* (non-Javadoc)
137
     * In SubCoolBarManager we do nothing.
86
     * In SubCoolBarManager we do nothing.
138
     */
87
     */
Lines 140-153 Link Here
140
        // do nothing
89
        // do nothing
141
    }
90
    }
142
91
143
    /*
144
     *  (non-Javadoc)
145
     * @see org.eclipse.jface.action.ICoolBarManager#setItems(org.eclipse.jface.action.IContributionItem[])
146
     */
147
    public void setItems(IContributionItem[] newItems) {
148
    	// do nothing
149
    }
150
151
    /* (non-Javadoc)
92
    /* (non-Javadoc)
152
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
93
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
153
     */
94
     */
Lines 158-174 Link Here
158
        getParentCoolBarManager().update(force);
99
        getParentCoolBarManager().update(force);
159
    }
100
    }
160
101
161
	/* (non-Javadoc)
162
	 * @see org.eclipse.jface.action.ICoolBarManager#dispose()
163
	 */
164
	public void dispose() {
165
		// do nothing
166
	}
167
168
169
170
171
172
173
174
}
102
}
(-)src/org/eclipse/jface/action/IToolBarManager2.java (-111 lines)
Removed Link Here
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.jface.action;
12
13
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.swt.widgets.ToolBar;
17
18
/**
19
 * The <code>IToolBarManager2</code> interface provides protocol for managing
20
 * contributions to a tool bar. It extends <code>IToolBarManager</code>
21
 * and provides a <code>dispose</code> method.
22
 * 
23
 * <p>
24
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
25
 * part of a work in progress. There is a guarantee neither that this API will
26
 * work nor that it will remain the same. Please do not use this API without
27
 * consulting with the Platform/UI team.
28
 * </p>
29
 * 
30
 * This package also provides a concrete tool bar manager implementation,
31
 * {@link ToolBarManager <code>ToolBarManager</code>}.
32
 * </p>
33
 * 
34
 * @since 3.2
35
 */
36
public interface IToolBarManager2 extends IToolBarManager {
37
	
38
	/**
39
	 * The property id for changes to the control's layout
40
	 */
41
	public static final String PROP_LAYOUT = "PROP_LAYOUT"; //$NON-NLS-1$
42
	
43
    /**
44
     * Creates and returns this manager's toolbar control. Does not create a
45
     * new control if one already exists.
46
     * 
47
     * @param parent
48
     *            the parent control
49
     * @return the toolbar control
50
     */
51
	public ToolBar createControl(Composite parent);
52
	
53
    /**
54
     * Creates and returns this manager's control. Does not create a
55
     * new control if one already exists.
56
     * 
57
     * @param parent
58
     *            the parent control
59
     * @return the control
60
     */
61
	public Control createControl2(Composite parent);
62
	
63
    /**
64
     * Returns the toolbar control for this manager.
65
     * 
66
     * @return the toolbar control, or <code>null</code> if none
67
     */
68
	public ToolBar getControl();
69
	
70
    /**
71
     * Returns the control for this manager.
72
     * 
73
     * @return the control, or <code>null</code> if none
74
     */
75
	public Control getControl2();
76
77
    /**
78
	 * Disposes the resources for this manager.
79
     */
80
	public void dispose();
81
	
82
	/**
83
	 * Returns the item count of the control used 
84
	 * by this manager.
85
	 * 
86
	 * @return the number of items in the control
87
	 */
88
	public int getItemCount();
89
	
90
	/**
91
	 * Registers a property change listner with this manager.
92
	 * 
93
	 * @param listener
94
	 */
95
	public void addPropertyChangeListener(IPropertyChangeListener listener);
96
	
97
	/**
98
	 * Removes a property change listner from this manager.
99
	 * 
100
	 * @param listener
101
	 */
102
	public void removePropertyChangeListener(IPropertyChangeListener listener);
103
	
104
    /**
105
     * Sets the overrides for this contribution manager
106
     * 
107
     * @param newOverrides the overrides for the items of this manager
108
     */
109
    public void setOverrides(IContributionManagerOverrides newOverrides);
110
	
111
}
(-)src/org/eclipse/jface/action/IToolBarContributionItem.java (-120 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.jface.action;
13
14
/**
15
 * The intention of this interface is to provide in interface for 
16
 * ToolBarContributionItem so that the implementation can be replaced.
17
 * 
18
 * <p>
19
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
20
 * part of a work in progress. There is a guarantee neither that this API will
21
 * work nor that it will remain the same. Please do not use this API without
22
 * consulting with the Platform/UI team.
23
 * </p>
24
 * 
25
 * @since 3.2
26
 */
27
public interface IToolBarContributionItem extends IContributionItem {
28
29
    /**
30
     * Returns the current height of the corresponding cool item.
31
     * 
32
     * @return the current height
33
     */
34
    public int getCurrentHeight();
35
36
    /**
37
     * Returns the current width of the corresponding cool item.
38
     * 
39
     * @return the current size
40
     */
41
    public int getCurrentWidth();
42
43
    /**
44
     * Returns the minimum number of tool items to show in the cool item.
45
     * 
46
     * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
47
     *         if a value was not set
48
     * @see #setMinimumItemsToShow(int)
49
     */
50
    public int getMinimumItemsToShow();
51
    
52
    /**
53
     * Returns whether chevron support is enabled.
54
     * 
55
     * @return <code>true</code> if chevron support is enabled, <code>false</code>
56
     *         otherwise
57
     */
58
    public boolean getUseChevron();
59
    
60
    /**
61
     * Sets the current height of the cool item. Update(SIZE) should be called
62
     * to adjust the widget.
63
     * 
64
     * @param currentHeight
65
     *            the current height to set
66
     */
67
    public void setCurrentHeight(int currentHeight);
68
69
    /**
70
     * Sets the current width of the cool item. Update(SIZE) should be called
71
     * to adjust the widget.
72
     * 
73
     * @param currentWidth
74
     *            the current width to set
75
     */
76
    public void setCurrentWidth(int currentWidth);
77
78
    /**
79
     * Sets the minimum number of tool items to show in the cool item. If this
80
     * number is less than the total tool items, a chevron will appear and the
81
     * hidden tool items appear in a drop down menu. By default, all the tool
82
     * items are shown in the cool item.
83
     * 
84
     * @param minimumItemsToShow
85
     *            the minimum number of tool items to show.
86
     * @see #getMinimumItemsToShow()
87
     * @see #setUseChevron(boolean)
88
     */
89
    public void setMinimumItemsToShow(int minimumItemsToShow);
90
91
    /**
92
     * Enables or disables chevron support for the cool item. By default,
93
     * chevron support is enabled.
94
     * 
95
     * @param value
96
     *            <code>true</code> to enable chevron support, <code>false</code>
97
     *            otherwise.
98
     */
99
    public void setUseChevron(boolean value);
100
    
101
    /**
102
     * Returns the internal tool bar manager of the contribution item.
103
     * 
104
     * @return the tool bar manager, or <code>null</code> if one is not
105
     *         defined.
106
     * @see IToolBarManager
107
     */
108
    public IToolBarManager getToolBarManager();
109
    
110
    /**
111
     * Returns the parent contribution manager, or <code>null</code> if this 
112
     * contribution item is not currently added to a contribution manager.
113
     * 
114
     * @return the parent contribution manager, or <code>null</code>
115
     * 
116
     * TODO may not need this, getToolBarManager may be enough.
117
     */
118
    public IContributionManager getParent();
119
    
120
}
(-)src/org/eclipse/jface/window/ApplicationWindow.java (-12 / +32 lines)
Lines 16-25 Link Here
16
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.jface.action.CoolBarManager;
17
import org.eclipse.jface.action.CoolBarManager;
18
import org.eclipse.jface.action.ICoolBarManager;
18
import org.eclipse.jface.action.ICoolBarManager;
19
import org.eclipse.jface.action.IToolBarManager2;
19
import org.eclipse.jface.action.IToolBarManager;
20
import org.eclipse.jface.action.MenuManager;
20
import org.eclipse.jface.action.MenuManager;
21
import org.eclipse.jface.action.StatusLineManager;
21
import org.eclipse.jface.action.StatusLineManager;
22
import org.eclipse.jface.action.ToolBarManager;
22
import org.eclipse.jface.action.ToolBarManager;
23
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
24
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
23
import org.eclipse.jface.operation.IRunnableContext;
25
import org.eclipse.jface.operation.IRunnableContext;
24
import org.eclipse.jface.operation.IRunnableWithProgress;
26
import org.eclipse.jface.operation.IRunnableWithProgress;
25
import org.eclipse.jface.operation.ModalContext;
27
import org.eclipse.jface.operation.ModalContext;
Lines 79-85 Link Here
79
     *
81
     *
80
     * @see #addToolBar
82
     * @see #addToolBar
81
     */
83
     */
82
    private IToolBarManager2 toolBarManager = null;
84
    private IToolBarManager toolBarManager = null;
83
85
84
    /**
86
    /**
85
     * Status line manager, or <code>null</code> if none (default).
87
     * Status line manager, or <code>null</code> if none (default).
Lines 296-302 Link Here
296
                menuBarManager = null;
298
                menuBarManager = null;
297
            }
299
            }
298
            if (toolBarManager != null) {
300
            if (toolBarManager != null) {
299
                toolBarManager.dispose();
301
            	if (toolBarManager instanceof IToolBarManager2) 
302
            		((IToolBarManager2) toolBarManager).dispose();
303
            	else if (toolBarManager instanceof ToolBarManager)
304
            		((ToolBarManager) toolBarManager).dispose();
300
                toolBarManager = null;
305
                toolBarManager = null;
301
            }
306
            }
302
            if (statusLineManager != null) {
307
            if (statusLineManager != null) {
Lines 304-310 Link Here
304
                statusLineManager = null;
309
                statusLineManager = null;
305
            }
310
            }
306
            if (coolBarManager != null) {
311
            if (coolBarManager != null) {
307
                coolBarManager.dispose();
312
            	if (coolBarManager instanceof ICoolBarManager2)
313
            		((ICoolBarManager2) coolBarManager).dispose();
314
            	else if (coolBarManager instanceof CoolBarManager)
315
            		((CoolBarManager) coolBarManager).dispose();
308
                coolBarManager = null;
316
                coolBarManager = null;
309
            }
317
            }
310
            return true;
318
            return true;
Lines 416-422 Link Here
416
     * </p>
424
     * </p>
417
     * 
425
     * 
418
	 * <p>
426
	 * <p>
419
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
427
	 * <strong>EXPERIMENTAL</strong>. This method has been added as
420
	 * part of a work in progress. There is a guarantee neither that this API will
428
	 * part of a work in progress. There is a guarantee neither that this API will
421
	 * work nor that it will remain the same. Please do not use this API without
429
	 * work nor that it will remain the same. Please do not use this API without
422
	 * consulting with the Platform/UI team.
430
	 * consulting with the Platform/UI team.
Lines 425-431 Link Here
425
     * @return a tool bar manager
433
     * @return a tool bar manager
426
     * @since 3.2
434
     * @since 3.2
427
     */
435
     */
428
    protected IToolBarManager2 createToolBarManager2(int style) {
436
    protected IToolBarManager createToolBarManager2(int style) {
429
        return createToolBarManager(style);
437
        return createToolBarManager(style);
430
    }
438
    }
431
439
Lines 451-457 Link Here
451
     * </p>
459
     * </p>
452
     * 
460
     * 
453
	 * <p>
461
	 * <p>
454
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
462
	 * <strong>EXPERIMENTAL</strong>. This method has been added as
455
	 * part of a work in progress. There is a guarantee neither that this API will
463
	 * part of a work in progress. There is a guarantee neither that this API will
456
	 * work nor that it will remain the same. Please do not use this API without
464
	 * work nor that it will remain the same. Please do not use this API without
457
	 * consulting with the Platform/UI team.
465
	 * consulting with the Platform/UI team.
Lines 473-479 Link Here
473
     */
481
     */
474
    protected Control createToolBarControl(Composite parent) {
482
    protected Control createToolBarControl(Composite parent) {
475
        if (toolBarManager != null) {
483
        if (toolBarManager != null) {
476
            return toolBarManager.createControl2(parent);
484
        	if (toolBarManager instanceof IToolBarManager2) 
485
        		return ((IToolBarManager2) toolBarManager).createControl2(parent);
486
        	if (toolBarManager instanceof ToolBarManager) 
487
        		return ((ToolBarManager) toolBarManager).createControl(parent);
477
        }
488
        }
478
        return null;
489
        return null;
479
    }
490
    }
Lines 489-495 Link Here
489
     */
500
     */
490
    protected Control createCoolBarControl(Composite composite) {
501
    protected Control createCoolBarControl(Composite composite) {
491
        if (coolBarManager != null) {
502
        if (coolBarManager != null) {
492
            return coolBarManager.createControl2(composite);
503
        	if (coolBarManager instanceof ICoolBarManager2) 
504
        		return ((ICoolBarManager2) coolBarManager).createControl2(composite);
505
        	if (coolBarManager instanceof CoolBarManager) 
506
        		return ((CoolBarManager) coolBarManager).createControl(composite);
493
        }
507
        }
494
        return null;
508
        return null;
495
    }
509
    }
Lines 576-582 Link Here
576
     * @see #addToolBar(int)
590
     * @see #addToolBar(int)
577
	 * @since 3.2
591
	 * @since 3.2
578
     */
592
     */
579
    public IToolBarManager2 getToolBarManager2() {
593
    public IToolBarManager getToolBarManager2() {
580
        return toolBarManager;
594
        return toolBarManager;
581
    }
595
    }
582
596
Lines 622-628 Link Here
622
     */
636
     */
623
    protected Control getToolBarControl() {
637
    protected Control getToolBarControl() {
624
        if (toolBarManager != null) {
638
        if (toolBarManager != null) {
625
            return toolBarManager.getControl();
639
        	if (toolBarManager instanceof IToolBarManager2)
640
        		return ((IToolBarManager2) toolBarManager).getControl2();
641
        	if (toolBarManager instanceof ToolBarManager)
642
        		return ((ToolBarManager) toolBarManager).getControl();
626
        }
643
        }
627
        return null;
644
        return null;
628
    }
645
    }
Lines 638-644 Link Here
638
     */
655
     */
639
    protected Control getCoolBarControl() {
656
    protected Control getCoolBarControl() {
640
        if (coolBarManager != null) {
657
        if (coolBarManager != null) {
641
            return coolBarManager.getControl();
658
        	if (coolBarManager instanceof ICoolBarManager2)
659
        		return ((ICoolBarManager2) coolBarManager).getControl2();
660
        	if (coolBarManager instanceof CoolBarManager)
661
        		return ((CoolBarManager) coolBarManager).getControl();
642
        }
662
        }
643
        return null;
663
        return null;
644
    }
664
    }
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 18-23 Link Here
18
 org.eclipse.jface.dialogs.images,
18
 org.eclipse.jface.dialogs.images,
19
 org.eclipse.jface.fieldassist,
19
 org.eclipse.jface.fieldassist,
20
 org.eclipse.jface.images,
20
 org.eclipse.jface.images,
21
 org.eclipse.jface.internal.provisional.action,
21
 org.eclipse.jface.layout,
22
 org.eclipse.jface.layout,
22
 org.eclipse.jface.menus,
23
 org.eclipse.jface.menus,
23
 org.eclipse.jface.operation,
24
 org.eclipse.jface.operation,
(-)src/org/eclipse/jface/internal/provisional/action/CoolBarManager2.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.jface.internal.provisional.action;
13
14
import org.eclipse.jface.action.CoolBarManager;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.CoolBar;
18
19
/**
20
 * Extends <code>CoolBarManager</code> to implement <code>ICoolBarManager2</code>
21
 * @since 3.2
22
 */
23
public class CoolBarManager2 extends CoolBarManager implements ICoolBarManager2 {
24
25
    /**
26
     * Creates a new cool bar manager with the default style. Equivalent to
27
     * <code>CoolBarManager(SWT.NONE)</code>.
28
     */
29
    public CoolBarManager2() {
30
        super();
31
    }
32
33
    /**
34
     * Creates a cool bar manager for an existing cool bar control. This
35
     * manager becomes responsible for the control, and will dispose of it when
36
     * the manager is disposed.
37
     * 
38
     * @param coolBar
39
     *            the cool bar control
40
     */
41
    public CoolBarManager2(CoolBar coolBar) {
42
        super(coolBar);
43
    }
44
45
    /**
46
     * Creates a cool bar manager with the given SWT style. Calling <code>createControl</code>
47
     * will create the cool bar control.
48
     * 
49
     * @param style
50
     *            the cool bar item style; see
51
     *            {@link org.eclipse.swt.widgets.CoolBar CoolBar}for for valid
52
     *            style bits
53
     */
54
    public CoolBarManager2(int style) {
55
       super(style);
56
    }
57
    
58
    /**
59
     * Creates and returns this manager's cool bar control. Does not create a
60
     * new control if one already exists.
61
     * 
62
	 * <p>
63
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
64
	 * part of a work in progress. There is a guarantee neither that this API will
65
	 * work nor that it will remain the same. Please do not use this API without
66
	 * consulting with the Platform/UI team.
67
	 * </p>
68
     * 
69
     * @param parent
70
     *            the parent control
71
     * @return the cool bar control
72
	 * @since 3.2
73
     */
74
    public Control createControl2(Composite parent) {
75
        return createControl(parent);
76
    }
77
    
78
    /**
79
     * Returns the control for this manager.
80
     * 
81
	 * <p>
82
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
83
	 * part of a work in progress. There is a guarantee neither that this API will
84
	 * work nor that it will remain the same. Please do not use this API without
85
	 * consulting with the Platform/UI team.
86
	 * </p>
87
     * 
88
     * @return the control, or <code>null</code> if none
89
	 * @since 3.2
90
     */
91
    public Control getControl2() {
92
        return getControl();
93
    }
94
95
}
(-)src/org/eclipse/jface/internal/provisional/action/ToolBarManager2.java (+161 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
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
/**
23
 * Extends <code>ToolBarManager</code> to implement <code>IToolBarManager2</code>.
24
 * 
25
 * @since 3.2
26
 */
27
public class ToolBarManager2 extends ToolBarManager implements IToolBarManager2 {
28
29
	/**
30
	 * A collection of objects listening to changes to this manager. This
31
	 * collection is <code>null</code> if there are no listeners.
32
	 */
33
	private transient ListenerList listenerList = null;
34
	
35
	/**
36
	 * Creates a new tool bar manager with the default SWT button style. Use the
37
	 * <code>createControl</code> method to create the tool bar control.
38
	 */
39
	public ToolBarManager2() {
40
		super();
41
	}
42
43
	/**
44
	 * Creates a tool bar manager with the given SWT button style. Use the
45
	 * <code>createControl</code> method to create the tool bar control.
46
	 * 
47
	 * @param style
48
	 *            the tool bar item style
49
	 * @see org.eclipse.swt.widgets.ToolBar for valid style bits
50
	 */
51
	public ToolBarManager2(int style) {
52
		super(style);
53
	}
54
55
	/**
56
	 * Creates a tool bar manager for an existing tool bar control. This manager
57
	 * becomes responsible for the control, and will dispose of it when the
58
	 * manager is disposed.
59
	 * 
60
	 * @param toolbar
61
	 *            the tool bar control
62
	 */
63
	public ToolBarManager2(ToolBar toolbar) {
64
		super(toolbar);
65
	}
66
	
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.jface.action.IToolBarManager2#createControl2(org.eclipse.swt.widgets.Composite)
69
	 */
70
	public Control createControl2(Composite parent) {
71
		return createControl(parent);
72
	}
73
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.jface.action.IToolBarManager2#getControl2()
76
	 */
77
	public Control getControl2() {
78
		return getControl();
79
	}
80
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.jface.action.IToolBarManager2#getItemCount()
83
	 */
84
	public int getItemCount() {
85
		ToolBar toolBar = getControl();
86
		if (toolBar == null || toolBar.isDisposed())
87
			return 0;
88
		return toolBar.getItemCount();
89
	}
90
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.jface.action.IToolBarManager2#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
93
	 */
94
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
95
		if (listenerList == null) {
96
			listenerList = new ListenerList(ListenerList.IDENTITY);
97
		}
98
99
		listenerList.add(listener);
100
	}
101
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.jface.action.IToolBarManager2#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
104
	 */
105
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
106
		if (listenerList != null) {
107
			listenerList.remove(listener);
108
109
			if (listenerList.isEmpty()) {
110
				listenerList = null;
111
			}
112
		}
113
	}
114
	
115
	/*
116
	 * Returns the listeners attached to this event manager.
117
	 * The listeners currently attached; may be empty, but never
118
	 * null.
119
	 */
120
	protected final Object[] getListeners() {
121
		final ListenerList list = listenerList;
122
		if (list == null) {
123
			return new Object[0];
124
		}
125
126
		return list.getListeners();
127
	}
128
129
	/*
130
	 * Notifies any property change listeners that a property has changed. Only
131
	 * listeners registered at the time this method is called are notified.
132
	 */
133
	private void firePropertyChange(final PropertyChangeEvent event) {
134
		final Object[] list = getListeners();
135
		for (int i = 0; i < list.length; ++i) {
136
			((IPropertyChangeListener) list[i]).propertyChange(event);
137
		}
138
	}
139
140
	/*
141
	 * Notifies any property change listeners that a property has changed. Only
142
	 * listeners registered at the time this method is called are notified. This
143
	 * method avoids creating an event object if there are no listeners
144
	 * registered, but calls firePropertyChange(PropertyChangeEvent) if there are.
145
	 */
146
	private void firePropertyChange(final String propertyName,
147
			final Object oldValue, final Object newValue) {
148
		if (listenerList != null) {
149
			firePropertyChange(new PropertyChangeEvent(this, propertyName,
150
					oldValue, newValue));
151
		}
152
	}
153
154
	/* (non-Javadoc)
155
	 * @see org.eclipse.jface.action.ToolBarManager#relayout(org.eclipse.swt.widgets.ToolBar, int, int)
156
	 */
157
	protected void relayout(ToolBar layoutBar, int oldCount, int newCount) {
158
		super.relayout(layoutBar, oldCount, newCount);
159
		firePropertyChange(PROP_LAYOUT, new Integer(oldCount), new Integer(newCount));
160
	}
161
}
(-)src/org/eclipse/jface/internal/provisional/action/ToolBarContributionItem2.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.jface.internal.provisional.action;
13
14
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.action.ToolBarContributionItem;
16
17
/**
18
 * Extends <code>ToolBarContributionItem</code> to implement <code>IToolBarContributionItem</code>.
19
 * 
20
 * @since 3.2
21
 */
22
public class ToolBarContributionItem2 extends ToolBarContributionItem implements
23
		IToolBarContributionItem {
24
25
	/**
26
	 * 
27
	 */
28
	public ToolBarContributionItem2() {
29
		super();
30
	}
31
32
	/**
33
	 * @param toolBarManager
34
	 */
35
	public ToolBarContributionItem2(IToolBarManager toolBarManager) {
36
		super(toolBarManager);
37
	}
38
39
	/**
40
	 * @param toolBarManager
41
	 * @param id
42
	 */
43
	public ToolBarContributionItem2(IToolBarManager toolBarManager, String id) {
44
		super(toolBarManager, id);
45
	}
46
47
}
(-)src/org/eclipse/jface/internal/provisional/action/IToolBarContributionItem.java (+124 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.jface.internal.provisional.action;
13
14
import org.eclipse.jface.action.IContributionItem;
15
import org.eclipse.jface.action.IContributionManager;
16
import org.eclipse.jface.action.IToolBarManager;
17
18
/**
19
 * The intention of this interface is to provide in interface for 
20
 * ToolBarContributionItem so that the implementation can be replaced.
21
 * 
22
 * <p>
23
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
24
 * part of a work in progress. There is a guarantee neither that this API will
25
 * work nor that it will remain the same. Please do not use this API without
26
 * consulting with the Platform/UI team.
27
 * </p>
28
 * 
29
 * @since 3.2
30
 */
31
public interface IToolBarContributionItem extends IContributionItem {
32
33
    /**
34
     * Returns the current height of the corresponding cool item.
35
     * 
36
     * @return the current height
37
     */
38
    public int getCurrentHeight();
39
40
    /**
41
     * Returns the current width of the corresponding cool item.
42
     * 
43
     * @return the current size
44
     */
45
    public int getCurrentWidth();
46
47
    /**
48
     * Returns the minimum number of tool items to show in the cool item.
49
     * 
50
     * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
51
     *         if a value was not set
52
     * @see #setMinimumItemsToShow(int)
53
     */
54
    public int getMinimumItemsToShow();
55
    
56
    /**
57
     * Returns whether chevron support is enabled.
58
     * 
59
     * @return <code>true</code> if chevron support is enabled, <code>false</code>
60
     *         otherwise
61
     */
62
    public boolean getUseChevron();
63
    
64
    /**
65
     * Sets the current height of the cool item. Update(SIZE) should be called
66
     * to adjust the widget.
67
     * 
68
     * @param currentHeight
69
     *            the current height to set
70
     */
71
    public void setCurrentHeight(int currentHeight);
72
73
    /**
74
     * Sets the current width of the cool item. Update(SIZE) should be called
75
     * to adjust the widget.
76
     * 
77
     * @param currentWidth
78
     *            the current width to set
79
     */
80
    public void setCurrentWidth(int currentWidth);
81
82
    /**
83
     * Sets the minimum number of tool items to show in the cool item. If this
84
     * number is less than the total tool items, a chevron will appear and the
85
     * hidden tool items appear in a drop down menu. By default, all the tool
86
     * items are shown in the cool item.
87
     * 
88
     * @param minimumItemsToShow
89
     *            the minimum number of tool items to show.
90
     * @see #getMinimumItemsToShow()
91
     * @see #setUseChevron(boolean)
92
     */
93
    public void setMinimumItemsToShow(int minimumItemsToShow);
94
95
    /**
96
     * Enables or disables chevron support for the cool item. By default,
97
     * chevron support is enabled.
98
     * 
99
     * @param value
100
     *            <code>true</code> to enable chevron support, <code>false</code>
101
     *            otherwise.
102
     */
103
    public void setUseChevron(boolean value);
104
    
105
    /**
106
     * Returns the internal tool bar manager of the contribution item.
107
     * 
108
     * @return the tool bar manager, or <code>null</code> if one is not
109
     *         defined.
110
     * @see IToolBarManager
111
     */
112
    public IToolBarManager getToolBarManager();
113
    
114
    /**
115
     * Returns the parent contribution manager, or <code>null</code> if this 
116
     * contribution item is not currently added to a contribution manager.
117
     * 
118
     * @return the parent contribution manager, or <code>null</code>
119
     * 
120
     * TODO may not need this, getToolBarManager may be enough.
121
     */
122
    public IContributionManager getParent();
123
    
124
}
(-)src/org/eclipse/jface/internal/provisional/action/ICoolBarManager2.java (+127 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.jface.internal.provisional.action;
12
13
import org.eclipse.jface.action.IContributionItem;
14
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Control;
17
18
/**
19
 * Extends <code>ICoolBarManager</code> to allow clients to be decoupled
20
 * from the actual kind of control used.
21
 * 
22
 * @since 3.2
23
 */
24
public interface ICoolBarManager2 extends ICoolBarManager {
25
26
    /**
27
     * Creates and returns this manager's control. Does not create a
28
     * new control if one already exists.
29
     * 
30
	 * <p>
31
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
32
	 * part of a work in progress. There is a guarantee neither that this API will
33
	 * work nor that it will remain the same. Please do not use this API without
34
	 * consulting with the Platform/UI team.
35
	 * </p>
36
     * 
37
     * @param parent
38
     *            the parent control
39
     * @return the control
40
	 * @since 3.2
41
     */
42
    public Control createControl2(Composite parent);
43
44
    /**
45
     * Returns the bar control for this manager.
46
     * 
47
	 * <p>
48
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
49
	 * part of a work in progress. There is a guarantee neither that this API will
50
	 * work nor that it will remain the same. Please do not use this API without
51
	 * consulting with the Platform/UI team.
52
	 * </p>
53
     *  
54
     * @return the bar control, or <code>null</code> if none
55
	 * @since 3.2
56
     */
57
    public Control getControl2();
58
59
    /**
60
     * Synchronizes the visual order of the cool items in the control with this
61
     * manager's internal data structures. This method should be called before
62
     * requesting the order of the contribution items to ensure that the order
63
     * is accurate.
64
     * <p>
65
     * Note that <code>update()</code> and <code>refresh()</code> are
66
     * converses: <code>update()</code> changes the visual order to match the
67
     * internal structures, and <code>refresh</code> changes the internal
68
     * structures to match the visual order.
69
     * </p>
70
     * 
71
	 * <p>
72
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
73
	 * part of a work in progress. There is a guarantee neither that this API will
74
	 * work nor that it will remain the same. Please do not use this API without
75
	 * consulting with the Platform/UI team.
76
	 * </p>
77
     * 
78
	 * @since 3.2
79
     */
80
    public void refresh();
81
    
82
    /**
83
	 * Disposes the resources for this manager.
84
     * 
85
	 * <p>
86
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
87
	 * part of a work in progress. There is a guarantee neither that this API will
88
	 * work nor that it will remain the same. Please do not use this API without
89
	 * consulting with the Platform/UI team.
90
	 * </p>
91
     * 
92
     * @since 3.2 
93
     */
94
    public void dispose();
95
96
    /**
97
     * Restores the canonical order of this cool bar manager. The canonical
98
     * order is the order in which the contribution items where added.
99
     * 
100
	 * <p>
101
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
102
	 * part of a work in progress. There is a guarantee neither that this API will
103
	 * work nor that it will remain the same. Please do not use this API without
104
	 * consulting with the Platform/UI team.
105
	 * </p>
106
     * 
107
	 * @since 3.2     
108
	 */
109
    public void resetItemOrder();
110
111
    /**
112
     * Replaces the current items with the given items.
113
     * Forces an update.
114
     * 
115
	 * <p>
116
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
117
	 * part of a work in progress. There is a guarantee neither that this API will
118
	 * work nor that it will remain the same. Please do not use this API without
119
	 * consulting with the Platform/UI team.
120
	 * </p>
121
     * 
122
     * @param newItems the items with which to replace the current items
123
     * @since 3.2
124
	 */
125
    public void setItems(IContributionItem[] newItems);
126
127
}
(-)src/org/eclipse/jface/internal/provisional/action/IToolBarManager2.java (+114 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.jface.internal.provisional.action;
12
13
import org.eclipse.jface.action.IContributionManagerOverrides;
14
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.action.ToolBarManager;
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.ToolBar;
20
21
/**
22
 * The <code>IToolBarManager2</code> interface provides protocol for managing
23
 * contributions to a tool bar. It extends <code>IToolBarManager</code>
24
 * and provides a <code>dispose</code> method.
25
 * 
26
 * <p>
27
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
28
 * part of a work in progress. There is a guarantee neither that this API will
29
 * work nor that it will remain the same. Please do not use this API without
30
 * consulting with the Platform/UI team.
31
 * </p>
32
 * 
33
 * This package also provides a concrete tool bar manager implementation,
34
 * {@link ToolBarManager <code>ToolBarManager</code>}.
35
 * </p>
36
 * 
37
 * @since 3.2
38
 */
39
public interface IToolBarManager2 extends IToolBarManager {
40
	
41
	/**
42
	 * The property id for changes to the control's layout
43
	 */
44
	public static final String PROP_LAYOUT = "PROP_LAYOUT"; //$NON-NLS-1$
45
	
46
    /**
47
     * Creates and returns this manager's toolbar control. Does not create a
48
     * new control if one already exists.
49
     * 
50
     * @param parent
51
     *            the parent control
52
     * @return the toolbar control
53
     */
54
	public ToolBar createControl(Composite parent);
55
	
56
    /**
57
     * Creates and returns this manager's control. Does not create a
58
     * new control if one already exists.
59
     * 
60
     * @param parent
61
     *            the parent control
62
     * @return the control
63
     */
64
	public Control createControl2(Composite parent);
65
	
66
    /**
67
     * Returns the toolbar control for this manager.
68
     * 
69
     * @return the toolbar control, or <code>null</code> if none
70
     */
71
	public ToolBar getControl();
72
	
73
    /**
74
     * Returns the control for this manager.
75
     * 
76
     * @return the control, or <code>null</code> if none
77
     */
78
	public Control getControl2();
79
80
    /**
81
	 * Disposes the resources for this manager.
82
     */
83
	public void dispose();
84
	
85
	/**
86
	 * Returns the item count of the control used 
87
	 * by this manager.
88
	 * 
89
	 * @return the number of items in the control
90
	 */
91
	public int getItemCount();
92
	
93
	/**
94
	 * Registers a property change listner with this manager.
95
	 * 
96
	 * @param listener
97
	 */
98
	public void addPropertyChangeListener(IPropertyChangeListener listener);
99
	
100
	/**
101
	 * Removes a property change listner from this manager.
102
	 * 
103
	 * @param listener
104
	 */
105
	public void removePropertyChangeListener(IPropertyChangeListener listener);
106
	
107
    /**
108
     * Sets the overrides for this contribution manager
109
     * 
110
     * @param newOverrides the overrides for the items of this manager
111
     */
112
    public void setOverrides(IContributionManagerOverrides newOverrides);
113
	
114
}
(-)plugin.xml (-3 / +4 lines)
Lines 46-54 Link Here
46
            class="org.eclipse.ui.examples.presentation.wrappedtabs.WrappedTabsPresentationFactory"
46
            class="org.eclipse.ui.examples.presentation.wrappedtabs.WrappedTabsPresentationFactory"
47
            name="Wrapped tabs presentation"
47
            name="Wrapped tabs presentation"
48
            id="org.eclipse.ui.examples.presentation.wrappedtabs"/>
48
            id="org.eclipse.ui.examples.presentation.wrappedtabs"/>
49
   </extension>
50
      <extension
51
         point="org.eclipse.ui.presentationFactories">
52
      <factory
49
      <factory
53
            class="org.eclipse.ui.internal.presentations.defaultpresentation.NativePresentationFactory"
50
            class="org.eclipse.ui.internal.presentations.defaultpresentation.NativePresentationFactory"
54
            name="Native Tabs"
51
            name="Native Tabs"
Lines 61-66 Link Here
61
            class="org.eclipse.ui.examples.presentation.sidewinder.SideWinderPresentationFactory"
58
            class="org.eclipse.ui.examples.presentation.sidewinder.SideWinderPresentationFactory"
62
            id="org.eclipse.ui.examples.presentation.factory2"
59
            id="org.eclipse.ui.examples.presentation.factory2"
63
            name="Side Winder"/>
60
            name="Side Winder"/>
61
      <factory
62
            class="org.eclipse.ui.examples.presentation.customtoolbar.CustomToolBarPresentationFactory"
63
            id="org.eclipse.ui.examples.presentation.customtoolbar"
64
            name="Custom Toolbar"/>
64
   </extension>
65
   </extension>
65
66
66
<!-- =================================================================================== -->
67
<!-- =================================================================================== -->
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/ISContributionItem.java (+8 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.jface.action.IContributionItem;
4
5
public interface ISContributionItem extends IContributionItem {
6
	public void fill(SCoolBar parent, int index);
7
	public void fill(SToolBar parent, int index);
8
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SToolBarManager2.java (+512 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
5
6
import java.util.ArrayList;
7
import java.util.Iterator;
8
9
import org.eclipse.core.runtime.ListenerList;
10
import org.eclipse.jface.action.ActionContributionItem;
11
import org.eclipse.jface.action.ContributionManager;
12
import org.eclipse.jface.action.IAction;
13
import org.eclipse.jface.action.IContributionItem;
14
import org.eclipse.jface.action.MenuManager;
15
import org.eclipse.jface.action.SubContributionItem;
16
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
17
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.accessibility.ACC;
21
import org.eclipse.swt.accessibility.AccessibleAdapter;
22
import org.eclipse.swt.accessibility.AccessibleEvent;
23
import org.eclipse.swt.accessibility.AccessibleListener;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Menu;
27
import org.eclipse.swt.widgets.ToolBar;
28
29
public class SToolBarManager2 extends ContributionManager implements IToolBarManager2 {
30
31
	/**
32
	 * The tool bar items style; <code>SWT.NONE</code> by default.
33
	 */
34
	private int itemStyle = SWT.NONE;
35
36
	/**
37
	 * The tool bat control; <code>null</code> before creation and after
38
	 * disposal.
39
	 */
40
	private Control toolBar = null;
41
42
	/**
43
	 * The menu manager to the context menu associated with the toolbar.
44
	 * 
45
	 * @since 3.0
46
	 */
47
	private MenuManager contextMenuManager = null;
48
	
49
	/**
50
	 * A collection of objects listening to changes to this manager. This
51
	 * collection is <code>null</code> if there are no listeners.
52
	 */
53
	private transient ListenerList listenerList = null;
54
55
	/**
56
	 * Creates a new tool bar manager with the default SWT button style. Use the
57
	 * <code>createControl</code> method to create the tool bar control.
58
	 */
59
	public SToolBarManager2() {
60
		//Do nothing if there are no parameters
61
	}
62
63
	/**
64
	 * Creates a tool bar manager with the given SWT button style. Use the
65
	 * <code>createControl</code> method to create the tool bar control.
66
	 * 
67
	 * @param style
68
	 *            the tool bar item style
69
	 * @see org.eclipse.swt.widgets.ToolBar for valid style bits
70
	 */
71
	public SToolBarManager2(int style) {
72
		itemStyle = style;
73
	}
74
75
	/**
76
	 * Creates a tool bar manager for an existing tool bar control. This manager
77
	 * becomes responsible for the control, and will dispose of it when the
78
	 * manager is disposed.
79
	 * 
80
	 * @param toolbar
81
	 *            the tool bar control
82
	 */
83
	public SToolBarManager2(ToolBar toolbar) {
84
		this();
85
		this.toolBar = toolbar;
86
	}
87
88
    public void add(IAction action) {
89
        super.add(new SActionContributionItem(action));
90
    }
91
92
    public void add(IContributionItem item) {
93
    	/*if (item instanceof Separator) {
94
    		Separator separator = (Separator)item;
95
    		String label = separator.getGroupName();
96
    		SActionContributionItem sItem = new SActionContributionItem();
97
    		IAction action = sItem.getAction();
98
    		action.setText(label);
99
    		item = sItem;
100
    	}
101
    	if (item instanceof ActionContributionItem) {
102
    		SActionContributionItem proxyItem = 
103
    			new SActionContributionItem(((ActionContributionItem)item).getAction());
104
    		item = proxyItem;
105
    	}*/
106
    	if (item instanceof SubContributionItem) {
107
    		SubContributionItem wrapper = (SubContributionItem)item;
108
    		item = wrapper.getInnerItem();
109
    		add(item);
110
    	}
111
    	else
112
    		super.add(item);
113
    }
114
115
	/**
116
	 * Creates and returns this manager's tool bar control. Does not create a
117
	 * new control if one already exists.
118
	 * 
119
	 * @param parent
120
	 *            the parent control
121
	 * @return the tool bar control
122
	 */
123
	public ToolBar createControl(Composite parent) {
124
		return null;
125
	}
126
	
127
	/* (non-Javadoc)
128
	 * @see org.eclipse.jface.action.IToolBarManager2#createControl2(org.eclipse.swt.widgets.Composite)
129
	 */
130
	public Control createControl2(Composite parent) {
131
		if (!toolBarExist() && parent != null) {
132
			toolBar = new SToolBar(parent, itemStyle);
133
			((SToolBar)toolBar).setSkin(new HannoverGlobalToolBarSkin());
134
			toolBar.setMenu(getContextMenuControl());
135
			update(false);
136
			
137
			toolBar.getAccessible().addAccessibleListener(getAccessibleListener());
138
		}
139
		return toolBar;
140
	}
141
142
	/**
143
	 * Get the accessible listener for the tool bar.
144
	 * 
145
	 * @return AccessibleListener
146
	 * 
147
	 * @since 3.1
148
	 */
149
	private AccessibleListener getAccessibleListener() {
150
		return new AccessibleAdapter() {
151
			public void getName(AccessibleEvent e) {
152
				if (e.childID != ACC.CHILDID_SELF) {
153
					SToolItem item = ((SToolBar)toolBar).getItem(e.childID);
154
					if (item != null) {
155
						String toolTip = item.getToolTipText();
156
						if (toolTip != null) {
157
							e.result = toolTip;
158
						}
159
					}
160
				}
161
			}
162
		};
163
164
	}
165
166
	/**
167
	 * Disposes of this tool bar manager and frees all allocated SWT resources.
168
	 * Notifies all contribution items of the dispose. Note that this method
169
	 * does not clean up references between this tool bar manager and its
170
	 * associated contribution items. Use <code>removeAll</code> for that
171
	 * purpose.
172
	 */
173
	public void dispose() {
174
175
		if (toolBarExist()) {
176
			toolBar.dispose();
177
		}
178
		toolBar = null;
179
180
		IContributionItem[] items = getItems();
181
		for (int i = 0; i < items.length; i++) {
182
			items[i].dispose();
183
		}
184
185
		if (getContextMenuManager() != null) {
186
			getContextMenuManager().dispose();
187
			setContextMenuManager(null);
188
		}
189
	}
190
191
	/* (non-Javadoc)
192
	 * @see org.eclipse.jface.action.IToolBarManager2#getControl()
193
	 */
194
	public ToolBar getControl() {
195
		return null;
196
	}
197
198
	/* (non-Javadoc)
199
	 * @see org.eclipse.jface.action.IToolBarManager2#getControl2()
200
	 */
201
	public Control getControl2() {
202
		return toolBar;
203
	}
204
	
205
	/**
206
	 * Re-lays out the tool bar.
207
	 * <p>
208
	 * The default implementation of this framework method re-lays out the
209
	 * parent when the number of items crosses the zero threshold. Subclasses
210
	 * should override this method to implement their own re-layout strategy
211
	 * 
212
	 * @param layoutBar
213
	 *            the tool bar control
214
	 * @param oldCount
215
	 *            the old number of items
216
	 * @param newCount
217
	 *            the new number of items
218
	 */
219
	protected void relayout(SToolBar layoutBar, int oldCount, int newCount) {
220
		if ((oldCount == 0) != (newCount == 0))
221
			layoutBar.getParent().layout();
222
		firePropertyChange(PROP_LAYOUT, new Integer(oldCount), new Integer(newCount));
223
	}
224
225
	/**
226
	 * Returns whether the tool bar control is created and not disposed.
227
	 * 
228
	 * @return <code>true</code> if the control is created and not disposed,
229
	 *         <code>false</code> otherwise
230
	 */
231
	private boolean toolBarExist() {
232
		return toolBar != null && !toolBar.isDisposed();
233
	}
234
235
	/*
236
	 * (non-Javadoc) Method declared on IContributionManager.
237
	 */
238
	public void update(boolean force) {
239
240
		//	long startTime= 0;
241
		//	if (DEBUG) {
242
		//		dumpStatistics();
243
		//		startTime= (new Date()).getTime();
244
		//	}
245
246
		if (isDirty() || force) {
247
248
			if (toolBarExist()) {
249
250
				int oldCount = ((SToolBar)toolBar).getItemCount();
251
252
				// clean contains all active items without double separators
253
				IContributionItem[] items = getItems();
254
				ArrayList clean = new ArrayList(items.length);
255
				IContributionItem separator = null;
256
				//			long cleanStartTime= 0;
257
				//			if (DEBUG) {
258
				//				cleanStartTime= (new Date()).getTime();
259
				//			}
260
				for (int i = 0; i < items.length; ++i) {
261
					IContributionItem ci = items[i];
262
					if (!ci.isVisible())
263
						continue;
264
					if (ci.isSeparator()) {
265
						// delay creation until necessary
266
						// (handles both adjacent separators, and separator at
267
						// end)
268
						separator = ci;
269
					} else {
270
						if (separator != null) {
271
							if (clean.size() > 0) // no separator if first item
272
								clean.add(separator);
273
							separator = null;
274
						}
275
						clean.add(ci);
276
					}
277
				}
278
				//			if (DEBUG) {
279
				//				System.out.println(" Time needed to build clean vector: " +
280
				// ((new Date()).getTime() - cleanStartTime));
281
				//			}
282
283
				// determine obsolete items (removed or non active)
284
				SToolItem[] mi = ((SToolBar)toolBar).getItems();
285
				ArrayList toRemove = new ArrayList(mi.length);
286
				for (int i = 0; i < mi.length; i++) {
287
					Object data = mi[i].getData();
288
					if (data == null
289
							|| !clean.contains(data)
290
							|| (data instanceof IContributionItem && ((IContributionItem) data)
291
									.isDynamic())) {
292
						toRemove.add(mi[i]);
293
					}
294
				}
295
296
				// Turn redraw off if the number of items to be added
297
				// is above a certain threshold, to minimize flicker,
298
				// otherwise the toolbar can be seen to redraw after each item.
299
				// Do this before any modifications are made.
300
				// We assume each contribution item will contribute at least one
301
				// toolbar item.
302
				boolean useRedraw = (clean.size() - (mi.length - toRemove
303
						.size())) >= 3;
304
                try {
305
                    if (useRedraw) {
306
                        toolBar.setRedraw(false);
307
                    }
308
309
                    // remove obsolete items
310
                    for (int i = toRemove.size(); --i >= 0;) {
311
                        SToolItem item = (SToolItem) toRemove.get(i);
312
                        if (!item.isDisposed()) {
313
                            Control ctrl = item.getControl();
314
                            if (ctrl != null) {
315
                                item.setControl(null);
316
                                ctrl.dispose();
317
                            }
318
                            item.dispose();
319
                        }
320
                    }
321
322
                    // add new items
323
                    IContributionItem src, dest;
324
                    mi = ((SToolBar)toolBar).getItems();
325
                    int srcIx = 0;
326
                    int destIx = 0;
327
                    for (Iterator e = clean.iterator(); e.hasNext();) {
328
                        src = (IContributionItem) e.next();
329
330
                        // get corresponding item in SWT widget
331
                        if (srcIx < mi.length)
332
                            dest = (IContributionItem) mi[srcIx].getData();
333
                        else
334
                            dest = null;
335
336
                        if (dest != null && src.equals(dest)) {
337
                            srcIx++;
338
                            destIx++;
339
                            continue;
340
                        }
341
342
                        if (dest != null && dest.isSeparator()
343
                                && src.isSeparator()) {
344
                            mi[srcIx].setData(src);
345
                            srcIx++;
346
                            destIx++;
347
                            continue;
348
                        }
349
350
                        int start = ((SToolBar)toolBar).getItemCount();
351
                        
352
                        if (src instanceof ISContributionItem)
353
                        	((ISContributionItem)src).fill(((SToolBar)toolBar), destIx);
354
                        else if (src instanceof ActionContributionItem) {
355
                    		SActionContributionItem proxyItem = 
356
                    			new SActionContributionItem(((ActionContributionItem)src).getAction());
357
                    		proxyItem.fill(((SToolBar)toolBar), destIx);
358
                    	}
359
                        
360
                        int newItems = ((SToolBar)toolBar).getItemCount() - start;
361
                        for (int i = 0; i < newItems; i++) {
362
                            SToolItem item = ((SToolBar)toolBar).getItem(destIx++);
363
                            item.setData(src);
364
                        }
365
                    }
366
367
                    // remove any old tool items not accounted for
368
                    for (int i = mi.length; --i >= srcIx;) {
369
                        SToolItem item = mi[i];
370
                        if (!item.isDisposed()) {
371
                            Control ctrl = item.getControl();
372
                            if (ctrl != null) {
373
                                item.setControl(null);
374
                                ctrl.dispose();
375
                            }
376
                            item.dispose();
377
                        }
378
                    }
379
380
                    setDirty(false);
381
382
                    // turn redraw back on if we turned it off above
383
                } finally {
384
                    if (useRedraw) {
385
                        toolBar.setRedraw(true);
386
                    }
387
                }
388
389
				int newCount = ((SToolBar)toolBar).getItemCount();
390
				relayout((SToolBar)toolBar, oldCount, newCount);
391
			}
392
393
		}
394
395
		//	if (DEBUG) {
396
		//		System.out.println(" Time needed for update: " + ((new
397
		// Date()).getTime() - startTime));
398
		//		System.out.println();
399
		//	}
400
	}
401
402
	/**
403
	 * Returns the control of the Menu Manager. If the menu manager does not
404
	 * have a control then one is created.
405
	 * 
406
	 * @return menu widget associated with manager
407
	 */
408
	private Menu getContextMenuControl() {
409
		if ((contextMenuManager != null) && (toolBar != null)) {
410
			Menu menuWidget = contextMenuManager.getMenu();
411
			if ((menuWidget == null) || (menuWidget.isDisposed())) {
412
				menuWidget = contextMenuManager.createContextMenu(toolBar);
413
			}
414
			return menuWidget;
415
		}
416
		return null;
417
	}
418
419
	/**
420
	 * Returns the context menu manager for this tool bar manager.
421
	 * 
422
	 * @return the context menu manager, or <code>null</code> if none
423
	 * @since 3.0
424
	 */
425
	public MenuManager getContextMenuManager() {
426
		return contextMenuManager;
427
	}
428
429
	/**
430
	 * Sets the context menu manager for this tool bar manager to the given menu
431
	 * manager. If the tool bar control exists, it also adds the menu control to
432
	 * the tool bar.
433
	 * 
434
	 * @param contextMenuManager
435
	 *            the context menu manager, or <code>null</code> if none
436
	 * @since 3.0
437
	 */
438
	public void setContextMenuManager(MenuManager contextMenuManager) {
439
		this.contextMenuManager = contextMenuManager;
440
		if (toolBar != null) {
441
			toolBar.setMenu(getContextMenuControl());
442
		}
443
	}
444
445
	public int getItemCount() {
446
		return 1;
447
	}
448
449
	/* (non-Javadoc)
450
	 * @see org.eclipse.jface.action.IToolBarManager2#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
451
	 */
452
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
453
		if (listenerList == null) {
454
			listenerList = new ListenerList(ListenerList.IDENTITY);
455
		}
456
457
		listenerList.add(listener);
458
	}
459
460
	/* (non-Javadoc)
461
	 * @see org.eclipse.jface.action.IToolBarManager2#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
462
	 */
463
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
464
		if (listenerList != null) {
465
			listenerList.remove(listener);
466
467
			if (listenerList.isEmpty()) {
468
				listenerList = null;
469
			}
470
		}
471
	}
472
	
473
	/*
474
	 * Returns the listeners attached to this event manager.
475
	 * The listeners currently attached; may be empty, but never
476
	 * null.
477
	 */
478
	protected final Object[] getListeners() {
479
		final ListenerList list = listenerList;
480
		if (list == null) {
481
			return new Object[0];
482
		}
483
484
		return list.getListeners();
485
	}
486
487
	/*
488
	 * Notifies any property change listeners that a property has changed. Only
489
	 * listeners registered at the time this method is called are notified.
490
	 */
491
	private void firePropertyChange(final PropertyChangeEvent event) {
492
		final Object[] list = getListeners();
493
		for (int i = 0; i < list.length; ++i) {
494
			((IPropertyChangeListener) list[i]).propertyChange(event);
495
		}
496
	}
497
498
	/*
499
	 * Notifies any property change listeners that a property has changed. Only
500
	 * listeners registered at the time this method is called are notified. This
501
	 * method avoids creating an event object if there are no listeners
502
	 * registered, but calls firePropertyChange(PropertyChangeEvent) if there are.
503
	 */
504
	private void firePropertyChange(final String propertyName,
505
			final Object oldValue, final Object newValue) {
506
		if (listenerList != null) {
507
			firePropertyChange(new PropertyChangeEvent(this, propertyName,
508
					oldValue, newValue));
509
		}
510
	}
511
	
512
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SToolItem.java (+731 lines)
Added Link Here
1
/*
2
*	Copyright IBM Corporation 2003, 2005
3
*	All rights reserved.
4
*	US Government Users Restricted Rights - Use, duplication or disclosure
5
*	restricted by GS ADP Schedule Contract with IBM Corp.
6
*/
7
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
8
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.SelectionListener;
11
import org.eclipse.swt.graphics.FontMetrics;
12
import org.eclipse.swt.graphics.GC;
13
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.swt.widgets.Item;
19
import org.eclipse.swt.widgets.TypedListener;
20
 
21
public class SToolItem extends Item {
22
	SToolBar parent;
23
	Control control;
24
	int index;
25
	String toolTipText;
26
	Image disabledImage;
27
	Image hotImage;
28
	Image pressedImage;
29
	boolean enabled = true;
30
	boolean selected;
31
	int separatorWidth;
32
	int width = -1;
33
	Point arrowSize = new Point(5, 5);
34
	int state;
35
	int arrowState;
36
37
	/** the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT */
38
	private int align = SWT.LEFT;
39
40
	Rectangle itemRect = new Rectangle(0,0,0,0);
41
	Rectangle arrowRect;
42
43
	/**
44
	 * @param parent
45
	 * @param style
46
	 */
47
	public SToolItem(SToolBar parent, int style) {
48
		super(parent, style);
49
		this.parent = parent;
50
		parent.createItem(this, parent.getItemCount());
51
	}
52
53
	/**
54
	 * @param parent
55
	 * @param style
56
	 * @param index
57
	 */
58
	public SToolItem(SToolBar parent, int style, int index) {
59
		super(parent, style, index);
60
		this.parent = parent;
61
		parent.createItem(this, index);
62
	}
63
64
	public void addSelectionListener(SelectionListener listener) {
65
		checkWidget();
66
		if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
67
		TypedListener typedListener = new TypedListener (listener);
68
		addListener (SWT.Selection, typedListener);
69
		addListener (SWT.DefaultSelection, typedListener);
70
	}
71
	
72
	public Point computeSize(int wHint, int hHint, boolean changed) {
73
		checkWidget();
74
		Skin skin = parent.getSkin();
75
		
76
		Rectangle insets = skin.getRect(Skin.TYPE_ITEM_INSETS, Skin.NORMAL);
77
		if (insets == null) {
78
			insets = new Rectangle(0, 0, 0, 0);
79
		}
80
		
81
		Point size = null;
82
		String t = getText();
83
		if (t != null && t.length() == 0) {
84
			t = null;
85
		}
86
87
		if (control == null && (getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR && 
88
				t == null) {
89
			size = skin.getSize(Skin.TYPE_DECORATION_SEPARATOR, Skin.NORMAL);
90
		}
91
		else {
92
			size = getContentSize(getImage(), getText());
93
		}
94
		if (size == null) {
95
			size = new Point(0, 0);
96
		}
97
		
98
		if (wHint == SWT.DEFAULT) {
99
			size.x += (insets.x + insets.width);
100
		} else {
101
			size.x = wHint;
102
		}
103
		if (hHint == SWT.DEFAULT) {
104
			if (size.y != SWT.DEFAULT) {
105
				if (getControl() == null) {
106
					size.y += (insets.y + insets.height);
107
				}
108
			}
109
		} else {
110
			size.y = hHint;
111
		}
112
113
		//
114
		// Everything gets measured for a min/max width and height except if 
115
		// it is exclusively a SEPARATOR or if it is a separator with a control. 
116
		//
117
		boolean measureMinMax = true;
118
		if ((getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR) {
119
			if (control != null || t == null) { 
120
				measureMinMax = false;
121
			}
122
		}
123
		
124
		if (measureMinMax) {
125
			Point minMax = skin.getSize(Skin.TYPE_ITEM_MIN_MAX_WIDTHS, Skin.NORMAL);
126
			if (minMax != null) {
127
				if (minMax.x > size.x && minMax.x != SWT.DEFAULT) {
128
					size.x = minMax.x;
129
				}
130
				if (minMax.y < size.x && minMax.y != SWT.DEFAULT) {
131
					size.x = minMax.y;
132
				}
133
			}
134
	
135
			minMax = skin.getSize(Skin.TYPE_ITEM_MIN_MAX_HEIGHT, Skin.NORMAL);
136
			if (minMax != null) {
137
				if (minMax.x > size.y && minMax.x != SWT.DEFAULT) {
138
					size.y = minMax.x;
139
				}
140
				if (minMax.y < size.y && minMax.y != SWT.DEFAULT) {
141
					size.y = minMax.y;
142
				}
143
			}
144
		}
145
		
146
		return size;
147
	}
148
	
149
	public void dispose() {
150
		if (isDisposed ()) return;
151
		parent.destroyItem(this);
152
		super.dispose();
153
	}
154
155
	/**
156
	 * @return
157
	 */
158
	public Rectangle getBounds() {
159
		return itemRect;
160
	}
161
162
	/**
163
	 * @return
164
	 */
165
	public Control getControl() {
166
		return control;
167
	}
168
169
	Skin getSkin() {
170
		Skin skin = parent.getSkin();
171
		return skin;
172
	}
173
	
174
	/**
175
	 * @return
176
	 */
177
	public Image getDisabledImage() {
178
		return disabledImage;
179
	}
180
181
	/**
182
	 * @return
183
	 */
184
	public boolean getEnabled() {
185
		return enabled;
186
	}
187
	
188
	/**
189
	 * @return
190
	 */
191
	public Image getHotImage() {
192
		return hotImage;
193
	}
194
195
	/**
196
	 * @return pressed image.
197
	 */
198
	public Image getPressedImage() {
199
		return pressedImage;
200
	}
201
	
202
	/**
203
	 * @return
204
	 */
205
	public SToolBar getParent() {
206
		return this.parent;
207
	}
208
	
209
	/**
210
	 * @return
211
	 */
212
	public boolean getSelection() {
213
		return selected;
214
	}
215
216
	private int getState() {
217
		return state;
218
	}
219
	
220
	private int getArrowState() {
221
		return arrowState;
222
	}
223
	
224
	/**
225
	 * Compute the minimum size.
226
	 */
227
	private Point getContentSize(Image image, String text) {
228
		Point size = new Point(0, 0);
229
		Skin skin = getSkin();
230
		
231
		Control control = getControl();
232
		if (control != null) {
233
			size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
234
			if (width != -1)
235
				size.x = width;
236
			return size;
237
		}
238
239
		if (image != null) {
240
			Rectangle r;
241
			Point imageSize = skin.getSize(Skin.TYPE_ITEM_ICON_SIZE, state);
242
			if (imageSize != null && imageSize.y != SWT.DEFAULT) {
243
				r = new Rectangle(0, 0, imageSize.x, imageSize.y);
244
			} else {
245
				r = image.getBounds();
246
			}
247
			size.x += r.width;
248
			size.y += r.height;
249
		}
250
251
		if (skin != null) {
252
			Rectangle margins = skin.getRect(Skin.TYPE_ITEM_MARGINS, Skin.NORMAL);
253
			if (margins == null) {
254
				margins = new Rectangle(0, 0, 0, 0);
255
			}
256
			
257
			if (text != null && text.length() > 0) {
258
				GC gc = new GC(this.getParent());
259
				gc.setFont(skin.getFont(Skin.TYPE_ITEM_FONT, Skin.NORMAL));
260
				FontMetrics fm = gc.getFontMetrics();
261
				Point e = gc.textExtent(text, SWT.DRAW_TRANSPARENT);
262
				size.x += e.x;
263
				size.y = Math.max(size.y, fm.getAscent());
264
				if (image != null) {
265
					size.x += margins.x;
266
				}
267
				gc.dispose();
268
			} 
269
	
270
			if ((getStyle() & SWT.DROP_DOWN) != 0) {
271
				Point hinkySize = skin.getSize(Skin.TYPE_DECORATION_ARROW, Skin.NORMAL);
272
				if (hinkySize == null) {
273
					hinkySize = new Point(0, 0);
274
				}
275
				size.x += hinkySize.x + margins.y;
276
				
277
				if ((getStyle() & SWT.SIMPLE) != SWT.SIMPLE) {
278
					Point separatorSize = skin.getSize(Skin.TYPE_DECORATION_INTERNAL_SEPARATOR, Skin.NORMAL);
279
					if (separatorSize == null) {
280
						separatorSize = new Point(0, 0);
281
					}
282
					size.x += separatorSize.x;
283
				}
284
			}
285
		}
286
		
287
		return size;
288
	}
289
	
290
	/**
291
	 * @return
292
	 */
293
	public String getToolTipText() {
294
		return toolTipText;
295
	}
296
	
297
	/**
298
	 * @return
299
	 */
300
	public int getWidth() {
301
		return itemRect.width;
302
	}
303
	
304
	public Rectangle getArrowRect() {
305
		return arrowRect;
306
	}
307
	
308
	/**
309
	 * @return
310
	 */
311
	public boolean isEnabled() {
312
		return enabled;
313
	}
314
	
315
	/**
316
	 * 
317
	 */
318
	void onDispose() {
319
		// TODO Auto-generated method stub
320
	}
321
	
322
	/**
323
	 * @param event
324
	 */
325
	void onFocus(Event event) {
326
		// TODO Auto-generated method stub
327
	}
328
329
	/**
330
	 * @param event
331
	 */
332
	void onMouseDoubleClick(Event event) {		
333
	}
334
	
335
	/**
336
	 * @param event
337
	 */
338
	void onMouseDown(Event event) {
339
		if (arrowRect != null) {
340
			if (arrowRect.contains(event.x, event.y)) {
341
				setArrowPressed(true);
342
			}
343
		}
344
		if ((arrowState & Skin.PRESSED) == 0) {
345
			setPressed(true);
346
		}
347
		notifyListeners(SWT.MouseDown, event);
348
		
349
		if ((getStyle() & SWT.RADIO) == SWT.RADIO) {
350
			Event e = new Event();
351
			e.button = event.button;
352
			e.character = event.character;
353
			e.count = event.count;
354
			e.data = event.data;
355
			e.detail = event.detail;
356
			e.display = event.display;
357
			e.doit = event.doit;
358
			e.end = event.end;
359
			e.gc = event.gc;
360
			e.height = event.height;
361
			e.item = event.item;
362
			e.keyCode = event.keyCode;
363
			e.start = event.start;
364
			e.stateMask = event.stateMask;
365
			e.text = event.text;
366
			e.time = event.time;
367
			e.widget = event.widget;
368
			e.width = event.width;
369
			e.x = event.x;
370
			e.y = event.y;
371
			
372
			e.type = SWT.Selection;
373
			notifyListeners(SWT.Selection, e);
374
			setSelected(true);
375
		}
376
	}
377
378
	/**
379
	 * @param event
380
	 */
381
	void onMouseExit(Event event) {
382
	}
383
384
	/**
385
	 * @param event
386
	 */
387
	void onMouseHover(Event event) {
388
		notifyListeners(SWT.MouseHover, event);
389
	}
390
	
391
	void setHot(boolean hot) {
392
		if (hot)
393
			state |= Skin.HOVER;
394
		else if ((state & Skin.HOVER) != 0) 
395
			state = (state & ~Skin.HOVER);
396
	}
397
398
	void setArrowHot(boolean hot) {
399
		if (hot) {
400
			arrowState |= Skin.HOVER;
401
		} else if ((arrowState & Skin.HOVER) == Skin.HOVER) {
402
			arrowState = (arrowState & ~Skin.HOVER);
403
		}
404
	}
405
	
406
	void setPressed(boolean pressed) {
407
		if (pressed)
408
			state |= Skin.PRESSED;
409
		else if ((state & Skin.PRESSED) != 0) 
410
			state = (state & ~Skin.PRESSED);
411
	}
412
	
413
	void setArrowPressed(boolean pressed) {
414
		if (pressed)
415
			arrowState |= Skin.PRESSED;
416
		else if ((arrowState & Skin.PRESSED) == Skin.PRESSED) 
417
			arrowState = (arrowState & ~Skin.PRESSED);
418
	}
419
420
	public void setSelected(boolean selected) {
421
		if (selected) {
422
			/* Clear all adjacent selected radio buttons */
423
			int itemIndex = parent.indexOf(this);
424
			int i;
425
			SToolItem item;
426
			
427
			for (i = itemIndex -1; i > 0; i--) {
428
				item = parent.getItem(i);
429
				if ((item.getStyle() & SWT.RADIO) == SWT.RADIO) {
430
					item.setSelected(false);
431
				} else {
432
					break;
433
				}
434
			}
435
			for (i = itemIndex +1; i < parent.getItemCount(); i++) {
436
				item = parent.getItem(i);
437
				if ((item.getStyle() & SWT.RADIO) == SWT.RADIO) {
438
					item.setSelected(false);
439
				} else {
440
					break;
441
				}
442
			}
443
			state |= Skin.SELECTED;
444
		} else if ((state & Skin.SELECTED) == Skin.SELECTED) { 
445
			state = (state & ~Skin.SELECTED);
446
		}
447
	}
448
	
449
	/**
450
	 * @param event
451
	 */
452
	void onMouseMove(Event event) {
453
	}
454
455
	/**
456
	 * @param event
457
	 */
458
	void onMouseUp(Event event) {
459
		setPressed(false);
460
		
461
		Event e = new Event();
462
		e.type = SWT.MouseUp;
463
		e.widget = this;
464
		e.gc = event.gc;
465
		e.x = event.x;
466
		e.y = event.y;
467
		notifyListeners(SWT.MouseUp, event);
468
469
		if ((getStyle() & SWT.RADIO) != SWT.RADIO) {
470
			e = new Event();
471
			e.type = SWT.Selection;
472
			e.widget = this;
473
			e.gc = event.gc;
474
			e.x = event.x;
475
			e.y = event.y;
476
			if (arrowRect != null && arrowRect.contains(event.x, event.y))
477
				e.detail |= SWT.ARROW;
478
			notifyListeners(SWT.Selection, e);
479
		}
480
	}
481
		
482
	
483
	/*
484
	 * Process the paint event
485
	 */
486
	void onPaint(GC gc) {
487
		Skin skin = parent.getSkin();
488
		String t = getText();
489
		if (t != null && t.length() == 0) {
490
			t = null;
491
		}
492
		Image img = null;
493
494
		int state = getState();
495
496
		/*
497
		 * A separator with text will just draw static text rather than a line separator
498
		 * so always keep the state normal so it doesn't behave like a button. 
499
		 */
500
		if (control == null && (getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR && t != null) {
501
			state = Skin.NORMAL;
502
		}
503
504
		if (isEnabled() == false) {
505
			img = getDisabledImage();
506
		} else if ((state & Skin.PRESSED) == Skin.PRESSED) {
507
			img = getPressedImage();
508
		} else if ((state & Skin.HOVER) == Skin.HOVER) {
509
			img = getHotImage();
510
		}
511
		
512
		if (img == null) {
513
			img = getImage();
514
		}
515
		
516
		Rectangle insets = skin.getRect(Skin.TYPE_ITEM_INSETS, state);
517
		if (insets == null) {
518
			insets = new Rectangle(0, 0, 0, 0);
519
		}
520
		gc.setFont(skin.getFont(Skin.TYPE_ITEM_FONT, state));
521
522
		Rectangle rect = getBounds();
523
		if (rect.width == 0 || rect.height == 0)
524
			return;
525
		
526
		int availableWidth = rect.width - (insets.x + insets.width);
527
		Point extent = getContentSize(img, t);
528
		if (extent.x > availableWidth) {
529
			img = null;
530
			extent = getContentSize(img, t);
531
		}
532
533
		// determine horizontal position
534
		int x = (rect.x + insets.x);
535
		if (align == SWT.CENTER) {
536
			x = (rect.width - extent.x) / 2;
537
		}
538
		else if (align == SWT.RIGHT) {
539
			x = rect.width - extent.x - insets.width;
540
		}
541
//gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_RED));
542
//gc.drawRectangle(rect);
543
		if (control == null && (getStyle() & SWT.SEPARATOR) == SWT.SEPARATOR && t == null) {
544
			state = (state & ~(Skin.PRESSED));
545
			skin.drawDecoration(gc, rect, parent, Skin.TYPE_DECORATION_SEPARATOR, state);
546
			return;
547
		}
548
		
549
		// paint background
550
		skin.drawBackground(gc, rect, parent, Skin.TYPE_ITEM_BACKGROUND, state);
551
		
552
		// paint border
553
		skin.drawBorder(gc, rect, parent, Skin.TYPE_ITEM_BORDER, state);
554
		
555
		Rectangle itemMargins = skin.getRect(Skin.TYPE_ITEM_MARGINS, state);
556
		if (itemMargins == null) {
557
			itemMargins = new Rectangle(0, 0, 0, 0);
558
		}
559
		
560
		// draw the image
561
		
562
		if (img != null) {
563
			Rectangle imageRect;
564
			Point imageSize = skin.getSize(Skin.TYPE_ITEM_ICON_SIZE, state);
565
			if (imageSize != null && imageSize.y != SWT.DEFAULT) {
566
				imageRect = new Rectangle(0, 0, imageSize.x, imageSize.y);
567
			} else {
568
				imageRect = img.getBounds();
569
			}
570
571
			imageRect = new Rectangle(x, rect.y + ((rect.height - imageRect.height) / 2),
572
					imageRect.width, imageRect.height);
573
			skin.drawImage(gc, imageRect, img, parent, Skin.TYPE_ITEM_IMAGE, state);
574
			
575
			x += imageRect.width + itemMargins.x;
576
		}
577
		
578
		// draw the text
579
		if (t != null) {
580
			FontMetrics fm = gc.getFontMetrics();
581
			int textHeight = fm.getAscent();
582
			int textWidth = gc.textExtent(getText(), SWT.DRAW_TRANSPARENT  | SWT.DRAW_MNEMONIC).x;
583
			int y = rect.y;
584
			int availableHeight = rect.height;
585
			y = y + ((availableHeight / 2) - (textHeight / 2));
586
			Rectangle textRect = new Rectangle(x, y, textWidth, textHeight);
587
//Used for debugging text rect rendering.
588
//			gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));
589
//			gc.fillRectangle(textRect);
590
			/* Don't include leading so top of text lines up when expected in the drawing rect. */
591
			textRect.y -= fm.getLeading();
592
			skin.drawText(gc, textRect, getText(), SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC, parent, Skin.TYPE_ITEM_TEXT, state);
593
			/* Add leading back in to get the "text rect" that the text is actually rendered in. */
594
			textRect.y += fm.getLeading();
595
			x += textRect.width + itemMargins.y;
596
		}
597
598
		// draw the hinky and text/hinky separator
599
		if ((getStyle() & SWT.DROP_DOWN) != 0) {
600
			Point hinkySize = skin.getSize(Skin.TYPE_DECORATION_ARROW, state);
601
			if (hinkySize == null) {
602
				hinkySize = new Point(0, 0);
603
			}
604
			int myX = x;
605
			int myY = rect.y + ((rect.height /2) - ((hinkySize.y == SWT.DEFAULT ? 0 : hinkySize.y) / 2));
606
			Point separatorSize = skin.getSize(Skin.TYPE_DECORATION_INTERNAL_SEPARATOR, state);
607
			if (separatorSize == null) {
608
				separatorSize = new Point(0, 0);
609
			}
610
			int sepLineX = myX -2;
611
612
			int arrowState = state;
613
			// separator
614
			Rectangle sepLineRectangle = null;
615
			if ((getStyle() & SWT.SIMPLE) != SWT.SIMPLE) {
616
				int y = rect.y + (((rect.height / 2) - ((separatorSize.y == SWT.DEFAULT ? rect.height : separatorSize.y)) / 2));
617
				sepLineRectangle = new Rectangle(sepLineX, y, separatorSize.x, (separatorSize.y == SWT.DEFAULT ? rect.height : separatorSize.y));
618
				skin.drawDecoration(gc, sepLineRectangle, parent, Skin.TYPE_DECORATION_INTERNAL_SEPARATOR, state);
619
				myX += separatorSize.x;
620
				/* Since it is separate, use the arrow state to draw the hinky below. */
621
				arrowState = getArrowState();
622
			}
623
			
624
			// hinky
625
			int height = (hinkySize.y == SWT.DEFAULT ? rect.height : hinkySize.y); 
626
			Rectangle arrowImageRect = new Rectangle(myX, myY, hinkySize.x, height);
627
			skin.drawDecoration(gc, arrowImageRect, parent, Skin.TYPE_DECORATION_ARROW, arrowState);
628
			
629
			if (sepLineRectangle != null)
630
				arrowRect = new Rectangle(sepLineRectangle.x, 0, myX, rect.height);
631
			else
632
				arrowRect = null;
633
		}
634
	}
635
636
	public void removeSelectionListener (SelectionListener listener) {
637
		checkWidget();
638
		if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
639
		removeListener(SWT.Selection, listener);
640
		removeListener(SWT.DefaultSelection,listener);	
641
	}
642
	
643
	/**
644
	 * @param control
645
	 */
646
	public void setControl(Control control) {
647
		this.control = control;
648
		if (control != null) {
649
			Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
650
			itemRect = new Rectangle(0, 0, pt.x, pt.y);
651
			control.setBounds(itemRect);
652
			parent.itemChanged(this);
653
		}
654
	}
655
	
656
	/**
657
	 * @param image
658
	 */
659
	public void setDisabledImage(Image image) {
660
		this.disabledImage = image;
661
		parent.itemChanged(this);
662
	}
663
	
664
	/**
665
	 * @param enabled
666
	 */
667
	public void setEnabled(boolean enabled) {
668
		this.enabled = enabled;
669
		parent.itemChanged(this);
670
	}
671
	
672
	/**
673
	 * @param image
674
	 */
675
	public void setHotImage(Image image) {
676
		this.hotImage = image;
677
		parent.itemChanged(this);
678
	}
679
	
680
	/**
681
	 * @param pressed image
682
	 */
683
	public void setPressedImage(Image image) {
684
		this.pressedImage = image;
685
		parent.itemChanged(this);
686
	}
687
	
688
	/* (non-Javadoc)
689
	 * @see org.eclipse.swt.widgets.Item#setImage(org.eclipse.swt.graphics.Image)
690
	 */
691
	public void setImage(Image image) {
692
		if ((getStyle() & SWT.SEPARATOR) != 0)
693
			return;
694
		super.setImage(image);
695
		parent.itemChanged(this);
696
	}
697
698
	/**
699
	 * @param selected
700
	 */
701
	public void setSelection(boolean selected) {
702
		this.selected = selected;
703
		parent.itemChanged(this);
704
	}
705
	
706
	/* (non-Javadoc)
707
	 * @see org.eclipse.swt.widgets.Item#setText(java.lang.String)
708
	 */
709
	public void setText(String string) {
710
		super.setText(string);
711
		parent.itemChanged(this);
712
	}
713
	
714
	/**
715
	 * @param string
716
	 */
717
	public void setToolTipText(String string) {
718
		toolTipText = string;
719
		parent.itemChanged(this);
720
	}
721
	
722
	public void setWidth(int width) {
723
		this.width = width;
724
		if (control != null) {
725
			Point size = control.getSize();
726
			size.x = width;
727
			control.setSize(size);
728
		}
729
	}
730
731
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SCoolBar.java (+411 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import java.util.ArrayList;
4
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.graphics.GC;
7
import org.eclipse.swt.graphics.Point;
8
import org.eclipse.swt.graphics.Rectangle;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Event;
11
import org.eclipse.swt.widgets.Listener;
12
13
14
public class SCoolBar extends SWidget {
15
	
16
	private ArrayList items = new ArrayList();
17
18
	static final int DEFAULT_WIDTH	= 64;
19
	static final int DEFAULT_HEIGHT	= 64;
20
	static final int ITEM_INSET_TOP = 0;
21
	static final int ITEM_INSET_BOTTOM = 0;
22
	static final int LEFT_MARGIN = 6;
23
	static final int SHADOW_SIZE = 4;
24
25
	public SCoolBar(Composite parent, int style) {
26
		super(parent, checkStyle(style));
27
28
		Listener listener = new Listener() {
29
			public void handleEvent(Event event) {
30
				switch (event.type) {
31
					case SWT.Dispose:      		
32
						onDispose(event);
33
						break;
34
					case SWT.MouseDown:
35
						onMouseDown(event);
36
						break;
37
					case SWT.MouseExit:
38
						onMouseExit(event);
39
						break;
40
					case SWT.MouseMove:
41
						onMouseMove(event);
42
						break;
43
					case SWT.MouseUp:
44
						onMouseUp(event);
45
						break;
46
					case SWT.MouseDoubleClick:
47
						onMouseDoubleClick(event);
48
						break;
49
					case SWT.Paint:
50
						onPaint(event);
51
						break;
52
					case SWT.Resize:
53
						onResize(event);
54
						break;
55
				}
56
			}
57
		};
58
		int[] events = new int[] { 
59
			SWT.Dispose, 
60
			SWT.MouseDown,
61
			SWT.MouseExit, 
62
			SWT.MouseMove, 
63
			SWT.MouseUp, 
64
			SWT.MouseDoubleClick,
65
			SWT.Paint,
66
			SWT.Resize
67
		};
68
		for (int i = 0; i < events.length; i++) {
69
			addListener(events[i], listener);	
70
		}
71
	}
72
73
	private static int checkStyle(int style) {
74
		return style;
75
	}
76
77
	public Point computeSize(int wHint, int hHint) {
78
		return computeSize(wHint, hHint, true);
79
	}
80
	
81
	public Point computeSize(int wHint, int hHint, boolean changed) {
82
		checkWidget();
83
		int width = 0;
84
		int height = 0;
85
		int rowWidth = 0;
86
		int rowHeight = 0;
87
		for (int i = 0; i < items.size(); i++) {
88
			SCoolItem item = (SCoolItem)items.get(i);
89
			Point pt = item.getPreferredSize();
90
			if (i != 0 && item.wrap == true) {
91
				width = Math.max(rowWidth, width);
92
				height += rowHeight;
93
				rowWidth = 0;
94
				rowHeight = 0;
95
			}
96
			rowWidth += pt.x;
97
			rowHeight = Math.max(pt.y, rowHeight);
98
		}
99
		width = Math.max(rowWidth, width);
100
		height += rowHeight;
101
		if (wHint == 0) { 
102
			width = DEFAULT_WIDTH;
103
		}
104
		if (hHint == 0) {
105
			height = DEFAULT_HEIGHT;
106
		}
107
		
108
		Skin skin = getSkin();
109
		Rectangle borders = null;
110
		
111
		if (skin != null) {
112
			borders = skin.getRect(Skin.TYPE_BORDER, Skin.NORMAL);
113
		} 
114
		if (borders == null) {
115
			borders = new Rectangle(0, 0, 0, 0);
116
		}
117
		
118
		width += borders.x + borders.width;
119
		height += borders.y + borders.height;
120
		
121
		if (wHint != SWT.DEFAULT) {
122
			width = wHint;
123
		}
124
		if (hHint != SWT.DEFAULT) {
125
			height = hHint;
126
		}
127
		Rectangle trim = computeTrim(0, 0, width, height);
128
		Point pt = new Point(trim.width, trim.height);;
129
130
		return pt;
131
	}
132
133
	void createItem (SCoolItem item, int index) {
134
		int itemCount = getItemCount();
135
		if (!(0 <= index && index <= itemCount))
136
			SWT.error (SWT.ERROR_INVALID_RANGE);
137
		items.add(index, item);
138
		layout();
139
	}
140
	
141
	/**
142
	 * @return
143
	 */
144
	public int[] getAlignmentIndices () {
145
		checkWidget ();
146
		int itemCount = items.size();
147
		int[] indices = new int[itemCount];
148
		int count = 0;
149
		for (int i = 0; i < itemCount; i++) {
150
			SCoolItem item = (SCoolItem)items.get(i);
151
			if (item.alignment) {
152
				indices[count++] = i;
153
			}
154
		}
155
		int[] result = new int[count];
156
		System.arraycopy (indices, 0, result, 0, count);
157
		return result;		
158
	}
159
	
160
	public SCoolItem getItem(int index) {
161
		checkWidget();
162
		SCoolItem item = (SCoolItem)items.get(index);
163
		return item;
164
	}
165
	
166
	public int getItemCount() {
167
		checkWidget();
168
		return items.size();
169
	}
170
	
171
	public SCoolItem[] getItems() {
172
		checkWidget();
173
		if (items.size() == 0)
174
			return new SCoolItem[0];
175
		return (SCoolItem[])items.toArray(new SCoolItem[1]);
176
	}
177
178
	public boolean getLocked() {
179
		return false;
180
	}
181
	
182
	/**
183
	 * 
184
	 * @return
185
	 */
186
	public int[] getWrapIndices () {
187
		checkWidget ();
188
		int itemCount = items.size();
189
		int[] indices = new int[itemCount];
190
		int count = 0;
191
		for (int i = 0; i < itemCount; i++) {
192
			SCoolItem item = (SCoolItem)items.get(i);
193
			if (item.wrap) {
194
				indices[count++] = i;
195
			}
196
		}
197
		int[] result = new int[count];
198
		System.arraycopy (indices, 0, result, 0, count);
199
		return result;
200
	}
201
	
202
	public int indexOf(SCoolItem item) {
203
		checkWidget();
204
		if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
205
		if (item.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
206
		return items.indexOf(item);
207
	}
208
	
209
	protected void onDispose(Event event) {
210
		// TODO Auto-generated method stub
211
		
212
	}
213
214
	protected void onMouseDown(Event event) {
215
		// TODO Auto-generated method stub
216
		
217
	}
218
219
	protected void onMouseExit(Event event) {
220
		// TODO Auto-generated method stub
221
		
222
	}
223
224
	protected void onMouseMove(Event event) {
225
		// TODO Auto-generated method stub
226
		
227
	}
228
229
	protected void onMouseUp(Event event) {
230
		// TODO Auto-generated method stub
231
		
232
	}
233
234
	protected void onMouseDoubleClick(Event event) {
235
		// TODO Auto-generated method stub
236
		
237
	}
238
239
	protected void onPaint(Event event) {
240
		Skin skin = getSkin();
241
		GC gc = event.gc;
242
		
243
		if (skin == null)
244
			return;
245
				
246
		Rectangle rect = getClientArea();
247
		if (rect.width == 0 || rect.height == 0)
248
			return;
249
		
250
		int state = Skin.NORMAL;
251
		
252
		// paint background
253
		skin.drawBackground(gc, rect, this, Skin.TYPE_BACKGROUND, state);
254
		
255
		// paint border
256
		skin.drawBorder(gc, rect, this, Skin.TYPE_BORDER, state);
257
258
		// paint each item
259
		for (int i = 0; i < items.size(); i++) {
260
			SCoolItem item = getItem(i);
261
			if (item != null) {
262
				item.paint(gc, state);
263
			}
264
		}
265
	}
266
267
	protected void onResize(Event event) {
268
		layout();
269
	}
270
	
271
	/**
272
	 * Sets the indices of all item(s) in the receiver 
273
	 * that will begin right alignment on each row.
274
	 * For example, if indice contains 2, 
275
	 * that mean all the items from item2 to the end row are right aligned. 
276
	 *  
277
	 * @param indices
278
	 */
279
	public void setAlignmentIndices(int[] indices) {
280
		checkWidget();
281
		if (indices == null) 
282
			indices = new int[0];
283
		int count = items.size();
284
//		for (int i = 0; i< indices.length; i++) {
285
//			if (indices[i] < 0 || indices[i] >= count) {
286
//				SWT.error (SWT.ERROR_INVALID_ARGUMENT);
287
//			}
288
//		}
289
		for (int i = 0; i < items.size(); i++) {
290
			((SCoolItem)items.get(i)).alignment = false;
291
		}
292
		for (int i = 0; i < indices.length; i++) {
293
			int index = indices[i];
294
			if (index < items.size()) {
295
				((SCoolItem)items.get(index)).alignment = true;
296
			}
297
		}
298
		layout();
299
	}
300
301
	public void setBounds(int x, int y, int width, int height) {
302
		super.setBounds(x, y, width, height);
303
	}
304
	
305
	public void setBounds(Rectangle rect) {
306
		super.setBounds(rect);
307
	}
308
	
309
	public void setSize(int width, int height) {
310
		super.setSize(width, height);
311
	}
312
	 
313
	
314
	public void setLocked(boolean locked) {
315
		// TODO Auto-generated method stub
316
	}
317
318
	public void setWrapIndices(int[] wrapIndices) {
319
		// TODO Auto-generated method stub
320
	}
321
322
	public void layout(boolean changed) {
323
		int x = 1;
324
		int y = 0;
325
		int rowHeight = 0;
326
		int maxHeightInRow = 0;
327
		int maxWidth;
328
		int i;
329
		Skin skin = getSkin();
330
		Rectangle borders = null;
331
		
332
		if (skin != null) {
333
			borders = skin.getRect(Skin.TYPE_BORDER, Skin.NORMAL);
334
		} 
335
		if (borders == null) {
336
			borders = new Rectangle(0, 0, 0, 0);
337
		}
338
339
		maxWidth = getClientArea().width;
340
		if (maxWidth == 0)
341
			return;
342
		
343
		x = borders.x;
344
		
345
		for (i = 0; i < items.size(); i++) {
346
			SCoolItem item = (SCoolItem)items.get(i);
347
			Point itemSize = item.computeSize(SWT.DEFAULT, SWT.DEFAULT);
348
			maxHeightInRow = Math.max(itemSize.y, maxHeightInRow);
349
		}
350
351
		for (i = 0; i < items.size(); i++) {
352
			
353
			// TODO: multiple row support
354
			
355
			// calc max height in row
356
//			if (i == 0 || ((SCoolItem)items.get(i)).wrap) {
357
//				rowHeight = maxHeightInRow;
358
//				maxHeightInRow = 0;
359
//				for (int j = i; j < items.size(); j++) {
360
//					SCoolItem item = (SCoolItem)items.get(j);
361
//					if (j != 0 && item.wrap)
362
//						break;
363
//					Point itemSize = item.computeSize(SWT.DEFAULT, SWT.DEFAULT);
364
//					maxHeightInRow = Math.max(itemSize.y, maxHeightInRow);
365
//				}
366
//			}
367
			
368
			// layout item
369
			SCoolItem item = (SCoolItem)items.get(i);
370
			Point itemSize = item.computeSize(SWT.DEFAULT, SWT.DEFAULT);
371
			Rectangle oldBounds = item.getBounds();
372
			if (i != 0 && item.wrap) {
373
				x = borders.x;
374
				y += rowHeight;
375
			} else if (item.alignment) {
376
				// right align from this item till the last item in the row
377
				
378
				int rightAlignWidth = 0;
379
				for (int j = i; j < items.size(); j++) {
380
					SCoolItem rightItem = (SCoolItem)items.get(j);
381
					int itemWidth = rightItem.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
382
					rightAlignWidth += itemWidth; 
383
					if (rightItem.wrap == true)
384
						break;
385
				}
386
				int prevx = x;
387
				x = maxWidth - rightAlignWidth;	 // new x position after right alingn
388
				if (i > 0 && prevx != x) {
389
					// change the previous item width wider
390
					SCoolItem prevItem = (SCoolItem)items.get(i-1);
391
					Point pt = prevItem.computeSize(SWT.DEFAULT, SWT.DEFAULT);
392
					Rectangle r = prevItem.getBounds();
393
					prevItem.setBounds(r.x, r.y, pt.x + x - prevx, pt.y);
394
					//prevItem.setBounds(r.x, r.y, r.width + x - prevx, r.height);
395
				}
396
			}		
397
			if (x + itemSize.x > maxWidth) {
398
				itemSize.x -= (x + itemSize.x - maxWidth); 
399
			}
400
			Rectangle newBounds = new Rectangle(x, y, itemSize.x, maxHeightInRow);
401
			if (!oldBounds.equals(newBounds)) {
402
				item.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);	
403
			}
404
			x += newBounds.width;
405
		}
406
		y += maxHeightInRow;
407
	}
408
409
410
	
411
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SToolBarContributionItem2.java (+710 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import java.util.ArrayList;
4
import java.util.Iterator;
5
6
import org.eclipse.jface.action.ActionContributionItem;
7
import org.eclipse.jface.action.ContributionItem;
8
import org.eclipse.jface.action.IContributionItem;
9
import org.eclipse.jface.action.ICoolBarManager;
10
import org.eclipse.jface.action.IToolBarManager;
11
import org.eclipse.jface.action.MenuManager;
12
import org.eclipse.jface.action.Separator;
13
import org.eclipse.jface.action.SubContributionItem;
14
import org.eclipse.jface.action.ToolBarContributionItem;
15
import org.eclipse.jface.action.ToolBarManager;
16
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
17
import org.eclipse.jface.util.Policy;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.DisposeEvent;
20
import org.eclipse.swt.events.DisposeListener;
21
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.CoolBar;
27
import org.eclipse.swt.widgets.CoolItem;
28
import org.eclipse.swt.widgets.Event;
29
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.Menu;
31
import org.eclipse.swt.widgets.ToolBar;
32
import org.eclipse.swt.widgets.ToolItem;
33
34
public class SToolBarContributionItem2 extends ContributionItem implements ISContributionItem, IToolBarContributionItem {
35
36
    /**
37
     * A constant used by <code>setMinimumItemsToShow</code> and <code>getMinimumItemsToShow</code>
38
     * to indicate that all tool items should be shown in the cool item.
39
     */
40
    public static final int SHOW_ALL_ITEMS = -1;
41
42
    /**
43
     * The pull down menu used to list all hidden tool items if the current
44
     * size is less than the preffered size.
45
     */
46
    private MenuManager chevronMenuManager = null;
47
48
    /**
49
     * The widget created for this item; <code>null</code> before creation
50
     * and after disposal.
51
     */
52
    private SCoolItem coolItem = null;
53
54
    /**
55
     * Current height of cool item
56
     */
57
    private int currentHeight = -1;
58
59
    /**
60
     * Current width of cool item.
61
     */
62
    private int currentWidth = -1;
63
64
    /**
65
     * A flag indicating that this item has been disposed. This prevents future
66
     * method invocations from doing things they shouldn't.
67
     */
68
    private boolean disposed = false;
69
70
    /**
71
     * Mininum number of tool items to show in the cool item widget.
72
     */
73
    private int minimumItemsToShow = SHOW_ALL_ITEMS;
74
75
    /**
76
     * The tool bar manager used to manage the tool items contained in the cool
77
     * item widget.
78
     */
79
    private IToolBarManager toolBarManager = null;
80
81
    /**
82
     * Enable/disable chevron support.
83
     */
84
    private boolean useChevron = true;
85
86
	private String id;
87
88
    /**
89
     * Convenience method equivalent to <code>ToolBarContributionItem(new ToolBarManager(), null)</code>.
90
     */
91
    public SToolBarContributionItem2() {
92
        this(new SToolBarManager2(), (String)null);
93
    }
94
    
95
    /**
96
     * Convenience method equivalent to <code>ToolBarContributionItem(toolBarManager, null)</code>.
97
     * 
98
     * @param toolBarManager
99
     *            the tool bar manager
100
     */
101
    public SToolBarContributionItem2(IToolBarManager toolBarManager) {
102
        this(toolBarManager, (String)null);
103
    }
104
105
    /**
106
     * Creates a tool bar contribution item.
107
     * 
108
     * @param toolBarManager
109
     *            the tool bar manager to wrap
110
     * @param id
111
     *            the contribution item id, or <code>null</code> if none
112
     */
113
    public SToolBarContributionItem2(IToolBarManager toolBarManager, String id) {
114
        super();
115
        this.toolBarManager = toolBarManager;
116
        this.id = id;
117
    }
118
    
119
    /**
120
     * Checks whether this contribution item has been disposed. If it has, and
121
     * the tracing options are active, then it prints some debugging
122
     * information.
123
     * 
124
     * @return <code>true</code> if the item is disposed; <code>false</code>
125
     *         otherwise.
126
     *  
127
     */
128
    private final boolean checkDisposed() {
129
        if (disposed) {
130
            if (Policy.TRACE_TOOLBAR) { //$NON-NLS-1$
131
                System.out
132
                        .println("Method invocation on a disposed tool bar contribution item."); //$NON-NLS-1$
133
                new Exception().printStackTrace(System.out);
134
            }
135
136
            return true;
137
        }
138
139
        return false;
140
    }
141
142
    /*
143
     * (non-Javadoc)
144
     * 
145
     * @see org.eclipse.jface.action.IContributionItem#dispose()
146
     */
147
    public void dispose() {
148
        // Dispose of the ToolBar and all its contributions
149
        if (toolBarManager != null) {
150
        	// TODO: handle dispose
151
        	if (toolBarManager instanceof ToolBarManager)
152
        		((ToolBarManager)toolBarManager).dispose();
153
        	else if (toolBarManager instanceof SToolBarManager2)
154
        		((SToolBarManager2)toolBarManager).dispose();
155
            toolBarManager = null;
156
        }
157
158
        /*
159
         * We need to dispose the cool item or we might be left holding a cool
160
         * item with a disposed control.
161
         */
162
        if ((coolItem != null) && (!coolItem.isDisposed())) {
163
            coolItem.dispose();
164
            coolItem = null;
165
        }
166
167
        // Mark this item as disposed.
168
        disposed = true;
169
    }
170
171
    /*
172
     * (non-Javadoc)
173
     * 
174
     * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.CoolBar,
175
     *      int)
176
     */
177
    public void fill(CoolBar coolBar, int index) {
178
    	// do nothing
179
    }
180
    
181
    /**
182
     * Returns a consistent set of wrap indices. The return value will always
183
     * include at least one entry and the first entry will always be zero.
184
     * CoolBar.getWrapIndices() is inconsistent in whether or not it returns an
185
     * index for the first row.
186
     */
187
    private int[] getAdjustedWrapIndices(int[] wraps) {
188
        int[] adjustedWrapIndices;
189
        if (wraps.length == 0) {
190
            adjustedWrapIndices = new int[] { 0 };
191
        } else {
192
            if (wraps[0] != 0) {
193
                adjustedWrapIndices = new int[wraps.length + 1];
194
                adjustedWrapIndices[0] = 0;
195
                for (int i = 0; i < wraps.length; i++) {
196
                    adjustedWrapIndices[i + 1] = wraps[i];
197
                }
198
            } else {
199
                adjustedWrapIndices = wraps;
200
            }
201
        }
202
        return adjustedWrapIndices;
203
    }
204
205
    /**
206
     * Returns the current height of the corresponding cool item.
207
     * 
208
     * @return the current height
209
     */
210
    public int getCurrentHeight() {
211
        if (checkDisposed()) {
212
            return -1;
213
        }
214
        return currentHeight;
215
    }
216
217
    /**
218
     * Returns the current width of the corresponding cool item.
219
     * 
220
     * @return the current size
221
     */
222
    public int getCurrentWidth() {
223
        if (checkDisposed()) {
224
            return -1;
225
        }
226
        return currentWidth;
227
    }
228
229
    /*
230
     *  (non-Javadoc)
231
     * @see org.eclipse.jface.action.IContributionItem#getId()
232
     */
233
    public String getId() {
234
    	return this.id;
235
    }
236
    
237
    /**
238
     * Returns the minimum number of tool items to show in the cool item.
239
     * 
240
     * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
241
     *         if a value was not set
242
     * @see #setMinimumItemsToShow(int)
243
     */
244
    public int getMinimumItemsToShow() {
245
        if (checkDisposed()) {
246
            return -1;
247
        }
248
        return minimumItemsToShow;
249
    }
250
251
    /**
252
     * Returns the internal tool bar manager of the contribution item.
253
     * 
254
     * @return the tool bar manager, or <code>null</code> if one is not
255
     *         defined.
256
     * @see IToolBarManager
257
     */
258
    public IToolBarManager getToolBarManager() {
259
        if (checkDisposed()) {
260
            return null;
261
        }
262
        return toolBarManager;
263
    }
264
265
    /**
266
     * Returns whether chevron support is enabled.
267
     * 
268
     * @return <code>true</code> if chevron support is enabled, <code>false</code>
269
     *         otherwise
270
     */
271
    public boolean getUseChevron() {
272
        if (checkDisposed()) {
273
            return false;
274
        }
275
        return useChevron;
276
    }
277
278
    /**
279
     * Create and display the chevron menu.
280
     */
281
    private void handleChevron(SelectionEvent event) {
282
        CoolItem item = (CoolItem) event.widget;
283
        Control control = item.getControl();
284
        if ((control instanceof ToolBar) == false) {
285
            return;
286
        }
287
        CoolBar coolBar = item.getParent();
288
        ToolBar toolBar = (ToolBar) control;
289
        Rectangle toolBarBounds = toolBar.getBounds();
290
        ToolItem[] items = toolBar.getItems();
291
        ArrayList hidden = new ArrayList();
292
        for (int i = 0; i < items.length; ++i) {
293
            Rectangle itemBounds = items[i].getBounds();
294
            if (!((itemBounds.x + itemBounds.width <= toolBarBounds.width) && (itemBounds.y
295
                    + itemBounds.height <= toolBarBounds.height))) {
296
                hidden.add(items[i]);
297
            }
298
        }
299
300
        // Create a pop-up menu with items for each of the hidden buttons.
301
        if (chevronMenuManager != null) {
302
            chevronMenuManager.dispose();
303
        }
304
        chevronMenuManager = new MenuManager();
305
        for (Iterator i = hidden.iterator(); i.hasNext();) {
306
            ToolItem toolItem = (ToolItem) i.next();
307
            IContributionItem data = (IContributionItem) toolItem.getData();
308
            if (data instanceof ActionContributionItem) {
309
                ActionContributionItem contribution = new ActionContributionItem(
310
                        ((ActionContributionItem) data).getAction());
311
                chevronMenuManager.add(contribution);
312
            } else if (data instanceof SubContributionItem) {
313
                IContributionItem innerData = ((SubContributionItem) data)
314
                        .getInnerItem();
315
                if (innerData instanceof ActionContributionItem) {
316
                    ActionContributionItem contribution = new ActionContributionItem(
317
                            ((ActionContributionItem) innerData).getAction());
318
                    chevronMenuManager.add(contribution);
319
                }
320
            } else if (data.isSeparator()) {
321
                chevronMenuManager.add(new Separator());
322
            }
323
        }
324
        Menu popup = chevronMenuManager.createContextMenu(coolBar);
325
        Point chevronPosition = coolBar.toDisplay(event.x, event.y);
326
        popup.setLocation(chevronPosition.x, chevronPosition.y);
327
        popup.setVisible(true);
328
    }
329
330
    /**
331
     * Handles the event when the toobar item does not have its own context
332
     * menu.
333
     * 
334
     * @param event
335
     *            the event object
336
     */
337
    private void handleContextMenu(Event event) {
338
        Control toolBar = null;
339
        if (toolBarManager instanceof SToolBarManager2)
340
        	toolBar = ((SToolBarManager2)toolBarManager).getControl2();
341
        else if (toolBarManager instanceof ToolBarManager)
342
        	toolBar = ((ToolBarManager)toolBarManager).getControl();
343
        else
344
        	return;
345
        // If parent has a menu then use that one
346
        Menu parentMenu = toolBar.getParent().getMenu();
347
        if ((parentMenu != null) && (!parentMenu.isDisposed())) {
348
            toolBar.setMenu(parentMenu);
349
            // Hook listener to remove menu once it has disapeared
350
            parentMenu.addListener(SWT.Hide, new Listener() {
351
352
                public void handleEvent(Event innerEvent) {
353
                    Control innerToolBar = null;
354
                    if (toolBarManager instanceof ToolBarManager)
355
                    	innerToolBar = ((ToolBarManager)toolBarManager).getControl();
356
                    else if (toolBarManager instanceof SToolBarManager2)
357
                    	innerToolBar = ((SToolBarManager2)toolBarManager).getControl();
358
                    if (innerToolBar != null) {
359
                        innerToolBar.setMenu(null);
360
                        Menu innerParentMenu = innerToolBar.getParent()
361
                                .getMenu();
362
                        if (innerParentMenu != null) {
363
                            innerParentMenu.removeListener(SWT.Hide, this);
364
                        }
365
                    }
366
                }
367
            });
368
        }
369
    }
370
371
    /**
372
     * Handles the disposal of the widget.
373
     * 
374
     * @param event
375
     *            the event object
376
     */
377
    private void handleWidgetDispose(DisposeEvent event) {
378
        coolItem = null;
379
    }
380
381
    /**
382
     * A contribution item is visible iff its internal state is visible <em>or</em>
383
     * the tool bar manager contains something other than group markers and
384
     * separators.
385
     * 
386
     * @return <code>true</code> if the tool bar manager contains something
387
     *         other than group marks and separators, and the internal state is
388
     *         set to be visible.
389
     */
390
    public boolean isVisible() {
391
        if (checkDisposed()) {
392
            return false;
393
        }
394
395
        boolean visibleItem = false;
396
        if (toolBarManager != null) {
397
            IContributionItem[] contributionItems = toolBarManager.getItems();
398
            for (int i = 0; i < contributionItems.length; i++) {
399
                IContributionItem contributionItem = contributionItems[i];
400
                if ((!contributionItem.isGroupMarker())
401
                        && (!contributionItem.isSeparator())) {
402
                    visibleItem = true;
403
                    break;
404
                }
405
            }
406
        }
407
408
        return (visibleItem || super.isVisible());
409
    }
410
411
    /*
412
     * (non-Javadoc)
413
     * 
414
     * @see org.eclipse.jface.action.IContributionItem#saveWidgetState()
415
     */
416
    public void saveWidgetState() {
417
        if (checkDisposed()) {
418
            return;
419
        }
420
        if (coolItem == null)
421
            return;
422
423
        //1. Save current size
424
        SCoolBar coolBar = (SCoolBar)coolItem.getParent();
425
        boolean isLastOnRow = false;
426
        int lastIndex = coolBar.getItemCount() - 1;
427
        int coolItemIndex = coolBar.indexOf(coolItem);
428
        int[] wrapIndicies = getAdjustedWrapIndices(coolBar.getWrapIndices());
429
        // Traverse through all wrap indicies backwards
430
        for (int row = wrapIndicies.length - 1; row >= 0; row--) {
431
            if (wrapIndicies[row] <= coolItemIndex) {
432
433
                int nextRow = row + 1;
434
                int nextRowStartIndex;
435
                if (nextRow > (wrapIndicies.length - 1)) {
436
                    nextRowStartIndex = lastIndex + 1;
437
                } else {
438
                    nextRowStartIndex = wrapIndicies[nextRow];
439
                }
440
441
                // Check to see if its the last item on the row
442
                if (coolItemIndex == (nextRowStartIndex - 1)) {
443
                    isLastOnRow = true;
444
                }
445
                break;
446
            }
447
        }
448
449
        // Save the preferred size as actual size for the last item on a row
450
        int nCurrentWidth;
451
        if (isLastOnRow) {
452
            nCurrentWidth = coolItem.getPreferredSize().x;
453
        } else {
454
            nCurrentWidth = coolItem.getSize().x;
455
        }
456
        setCurrentWidth(nCurrentWidth);
457
        setCurrentHeight(coolItem.getSize().y);
458
    }
459
460
    /**
461
     * Sets the current height of the cool item. Update(SIZE) should be called
462
     * to adjust the widget.
463
     * 
464
     * @param currentHeight
465
     *            the current height to set
466
     */
467
    public void setCurrentHeight(int currentHeight) {
468
        if (checkDisposed()) {
469
            return;
470
        }
471
        this.currentHeight = currentHeight;
472
    }
473
474
    /**
475
     * Sets the current width of the cool item. Update(SIZE) should be called
476
     * to adjust the widget.
477
     * 
478
     * @param currentWidth
479
     *            the current width to set
480
     */
481
    public void setCurrentWidth(int currentWidth) {
482
        if (checkDisposed()) {
483
            return;
484
        }
485
        this.currentWidth = currentWidth;
486
    }
487
488
    /**
489
     * Sets the minimum number of tool items to show in the cool item. If this
490
     * number is less than the total tool items, a chevron will appear and the
491
     * hidden tool items appear in a drop down menu. By default, all the tool
492
     * items are shown in the cool item.
493
     * 
494
     * @param minimumItemsToShow
495
     *            the minimum number of tool items to show.
496
     * @see #getMinimumItemsToShow()
497
     * @see #setUseChevron(boolean)
498
     */
499
    public void setMinimumItemsToShow(int minimumItemsToShow) {
500
        if (checkDisposed()) {
501
            return;
502
        }
503
        this.minimumItemsToShow = minimumItemsToShow;
504
    }
505
506
    /**
507
     * Enables or disables chevron support for the cool item. By default,
508
     * chevron support is enabled.
509
     * 
510
     * @param value
511
     *            <code>true</code> to enable chevron support, <code>false</code>
512
     *            otherwise.
513
     */
514
    public void setUseChevron(boolean value) {
515
        if (checkDisposed()) {
516
            return;
517
        }
518
        useChevron = value;
519
    }
520
521
    /*
522
     * (non-Javadoc)
523
     * 
524
     * @see org.eclipse.jface.action.IContributionItem#update(java.lang.String)
525
     */
526
    public void update(String propertyName) {
527
        if (checkDisposed()) {
528
            return;
529
        }
530
        if (coolItem != null) {
531
            IToolBarManager manager = getToolBarManager();
532
            if (manager != null) {
533
                manager.update(true);
534
            }
535
536
            if ((propertyName == null)
537
                    || propertyName.equals(ICoolBarManager.SIZE)) {
538
                updateSize(true);
539
            }
540
        }
541
    }
542
543
    /**
544
     * Updates the cool items' preferred, minimum, and current size. The
545
     * preferred size is calculated based on the tool bar size and extra trim.
546
     * 
547
     * @param changeCurrentSize
548
     *            <code>true</code> if the current size should be changed to
549
     *            the preferred size, <code>false</code> to not change the
550
     *            current size
551
     */
552
    private void updateSize(boolean changeCurrentSize) {
553
        if (checkDisposed()) {
554
            return;
555
        }
556
        // cannot set size if coolItem is null
557
        if (coolItem == null || coolItem.isDisposed()) {
558
            return;
559
        }
560
        boolean locked = false;
561
        SCoolBar coolBar = (SCoolBar)coolItem.getParent();
562
        try {
563
            // Fix odd behaviour with locked tool bars
564
            if (coolBar != null) {
565
                if (coolBar.getLocked()) {
566
                    coolBar.setLocked(false);
567
                    locked = true;
568
                }
569
            }
570
            SToolBar toolBar = (SToolBar) coolItem.getControl();
571
            if ((toolBar == null) || (toolBar.isDisposed())
572
                    || (toolBar.getItemCount() <= 0)) {
573
                // if the toolbar does not contain any items then dispose of
574
                // coolItem
575
                coolItem.setData(null);
576
                Control control = coolItem.getControl();
577
                if ((control != null) && !control.isDisposed()) {
578
                    control.dispose();
579
                    coolItem.setControl(null);
580
                }
581
                if (!coolItem.isDisposed()) {
582
                    coolItem.dispose();
583
                }
584
            } else {
585
                // If the toolbar item exists then adjust the size of the cool
586
                // item
587
                Point toolBarSize = toolBar.computeSize(SWT.DEFAULT,
588
                        SWT.DEFAULT);
589
                // Set the preffered size to the size of the toolbar plus trim
590
/* FIXME TFS Why is this needed? For repositioning..???
591
 * 		Oh well. Interferring with the LS build so commenting out.              
592
 * 				Point preferredSize = coolItem.computeSize(toolBarSize.x,
593
                        toolBarSize.y);
594
                coolItem.setPreferredSize(preferredSize);
595
*/                // note setMinimumSize must be called before setSize, see PR
596
                // 15565
597
                // Set minimum size
598
                if (getMinimumItemsToShow() != SHOW_ALL_ITEMS) {
599
                    int toolItemWidth = toolBar.getItems()[0].getWidth();
600
                    int minimumWidth = toolItemWidth * getMinimumItemsToShow();
601
                    coolItem.setMinimumSize(minimumWidth, toolBarSize.y);
602
                } else {
603
                    coolItem.setMinimumSize(toolBarSize.x, toolBarSize.y);
604
                }
605
/* FIXME TFS See the fixme above. 
606
 *                if (changeCurrentSize) {
607
                    // Set current size to preferred size
608
                    coolItem.setSize(preferredSize);
609
                }
610
*/            }
611
        } finally {
612
            // If the cool bar was locked, then set it back to locked
613
            if ((locked) && (coolBar != null)) {
614
                coolBar.setLocked(true);
615
            }
616
        }
617
    }
618
619
    public void fill(SCoolBar coolBar, int index) {
620
        if (checkDisposed()) {
621
            return;
622
        }
623
624
        if (coolItem == null && coolBar != null) {
625
            Control oldToolBar = null;
626
            Control toolBar = null;
627
            if (toolBarManager instanceof ToolBarManager) {
628
                oldToolBar = ((ToolBarManager)toolBarManager).getControl();
629
                toolBar = ((ToolBarManager)toolBarManager).createControl(coolBar);
630
            } else if (toolBarManager instanceof SToolBarManager2) {
631
                oldToolBar = ((SToolBarManager2)toolBarManager).getControl();
632
                toolBar = ((SToolBarManager2)toolBarManager).createControl2(coolBar);
633
            }
634
            if ((oldToolBar != null) && (oldToolBar.equals(toolBar))) {
635
                // We are using an old tool bar, so we need to update.
636
                toolBarManager.update(true);
637
            }
638
639
            // Do not create a coolItem if the toolbar is empty
640
            if (toolBar instanceof ToolBar) {
641
                if (((ToolBar)toolBar).getItemCount() < 1)
642
                    return;
643
            } else if (toolBar instanceof SToolBar) {
644
                if (((SToolBar)toolBar).getItemCount() < 1)
645
                    return;
646
            }
647
            int flags = SWT.DROP_DOWN;
648
            if (index >= 0) {
649
                coolItem = new SCoolItem(coolBar, flags, index);
650
            } else {
651
                coolItem = new SCoolItem(coolBar, flags);
652
            }
653
            // sets the back reference
654
            coolItem.setData(this);
655
            // Add the toolbar to the CoolItem widget
656
            coolItem.setControl(toolBar);
657
658
            // Handle Context Menu
659
            // ToolBarManager.createControl can actually return a pre-existing control.
660
            // Only add the listener if the toolbar was newly created (bug 62097).
661
            if (oldToolBar != toolBar) {
662
	            toolBar.addListener(SWT.MenuDetect, new Listener() {
663
	
664
	                public void handleEvent(Event event) {
665
	                    // if the toolbar does not have its own context menu then
666
	                    // handle the event
667
	                    if (toolBarManager instanceof ToolBarManager) {
668
		                    if (((ToolBarManager)toolBarManager).getContextMenuManager() == null) {
669
		                        handleContextMenu(event);
670
		                    }
671
	                    } else if (toolBarManager instanceof SToolBarManager2) {
672
		                    if (((SToolBarManager2)toolBarManager).getContextMenuManager() == null) {
673
		                        handleContextMenu(event);
674
		                    }
675
	                    }
676
	                }
677
	            });
678
            }
679
680
            // Handle for chevron clicking
681
            if (getUseChevron()) {
682
                // Chevron Support
683
                coolItem.addSelectionListener(new SelectionAdapter() {
684
685
                    public void widgetSelected(SelectionEvent event) {
686
                        if (event.detail == SWT.ARROW) {
687
                            handleChevron(event);
688
                        }
689
                    }
690
                });
691
            }
692
693
            // Handle for disposal
694
            coolItem.addDisposeListener(new DisposeListener() {
695
696
                public void widgetDisposed(DisposeEvent event) {
697
                    handleWidgetDispose(event);
698
                }
699
            });
700
701
            // Sets the size of the coolItem
702
            updateSize(true);
703
        }
704
    }
705
706
	public void fill(SToolBar parent, int index) {
707
		// Do nothing
708
	}
709
710
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/HannoverGlobalToolBarSkin.java (+207 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.graphics.Color;
5
import org.eclipse.swt.graphics.Font;
6
import org.eclipse.swt.graphics.FontData;
7
import org.eclipse.swt.graphics.GC;
8
import org.eclipse.swt.graphics.Image;
9
import org.eclipse.swt.graphics.Point;
10
import org.eclipse.swt.graphics.Rectangle;
11
import org.eclipse.swt.widgets.Control;
12
import org.eclipse.swt.widgets.Display;
13
14
public class HannoverGlobalToolBarSkin implements Skin {
15
	
16
	// border colors
17
	Color borderTopColor = new Color(null, 255, 255, 255);
18
	Color borderBottomColor = new Color(null, 144, 161, 181);
19
	Color borderColor = new Color(null, 132, 132, 132);
20
	Color borderLeftRightColor = new Color(null, 255, 255, 255);
21
	Color itemBorderColor = new Color(null, 180, 180, 180);
22
	
23
	// background colors
24
	Color shadowColor = new Color(null, 109, 131, 180);
25
	Color backgroundTopColor = new Color(null, 247, 247, 247);
26
	Color backgroundBottomColor = new Color(null, 189, 198, 216);
27
	Color hoverItemBackgroundColor = new Color(null, 224, 233, 237);
28
	Color pressedItemBackgroundColor = new Color(null, 231, 231, 231);
29
	
30
	// arrows and text colors
31
	Color arrowColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
32
	Color textColor = new Color(null, 43,73,111);
33
	Color hoverTextColor = new Color(null, 20, 38, 54);
34
	
35
	Color separatorColor = new Color(null, 168, 181, 197);
36
	Font textFont;
37
	
38
	public HannoverGlobalToolBarSkin() {
39
		super();
40
		FontData fd = new FontData("Tahoma", 9, SWT.NORMAL);
41
		textFont = new Font(null, fd);
42
	}
43
44
	/**
45
	 * @deprecated use getRect() instead.
46
	 */
47
	public Rectangle getInsets(int type, int state) {
48
		return null;
49
	}
50
51
	/**
52
	 * @deprecated use getRect() instead.
53
	 */
54
	public Rectangle getMargins(int type, int state) {
55
		return new Rectangle(0,0,0,0);
56
	}
57
58
	public Font getFont(int type, int state) {
59
		return textFont;
60
	}
61
62
	public Point getSize(int type, int state) {
63
		if (type == Skin.TYPE_ITEM_MIN_MAX_HEIGHT) {
64
			return new Point(SWT.DEFAULT, SWT.DEFAULT);
65
		} else if (type == Skin.TYPE_ITEM_MIN_MAX_WIDTHS) {
66
			return new Point(SWT.DEFAULT, SWT.DEFAULT);
67
		} else if (type == Skin.TYPE_DECORATION_ARROW) {
68
			return new Point(5, 3);
69
		} else if (type == Skin.TYPE_DECORATION_SEPARATOR) {
70
			return new Point(3, SWT.DEFAULT);
71
		} else if (type == Skin.TYPE_ITEM_ICON_SIZE) {
72
			return new Point(20, 20);
73
		}
74
		return null;
75
	}
76
77
	public Rectangle getRect(int type, int state) {
78
		if (type == Skin.TYPE_ITEM_AREA_INSETS) {
79
			/*
80
			 * x - leading space before first item.
81
			 * y - space between top of toolbar and top of item
82
			 * width - trailing space after last item
83
			 * height - space between bottom of toolbar and bottom of item.
84
			 */
85
			return new Rectangle(1, 3, 1, 3);
86
		} else if (type == Skin.TYPE_ITEM_AREA_MARGINS) {
87
			/*
88
			 * x - space between items
89
			 * y - undefined
90
			 * width - undefined;
91
			 * height - undefined;
92
			 */
93
			return new Rectangle(5, 0, 0, 0);
94
		} else if (type == Skin.TYPE_ITEM_MARGINS) {
95
			/*
96
			 * x = horizontal space between image and text.
97
			 * y = horizontal space between image or text and hinky.
98
			 * width = undefined 
99
			 * height = undefined 
100
			 */
101
			return new Rectangle(3, 2, 0, 0);
102
		} else if (type == Skin.TYPE_ITEM_INSETS) {
103
			/* 
104
			 * x = left edge of tool item to left edge of image or text
105
			 * y = top edge of tool item to top edge of image or text
106
			 * width = right edge of last internal element and right edge of tool item.
107
			 * height = bottom edge of last internal element and bottom edge of tool item.
108
			 */
109
			return new Rectangle(0, 0, 0, 0);
110
		}
111
		
112
		return new Rectangle(0, 0, 0, 0);
113
	}
114
115
	public void drawBorder(GC gc, Rectangle rect, SWidget widget, int type, int state) {
116
		if (type == Skin.TYPE_BORDER) {
117
			// top edge
118
			gc.setForeground(borderTopColor);
119
			gc.drawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
120
			// bottom edge
121
			gc.setForeground(borderBottomColor);
122
			gc.drawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1);
123
		}
124
		
125
	}
126
127
	public void drawBackground(GC gc, Rectangle rect, SWidget widget, int type, int state) {
128
		if (type == Skin.TYPE_BACKGROUND) {
129
			if (widget instanceof Control) {
130
				gc.setForeground(backgroundTopColor); 
131
				gc.setBackground(backgroundBottomColor); 
132
				gc.fillGradientRectangle(rect.x, rect.y-1, rect.width, rect.height+1, true);
133
			}
134
		}
135
	}
136
137
	public void drawDecoration(GC gc, Rectangle rect, SWidget widget, int type, int state) {
138
		if (type == Skin.TYPE_DECORATION_ARROW) {
139
			int delta = 0;
140
			if ((state & Skin.PRESSED) == Skin.PRESSED) {
141
				delta = 1;
142
			}
143
			gc.setForeground(arrowColor);
144
			gc.drawLine(rect.x + delta, rect.y + delta, rect.x + rect.width -1 + delta, rect.y + delta);
145
			gc.drawLine(rect.x + 1 + delta, rect.y + 1 + delta, rect.x + rect.width -2 + delta, rect.y + 1 + delta);
146
			gc.drawPoint(rect.x + 2 + delta, rect.y + 2 + delta);
147
		} else if (type == Skin.TYPE_DECORATION_SEPARATOR) {
148
			gc.setForeground(separatorColor);
149
			gc.drawLine(rect.x + (rect.width /2), rect.y, rect.x + (rect.width /2), rect.y + rect.height - 1);
150
		}
151
	}
152
153
	public void drawText(GC gc, Rectangle rect, String text, int style, SWidget widget, int type, int state) {
154
		int delta = 0;
155
		if ((state & Skin.PRESSED) == Skin.PRESSED) {
156
			delta = 1;
157
			gc.setForeground(textColor);
158
		} 
159
		else if ((state & Skin.HOVER) == Skin.HOVER) {
160
			gc.setForeground(textColor);
161
		} 
162
		else {
163
			gc.setForeground(textColor);
164
		}
165
		gc.drawText(text, rect.x + delta, rect.y + delta, style);
166
	}
167
168
	public void drawImage(GC gc, Rectangle rect, Image image, SWidget widget, int type, int state) {
169
		Rectangle imageRect = image.getBounds();
170
		gc.drawImage(image, imageRect.x, imageRect.y, imageRect.width, imageRect.height,
171
					 rect.x, rect.y, imageRect.width, imageRect.height);
172
	}
173
174
	public void dispose() {
175
		if (borderColor != null && borderColor.isDisposed() == false)
176
			borderColor.dispose();
177
		if (itemBorderColor != null && itemBorderColor.isDisposed() == false)
178
			itemBorderColor.dispose();
179
180
		if (shadowColor != null && shadowColor.isDisposed() == false)
181
			shadowColor.dispose();
182
		if (backgroundTopColor != null && backgroundTopColor.isDisposed() == false)
183
			backgroundTopColor.dispose();
184
		if (backgroundBottomColor != null && backgroundBottomColor.isDisposed() == false)
185
			backgroundBottomColor.dispose();
186
		if (hoverItemBackgroundColor != null && hoverItemBackgroundColor.isDisposed() == false)
187
			hoverItemBackgroundColor.dispose();
188
		if (pressedItemBackgroundColor != null && pressedItemBackgroundColor.isDisposed() == false)
189
			pressedItemBackgroundColor.dispose();
190
		
191
		if (arrowColor != null && arrowColor.isDisposed() == false)
192
			arrowColor.dispose();
193
		if (textColor != null && textColor.isDisposed() == false)
194
			textColor.dispose();
195
		if (hoverTextColor != null && hoverTextColor.isDisposed() == false)
196
			hoverTextColor.dispose();
197
		
198
		if (separatorColor != null) {
199
			separatorColor.dispose();
200
		}
201
		
202
		if (textFont != null) {
203
			textFont.dispose();
204
			textFont = null;
205
		}
206
	}
207
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/Skin.java (+94 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.swt.graphics.Font;
4
import org.eclipse.swt.graphics.GC;
5
import org.eclipse.swt.graphics.Image;
6
import org.eclipse.swt.graphics.Point;
7
import org.eclipse.swt.graphics.Rectangle;
8
9
public interface Skin {
10
11
	// states
12
	public static final int NORMAL = 0;
13
	public static final int HOVER = 1 << 1;
14
	public static final int SELECTED = 1 << 2;
15
	public static final int PRESSED = 1 << 3;
16
	public static final int DISABLED = 1 << 4;
17
	public static final int COLLAPSED = 1 << 5;
18
	
19
	// decorations
20
	public final static int TYPE_DECORATION_CLOSE = 1;
21
	public final static int TYPE_DECORATION_SEPARATOR = 2;
22
	public final static int TYPE_DECORATION_FOCUS = 3;
23
	public final static int TYPE_DECORATION_ARROW = 4;
24
	public final static int TYPE_DECORATION_CHEVRON = 5;
25
	public final static int TYPE_DECORATION_DROPDOWN_BUTTON = 6;
26
	public final static int TYPE_DECORATION_COLLAPSE_BUTTON = 7;
27
	public final static int TYPE_DECORATION_EXPAND_BUTTON = 8;
28
	public final static int TYPE_DECORATION_GRIPPER = 9;
29
	public final static int TYPE_DECORATION_INTERNAL_SEPARATOR = 10;
30
	
31
	// borders
32
	public final static int TYPE_ITEM_MENU_BORDER = 11;
33
	public final static int TYPE_ITEM_AREA_BORDER = 12;
34
	public final static int TYPE_ITEM_BORDER = 13;
35
	public final static int TYPE_BORDER = 14;
36
	public final static int TYPE_GROUP_ITEM_BORDER = 15;
37
	public final static int TYPE_GROUP_BORDER = 16;
38
	public final static int TYPE_HEADER_ITEM_BORDER = 17;
39
	public final static int TYPE_HEADER_BORDER = 18;
40
	
41
	// backgrounds
42
	public final static int TYPE_ITEM_MENU_BACKGROUND = 19;
43
	public final static int TYPE_ITEM_AREA_BACKGROUND = 20;
44
	public final static int TYPE_ITEM_BACKGROUND = 21;
45
	public final static int TYPE_BACKGROUND = 22;
46
	public final static int TYPE_GROUP_ITEM_BACKGROUND = 23;
47
	public final static int TYPE_HEADER_ITEM_BACKGROUND = 24;
48
	public final static int TYPE_HEADER_BACKGROUND = 25;
49
50
	// fonts
51
	public final static int TYPE_ITEM_MENU_FONT = 26;
52
	public final static int TYPE_ITEM_FONT = 27;
53
	public final static int TYPE_FONT = 28;
54
	
55
	// text
56
	public final static int TYPE_ITEM_MENU_TEXT = 29;
57
	public final static int TYPE_ITEM_TEXT = 30;
58
	public final static int TYPE_TEXT= 31;
59
	public final static int TYPE_GROUP_ITEM_TEXT = 32;				
60
	public final static int TYPE_HEADER_ITEM_TEXT = 33;				
61
	
62
	// images
63
	public final static int TYPE_ITEM_IMAGE = 34;
64
	public final static int TYPE_IMAGE = 35;
65
	
66
	// properties
67
	public final static int TYPE_MARGINS = 36;
68
	public final static int TYPE_INSETS = 37;
69
	public final static int TYPE_ITEM_MARGINS = 38;
70
	public final static int TYPE_ITEM_INSETS = 39;
71
	public final static int TYPE_ITEM_AREA_MARGINS = 40;
72
	public final static int TYPE_ITEM_AREA_INSETS = 41;
73
	public final static int TYPE_ITEM_MENU_MARGINS = 42;
74
	public final static int TYPE_ITEM_MENU_INSETS = 43;	
75
	public final static int TYPE_DECORATION_CLOSE_INSETS = 44;
76
	public final static int TYPE_ITEM_MIN_MAX_WIDTHS = 45;
77
	public final static int TYPE_ITEM_ICON_SIZE = 46;
78
	public final static int TYPE_ITEM_MIN_MAX_HEIGHT = 47;
79
	
80
	abstract public Rectangle getInsets(int type, int state);
81
	abstract public Point getSize(int type, int state);
82
	abstract public Font getFont(int type, int state);
83
	abstract public Rectangle getMargins(int type, int state);
84
	abstract public Rectangle getRect(int type, int state);
85
86
	public abstract void drawBorder(GC gc, Rectangle rect, SWidget widget, int type, int state);
87
	public abstract void drawBackground(GC gc, Rectangle rect, SWidget widget, int type, int state);
88
	public abstract void drawDecoration(GC gc, Rectangle rect, SWidget widget, int type, int state);
89
	public abstract void drawText(GC gc, Rectangle rect, String text, int style, SWidget widget, int type, int state);
90
	public abstract void drawImage(GC gc, Rectangle rect, Image image, SWidget widget, int type, int state);
91
92
	abstract public void dispose();
93
94
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SActionContributionItem.java (+627 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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.ui.examples.presentation.customtoolbar.widgets;
12
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.ActionContributionItem;
15
import org.eclipse.jface.action.ExternalActionManager;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.action.IContributionManagerOverrides;
18
import org.eclipse.jface.action.IMenuCreator;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.JFaceResources;
21
import org.eclipse.jface.resource.LocalResourceManager;
22
import org.eclipse.jface.resource.ResourceManager;
23
import org.eclipse.jface.util.IPropertyChangeListener;
24
import org.eclipse.jface.util.Policy;
25
import org.eclipse.jface.util.PropertyChangeEvent;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.graphics.Point;
28
import org.eclipse.swt.graphics.Rectangle;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.CoolBar;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Event;
33
import org.eclipse.swt.widgets.Item;
34
import org.eclipse.swt.widgets.Listener;
35
import org.eclipse.swt.widgets.Menu;
36
import org.eclipse.swt.widgets.ToolBar;
37
import org.eclipse.swt.widgets.Widget;
38
39
/**
40
 * A contribution item which delegates to an action.
41
 * <p>
42
 * This class may be instantiated; it is not intended to be subclassed.
43
 * </p>
44
 */
45
public class SActionContributionItem extends ActionContributionItem implements ISContributionItem {
46
47
	ActionContributionItem actionContributionItem = null;
48
49
	private boolean isSeparator;
50
	
51
	/**
52
     * The listener for changes to the text of the action contributed by an
53
     * external source.
54
     */
55
    private final IPropertyChangeListener actionTextListener = new IPropertyChangeListener() {
56
57
        /**
58
         * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
59
         */
60
        public void propertyChange(PropertyChangeEvent event) {
61
            update(event.getProperty());
62
        }
63
    };
64
65
    /**
66
     * Remembers all images in use by this contribution item
67
     */
68
    private LocalResourceManager imageManager;
69
70
    private boolean isWidgetSet = false;
71
    
72
    /**
73
     * Listener for SWT tool item widget events.
74
     */
75
    private Listener toolItemListener;
76
    
77
    /**
78
     * The widget created for this item; <code>null</code>
79
     * before creation and after disposal.
80
     */
81
    private Widget widget = null;
82
    
83
    /**
84
     * Listener for action property change notifications.
85
     */
86
    private final IPropertyChangeListener propertyListener = new IPropertyChangeListener() {
87
        public void propertyChange(PropertyChangeEvent event) {
88
            actionPropertyChange(event);
89
        }
90
    };
91
	
92
	public SActionContributionItem() {
93
		this(new ActionContributionItem(new Action() {public void run() {}}));
94
		this.isSeparator = true;
95
	}
96
	
97
    /**
98
     * @param action
99
     */
100
    public SActionContributionItem(IAction action) {
101
		this(new ActionContributionItem(action));
102
	}
103
    
104
    /**
105
     * 
106
     * @param action
107
     */
108
    public SActionContributionItem(ActionContributionItem actionContributionItem) {
109
		super(actionContributionItem.getAction());
110
		this.actionContributionItem = actionContributionItem;
111
    }
112
113
	public boolean isSeparator() {
114
		return isSeparator;
115
	}
116
117
    /**
118
     * Handles a property change event on the action (forwarded by nested listener).
119
     */
120
    private void actionPropertyChange(final PropertyChangeEvent e) {
121
        // This code should be removed. Avoid using free asyncExec
122
123
        if (isVisible() && widget != null) {
124
            Display display = widget.getDisplay();
125
            if (display.getThread() == Thread.currentThread()) {
126
                update(e.getProperty());
127
            } else {
128
                display.asyncExec(new Runnable() {
129
                    public void run() {
130
                        update(e.getProperty());
131
                    }
132
                });
133
            }
134
135
        }
136
    }
137
	
138
    /**
139
     * Dispose any images allocated for this contribution item
140
     */
141
    private void disposeOldImages() {
142
        if (imageManager != null) {
143
            imageManager.dispose();
144
            imageManager = null;
145
        }
146
    }
147
    
148
	/* (non-Javadoc)
149
	 * @see org.eclipse.jface.action.ActionContributionItem#fill(org.eclipse.swt.widgets.Composite)
150
	 */
151
	public void fill(Composite parent) {
152
		isWidgetSet = true;
153
		actionContributionItem.fill(parent);
154
	}
155
156
	/* (non-Javadoc)
157
	 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.CoolBar, int)
158
	 */
159
	public void fill(CoolBar parent, int index) {
160
		if (widget instanceof SToolItem)
161
			return;
162
		isWidgetSet = true;
163
		actionContributionItem.fill(parent, index);
164
	}
165
	
166
	/* (non-Javadoc)
167
	 * @see org.eclipse.jface.action.ActionContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
168
	 */
169
	public void fill(Menu parent, int index) {
170
		if (widget instanceof SToolItem)
171
			return;
172
		isWidgetSet = true;
173
		actionContributionItem.fill(parent, index);
174
	}
175
176
	/* (non-Javadoc)
177
	 * @see org.eclipse.jface.action.ActionContributionItem#fill(org.eclipse.swt.widgets.ToolBar, int)
178
	 */
179
	public void fill(ToolBar parent, int index) {
180
		if (widget instanceof SToolItem)
181
			return;
182
		isWidgetSet = true;
183
		actionContributionItem.fill(parent, index);
184
	}
185
    
186
	public void fill(SCoolBar parent, int index) {
187
		// do nothing
188
	}
189
190
	public void fill(SToolBar parent, int index) {
191
        if (isWidgetSet == false && widget == null && parent != null) {
192
            int flags = SWT.PUSH;
193
            IAction action = getAction();
194
            if (action != null) {
195
				if (isSeparator) {
196
					flags = SWT.SEPARATOR;
197
				} else {
198
	                int style = action.getStyle();
199
	                if (style == IAction.AS_CHECK_BOX)
200
	                    flags = SWT.CHECK;
201
	                else if (style == IAction.AS_RADIO_BUTTON)
202
	                    flags = SWT.RADIO;
203
	                else if (style == IAction.AS_DROP_DOWN_MENU)
204
	                    flags = SWT.DROP_DOWN;
205
				}
206
            }
207
208
            Item ti = null;
209
            if (index >= 0)
210
                ti = new SToolItem(parent, flags, index);
211
            else
212
                ti = new SToolItem(parent, flags);
213
            ti.setData(this);
214
            ti.addListener(SWT.Selection, getToolItemListener());
215
            ti.addListener(SWT.Dispose, getToolItemListener());
216
217
            widget = ti;
218
219
            update(null);
220
221
            // Attach some extra listeners.
222
            action.addPropertyChangeListener(propertyListener);
223
            if (action != null) {
224
                String commandId = action.getActionDefinitionId();
225
                ExternalActionManager.ICallback callback = ExternalActionManager
226
                        .getInstance().getCallback();
227
228
                if ((callback != null) && (commandId != null)) {
229
                    callback.addPropertyChangeListener(commandId,
230
                            actionTextListener);
231
                }
232
            }
233
        }
234
	}
235
	
236
    private Listener getToolItemListener() {
237
        if (toolItemListener == null) {
238
            toolItemListener = new Listener() {
239
                public void handleEvent(Event event) {
240
                    switch (event.type) {
241
                    case SWT.Dispose:
242
                        handleWidgetDispose(event);
243
                        break;
244
                    case SWT.Selection:
245
                        Widget ew = event.widget;
246
                        if (ew != null) {
247
                            handleWidgetSelection(event, ((SToolItem) ew)
248
                                    .getSelection());
249
                        }
250
                        break;
251
                    }
252
                }
253
            };
254
        }
255
        return toolItemListener;
256
    }
257
    
258
    /**
259
     * Handles a widget dispose event for the widget corresponding to this item.
260
     */
261
    private void handleWidgetDispose(Event e) {
262
        // Check if our widget is the one being disposed.
263
        if (e.widget == widget) {
264
            IAction action = getAction();
265
            // Dispose of the menu creator.
266
            if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
267
                IMenuCreator mc = action.getMenuCreator();
268
                if (mc != null) {
269
                    mc.dispose();
270
                }
271
            }
272
273
            // Unhook all of the listeners.
274
            action.removePropertyChangeListener(propertyListener);
275
            if (action != null) {
276
                String commandId = action.getActionDefinitionId();
277
                ExternalActionManager.ICallback callback = ExternalActionManager
278
                        .getInstance().getCallback();
279
280
                if ((callback != null) && (commandId != null)) {
281
                    callback.removePropertyChangeListener(commandId,
282
                            actionTextListener);
283
                }
284
            }
285
286
            // Clear the widget field.
287
            widget = null;
288
            
289
            disposeOldImages();
290
        }
291
    }
292
293
    /**
294
     * Handles a widget selection event.
295
     */
296
    private void handleWidgetSelection(Event e, boolean selection) {
297
298
        Widget item = e.widget;
299
        if (item != null) {
300
            int style = item.getStyle();
301
            IAction action = getAction();
302
303
            if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) {
304
                if (action.getStyle() == IAction.AS_CHECK_BOX) {
305
                    action.setChecked(selection);
306
                }
307
            } else if ((style & SWT.RADIO) != 0) {
308
                if (action.getStyle() == IAction.AS_RADIO_BUTTON) {
309
                    action.setChecked(selection);
310
                }
311
            } else if ((style & SWT.DROP_DOWN) != 0) {
312
                if (e.detail == 4) { // on drop-down button
313
                    if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
314
                        IMenuCreator mc = action.getMenuCreator();
315
                        SToolItem ti = (SToolItem) item;
316
                        // we create the menu as a sub-menu of "dummy" so that we can use
317
                        // it in a cascading menu too.
318
                        // If created on a SWT control we would get an SWT error...
319
                        //Menu dummy= new Menu(ti.getParent());
320
                        //Menu m= mc.getMenu(dummy);
321
                        //dummy.dispose();
322
                        if (mc != null) {
323
                            Menu m = mc.getMenu(ti.getParent());
324
                            if (m != null) {
325
                                // position the menu below the drop down item
326
                                Rectangle b = ti.getBounds();
327
                                Point p = ti.getParent().toDisplay(
328
                                        new Point(b.x, b.y + b.height));
329
                                m.setLocation(p.x, p.y); // waiting for SWT 0.42
330
                                m.setVisible(true);
331
                                return; // we don't fire the action
332
                            }
333
                        }
334
                    }
335
                }
336
            }
337
            // Ensure action is enabled first.
338
            // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be executed while disabled.
339
            if (action.isEnabled()) {
340
                boolean trace = Policy.TRACE_ACTIONS;
341
342
                long ms = System.currentTimeMillis();
343
                if (trace)
344
                    System.out.println("Running action: " + action.getText()); //$NON-NLS-1$
345
346
                action.runWithEvent(e);
347
348
                if (trace)
349
                    System.out.println((System.currentTimeMillis() - ms)
350
                            + " ms to run action: " + action.getText()); //$NON-NLS-1$
351
            }
352
        }
353
    }
354
    
355
    /**
356
     * Returns whether the given action has any images.
357
     * 
358
     * @param actionToCheck the action
359
     * @return <code>true</code> if the action has any images, <code>false</code> if not
360
     */
361
    private boolean hasImages(IAction actionToCheck) {
362
        return actionToCheck.getImageDescriptor() != null
363
                || actionToCheck.getHoverImageDescriptor() != null
364
                || actionToCheck.getDisabledImageDescriptor() != null;
365
    }
366
    
367
    /**
368
     * Synchronizes the UI with the given property.
369
     *
370
     * @param propertyName the name of the property, or <code>null</code> meaning all applicable
371
     *   properties 
372
     */
373
    public void update(String propertyName) {
374
    	
375
        if (widget instanceof SToolItem) {
376
        	
377
            // determine what to do
378
        	IAction action = getAction();
379
            boolean textChanged = propertyName == null
380
                    || propertyName.equals(IAction.TEXT);
381
            boolean imageChanged = propertyName == null
382
                    || propertyName.equals(IAction.IMAGE);
383
            boolean tooltipTextChanged = propertyName == null
384
                    || propertyName.equals(IAction.TOOL_TIP_TEXT);
385
            boolean enableStateChanged = propertyName == null
386
                    || propertyName.equals(IAction.ENABLED)
387
                    || propertyName
388
                            .equals(IContributionManagerOverrides.P_ENABLED);
389
            boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX || action
390
                    .getStyle() == IAction.AS_RADIO_BUTTON)
391
                    && (propertyName == null || propertyName
392
                            .equals(IAction.CHECKED));
393
394
            if (widget instanceof SToolItem) {
395
                SToolItem ti = (SToolItem) widget;
396
                String text = action.getText();
397
                // the set text is shown only if there is no image or if forced by MODE_FORCE_TEXT
398
                boolean showText = text != null
399
                        && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action));
400
401
                // only do the trimming if the text will be used
402
                if (showText && text != null) {
403
                    text = Action.removeAcceleratorText(text);
404
                    text = Action.removeMnemonics(text);
405
                }
406
407
                if (textChanged) {
408
                    String textToSet = showText ? text : ""; //$NON-NLS-1$
409
                    boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0;
410
                    if (rightStyle || !ti.getText().equals(textToSet)) {
411
                        // In addition to being required to update the text if it
412
                        // gets nulled out in the action, this is also a workaround 
413
                        // for bug 50151: Using SWT.RIGHT on a ToolBar leaves blank space
414
                        ti.setText(textToSet);
415
                    }
416
                }
417
418
                if (imageChanged) {
419
                    // only substitute a missing image if it has no text
420
                    updateImages(!showText);
421
                }
422
423
                if (tooltipTextChanged || textChanged) {
424
                    String toolTip = action.getToolTipText();
425
                    // if the text is showing, then only set the tooltip if different
426
                    if (!showText || toolTip != null && !toolTip.equals(text)) {
427
                        ti.setToolTipText(toolTip);
428
                    } else {
429
                        ti.setToolTipText(null);
430
                    }
431
                }
432
433
/* FIXME TFS -- Need to keep the buttons enabled for now so they actually look like they work.
434
 * 			[Terry Smith 12/9/2005].
435
 *                 if (enableStateChanged) {
436
                    boolean shouldBeEnabled = action.isEnabled()
437
                            && isEnabledAllowed();
438
439
                    if (ti.getEnabled() != shouldBeEnabled)
440
                       ti.setEnabled(shouldBeEnabled);
441
                }
442
*/
443
                if (checkChanged) {
444
                    boolean bv = action.isChecked();
445
446
                    if (ti.getSelection() != bv)
447
                        ti.setSelection(bv);
448
                }
449
                return;
450
            }
451
        } else {
452
       		actionContributionItem.update(propertyName);
453
        }
454
    }
455
456
    /**
457
     * Updates the images for this action.
458
     *
459
     * @param forceImage <code>true</code> if some form of image is compulsory,
460
     *  and <code>false</code> if it is acceptable for this item to have no image
461
     * @return <code>true</code> if there are images for this action, <code>false</code> if not
462
     */
463
    private boolean updateImages(boolean forceImage) {
464
465
        ResourceManager parentResourceManager = JFaceResources.getResources();
466
        
467
        if (widget instanceof SToolItem) {
468
        	IAction action = getAction();
469
            if (getUseColorIconsInToolbars()) {
470
                ImageDescriptor imageDesc = action.getImageDescriptor();
471
                ImageDescriptor hoverImageDesc = action.getHoverImageDescriptor();
472
                ImageDescriptor disabledImageDesc = action.getDisabledImageDescriptor();
473
                ImageDescriptor pressedImageDesc = null;
474
                                
475
                if (imageDesc == null && forceImage) {
476
                    imageDesc = ImageDescriptor.getMissingImageDescriptor();
477
                }
478
                
479
//                if (disabledImageDesc == null && imageDesc != null) {
480
//               	disabledImageDesc = ImageDescriptor.createWithFlags(imageDesc, SWT.IMAGE_GRAY); 
481
//                }
482
483
                LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);
484
                
485
                // performance: more efficient in SWT to set disabled and hot image before regular image
486
                ((SToolItem) widget).setDisabledImage(disabledImageDesc != null ? localManager.createImageWithDefault(disabledImageDesc) : null);
487
                ((SToolItem) widget).setHotImage(hoverImageDesc != null ? localManager.createImageWithDefault(hoverImageDesc) : null);
488
                ((SToolItem) widget).setImage(imageDesc != null ? localManager.createImageWithDefault(imageDesc) : null);
489
                disposeOldImages();
490
                imageManager = localManager;
491
492
                return imageDesc != null;
493
/* TODO TFS Old Crap             	
494
                ImageDescriptor image = action.getHoverImageDescriptor();
495
                if (image == null) {
496
                    image = action.getImageDescriptor();
497
                }
498
                ImageDescriptor disabledImage = action.getDisabledImageDescriptor();
499
500
                // Make sure there is a valid image.
501
                if (image == null && forceImage) {
502
                    image = ImageDescriptor.getMissingImageDescriptor();
503
                }
504
        
505
                LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);
506
                
507
                // performance: more efficient in SWT to set disabled and hot image before regular image
508
                ((SToolItem) widget).setDisabledImage(disabledImage == null ? null : localManager.createImageWithDefault(disabledImage));
509
                ((SToolItem) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));
510
511
                disposeOldImages();
512
                imageManager = localManager;
513
                
514
                return image != null;
515
*/
516
            }
517
            ImageDescriptor image = action.getImageDescriptor();
518
            ImageDescriptor hoverImage = action
519
                    .getHoverImageDescriptor();
520
            ImageDescriptor disabledImage = action
521
                    .getDisabledImageDescriptor();
522
523
            // If there is no regular image, but there is a hover image,
524
            // convert the hover image to gray and use it as the regular image.
525
            if (image == null && hoverImage != null) {
526
                image = ImageDescriptor.createWithFlags(action.getHoverImageDescriptor(), SWT.IMAGE_GRAY); 
527
            } else {
528
                // If there is no hover image, use the regular image as the hover image,
529
                // and convert the regular image to gray
530
                if (hoverImage == null && image != null) {
531
                    hoverImage = image;
532
                    image = ImageDescriptor.createWithFlags(action.getImageDescriptor(), SWT.IMAGE_GRAY);
533
                }
534
            }
535
536
            // Make sure there is a valid image.
537
            if (hoverImage == null && image == null && forceImage) {
538
                image = ImageDescriptor.getMissingImageDescriptor();
539
            }
540
541
            // Create a local resource manager to remember the images we've allocated for this tool item
542
            LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);
543
            
544
            // performance: more efficient in SWT to set disabled and hot image before regular image
545
            ((SToolItem) widget).setDisabledImage(disabledImage == null? null : localManager.createImageWithDefault(disabledImage));
546
            ((SToolItem) widget).setHotImage(hoverImage == null? null : localManager.createImageWithDefault(hoverImage));
547
            ((SToolItem) widget).setImage(image == null? null : localManager.createImageWithDefault(image));
548
549
            // Now that we're no longer referencing the old images, clear them out.
550
            disposeOldImages();
551
            imageManager = localManager;
552
            
553
            return image != null;
554
        }
555
        return false;
556
    }
557
558
	/* (non-Javadoc)
559
	 * @see org.eclipse.jface.action.ActionContributionItem#equals(java.lang.Object)
560
	 */
561
	public boolean equals(Object o) {
562
		
563
        if (!(o instanceof ActionContributionItem)) {
564
            return false;
565
        }
566
        return actionContributionItem.getAction().equals(((ActionContributionItem) o).getAction());
567
	}
568
569
	/* (non-Javadoc)
570
	 * @see org.eclipse.jface.action.ActionContributionItem#getAction()
571
	 */
572
	public IAction getAction() {
573
		return actionContributionItem.getAction();
574
	}
575
576
	/* (non-Javadoc)
577
	 * @see org.eclipse.jface.action.ActionContributionItem#getMode()
578
	 */
579
	public int getMode() {
580
		return actionContributionItem.getMode();
581
	}
582
583
	/* (non-Javadoc)
584
	 * @see org.eclipse.jface.action.ActionContributionItem#hashCode()
585
	 */
586
	public int hashCode() {
587
		return actionContributionItem.hashCode();
588
	}
589
590
	/* (non-Javadoc)
591
	 * @see org.eclipse.jface.action.ActionContributionItem#isDynamic()
592
	 */
593
	public boolean isDynamic() {
594
		return actionContributionItem.isDynamic();
595
	}
596
597
	/* (non-Javadoc)
598
	 * @see org.eclipse.jface.action.ActionContributionItem#isEnabled()
599
	 */
600
	public boolean isEnabled() {
601
		return actionContributionItem.isEnabled();
602
	}
603
604
	/* (non-Javadoc)
605
	 * @see org.eclipse.jface.action.ActionContributionItem#isEnabledAllowed()
606
	 */
607
	protected boolean isEnabledAllowed() {
608
        if (actionContributionItem.getParent() == null)
609
            return true;
610
        Boolean value = actionContributionItem.getParent().getOverrides().getEnabled(this);
611
        return (value == null) ? true : value.booleanValue();
612
	}
613
614
	/* (non-Javadoc)
615
	 * @see org.eclipse.jface.action.ActionContributionItem#isVisible()
616
	 */
617
	public boolean isVisible() {
618
		return actionContributionItem.isVisible();
619
	}
620
621
	/* (non-Javadoc)
622
	 * @see org.eclipse.jface.action.ActionContributionItem#setMode(int)
623
	 */
624
	public void setMode(int mode) {
625
		actionContributionItem.setMode(mode);
626
	}
627
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SCoolItem.java (+322 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.SelectionAdapter;
5
import org.eclipse.swt.graphics.GC;
6
import org.eclipse.swt.graphics.Image;
7
import org.eclipse.swt.graphics.Point;
8
import org.eclipse.swt.graphics.Rectangle;
9
import org.eclipse.swt.widgets.Control;
10
import org.eclipse.swt.widgets.Item;
11
12
public class SCoolItem extends Item {
13
	Control control;
14
	int preferredHeight = -1;
15
	int preferredWidth = -1;
16
	int width = -1;
17
	int height = -1;
18
	//int hIndent = 8;
19
	int hIndent = 0;
20
	//int vIndent = 8;
21
	int vIndent = 0;
22
	Rectangle itemBounds = new Rectangle(0, 0, 0, 0);
23
	boolean wrap = false;  // true if the item should be moved onto the next row.
24
	boolean alignment = false;  // true if the item and (the items following the items) should be right-aligned. 
25
	Image arrowImage = null;
26
	private SCoolBar parent = null;
27
	
28
	public SCoolItem(SCoolBar parent, int style) {
29
		this(parent, style, parent.getItemCount());
30
	}
31
32
	public SCoolItem(SCoolBar parent, int style, int index) {
33
		super(parent, style);
34
		this.parent = parent;
35
		parent.createItem (this, index);
36
	}
37
38
	public void addSelectionListener(SelectionAdapter adapter) {
39
		// TODO Auto-generated method stub
40
	}
41
42
	public Point computeSize(int wHint, int hHint) {
43
		return computeSize(wHint, hHint, true);
44
	}
45
	
46
	public Point computeSize(int wHint, int hHint, boolean changed) {
47
		checkWidget();
48
49
		Skin skin = parent.getSkin();
50
		int width = wHint;
51
		int height = hHint;
52
		
53
		if (control != null && (width == SWT.DEFAULT || height == SWT.DEFAULT)) {
54
			Point size = control.computeSize(width, height);
55
			if (width == SWT.DEFAULT) {
56
				width = size.x;
57
			}
58
			if (height == SWT.DEFAULT) {
59
				height = size.y;
60
			}
61
			
62
			size = null;
63
			if (skin != null) {
64
				size = skin.getSize(Skin.TYPE_DECORATION_GRIPPER, Skin.NORMAL);
65
			} 
66
			if (size == null) {
67
				size = new Point(0, 0);
68
			}
69
			if ((parent.getStyle() & SWT.VERTICAL) == SWT.VERTICAL) {
70
				height += size.x;
71
				if (size.y != SWT.DEFAULT) {
72
					width = Math.max(width, size.y);
73
				}
74
			} else {
75
				width += size.x;
76
				if (size.y != SWT.DEFAULT) {
77
					height = Math.max(height, size.y);
78
				}
79
			}
80
		} else {
81
			Point minMax = null;
82
			if (skin != null) {
83
				minMax = skin.getSize(Skin.TYPE_ITEM_MIN_MAX_HEIGHT, Skin.NORMAL);
84
			} 
85
			if (minMax == null) {
86
				minMax = new Point(SWT.DEFAULT, SWT.DEFAULT);
87
			}
88
			
89
			if (height == SWT.DEFAULT) {
90
				if (minMax.x != SWT.DEFAULT) {
91
					height = minMax.x;
92
				} else {
93
					height = 0;
94
				}
95
			}
96
97
			minMax = null;
98
			if (skin != null) {
99
				minMax = skin.getSize(Skin.TYPE_ITEM_MIN_MAX_HEIGHT, Skin.NORMAL);
100
			} 
101
			if (minMax == null) {
102
				minMax = new Point(SWT.DEFAULT, SWT.DEFAULT);
103
			}
104
			if (width == SWT.DEFAULT) {
105
				if (minMax.x != SWT.DEFAULT) {
106
					width = minMax.x;
107
				} else {
108
					width = 0;
109
				}
110
			}
111
		}
112
113
		Rectangle borders = null;
114
		if (skin != null) {
115
			borders = skin.getRect(Skin.TYPE_ITEM_BORDER, Skin.NORMAL);
116
		} 
117
		if (borders == null) {
118
			borders = new Rectangle(0, 0, 0, 0);
119
		}
120
		
121
		width += borders.x + borders.width;
122
		height += borders.y + borders.height;
123
		
124
		return new Point(width, height);
125
	}
126
127
	public Rectangle getBounds() {
128
		return itemBounds;
129
	}
130
	
131
	public Control getControl() {
132
		return control;
133
	}
134
135
	public Control getParent() {
136
		return this.parent;
137
	}
138
	
139
	public Point getPreferredSize() {
140
		checkWidget();
141
		int width = preferredWidth;
142
		int height = preferredHeight;
143
		if (control != null && (width == SWT.DEFAULT || height == SWT.DEFAULT)) {
144
			Point size = control.computeSize(width, height);
145
			if (width == SWT.DEFAULT) {
146
				width = size.x;
147
			}
148
			if (height == SWT.DEFAULT) {
149
				height = size.y;
150
			}
151
			
152
			Skin skin = parent.getSkin();
153
			size = null;
154
			if (skin != null) {
155
				size = skin.getSize(Skin.TYPE_DECORATION_GRIPPER, Skin.NORMAL);
156
			} 
157
			if (size == null) {
158
				size = new Point(0, 0);
159
			}
160
			if ((parent.getStyle() & SWT.VERTICAL) == SWT.VERTICAL) {
161
				height += size.x;
162
				if (size.y != SWT.DEFAULT) {
163
					width = Math.max(width, size.y);
164
				}
165
			} else {
166
				width += size.x;
167
				if (size.y != SWT.DEFAULT) {
168
					height = Math.max(height, size.y);
169
				}
170
			}
171
172
			Rectangle borders = null;
173
			if (skin != null) {
174
				borders = skin.getRect(Skin.TYPE_ITEM_BORDER, Skin.NORMAL);
175
			} 
176
			if (borders == null) {
177
				borders = new Rectangle(0, 0, 0, 0);
178
			}
179
			
180
			width += borders.x + borders.width;
181
			height += borders.y + borders.height;
182
		}
183
		
184
		return new Point(width, height);
185
	}
186
187
	public Point getSize() {
188
		checkWidget();
189
		if (itemBounds == null)
190
			itemBounds = new Rectangle(0,0,0,0);
191
		return new Point(itemBounds.width, itemBounds.height);
192
	}
193
	
194
	public void setBounds(int x, int y, int width, int height) {
195
		itemBounds.x = x;
196
		itemBounds.y = y;
197
		itemBounds.width = width;
198
		itemBounds.height = height;
199
200
		if (control != null) {
201
			Skin skin = parent.getSkin();
202
			Point size = null;
203
			if (skin != null) {
204
				size = skin.getSize(Skin.TYPE_DECORATION_GRIPPER, Skin.NORMAL);
205
			} 
206
			if (size == null) {
207
				size = new Point(0, 0);
208
			}
209
210
			if (width > size.x) {
211
				width -= size.x;
212
			} else {
213
				width = size.x;
214
			}
215
216
			Rectangle borders = null;
217
			if (skin != null) {
218
				borders = skin.getRect(Skin.TYPE_ITEM_BORDER, Skin.NORMAL);
219
			} 
220
			if (borders == null) {
221
				borders = new Rectangle(0, 0, 0, 0);
222
			}
223
			
224
			width -= (borders.x + borders.width);
225
			height -= (borders.y + borders.height);
226
227
			Rectangle controlRect = new Rectangle(itemBounds.x + size.x, y, width - size.x, height);
228
			control.setBounds(controlRect);
229
		}
230
	}
231
232
	public void setControl(Control control) {
233
		if (control != null) {
234
			if (control.isDisposed()) 
235
				SWT.error (SWT.ERROR_INVALID_ARGUMENT);
236
			if (control.getParent() != parent) 
237
				SWT.error (SWT.ERROR_INVALID_PARENT);
238
		}
239
		this.control = control;
240
		
241
		parent.layout();
242
	}
243
	
244
	public void setMinimumSize(int width, int height) {
245
		// TODO Auto-generated method stub
246
	}
247
	
248
	public void setPreferredSize(Point preferredSize) {
249
		setPreferredSize(preferredSize.x, preferredSize.y);
250
	}
251
252
	public void setPreferredSize (int width, int height) {
253
		preferredWidth = width;
254
		preferredHeight = height;
255
	}
256
257
	public void setSize(int width, int height) {
258
		checkWidget();
259
		itemBounds.width = width;
260
		itemBounds.height = height;
261
		
262
		if (preferredWidth == -1)
263
			preferredWidth = width;
264
		if (preferredHeight == -1)
265
			preferredHeight = height;
266
		
267
//		if (control != null) {
268
//			control.setSize(width - SCoolBar.GRIPPER_AREA_WIDTH, height);
269
//		}
270
//	TFS - parent.layout()?
271
	}
272
	
273
	public void setSize(Point pt) {
274
		checkWidget();
275
		if (pt == null) {
276
			SWT.error (SWT.ERROR_NULL_ARGUMENT);
277
		}
278
		setSize(pt.x, pt.y);
279
	}
280
281
	public void paint(GC gc, int state) {
282
		Skin skin = parent.getSkin();
283
284
		if (skin == null) {
285
			return;
286
		}
287
288
		skin.drawBackground(gc, itemBounds, parent, Skin.TYPE_ITEM_BACKGROUND, state);
289
		skin.drawBorder(gc, itemBounds, parent, Skin.TYPE_ITEM_BORDER, state);
290
291
		Point size = skin.getSize(Skin.TYPE_DECORATION_GRIPPER, state);
292
		if (size == null) {
293
			return;
294
		}
295
296
		if ((parent.getStyle() & SWT.VERTICAL) == SWT.VERTICAL) {
297
			if (size.y == SWT.DEFAULT) {
298
				size.y = 0;
299
			}
300
			if (size.x == SWT.DEFAULT) {
301
				size.x = itemBounds.width;
302
			}
303
			
304
		} else {
305
			if (size.x == SWT.DEFAULT) {
306
				size.x = 0;
307
			}
308
			if (size.y == SWT.DEFAULT) {
309
				size.y = itemBounds.height;
310
			}
311
		}
312
		
313
		if (size.x == 0 || size.y == 0) {
314
			return;
315
		}
316
		
317
		Rectangle gripperRect = new Rectangle(itemBounds.x, itemBounds.y, size.x, size.y);
318
		skin.drawDecoration(gc, gripperRect, parent, Skin.TYPE_DECORATION_GRIPPER, state);
319
320
	}
321
322
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/CustomToolBarPresentationFactory.java (+75 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar;
2
3
import org.eclipse.jface.action.ICoolBarManager;
4
import org.eclipse.jface.action.IToolBarManager;
5
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
6
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
7
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
8
import org.eclipse.swt.SWT;
9
import org.eclipse.swt.widgets.Composite;
10
import org.eclipse.swt.widgets.Control;
11
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SCoolBarManager;
12
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SToolBarContributionItem2;
13
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SToolBarManager2;
14
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
15
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
16
17
/**
18
 * Demonstrates how to customize the tool bars in an RCP application.
19
 *
20
 */
21
public class CustomToolBarPresentationFactory extends WorkbenchPresentationFactory implements IActionBarPresentationFactory {
22
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarManager()
25
	 */
26
	public ICoolBarManager2 createCoolBarManager() {
27
		SCoolBarManager coolBarManager = new SCoolBarManager(SWT.FLAT);
28
		return coolBarManager;
29
	}
30
	
31
	/* (non-Javadoc)
32
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarManager()
33
	 */
34
	public IToolBarManager2 createToolBarManager() {
35
		SToolBarManager2 toolBarManager = new SToolBarManager2(SWT.FLAT);
36
		return toolBarManager;
37
	}
38
	
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createViewToolBarManager()
41
	 */
42
	public IToolBarManager2 createViewToolBarManager() {
43
		SToolBarManager2 toolBarManager = new SToolBarManager2(SWT.FLAT);
44
		return toolBarManager;
45
	}
46
	
47
    /* (non-Javadoc)
48
     * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
49
     */
50
    public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
51
    	return new SToolBarContributionItem2(toolBarManager, id);
52
    }
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarControl(org.eclipse.jface.action.ICoolBarManager, org.eclipse.swt.widgets.Composite)
56
	 */
57
	public Control createCoolBarControl(ICoolBarManager2 coolBarManager, Composite parent) {
58
		return coolBarManager.createControl2(parent);
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarControl(org.eclipse.jface.action.IToolBarManager2, org.eclipse.swt.widgets.Composite)
63
	 */
64
	public Control createToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
65
		return toolBarManager.createControl2(parent);
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createViewToolBarControl(org.eclipse.jface.action.IToolBarManager2, org.eclipse.swt.widgets.Composite)
70
	 */
71
	public Control createViewToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
72
		return toolBarManager.createControl2(parent);
73
	}		
74
	
75
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SCoolBarManager.java (+1036 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.ListIterator;
8
9
import org.eclipse.jface.action.ContributionManager;
10
import org.eclipse.jface.action.IContributionItem;
11
import org.eclipse.jface.action.ICoolBarManager;
12
import org.eclipse.jface.action.IMenuManager;
13
import org.eclipse.jface.action.IToolBarManager;
14
import org.eclipse.jface.action.MenuManager;
15
import org.eclipse.jface.action.Separator;
16
import org.eclipse.jface.action.ToolBarContributionItem;
17
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
18
import org.eclipse.jface.util.Assert;
19
import org.eclipse.jface.util.Policy;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.CoolBar;
24
import org.eclipse.swt.widgets.Menu;
25
26
public class SCoolBarManager extends ContributionManager implements ICoolBarManager2 {
27
28
    /**
29
     * A separator created by the end user.
30
     */
31
    public final static String USER_SEPARATOR = "UserSeparator"; //$NON-NLS-1$
32
33
    /**
34
     * The original creation order of the contribution items.
35
     */
36
    private ArrayList cbItemsCreationOrder = new ArrayList();
37
38
    /**
39
     * MenuManager for cool bar pop-up menu, or null if none.
40
     */
41
    private MenuManager contextMenuManager = null;
42
43
    /**
44
     * The cool bar control; <code>null</code> before creation and after
45
     * disposal.
46
     */
47
    private SCoolBar coolBar = null;
48
49
    /**
50
     * The cool bar items style; <code>SWT.NONE</code> by default.
51
     */
52
    private int itemStyle = SWT.NONE;
53
54
    /**
55
     * Creates a new cool bar manager with the default style. Equivalent to
56
     * <code>CoolBarManager(SWT.NONE)</code>.
57
     */
58
    public SCoolBarManager() {
59
        // do nothing
60
    }
61
62
    /**
63
     * Creates a cool bar manager for an existing cool bar control. This
64
     * manager becomes responsible for the control, and will dispose of it when
65
     * the manager is disposed.
66
     * 
67
     * @param coolBar
68
     *            the cool bar control
69
     */
70
    public SCoolBarManager(SCoolBar coolBar) {
71
        this();
72
        Assert.isNotNull(coolBar);
73
        this.coolBar = coolBar;
74
        itemStyle = coolBar.getStyle();
75
    }
76
77
    /**
78
     * Creates a cool bar manager with the given SWT style. Calling <code>createControl</code>
79
     * will create the cool bar control.
80
     * 
81
     * @param style
82
     *            the cool bar item style; see
83
     *            {@link org.eclipse.swt.widgets.CoolBar CoolBar}for for valid
84
     *            style bits
85
     */
86
    public SCoolBarManager(int style) {
87
        itemStyle = style;
88
    }
89
90
    /*
91
     * (non-Javadoc)
92
     * 
93
     * @see org.eclipse.jface.action.ICoolBarManager#add(org.eclipse.jface.action.IToolBarManager)
94
     */
95
    public void add(IToolBarManager toolBarManager) {
96
        Assert.isNotNull(toolBarManager);
97
        SToolBarContributionItem2 toolBarContributionItem = new SToolBarContributionItem2(toolBarManager);
98
        super.add(toolBarContributionItem);
99
    }
100
    
101
    public void add(IContributionItem item) {
102
    	super.add(item);
103
    }
104
105
    /**
106
     * Collapses consecutive separators and removes a separator from the
107
     * beginning and end of the list.
108
     * 
109
     * @param contributionList
110
     *            the list of contributions; must not be <code>null</code>.
111
     * @return The contribution list provided with extraneous separators
112
     *         removed; this value is never <code>null</code>, but may be
113
     *         empty.
114
     */
115
    private ArrayList adjustContributionList(ArrayList contributionList) {
116
        IContributionItem item;
117
        // Fist remove a separator if it is the first element of the list
118
        if (contributionList.size() != 0) {
119
            item = (IContributionItem) contributionList.get(0);
120
            if (item.isSeparator()) {
121
                contributionList.remove(0);
122
            }
123
124
            ListIterator iterator = contributionList.listIterator();
125
            // collapse consecutive separators
126
            while (iterator.hasNext()) {
127
                item = (IContributionItem) iterator.next();
128
                if (item.isSeparator()) {
129
                    while (iterator.hasNext()) {
130
                        item = (IContributionItem) iterator.next();
131
                        if (item.isSeparator()) {
132
                            iterator.remove();
133
                        } else {
134
                            break;
135
                        }
136
                    }
137
138
                }
139
            }
140
            // Now check last element to see if there is a separator
141
            item = (IContributionItem) contributionList.get(contributionList
142
                    .size() - 1);
143
            if (item.isSeparator()) {
144
                contributionList.remove(contributionList.size() - 1);
145
            }
146
        }
147
        return contributionList;
148
149
    }
150
151
    /* (non-Javadoc)
152
     * @see org.eclipse.jface.action.ContributionManager#checkDuplication(org.eclipse.jface.action.IContributionItem)
153
     */
154
    protected boolean allowItem(IContributionItem itemToAdd) {
155
        /* We will allow as many null entries as they like, though there should
156
         * be none.
157
         */
158
        if (itemToAdd == null) {
159
            return true;
160
        }
161
162
        /* Null identifiers can be expected in generic contribution items.
163
         */
164
        String firstId = itemToAdd.getId();
165
        if (firstId == null) {
166
            return true;
167
        }
168
169
        // Cycle through the current list looking for duplicates.
170
        IContributionItem[] currentItems = getItems();
171
        for (int i = 0; i < currentItems.length; i++) {
172
            IContributionItem currentItem = currentItems[i];
173
174
            // We ignore null entries.
175
            if (currentItem == null) {
176
                continue;
177
            }
178
179
            String secondId = currentItem.getId();
180
            if (firstId.equals(secondId)) {
181
                if (Policy.TRACE_TOOLBAR) { //$NON-NLS-1$
182
                    System.out.println("Trying to add a duplicate item."); //$NON-NLS-1$
183
                    new Exception().printStackTrace(System.out);
184
                    System.out.println("DONE --------------------------"); //$NON-NLS-1$
185
                }
186
                return false;
187
            }
188
        }
189
190
        return true;
191
    }
192
193
    /**
194
     * Positions the list iterator to the end of all the separators. Calling
195
     * <code>next()</code> the iterator should return the immediate object
196
     * following the last separator.
197
     * 
198
     * @param iterator
199
     *            the list iterator.
200
     */
201
    private void collapseSeparators(ListIterator iterator) {
202
203
        while (iterator.hasNext()) {
204
            IContributionItem item = (IContributionItem) iterator.next();
205
            if (!item.isSeparator()) {
206
                iterator.previous();
207
                return;
208
            }
209
        }
210
    }
211
212
    /**
213
     * Returns whether the cool bar control has been created and not yet
214
     * disposed.
215
     * 
216
     * @return <code>true</code> if the control has been created and not yet
217
     *         disposed, <code>false</code> otherwise
218
     */
219
    private boolean coolBarExist() {
220
        return coolBar != null && !coolBar.isDisposed();
221
    }
222
223
    /**
224
     * Creates and returns this manager's cool bar control. Does not create a
225
     * new control if one already exists.
226
     * 
227
     * @param parent
228
     *            the parent control
229
     * @return the cool bar control
230
     */
231
    public Control createControl2(Composite parent) {
232
        Assert.isNotNull(parent);
233
        if (!coolBarExist()) {
234
       		coolBar = new SCoolBar(parent, itemStyle);
235
       		((SCoolBar)coolBar).setSkin(new HannoverGlobalCoolBarSkin());
236
            coolBar.setMenu(getContextMenuControl());
237
            coolBar.setLocked(false);
238
            coolBar.setSkin(new HannoverGlobalCoolBarSkin());
239
            update(false);
240
        }
241
        return coolBar;
242
    }
243
244
    /**
245
     * Disposes of this cool bar manager and frees all allocated SWT resources.
246
     * Notifies all contribution items of the dispose. Note that this method
247
     * does not clean up references between this cool bar manager and its
248
     * associated contribution items. Use <code>removeAll</code> for that
249
     * purpose.
250
     */
251
    public void dispose() {
252
        if (coolBarExist()) {
253
            IContributionItem[] items = getItems();
254
            for (int i = 0; i < items.length; i++) {
255
                // Disposes of the contribution item.
256
                // If Contribution Item is a toolbar then it will dispose of
257
                // all the nested
258
                // contribution items.
259
                items[i].dispose();
260
            }
261
            coolBar.dispose();
262
            coolBar = null;
263
        }
264
        // If a context menu existed then dispose of it.
265
        if (contextMenuManager != null) {
266
            contextMenuManager.dispose();
267
            contextMenuManager = null;
268
        }
269
270
    }
271
272
    /**
273
     * Disposes the given cool item.
274
     * 
275
     * @param item
276
     *            the cool item to dispose
277
     */
278
    private void dispose(SCoolItem item) {
279
        if ((item != null) && !item.isDisposed()) {
280
281
            item.setData(null);
282
            Control control = item.getControl();
283
            // if the control is already disposed, setting the coolitem
284
            // control to null will cause an SWT exception, workaround
285
            // for 19630
286
            if ((control != null) && !control.isDisposed()) {
287
                item.setControl(null);
288
            }
289
            item.dispose();
290
        }
291
    }
292
293
    /**
294
     * Finds the cool item associated with the given contribution item.
295
     * 
296
     * @param item
297
     *            the contribution item
298
     * @return the associated cool item, or <code>null</code> if not found
299
     */
300
    private SCoolItem findCoolItem(IContributionItem item) {
301
        if (coolBar == null)
302
            return null;
303
        SCoolItem[] items = coolBar.getItems();
304
        for (int i = 0; i < items.length; i++) {
305
            SCoolItem coolItem = items[i];
306
            IContributionItem data = (IContributionItem) coolItem.getData();
307
            if (data != null && data.equals(item))
308
                return coolItem;
309
        }
310
        return null;
311
    }
312
313
    /**
314
     * Return a consistent set of wrap indices. The return value will always
315
     * include at least one entry and the first entry will always be zero.
316
     * CoolBar.getWrapIndices() is inconsistent in whether or not it returns an
317
     * index for the first row.
318
     * 
319
     * @param wraps
320
     *            the wrap indicies from the cool bar widget
321
     * @return the adjusted wrap indicies.
322
     */
323
    private int[] getAdjustedWrapIndices(int[] wraps) {
324
        int[] adjustedWrapIndices;
325
        if (wraps.length == 0) {
326
            adjustedWrapIndices = new int[] { 0 };
327
        } else {
328
            if (wraps[0] != 0) {
329
                adjustedWrapIndices = new int[wraps.length + 1];
330
                adjustedWrapIndices[0] = 0;
331
                for (int i = 0; i < wraps.length; i++) {
332
                    adjustedWrapIndices[i + 1] = wraps[i];
333
                }
334
            } else {
335
                adjustedWrapIndices = wraps;
336
            }
337
        }
338
        return adjustedWrapIndices;
339
    }
340
341
    /**
342
     * Returns the control of the Menu Manager. If the menu manager does not
343
     * have a control then one is created.
344
     * 
345
     * @return menu control associated with manager, or null if none
346
     */
347
    private Menu getContextMenuControl() {
348
        if ((contextMenuManager != null) && (coolBar != null)) {
349
            Menu menuWidget = contextMenuManager.getMenu();
350
            if ((menuWidget == null) || (menuWidget.isDisposed())) {
351
                menuWidget = contextMenuManager.createContextMenu(coolBar);
352
            }
353
            return menuWidget;
354
        }
355
        return null;
356
    }
357
358
    /*
359
     * (non-Javadoc)
360
     * 
361
     * @see org.eclipse.jface.action.ICoolBarManager#isLayoutLocked()
362
     */
363
    public IMenuManager getContextMenuManager() {
364
        return contextMenuManager;
365
    }
366
367
    /**
368
     * Returns the cool bar control for this manager.
369
     * 
370
     * @return the cool bar control, or <code>null</code> if none
371
     */
372
    public CoolBar getControl() {
373
        return null;
374
    }
375
376
    /**
377
     * Returns an array list of all the contribution items in the manager.
378
     * 
379
     * @return an array list of contribution items.
380
     */
381
    private ArrayList getItemList() {
382
        IContributionItem[] cbItems = getItems();
383
        ArrayList list = new ArrayList(cbItems.length);
384
        for (int i = 0; i < cbItems.length; i++) {
385
            list.add(cbItems[i]);
386
        }
387
        return list;
388
    }
389
390
    /*
391
     * (non-Javadoc)
392
     * 
393
     * @see org.eclipse.jface.action.ICoolBarManager#isLayoutLocked()
394
     */
395
    public boolean getLockLayout() {
396
        if (!coolBarExist()) {
397
            return false;
398
        }
399
        return coolBar.getLocked();
400
    }
401
402
    /**
403
     * Returns the number of rows that should be displayed visually.
404
     * 
405
     * @param items
406
     *            the array of contributin items
407
     * @return the number of rows
408
     */
409
    private int getNumRows(IContributionItem[] items) {
410
        int numRows = 1;
411
        boolean separatorFound = false;
412
        for (int i = 0; i < items.length; i++) {
413
            if (items[i].isSeparator()) {
414
                separatorFound = true;
415
            }
416
            if ((separatorFound) && (items[i].isVisible())
417
                    && (!items[i].isGroupMarker()) && (!items[i].isSeparator())) {
418
                numRows++;
419
                separatorFound = false;
420
            }
421
        }
422
        return numRows;
423
    }
424
425
    /*
426
     * (non-Javadoc)
427
     * 
428
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
429
     */
430
    public int getStyle() {
431
        return itemStyle;
432
    }
433
434
    /**
435
     * Subclasses may extend this <code>ContributionManager</code> method,
436
     * but must call <code>super.itemAdded</code>.
437
     * 
438
     * @see org.eclipse.jface.action.ContributionManager#itemAdded(org.eclipse.jface.action.IContributionItem)
439
     */
440
    protected void itemAdded(IContributionItem item) {
441
        Assert.isNotNull(item);
442
        super.itemAdded(item);
443
        int insertedAt = indexOf(item);
444
        boolean replaced = false;
445
        final int size = cbItemsCreationOrder.size();
446
        for (int i = 0; i < size; i++) {
447
            IContributionItem created = (IContributionItem) cbItemsCreationOrder
448
                    .get(i);
449
            if (created.getId() != null && created.getId().equals(item.getId())) {
450
                cbItemsCreationOrder.set(i, item);
451
                replaced = true;
452
                break;
453
            }
454
        }
455
456
        if (!replaced) {
457
            cbItemsCreationOrder.add(Math.min(Math.max(insertedAt, 0),
458
                    cbItemsCreationOrder.size()), item);
459
        }
460
    }
461
462
    /**
463
     * Subclasses may extend this <code>ContributionManager</code> method,
464
     * but must call <code>super.itemRemoved</code>.
465
     * 
466
     * @see org.eclipse.jface.action.ContributionManager#itemRemoved(org.eclipse.jface.action.IContributionItem)
467
     */
468
    protected void itemRemoved(IContributionItem item) {
469
        Assert.isNotNull(item);
470
        super.itemRemoved(item);
471
        SCoolItem coolItem = findCoolItem(item);
472
        if (coolItem != null) {
473
            coolItem.setData(null);
474
        }
475
    }
476
477
    /**
478
     * Positions the list iterator to the starting of the next row. By calling
479
     * next on the returned iterator, it will return the first element of the
480
     * next row.
481
     * 
482
     * @param iterator
483
     *            the list iterator of contribution items
484
     * @param ignoreCurrentItem
485
     *            Whether the current item in the iterator should be considered
486
     *            (as well as subsequent items).
487
     */
488
    private void nextRow(ListIterator iterator, boolean ignoreCurrentItem) {
489
490
        IContributionItem currentElement = null;
491
        if (!ignoreCurrentItem && iterator.hasPrevious()) {
492
            currentElement = (IContributionItem) iterator.previous();
493
            iterator.next();
494
        }
495
496
        if ((currentElement != null) && (currentElement.isSeparator())) {
497
            collapseSeparators(iterator);
498
            return;
499
        } else {
500
            //Find next separator
501
            while (iterator.hasNext()) {
502
                IContributionItem item = (IContributionItem) iterator.next();
503
                if (item.isSeparator()) {
504
                    // we we find a separator, collapse any consecutive
505
                    // separators
506
                    // and return
507
                    collapseSeparators(iterator);
508
                    return;
509
                }
510
            }
511
        }
512
    }
513
514
    /*
515
     * Used for debuging. Prints all the items in the internal structures.
516
     */
517
    //    private void printContributions(ArrayList contributionList) {
518
    //        int index = 0;
519
    //        System.out.println("----------------------------------\n"); //$NON-NLS-1$
520
    //        for (Iterator i = contributionList.iterator(); i.hasNext(); index++) {
521
    //            IContributionItem item = (IContributionItem) i.next();
522
    //            if (item.isSeparator()) {
523
    //                System.out.println("Separator"); //$NON-NLS-1$
524
    //            } else {
525
    //                System.out.println(index + ". Item id: " + item.getId() //$NON-NLS-1$
526
    //                        + " - is Visible: " //$NON-NLS-1$
527
    //                        + item.isVisible());
528
    //            }
529
    //        }
530
    //    }
531
    /**
532
     * Synchronizes the visual order of the cool items in the control with this
533
     * manager's internal data structures. This method should be called before
534
     * requesting the order of the contribution items to ensure that the order
535
     * is accurate.
536
     * <p>
537
     * Note that <code>update()</code> and <code>refresh()</code> are
538
     * converses: <code>update()</code> changes the visual order to match the
539
     * internal structures, and <code>refresh</code> changes the internal
540
     * structures to match the visual order.
541
     * </p>
542
     */
543
    public void refresh() {
544
        if (!coolBarExist()) {
545
            return;
546
        }
547
548
        // Retreives the list of contribution items as an array list
549
        ArrayList contributionList = getItemList();
550
551
        // Check the size of the list
552
        if (contributionList.size() == 0)
553
            return;
554
555
        // The list of all the cool items in their visual order
556
        SCoolItem[] coolItems = coolBar.getItems();
557
        // The wrap indicies of the coolbar
558
        int[] wrapIndicies = getAdjustedWrapIndices(coolBar.getWrapIndices());
559
560
        int row = 0;
561
        int coolItemIndex = 0;
562
563
        // Traverse through all cool items in the coolbar add them to a new
564
        // data structure
565
        // in the correct order
566
        ArrayList displayedItems = new ArrayList(coolBar.getItemCount());
567
        for (int i = 0; i < coolItems.length; i++) {
568
            SCoolItem coolItem = coolItems[i];
569
            if (coolItem.getData() instanceof IContributionItem) {
570
                IContributionItem cbItem = (IContributionItem) coolItem
571
                        .getData();
572
                displayedItems.add(Math.min(i, displayedItems.size()), cbItem);
573
            }
574
        }
575
576
        // Add separators to the displayed Items data structure
577
        int offset = 0;
578
        for (int i = 1; i < wrapIndicies.length; i++) {
579
            int insertAt = wrapIndicies[i] + offset;
580
            displayedItems.add(insertAt, new Separator(USER_SEPARATOR));
581
            offset++;
582
        }
583
584
        // Determine which rows are invisible
585
        ArrayList existingVisibleRows = new ArrayList(4);
586
        ListIterator rowIterator = contributionList.listIterator();
587
        collapseSeparators(rowIterator);
588
        int numRow = 0;
589
        while (rowIterator.hasNext()) {
590
            // Scan row
591
            while (rowIterator.hasNext()) {
592
                IContributionItem cbItem = (IContributionItem) rowIterator
593
                        .next();
594
                if (displayedItems.contains(cbItem)) {
595
                    existingVisibleRows.add(new Integer(numRow));
596
                    break;
597
                }
598
                if (cbItem.isSeparator()) {
599
                    break;
600
                }
601
            }
602
            nextRow(rowIterator, false);
603
            numRow++;
604
        }
605
606
        Iterator existingRows = existingVisibleRows.iterator();
607
        // Adjust row number to the first visible
608
        if (existingRows.hasNext()) {
609
            row = ((Integer) existingRows.next()).intValue();
610
        }
611
612
        HashMap itemLocation = new HashMap();
613
        for (ListIterator locationIterator = displayedItems.listIterator(); locationIterator
614
                .hasNext();) {
615
            IContributionItem item = (IContributionItem) locationIterator
616
                    .next();
617
            if (item.isSeparator()) {
618
                if (existingRows.hasNext()) {
619
                    Integer value = (Integer) existingRows.next();
620
                    row = value.intValue();
621
                } else {
622
                    row++;
623
                }
624
            } else {
625
                itemLocation.put(item, new Integer(row));
626
            }
627
628
        }
629
630
        // Insert the contribution items in their correct location
631
        for (ListIterator iterator = displayedItems.listIterator(); iterator
632
                .hasNext();) {
633
            IContributionItem cbItem = (IContributionItem) iterator.next();
634
            if (cbItem.isSeparator()) {
635
                coolItemIndex = 0;
636
            } else {
637
                relocate(cbItem, coolItemIndex, contributionList, itemLocation);
638
                cbItem.saveWidgetState();
639
                coolItemIndex++;
640
            }
641
        }
642
643
        if (contributionList.size() != 0) {
644
            contributionList = adjustContributionList(contributionList);
645
            IContributionItem[] array = new IContributionItem[contributionList
646
                    .size() - 1];
647
            array = (IContributionItem[]) contributionList.toArray(array);
648
            internalSetItems(array);
649
        }
650
651
    }
652
653
    /**
654
     * Relocates the given contribution item to the specified index.
655
     * 
656
     * @param cbItem
657
     *            the conribution item to relocate
658
     * @param index
659
     *            the index to locate this item
660
     * @param contributionList
661
     *            the current list of conrtributions
662
     * @param itemLocation
663
     */
664
    private void relocate(IContributionItem cbItem, int index,
665
            ArrayList contributionList, HashMap itemLocation) {
666
667
        if (!(itemLocation.get(cbItem) instanceof Integer))
668
            return;
669
        int targetRow = ((Integer) itemLocation.get(cbItem)).intValue();
670
671
        int cbInternalIndex = contributionList.indexOf(cbItem);
672
673
        //	by default add to end of list
674
        int insertAt = contributionList.size();
675
        // Find the row to place this item in.
676
        ListIterator iterator = contributionList.listIterator();
677
        // bypass any separators at the begining
678
        collapseSeparators(iterator);
679
        int currentRow = -1;
680
        while (iterator.hasNext()) {
681
682
            currentRow++;
683
            if (currentRow == targetRow) {
684
                // We found the row to insert the item
685
                int virtualIndex = 0;
686
                insertAt = iterator.nextIndex();
687
                // first check the position of the current element (item)
688
                // then get the next element
689
                while (iterator.hasNext()) {
690
                    IContributionItem item = (IContributionItem) iterator
691
                            .next();
692
                    Integer itemRow = (Integer) itemLocation.get(item);
693
                    if (item.isSeparator())
694
                        break;
695
                    // if the item has an associate widget
696
                    if ((itemRow != null) && (itemRow.intValue() == targetRow)) {
697
                        // if the next element is the index we are looking for
698
                        // then break
699
                        if (virtualIndex >= index)
700
                            break;
701
                        virtualIndex++;
702
703
                    }
704
                    insertAt++;
705
                }
706
                // If we don't need to move it then we return
707
                if (cbInternalIndex == insertAt)
708
                    return;
709
                break;
710
            }
711
            nextRow(iterator, true);
712
        }
713
        contributionList.remove(cbItem);
714
715
        // Adjust insertAt index
716
        if (cbInternalIndex < insertAt) {
717
            insertAt--;
718
        }
719
720
        // if we didn't find the row then add a new row
721
        if (currentRow != targetRow) {
722
            contributionList.add(new Separator(USER_SEPARATOR));
723
            insertAt = contributionList.size();
724
        }
725
        insertAt = Math.min(insertAt, contributionList.size());
726
        contributionList.add(insertAt, cbItem);
727
728
    }
729
730
    /**
731
     * Restores the canonical order of this cool bar manager. The canonical
732
     * order is the order in which the contribution items where added.
733
     */
734
    public void resetItemOrder() {
735
        for (ListIterator iterator = cbItemsCreationOrder.listIterator(); iterator
736
                .hasNext();) {
737
            IContributionItem item = (IContributionItem) iterator.next();
738
            // if its a user separator then do not include in original order.
739
            if ((item.getId() != null) && (item.getId().equals(USER_SEPARATOR))) {
740
                iterator.remove();
741
            }
742
        }
743
        IContributionItem[] itemsToSet = new IContributionItem[cbItemsCreationOrder
744
                .size()];
745
        cbItemsCreationOrder.toArray(itemsToSet);
746
        setItems(itemsToSet);
747
    }
748
749
    /*
750
     * (non-Javadoc)
751
     * 
752
     * @see org.eclipse.jface.action.ICoolBarManager#setContextMenuManager(org.eclipse.jface.action.IMenuManager)
753
     */
754
    public void setContextMenuManager(IMenuManager contextMenuManager) {
755
        this.contextMenuManager = (MenuManager) contextMenuManager;
756
        if (coolBar != null) {
757
            coolBar.setMenu(getContextMenuControl());
758
        }
759
    }
760
761
    /**
762
     * Replaces the current items with the given items.
763
     * Forces an update.
764
     * 
765
     * @param newItems the items with which to replace the current items
766
     */
767
    public void setItems(IContributionItem[] newItems) {
768
        // dispose of all the cool items on the cool bar manager
769
/* FIXME TFS
770
 *	This is disposing of the coolItems but references are still hanging around. Might
771
 *	be a problem with SCoolBar and or SCoolItem. [Terry Smith 12/9/2005]
772
 * 
773
        if (coolBar != null) {
774
            SCoolItem[] coolItems = coolBar.getItems();
775
           for (int i = 0; i < coolItems.length; i++) {
776
              dispose(coolItems[i]);
777
            }
778
        }
779
        // Set the internal structure to this order
780
        internalSetItems(newItems);
781
*/
782
        // Force and update
783
        update(true);
784
    }
785
786
    /*
787
     * (non-Javadoc)
788
     * 
789
     * @see org.eclipse.jface.action.ICoolBarManager#lockLayout(boolean)
790
     */
791
    public void setLockLayout(boolean value) {
792
        if (!coolBarExist()) {
793
            return;
794
        }
795
        coolBar.setLocked(value);
796
    }
797
798
    /**
799
     * Subclasses may extend this <code>IContributionManager</code> method,
800
     * but must call <code>super.update</code>.
801
     * 
802
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
803
     */
804
    public void update(boolean force) {
805
        if ((!isDirty() && !force) || (!coolBarExist())) {
806
            return;
807
        }
808
809
        boolean relock = false;
810
        boolean changed = false;
811
812
        try {
813
            coolBar.setRedraw(false);
814
815
            // Refresh the widget data with the internal data structure.
816
            refresh();
817
818
            if (coolBar.getLocked()) {
819
                coolBar.setLocked(false);
820
                relock = true;
821
            }
822
823
            /*
824
             * Make a list of items including only those items that are
825
             * visible. Separators should stay because they mark line breaks in
826
             * a cool bar.
827
             */
828
            final IContributionItem[] items = getItems();
829
            final List visibleItems = new ArrayList(items.length);
830
            for (int i = 0; i < items.length; i++) {
831
                final IContributionItem item = items[i];
832
                if (item.isVisible()) {
833
                    visibleItems.add(item);
834
                }
835
            }
836
837
            /*
838
             * Make a list of CoolItem widgets in the cool bar for which there
839
             * is no current visible contribution item. These are the widgets
840
             * to be disposed. Dynamic items are also removed.
841
             */
842
            SCoolItem[] coolItems = coolBar.getItems();
843
            final ArrayList coolItemsToRemove = new ArrayList(coolItems.length);
844
            for (int i = 0; i < coolItems.length; i++) {
845
                final Object data = coolItems[i].getData();
846
                if ((data == null)
847
                        || (!visibleItems.contains(data))
848
                        || ((data instanceof IContributionItem) && ((IContributionItem) data)
849
                                .isDynamic())) {
850
                    coolItemsToRemove.add(coolItems[i]);
851
                }
852
            }
853
854
            // Dispose of any items in the list to be removed.
855
            for (int i = coolItemsToRemove.size() - 1; i >= 0; i--) {
856
                SCoolItem coolItem = (SCoolItem) coolItemsToRemove.get(i);
857
                if (!coolItem.isDisposed()) {
858
                    Control control = coolItem.getControl();
859
                    if (control != null) {
860
                        coolItem.setControl(null);
861
                        control.dispose();
862
                    }
863
                    coolItem.dispose();
864
                }
865
            }
866
867
            // Add any new items by telling them to fill.
868
            coolItems = coolBar.getItems();
869
            IContributionItem sourceItem;
870
            IContributionItem destinationItem;
871
            int sourceIndex = 0;
872
            int destinationIndex = 0;
873
            final Iterator visibleItemItr = visibleItems.iterator();
874
            while (visibleItemItr.hasNext()) {
875
                sourceItem = (IContributionItem) visibleItemItr.next();
876
877
                // Retrieve the corresponding contribution item from SWT's
878
                // data.
879
                if (sourceIndex < coolItems.length) {
880
                    destinationItem = (IContributionItem) coolItems[sourceIndex]
881
                            .getData();
882
                } else {
883
                    destinationItem = null;
884
                }
885
886
                // The items match is they are equal or both separators.
887
                if (destinationItem != null) {
888
                    if (sourceItem.equals(destinationItem)) {
889
                        sourceIndex++;
890
                        destinationIndex++;
891
                        sourceItem.update();
892
                        continue;
893
894
                    } else if ((destinationItem.isSeparator())
895
                            && (sourceItem.isSeparator())) {
896
                        coolItems[sourceIndex].setData(sourceItem);
897
                        sourceIndex++;
898
                        destinationIndex++;
899
                        sourceItem.update();
900
                        continue;
901
902
                    }
903
                }
904
905
                // Otherwise, a new item has to be added.
906
                final int start = coolBar.getItemCount();
907
                if (sourceItem instanceof ISContributionItem)
908
                	((ISContributionItem)sourceItem).fill(coolBar, destinationIndex);
909
                final int newItems = coolBar.getItemCount() - start;
910
                for (int i = 0; i < newItems; i++) {
911
                    coolBar.getItem(destinationIndex++).setData(sourceItem);
912
                }
913
                changed = true;
914
            }
915
916
            // Remove any old widgets not accounted for.
917
            for (int i = coolItems.length - 1; i >= sourceIndex; i--) {
918
                final SCoolItem item = coolItems[i];
919
                if (!item.isDisposed()) {
920
                    Control control = item.getControl();
921
                    if (control != null) {
922
                        item.setControl(null);
923
                        control.dispose();
924
                    }
925
                    item.dispose();
926
                    changed = true;
927
                }
928
            }
929
930
            // Update wrap indices.
931
            updateWrapIndices();
932
933
            // Update the sizes.
934
            for (int i = 0; i < items.length; i++) {
935
                IContributionItem item = items[i];
936
                item.update(SIZE);
937
            }
938
939
            // if the coolBar was previously locked then lock it
940
            if (relock) {
941
                coolBar.setLocked(true);
942
            }
943
944
            if (changed) {
945
                updateTabOrder();
946
            }
947
948
            // We are no longer dirty.
949
            setDirty(false);
950
        } finally {
951
            coolBar.setRedraw(true);
952
        }
953
    }
954
955
    /**
956
     * Sets the tab order of the coolbar to the visual order of its items.
957
     */
958
    /* package */void updateTabOrder() {
959
        if (coolBar != null) {
960
            SCoolItem[] items = coolBar.getItems();
961
            if (items != null) {
962
                ArrayList children = new ArrayList(items.length);
963
                for (int i = 0; i < items.length; i++) {
964
                    if ((items[i].getControl() != null)
965
                            && (!items[i].getControl().isDisposed())) {
966
                        children.add(items[i].getControl());
967
                    }
968
                }
969
                // Convert array
970
                Control[] childrenArray = new Control[0];
971
                childrenArray = (Control[]) children.toArray(childrenArray);
972
973
                if (childrenArray != null) {
974
                    coolBar.setTabList(childrenArray);
975
                }
976
977
            }
978
        }
979
    }
980
981
    /**
982
     * Updates the indices at which the cool bar should wrap.
983
     */
984
    private void updateWrapIndices() {
985
        final IContributionItem[] items = getItems();
986
        final int numRows = getNumRows(items) - 1;
987
988
        // Generate the list of wrap indices.
989
        final int[] wrapIndices = new int[numRows];
990
        boolean foundSeparator = false;
991
        int j = 0;
992
        for (int i = 0; i < items.length; i++) {
993
            IContributionItem item = items[i];
994
            SCoolItem coolItem = findCoolItem(item);
995
            if (item.isSeparator()) {
996
                foundSeparator = true;
997
            }
998
            if ((!item.isSeparator()) && (!item.isGroupMarker())
999
                    && (item.isVisible()) && (coolItem != null)
1000
                    && (foundSeparator)) {
1001
                wrapIndices[j] = coolBar.indexOf(coolItem);
1002
                j++;
1003
                foundSeparator = false;
1004
            }
1005
        }
1006
1007
        /*
1008
         * Check to see if these new wrap indices are different than the old
1009
         * ones.
1010
         */
1011
        final int[] oldIndices = coolBar.getWrapIndices();
1012
        boolean shouldUpdate = false;
1013
        if (oldIndices.length == wrapIndices.length) {
1014
            for (int i = 0; i < oldIndices.length; i++) {
1015
                if (oldIndices[i] != wrapIndices[i]) {
1016
                    shouldUpdate = true;
1017
                    break;
1018
                }
1019
            }
1020
        } else {
1021
            shouldUpdate = true;
1022
        }
1023
1024
        if (shouldUpdate) {
1025
            coolBar.setWrapIndices(wrapIndices);
1026
        }
1027
    }
1028
1029
	public CoolBar createControl(Composite parent) {
1030
		return null;
1031
	}
1032
1033
	public Control getControl2() {
1034
		return coolBar;
1035
	}
1036
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SToolBar.java (+504 lines)
Added Link Here
1
/*
2
*	Copyright IBM Corporation 2003, 2005
3
*	All rights reserved.
4
*	US Government Users Restricted Rights - Use, duplication or disclosure
5
*	restricted by GS ADP Schedule Contract with IBM Corp.
6
*/
7
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
8
9
import java.util.ArrayList;
10
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.graphics.GC;
13
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.ImageData;
15
import org.eclipse.swt.graphics.PaletteData;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Event;
21
import org.eclipse.swt.widgets.Listener;
22
23
public class SToolBar extends SWidget {
24
	
25
	private ArrayList items = new ArrayList();
26
	private SToolItem hoverItem;
27
	private SToolItem mouseDownItem;
28
	
29
	private Point offscreenImageSize = new Point(-1, -1);
30
	private Image offscreenImage = null;
31
	private GC offscreenGc = null;
32
	
33
	static final int ITEM_INSET_TOP = 3;
34
	static final int ITEM_INSET_BOTTOM = 4;
35
	static final int LEFT_MARGIN = 6;
36
	static final int SHADOW_SIZE = 4;
37
	
38
	/**
39
	 * @param parent
40
	 * @param style
41
	 */
42
	public SToolBar(Composite parent, int style) {
43
		super(parent, checkStyle(style));
44
45
		// Add all listeners
46
		Listener listener = new Listener() {
47
			public void handleEvent(Event event) {
48
				switch (event.type) {
49
					case SWT.Dispose:          onDispose(); break;
50
					case SWT.FocusIn:          onFocus(event);	break;
51
					case SWT.FocusOut:         onFocus(event);	break;
52
					case SWT.MouseDoubleClick: onMouseDoubleClick(event); break;
53
					case SWT.MouseDown:        onMouseDown(event);	break;
54
					case SWT.MouseExit:        onMouseExit(event);	break;
55
					case SWT.MouseHover:       onMouseHover(event); break;
56
					case SWT.MouseMove:        onMouseMove(event); break;
57
					case SWT.MouseUp:          onMouseUp(event); break;
58
					case SWT.Paint:            onPaint(event);	break;
59
					case SWT.Traverse:         onTraverse(event); break;
60
				}
61
			}
62
		};
63
64
		int[] toolBarEvents = new int[]{
65
66
			SWT.Dispose,
67
			SWT.FocusIn, 
68
			SWT.FocusOut, 
69
			SWT.KeyDown,
70
			SWT.MouseDoubleClick, 
71
			SWT.MouseDown,
72
			SWT.MouseExit,
73
			SWT.MouseHover, 
74
			SWT.MouseMove,
75
			SWT.MouseUp,
76
			SWT.Paint,
77
			SWT.Resize,  
78
			SWT.Traverse
79
		};
80
		for (int i = 0; i < toolBarEvents.length; i++) {
81
			addListener(toolBarEvents[i], listener);
82
		}
83
	}
84
	
85
	private static int checkStyle(int style) {
86
		return SWT.NO_BACKGROUND;
87
	}
88
89
	void createItem(SToolItem item, int index) {
90
		if (!(0 <= index && index <= items.size()))
91
			SWT.error(SWT.ERROR_INVALID_RANGE);
92
		items.add(index, item);
93
		redraw();
94
	}
95
96
	public Point computeSize(int wHint, int hHint, boolean changed) {
97
		if (getLayout() != null) {
98
			return super.computeSize (wHint, hHint, changed);
99
		}
100
		
101
		Skin skin = getSkin();
102
		Rectangle itemAreaInsets = null; 
103
		Rectangle itemMargins = null;
104
		if (skin != null) {
105
			itemAreaInsets = skin.getRect(Skin.TYPE_ITEM_AREA_INSETS, Skin.NORMAL);
106
			itemMargins = skin.getRect(Skin.TYPE_ITEM_AREA_MARGINS, Skin.NORMAL);
107
		}
108
		if (itemAreaInsets == null) {
109
			itemAreaInsets = new Rectangle(0, 0, 0, 0);
110
		}
111
		if (itemMargins == null) {
112
			itemMargins = new Rectangle(0, 0, 0, 0);
113
		}
114
115
		int x;
116
		int y;
117
		Point size = getSize();
118
		int length = (items != null) ? items.size() : 0;
119
		if ((getStyle() & SWT.VERTICAL) == SWT.VERTICAL) {
120
			x = 0;
121
			y = itemAreaInsets.x + itemMargins.x;
122
			for (int i = 0; i < length; i++) {
123
				SToolItem item = (SToolItem)items.get(i);
124
				Point pt = item.computeSize(wHint, hHint, changed);
125
				x = (pt.x > x) ? pt.x : x;
126
				y += (pt.y + itemMargins.x);
127
			}
128
			x += itemAreaInsets.y + itemAreaInsets.height;
129
			y += itemAreaInsets.width;
130
		} else {
131
			x = itemAreaInsets.x + itemMargins.x;
132
			y = 0;
133
			for (int i = 0; i < length; i++) {
134
				SToolItem item = (SToolItem)items.get(i);
135
				Point pt = item.computeSize(wHint, hHint, changed);
136
				x += (pt.x + itemMargins.x);
137
				y = (pt.y > y) ? pt.y : y;
138
			}
139
			y += itemAreaInsets.y + itemAreaInsets.height;
140
			x += itemAreaInsets.width;
141
		}
142
		
143
		if (wHint != SWT.DEFAULT && wHint >= x)
144
			x = wHint;
145
		if (hHint != SWT.DEFAULT && hHint >= y)
146
			y = hHint;
147
		// TODO: to be refactored. we should not use the value from getSize(). 
148
		// Otherwise toolbar cannot be smaller.
149
		//if (wHint == SWT.DEFAULT && size.x > x)
150
		//	x = size.x; 
151
		if (hHint == SWT.DEFAULT && size.y > y)
152
			y = size.y; 
153
		return new Point(x, y);
154
	}
155
	
156
	public Rectangle computeTrim(int x, int y, int width, int height) {
157
		return new Rectangle(x+SHADOW_SIZE, y+SHADOW_SIZE, 
158
				width-(SHADOW_SIZE*2), height-(SHADOW_SIZE*2));
159
	}
160
161
	void destroyItem(SToolItem item) {
162
		if (items.contains(item))
163
			items.remove(item);
164
	}
165
	
166
	public SToolItem getItem(int index) {
167
		return (SToolItem)items.get(index);
168
	}
169
	
170
	public SToolItem getItem(Point point) {
171
		return null;
172
	}
173
	
174
	public int getItemCount() {
175
		return items.size();
176
	}
177
	
178
	public SToolItem[] getItems() {
179
		return (SToolItem[])items.toArray(new SToolItem[0]);
180
	}
181
	
182
	public int getRowCount() {
183
		return 0;
184
	}
185
	
186
	public int indexOf(SToolItem item) {
187
		return items.indexOf(item);
188
	}
189
190
	void itemChanged(SToolItem item) {
191
		updateItems();
192
		redraw();
193
	}
194
	
195
	/**
196
	 * 
197
	 */
198
	protected void onDispose() {
199
		Skin skin = getSkin();
200
		if (skin != null)
201
			skin.dispose();
202
	}
203
	
204
	/**
205
	 * @param event
206
	 */
207
	protected void onFocus(Event event) {
208
		// TODO Auto-generated method stub
209
	}
210
211
	/**
212
	 * @param event
213
	 */
214
	protected void onMouseDoubleClick(Event event) {
215
		// TODO Auto-generated method stub
216
	}
217
	
218
	/**
219
	 * @param event
220
	 */
221
	protected void onMouseDown(Event event) {
222
		SToolItem item = findToolItem(event.x, event.y);
223
		if (item != null) {
224
			item.onMouseDown(event);
225
			mouseDownItem = item;
226
			redraw();
227
		}
228
	}
229
230
	/**
231
	 * @param event
232
	 */
233
	protected void onMouseExit(Event event) {
234
		boolean needsRedraw = false;
235
		if (hoverItem != null) {
236
			hoverItem.setHot(false);
237
			hoverItem.setArrowHot(false);
238
			hoverItem = null;
239
			needsRedraw = true;
240
		}
241
		if (mouseDownItem != null) {
242
			mouseDownItem.setPressed(false);
243
			mouseDownItem.setArrowPressed(false);
244
			mouseDownItem = null;
245
			needsRedraw = true;
246
		}
247
		if (needsRedraw)
248
			redraw();
249
	}
250
251
	/**
252
	 * @param event
253
	 */
254
	protected void onMouseHover(Event event) {
255
		// TODO Auto-generated method stub
256
	}
257
	
258
	/**
259
	 * @param event
260
	 */
261
	protected void onMouseMove(Event event) {
262
		SToolItem item = findToolItem(event.x, event.y);
263
		if (item != null) {
264
			if (hoverItem != item) {
265
				item.setHot(true);
266
				Rectangle arrowRect = item.getArrowRect();
267
				if (arrowRect != null) {
268
					if (arrowRect.contains(event.x, event.y)) {
269
						item.setArrowHot(true);
270
					}
271
				}
272
				
273
				if (hoverItem != null) {
274
					hoverItem.setHot(false);
275
					hoverItem.setArrowHot(false);
276
				}
277
				
278
				hoverItem = item;
279
				redraw();
280
			}
281
		} else if (hoverItem != null) {
282
			hoverItem.setHot(false);
283
			hoverItem.setArrowHot(false);
284
			hoverItem = null;
285
			redraw();
286
		}
287
	}
288
289
	/**
290
	 * @param event
291
	 */
292
	protected void onMouseUp(Event event) {
293
		boolean needsRedraw = false;
294
		
295
		try {
296
			SToolItem item = findToolItem(event.x, event.y);
297
			if (item != null && item == mouseDownItem) {
298
				needsRedraw = true;
299
				item.onMouseUp(event);
300
			} else if (mouseDownItem != null) {
301
				needsRedraw = true;
302
				mouseDownItem.setPressed(false);
303
				mouseDownItem.setArrowPressed(false);
304
			}
305
		} finally {
306
			if (needsRedraw)
307
				redraw();
308
		}
309
	}
310
	
311
	
312
	/**
313
	 * @param event
314
	 */
315
	protected void onPaint(Event event) {
316
		Point size = getSize();
317
		GC gc = event.gc;
318
		
319
		try {
320
			if (offscreenImageSize.x != size.x || offscreenImageSize.y != size.y) {
321
				if (offscreenImage != null) {
322
					offscreenImage.dispose();
323
					offscreenImage = null;
324
				}
325
				if (offscreenGc != null) {
326
					offscreenGc.dispose();
327
					offscreenGc = null;
328
				}
329
				PaletteData offscreenImagePalette = new PaletteData(0x0000FF00, 0x00FF0000, 0xFF000000);
330
				ImageData offscreenImageData = new ImageData(size.x, size.y, 32, offscreenImagePalette);
331
				offscreenImageData.type = SWT.BITMAP;
332
				offscreenImage = new Image(null, offscreenImageData);
333
				offscreenGc = new GC(offscreenImage, getStyle());
334
				offscreenImageSize.x = size.x;
335
				offscreenImageSize.y = size.y;
336
			}
337
		} finally {
338
			if (offscreenGc != null) {
339
				offscreenGc.setForeground(event.gc.getForeground());
340
				offscreenGc.setBackground(event.gc.getBackground());
341
				offscreenGc.fillRectangle(0, 0, size.x, size.y);
342
				gc = offscreenGc;
343
			}
344
		}
345
		
346
		updateItems();
347
		Skin skin = getSkin();
348
		
349
		if (skin == null)
350
			return;
351
				
352
		Rectangle rect = getClientArea();
353
		if (rect.width == 0 || rect.height == 0)
354
			return;
355
		
356
		int state = Skin.NORMAL;
357
		
358
		// paint background
359
		skin.drawBackground(gc, rect, this, Skin.TYPE_BACKGROUND, state);
360
		
361
		// paint tool items
362
		for (int i = 0; i < items.size(); i++) {
363
			SToolItem item = this.getItem(i);
364
			item.onPaint(gc);
365
		}
366
367
		// paint border
368
		skin.drawBorder(gc, rect, this, Skin.TYPE_BORDER, state);
369
		
370
		// draw the offscreen image
371
		if (gc == offscreenGc)
372
			event.gc.drawImage(offscreenImage, 0, 0);
373
	
374
	}
375
	
376
	/**
377
	 * @param event
378
	 */
379
	protected void onTraverse(Event event) {
380
		// TODO Auto-generated method stub
381
	}
382
383
	private SToolItem findToolItem(int x, int y) {
384
		SToolItem item = null;
385
		for (int i=0; i<items.size(); i++) {
386
			Rectangle bounds = ((SToolItem)items.get(i)).getBounds();
387
			if (bounds.contains(x, y)){
388
				item = (SToolItem)items.get(i);
389
			}
390
		}
391
		return item;
392
	}
393
	
394
	public void setSkin(Skin skin) {
395
		super.setSkin(skin);
396
	}
397
	
398
	boolean setItemLocation() {
399
		if (items.size() == 0)
400
			return false;
401
		
402
		Skin skin = getSkin();
403
		Rectangle itemAreaInsets = null; 
404
		Rectangle itemMargins = null;
405
		if (skin != null) {
406
			itemAreaInsets = skin.getRect(Skin.TYPE_ITEM_AREA_INSETS, Skin.NORMAL);
407
			itemMargins = skin.getRect(Skin.TYPE_ITEM_AREA_MARGINS, Skin.NORMAL);
408
		}
409
		if (itemAreaInsets == null) {
410
			itemAreaInsets = new Rectangle(0, 0, 0, 0);
411
		}
412
		if (itemMargins == null) {
413
			itemMargins = new Rectangle(0, 0, 0, 0);
414
		}
415
416
		/*
417
		 * TODO Handle vertical toolbars.
418
		 */
419
		
420
		Rectangle barBounds = getBounds();
421
		int height = 0;
422
		if (barBounds != null) {
423
			height = barBounds.height;
424
		}
425
426
		boolean changed = false;
427
		int x = itemAreaInsets.x + itemMargins.x;
428
		int y;
429
		for (int i = 0; i < items.size(); i++) {
430
			SToolItem item = (SToolItem)items.get(i);
431
			if (item.itemRect.x != x) {
432
				item.itemRect.x = x;
433
				changed = true;
434
			}
435
436
			/*
437
			 * Center vertically.
438
			 */
439
			y = itemAreaInsets.y + (((height - itemAreaInsets.y - itemAreaInsets.height) / 2) - (item.itemRect.height / 2));
440
441
			if (item.itemRect.y != y) {
442
				item.itemRect.y = y;
443
				changed = true;
444
			}
445
			if (changed == true) {
446
				Control control = item.getControl(); 
447
				if (control != null) {
448
					Rectangle r = control.getBounds();
449
					r.x = item.itemRect.x + (item.itemRect.width - r.width) / 2;
450
					r.y = item.itemRect.y + (item.itemRect.height - r.height) / 2;
451
					control.setLocation(r.x, r.y);
452
				}
453
			}
454
			x += (item.itemRect.width + itemMargins.x);
455
		}
456
		return changed;
457
	}
458
459
	boolean setItemSize() {
460
		if (items.size() == 0)
461
			return false;
462
		
463
		boolean changed = false;
464
465
		Skin skin = getSkin();
466
		Rectangle itemAreaInsets = null; 
467
		if (skin != null) {
468
			itemAreaInsets = skin.getRect(Skin.TYPE_ITEM_AREA_INSETS, Skin.NORMAL);
469
		}
470
		if (itemAreaInsets == null) {
471
			itemAreaInsets = new Rectangle(0, 0, 0, 0);
472
		}
473
474
		for (int i = 0; i < items.size(); i++) {
475
			SToolItem item = (SToolItem)items.get(i);
476
			Point pt = item.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
477
			
478
			if (pt.y == SWT.DEFAULT) {
479
				if ((getStyle() & SWT.VERTICAL) == SWT.VERTICAL) {
480
					pt.y = pt.x;
481
					pt.x = getSize().x - (itemAreaInsets.y + itemAreaInsets.height);
482
				} else {
483
					pt.y = getSize().y - (itemAreaInsets.y + itemAreaInsets.height);
484
				}
485
			}
486
			
487
			if (pt.x != item.itemRect.width) {
488
				item.itemRect.width = pt.x;
489
				changed = true;
490
			}
491
		    if (pt.y != item.itemRect.height) {
492
		    	item.itemRect.height = pt.y;
493
				changed = true;
494
		    }
495
		}
496
		return changed;
497
	}
498
	
499
	void updateItems() {
500
		setItemSize();
501
		setItemLocation();
502
	}
503
504
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/HannoverGlobalCoolBarSkin.java (+200 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.graphics.Color;
5
import org.eclipse.swt.graphics.Font;
6
import org.eclipse.swt.graphics.GC;
7
import org.eclipse.swt.graphics.Image;
8
import org.eclipse.swt.graphics.Point;
9
import org.eclipse.swt.graphics.Rectangle;
10
import org.eclipse.swt.widgets.Display;
11
12
public class HannoverGlobalCoolBarSkin implements Skin {
13
14
	// border colors
15
	Color borderTopColor = new Color(null, 255, 255, 255);
16
	Color borderBottomColor = new Color(null, 144, 161, 181);
17
	Color borderLeftRightColor = new Color(null, 255, 255, 255);
18
	Color draggerLineColor = new Color(null, 168, 191, 197);
19
	Color draggerLineColor2 = new Color(null, 255, 255, 255);
20
	
21
	// background colors
22
	Color shadowColor = new Color(null, 109, 131, 180);
23
	Color backgroundTopColor = new Color(null, 247, 247, 247);
24
	Color backgroundBottomColor = new Color(null, 189, 198, 216);
25
	Color hoverItemBackgroundColor = new Color(null, 224, 233, 237);
26
	Color pressedItemBackgroundColor = new Color(null, 231, 231, 231);
27
	
28
	// arrows and text colors
29
	Color arrowColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
30
	Color textColor = new Color(null, 43,73,111);
31
	Color hoverTextColor = new Color(null, 20, 38, 54);
32
33
	// gripper
34
	private final static int GRIPPER_DOT_HEIGHT = 3;
35
	private final static int GRIPPER_DOT_COUNT = 3;
36
37
	Color[] gripperColors = {
38
				new Color(null,213,218,225),new Color(null,174,186,197),new Color(null,214,219,225),
39
				new Color(null,246,246,243),new Color(null,247,248,246),new Color(null,245,246,242),
40
				new Color(null,247,248,248),new Color(null,249,249,249),new Color(null,247,248,248),
41
				new Color(null,208,241,222),new Color(null,173,184,197),new Color(null,208,214,222),
42
				new Color(null,246,247,245),new Color(null,247,248,246),new Color(null,246,247,245),
43
				new Color(null,240,241,244),new Color(null,247,248,247),new Color(null,240,242,244),
44
				new Color(null,200,208,217),new Color(null,171,183,196),new Color(null,200,208,217),
45
				new Color(null,244,245,244),new Color(null,247,248,246),new Color(null,244,245,244),
46
				new Color(null,232,235,239),new Color(null,246,247,246),new Color(null,232,235,240)
47
	};
48
49
	public HannoverGlobalCoolBarSkin() {
50
		super();
51
	}
52
	
53
	public Rectangle getInsets(int type, int state) {
54
		return null;
55
	}
56
57
	public Point getSize(int type, int state) {
58
		if (type == Skin.TYPE_DECORATION_GRIPPER) {
59
			return new Point(6, SWT.DEFAULT);
60
		} else if (type == Skin.TYPE_ITEM_MIN_MAX_HEIGHT) {
61
			return new Point(26, SWT.DEFAULT);
62
		} else if (type == Skin.TYPE_ITEM_MIN_MAX_WIDTHS) {
63
			return new Point(26, SWT.DEFAULT);
64
		}
65
		return null;
66
	}
67
68
	public Font getFont(int type, int state) {
69
		return null;
70
	}
71
72
	public Rectangle getMargins(int type, int state) {
73
		return new Rectangle(0,0,0,0);
74
	}
75
76
	public Rectangle getRect(int type, int state) {
77
		if (type == Skin.TYPE_ITEM_BORDER) {
78
			/*
79
			 * x - border on left of cool item (does not include gripper decorator.
80
			 * y - border on top of cool item
81
			 * width - border on right of cool item
82
			 * height - border on bottom of cool item
83
			 */
84
			return new Rectangle(0, 0, 2, 0);
85
		} else if (type == Skin.TYPE_BORDER) {
86
			/*
87
			 * x - border on left of coolbar
88
			 * y - border on top of coolbar
89
			 * width - border on right of coolbar
90
			 * height - border on bottom of coolbar
91
			 */
92
			return new Rectangle(1, 0, 1, 0);
93
		}
94
		return null;
95
	}
96
97
	public void drawBorder(GC gc, Rectangle rect, SWidget widget, int type, int state) {
98
		if (type == Skin.TYPE_BORDER) {
99
			// left/right edge
100
			gc.setForeground(borderLeftRightColor);
101
			gc.drawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1);
102
			gc.drawLine(rect.x+rect.width-1, rect.y, rect.x+rect.width-1, rect.y+rect.height-1);
103
104
			// top edge
105
			gc.setForeground(borderTopColor);
106
			gc.drawLine(rect.x, rect.y, rect.x + rect.width -1, rect.y);
107
			// bottom edge
108
			gc.setForeground(borderBottomColor);
109
			gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width -1, rect.y + rect.height - 1);
110
		} else if (type == Skin.TYPE_ITEM_BORDER) {
111
			// top edge
112
			gc.setForeground(borderTopColor);
113
			gc.drawLine(rect.x, rect.y, rect.x + rect.width -1, rect.y);
114
			// bottom edge
115
			gc.setForeground(borderBottomColor);
116
			gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width -1, rect.y + rect.height - 1);
117
118
			// Right edge.
119
			gc.setForeground(draggerLineColor);
120
			gc.drawLine(rect.x + rect.width -2, rect.y, rect.x + rect.width -2, rect.y + rect.height - 2);
121
			gc.setForeground(draggerLineColor2);			
122
			gc.drawLine(rect.x + rect.width -1, rect.y, rect.x + rect.width -1, rect.y + rect.height - 2);
123
		}
124
	}
125
126
	public void drawBackground(GC gc, Rectangle rect, SWidget widget, int type, int state) {
127
		
128
		if (type == Skin.TYPE_BACKGROUND) {
129
			gc.setForeground(backgroundTopColor); 
130
			gc.setBackground(backgroundBottomColor); 
131
			gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height, true); 
132
		} 
133
	}
134
135
	public void drawDecoration(GC gc, Rectangle rect, SWidget widget, int type, int state) {
136
		if (type == Skin.TYPE_DECORATION_GRIPPER) {
137
			drawGripper(gc, rect, widget, type, state);
138
		}
139
	}
140
141
	public void drawText(GC gc, Rectangle rect, String text, int style, SWidget widget, int type, int state) {
142
	}
143
144
	public void drawImage(GC gc, Rectangle rect, Image image, SWidget widget, int type, int state) {
145
	}
146
147
	public void dispose() {
148
		if (borderTopColor != null && borderTopColor.isDisposed() == false)
149
			borderTopColor.dispose();
150
		if (draggerLineColor != null && draggerLineColor.isDisposed() == false)
151
			draggerLineColor.dispose();
152
153
		if (shadowColor != null && shadowColor.isDisposed() == false)
154
			shadowColor.dispose();
155
		if (backgroundTopColor != null && backgroundTopColor.isDisposed() == false)
156
			backgroundTopColor.dispose();
157
		if (backgroundBottomColor != null && backgroundBottomColor.isDisposed() == false)
158
			backgroundBottomColor.dispose();
159
		if (hoverItemBackgroundColor != null && hoverItemBackgroundColor.isDisposed() == false)
160
			hoverItemBackgroundColor.dispose();
161
		if (pressedItemBackgroundColor != null && pressedItemBackgroundColor.isDisposed() == false)
162
			pressedItemBackgroundColor.dispose();
163
		
164
		if (arrowColor != null && arrowColor.isDisposed() == false)
165
			arrowColor.dispose();
166
		if (textColor != null && textColor.isDisposed() == false)
167
			textColor.dispose();
168
		if (hoverTextColor != null && hoverTextColor.isDisposed() == false)
169
			hoverTextColor.dispose();
170
		
171
		for (int i = 0; i < gripperColors.length; i++) {
172
			if (gripperColors[i] != null && gripperColors[i].isDisposed() == false)
173
				gripperColors[i].dispose();
174
		}
175
	}
176
	
177
	private void drawGripper(GC gc, Rectangle rect, SWidget widget, int type, int state) {
178
179
		int dotGap = GRIPPER_DOT_HEIGHT;
180
		int gripperImageHeight = GRIPPER_DOT_HEIGHT * GRIPPER_DOT_COUNT + dotGap * (GRIPPER_DOT_COUNT-1);
181
		int left = rect.x + rect.width - 3;
182
		int top = rect.y + (rect.height - gripperImageHeight) / 2;
183
		
184
		int x = left;
185
		int y = top;
186
		for (int i = 0; i < gripperColors.length; i++) {
187
			if (i != 0 && i % 9 == 0) {
188
				x = left;
189
				y += dotGap+1;
190
			} else if (i != 0 && i % 3 == 0) {
191
				x = left;
192
				y++;
193
			}
194
			gc.setForeground(gripperColors[i]); 
195
			gc.drawPoint(x,y);
196
			x++;
197
		}
198
	}
199
200
}
(-)src/org/eclipse/ui/examples/presentation/customtoolbar/widgets/SWidget.java (+31 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar.widgets;
2
3
import org.eclipse.swt.widgets.Canvas;
4
import org.eclipse.swt.widgets.Composite;
5
6
public abstract class SWidget extends Canvas {
7
	
8
	public static final int HOVER = 1 << 1;
9
	public static final int SELECTED = 1 << 2;
10
	public static final int PRESSED = 1 << 3;
11
	
12
	private Skin skin;
13
14
	public SWidget(Composite parent, int style) {
15
		super(parent, style);
16
	}
17
	
18
	public void setSkin(Skin skin) {
19
		if (this.skin != null) {
20
			this.skin.dispose();
21
			this.skin = null;
22
		}
23
24
		this.skin = skin;
25
	}
26
27
	public Skin getSkin() {
28
		return skin;
29
	}
30
	
31
}
(-)Eclipse UI/org/eclipse/ui/internal/ViewPane.java (-2 / +2 lines)
Lines 13-20 Link Here
13
package org.eclipse.ui.internal;
13
package org.eclipse.ui.internal;
14
14
15
15
16
import org.eclipse.jface.action.IToolBarManager2;
17
import org.eclipse.jface.action.MenuManager;
16
import org.eclipse.jface.action.MenuManager;
17
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
18
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
Lines 30-36 Link Here
30
import org.eclipse.ui.IViewReference;
30
import org.eclipse.ui.IViewReference;
31
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.internal.dnd.DragUtil;
32
import org.eclipse.ui.internal.dnd.DragUtil;
33
import org.eclipse.ui.internal.presentations.IActionBarPresentationFactory;
33
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
34
import org.eclipse.ui.presentations.IPresentablePart;
34
import org.eclipse.ui.presentations.IPresentablePart;
35
import org.eclipse.ui.presentations.StackPresentation;
35
import org.eclipse.ui.presentations.StackPresentation;
36
36
(-)Eclipse UI/org/eclipse/ui/internal/PlaceholderContributionItem.java (-1 / +1 lines)
Lines 13-19 Link Here
13
13
14
import org.eclipse.jface.action.IContributionItem;
14
import org.eclipse.jface.action.IContributionItem;
15
import org.eclipse.jface.action.IContributionManager;
15
import org.eclipse.jface.action.IContributionManager;
16
import org.eclipse.jface.action.IToolBarContributionItem;
16
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
17
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.CoolBar;
18
import org.eclipse.swt.widgets.CoolBar;
19
import org.eclipse.swt.widgets.Menu;
19
import org.eclipse.swt.widgets.Menu;
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-6 / +7 lines)
Lines 37-46 Link Here
37
import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
37
import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
38
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
38
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
39
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
39
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
40
import org.eclipse.jface.action.ICoolBarManager;
41
import org.eclipse.jface.dialogs.ErrorDialog;
40
import org.eclipse.jface.dialogs.ErrorDialog;
42
import org.eclipse.jface.dialogs.IDialogConstants;
41
import org.eclipse.jface.dialogs.IDialogConstants;
43
import org.eclipse.jface.dialogs.MessageDialog;
42
import org.eclipse.jface.dialogs.MessageDialog;
43
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
44
import org.eclipse.jface.operation.IRunnableWithProgress;
44
import org.eclipse.jface.operation.IRunnableWithProgress;
45
import org.eclipse.jface.preference.IPreferenceStore;
45
import org.eclipse.jface.preference.IPreferenceStore;
46
import org.eclipse.jface.util.Assert;
46
import org.eclipse.jface.util.Assert;
Lines 2539-2554 Link Here
2539
        // Run op in busy cursor.
2539
        // Run op in busy cursor.
2540
        // Use set redraw to eliminate the "flash" that can occur in the
2540
        // Use set redraw to eliminate the "flash" that can occur in the
2541
        // coolbar as the perspective is reset.
2541
        // coolbar as the perspective is reset.
2542
        ICoolBarManager mgr = window.getCoolBarManager2();
2542
        ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
2543
        try {
2543
        try {
2544
            mgr.getControl().setRedraw(false);
2544
            mgr.getControl2().setRedraw(false);
2545
            BusyIndicator.showWhile(null, new Runnable() {
2545
            BusyIndicator.showWhile(null, new Runnable() {
2546
                public void run() {
2546
                public void run() {
2547
                    busyResetPerspective();
2547
                    busyResetPerspective();
2548
                }
2548
                }
2549
            });
2549
            });
2550
        } finally {
2550
        } finally {
2551
            mgr.getControl().setRedraw(true);
2551
            mgr.getControl2().setRedraw(true);
2552
        }
2552
        }
2553
    }
2553
    }
2554
2554
Lines 3148-3154 Link Here
3148
        // Going from multiple to single rows can make the coolbar
3148
        // Going from multiple to single rows can make the coolbar
3149
        // and its adjacent views appear jumpy as perspectives are
3149
        // and its adjacent views appear jumpy as perspectives are
3150
        // switched. Turn off redraw to help with this.
3150
        // switched. Turn off redraw to help with this.
3151
        ICoolBarManager mgr = window.getCoolBarManager2();
3151
        ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
3152
        try {
3152
        try {
3153
            mgr.getControl2().setRedraw(false);
3153
            mgr.getControl2().setRedraw(false);
3154
            getClientComposite().setRedraw(false);
3154
            getClientComposite().setRedraw(false);
Lines 3180-3186 Link Here
3180
     * Restore the toolbar layout for the active perspective.
3180
     * Restore the toolbar layout for the active perspective.
3181
     */
3181
     */
3182
    protected void resetToolBarLayout() {
3182
    protected void resetToolBarLayout() {
3183
        window.getCoolBarManager2().resetItemOrder();
3183
    	ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
3184
    	mgr.resetItemOrder();
3184
    }
3185
    }
3185
3186
3186
    /**
3187
    /**
(-)Eclipse UI/org/eclipse/ui/internal/PluginActionSetBuilder.java (-1 / +1 lines)
Lines 22-30 Link Here
22
import org.eclipse.jface.action.IContributionManager;
22
import org.eclipse.jface.action.IContributionManager;
23
import org.eclipse.jface.action.ICoolBarManager;
23
import org.eclipse.jface.action.ICoolBarManager;
24
import org.eclipse.jface.action.IMenuManager;
24
import org.eclipse.jface.action.IMenuManager;
25
import org.eclipse.jface.action.IToolBarContributionItem;
26
import org.eclipse.jface.action.IToolBarManager;
25
import org.eclipse.jface.action.IToolBarManager;
27
import org.eclipse.jface.action.Separator;
26
import org.eclipse.jface.action.Separator;
27
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
28
import org.eclipse.ui.IActionBars;
28
import org.eclipse.ui.IActionBars;
29
import org.eclipse.ui.IWorkbenchActionConstants;
29
import org.eclipse.ui.IWorkbenchActionConstants;
30
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.IWorkbenchWindow;
(-)Eclipse UI/org/eclipse/ui/internal/ActionSetActionBars.java (-4 / +4 lines)
Lines 18-31 Link Here
18
import org.eclipse.jface.action.IContributionManager;
18
import org.eclipse.jface.action.IContributionManager;
19
import org.eclipse.jface.action.ICoolBarManager;
19
import org.eclipse.jface.action.ICoolBarManager;
20
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.IMenuManager;
21
import org.eclipse.jface.action.IToolBarContributionItem;
22
import org.eclipse.jface.action.IToolBarManager;
21
import org.eclipse.jface.action.IToolBarManager;
23
import org.eclipse.jface.action.SubMenuManager;
22
import org.eclipse.jface.action.SubMenuManager;
24
import org.eclipse.jface.action.SubToolBarManager;
23
import org.eclipse.jface.action.SubToolBarManager;
24
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
25
import org.eclipse.ui.IActionBars2;
25
import org.eclipse.ui.IActionBars2;
26
import org.eclipse.ui.IWorkbenchActionConstants;
26
import org.eclipse.ui.IWorkbenchActionConstants;
27
import org.eclipse.ui.SubActionBars2;
27
import org.eclipse.ui.SubActionBars2;
28
import org.eclipse.ui.application.IActionBarConfigurer;
28
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
29
import org.eclipse.ui.services.IServiceLocator;
29
import org.eclipse.ui.services.IServiceLocator;
30
30
31
/**
31
/**
Lines 33-39 Link Here
33
 */
33
 */
34
public class ActionSetActionBars extends SubActionBars2 {
34
public class ActionSetActionBars extends SubActionBars2 {
35
	
35
	
36
	private IActionBarConfigurer actionBarConfigurer = null;
36
	private IActionBarConfigurer2 actionBarConfigurer = null;
37
37
38
	private String actionSetId;
38
	private String actionSetId;
39
39
Lines 46-52 Link Here
46
	/**
46
	/**
47
     * Constructs a new action bars object
47
     * Constructs a new action bars object
48
     */
48
     */
49
    public ActionSetActionBars(IActionBars2 parent, IServiceLocator serviceLocator, IActionBarConfigurer actionBarConfigurer, String actionSetId) {
49
    public ActionSetActionBars(IActionBars2 parent, IServiceLocator serviceLocator, IActionBarConfigurer2 actionBarConfigurer, String actionSetId) {
50
    	super(parent, serviceLocator);
50
    	super(parent, serviceLocator);
51
		this.actionSetId = actionSetId;		
51
		this.actionSetId = actionSetId;		
52
        this.actionBarConfigurer = actionBarConfigurer;
52
        this.actionBarConfigurer = actionBarConfigurer;
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java (-6 / +8 lines)
Lines 20-27 Link Here
20
import org.eclipse.jface.action.ICoolBarManager;
20
import org.eclipse.jface.action.ICoolBarManager;
21
import org.eclipse.jface.action.IMenuManager;
21
import org.eclipse.jface.action.IMenuManager;
22
import org.eclipse.jface.action.IStatusLineManager;
22
import org.eclipse.jface.action.IStatusLineManager;
23
import org.eclipse.jface.action.IToolBarContributionItem;
24
import org.eclipse.jface.action.IToolBarManager;
23
import org.eclipse.jface.action.IToolBarManager;
24
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
25
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
25
import org.eclipse.jface.window.Window;
26
import org.eclipse.jface.window.Window;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.dnd.DropTarget;
28
import org.eclipse.swt.dnd.DropTarget;
Lines 39-45 Link Here
39
import org.eclipse.ui.application.IWorkbenchConfigurer;
40
import org.eclipse.ui.application.IWorkbenchConfigurer;
40
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
41
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
41
import org.eclipse.ui.application.WorkbenchAdvisor;
42
import org.eclipse.ui.application.WorkbenchAdvisor;
42
import org.eclipse.ui.internal.presentations.IActionBarPresentationFactory;
43
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
44
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
43
import org.eclipse.ui.presentations.AbstractPresentationFactory;
45
import org.eclipse.ui.presentations.AbstractPresentationFactory;
44
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
46
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
45
47
Lines 143-158 Link Here
143
     * Action bar configurer that changes this workbench window.
145
     * Action bar configurer that changes this workbench window.
144
     * This implementation keeps track of of cool bar items
146
     * This implementation keeps track of of cool bar items
145
     */
147
     */
146
    class WindowActionBarConfigurer implements IActionBarConfigurer {
148
    class WindowActionBarConfigurer implements IActionBarConfigurer2 {
147
149
148
        private IActionBarConfigurer proxy;
150
        private IActionBarConfigurer2 proxy;
149
        
151
        
150
        /**
152
        /**
151
         * Sets the proxy to use, or <code>null</code> for none.
153
         * Sets the proxy to use, or <code>null</code> for none.
152
         * 
154
         * 
153
         * @param proxy the proxy
155
         * @param proxy the proxy
154
         */
156
         */
155
        public void setProxy(IActionBarConfigurer proxy) {
157
        public void setProxy(IActionBarConfigurer2 proxy) {
156
            this.proxy = proxy;
158
            this.proxy = proxy;
157
        }
159
        }
158
        
160
        
Lines 615-621 Link Here
615
     */
617
     */
616
    public Control createCoolBarControl(Composite parent) {
618
    public Control createCoolBarControl(Composite parent) {
617
        return actionBarConfigurer.getActionBarPresentationFactory().createCoolBarControl(
619
        return actionBarConfigurer.getActionBarPresentationFactory().createCoolBarControl(
618
        		window.getCoolBarManager2(), parent);
620
        		(ICoolBarManager2) window.getCoolBarManager2(), parent);
619
    }
621
    }
620
622
621
    /* (non-Javadoc)
623
    /* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java (-13 / +16 lines)
Lines 38-49 Link Here
38
import org.eclipse.jface.action.IContributionManager;
38
import org.eclipse.jface.action.IContributionManager;
39
import org.eclipse.jface.action.ICoolBarManager;
39
import org.eclipse.jface.action.ICoolBarManager;
40
import org.eclipse.jface.action.IMenuManager;
40
import org.eclipse.jface.action.IMenuManager;
41
import org.eclipse.jface.action.IToolBarContributionItem;
41
import org.eclipse.jface.action.IToolBarManager;
42
import org.eclipse.jface.action.IToolBarManager2;
43
import org.eclipse.jface.action.MenuManager;
42
import org.eclipse.jface.action.MenuManager;
44
import org.eclipse.jface.action.Separator;
43
import org.eclipse.jface.action.Separator;
45
import org.eclipse.jface.action.StatusLineManager;
44
import org.eclipse.jface.action.StatusLineManager;
46
import org.eclipse.jface.commands.ActionHandler;
45
import org.eclipse.jface.commands.ActionHandler;
46
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
47
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
48
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
47
import org.eclipse.jface.operation.IRunnableWithProgress;
49
import org.eclipse.jface.operation.IRunnableWithProgress;
48
import org.eclipse.jface.window.ApplicationWindow;
50
import org.eclipse.jface.window.ApplicationWindow;
49
import org.eclipse.jface.window.Window;
51
import org.eclipse.jface.window.Window;
Lines 90-96 Link Here
90
import org.eclipse.ui.PlatformUI;
92
import org.eclipse.ui.PlatformUI;
91
import org.eclipse.ui.WorkbenchException;
93
import org.eclipse.ui.WorkbenchException;
92
import org.eclipse.ui.application.ActionBarAdvisor;
94
import org.eclipse.ui.application.ActionBarAdvisor;
93
import org.eclipse.ui.application.IActionBarConfigurer;
94
import org.eclipse.ui.application.WorkbenchAdvisor;
95
import org.eclipse.ui.application.WorkbenchAdvisor;
95
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
96
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
96
import org.eclipse.ui.commands.ICommandService;
97
import org.eclipse.ui.commands.ICommandService;
Lines 123-130 Link Here
123
import org.eclipse.ui.internal.misc.UIListenerLogging;
124
import org.eclipse.ui.internal.misc.UIListenerLogging;
124
import org.eclipse.ui.internal.misc.UIStats;
125
import org.eclipse.ui.internal.misc.UIStats;
125
import org.eclipse.ui.internal.presentations.DefaultActionBarPresentationFactory;
126
import org.eclipse.ui.internal.presentations.DefaultActionBarPresentationFactory;
126
import org.eclipse.ui.internal.presentations.IActionBarPresentationFactory;
127
import org.eclipse.ui.internal.progress.ProgressRegion;
127
import org.eclipse.ui.internal.progress.ProgressRegion;
128
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
129
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
128
import org.eclipse.ui.internal.registry.ActionSetRegistry;
130
import org.eclipse.ui.internal.registry.ActionSetRegistry;
129
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
131
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
130
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
132
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
Lines 1660-1666 Link Here
1660
		// This needs to be done before pages are created to ensure proper
1662
		// This needs to be done before pages are created to ensure proper
1661
		// canonical creation
1663
		// canonical creation
1662
		// of cool items
1664
		// of cool items
1663
		ICoolBarManager coolBarMgr = getCoolBarManager2();
1665
		ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
1664
        if (coolBarMgr != null) {
1666
        if (coolBarMgr != null) {
1665
			IMemento coolBarMem = memento
1667
			IMemento coolBarMem = memento
1666
					.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
1668
					.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
Lines 1953-1959 Link Here
1953
		if (coolbarMem == null) {
1955
		if (coolbarMem == null) {
1954
			return false;
1956
			return false;
1955
		}
1957
		}
1956
        ICoolBarManager coolBarMgr = getCoolBarManager2();
1958
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
1957
		// Check to see if layout is locked
1959
		// Check to see if layout is locked
1958
		Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
1960
		Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
1959
		boolean state = (locked != null) && (locked.intValue() == 1);
1961
		boolean state = (locked != null) && (locked.intValue() == 1);
Lines 2286-2292 Link Here
2286
		}
2288
		}
2287
2289
2288
		// / Save the order of the cool bar contribution items
2290
		// / Save the order of the cool bar contribution items
2289
        ICoolBarManager coolBarMgr = getCoolBarManager2();
2291
        ICoolBarManager2 coolBarMgr = (ICoolBarManager2) getCoolBarManager2();
2290
        if (coolBarMgr != null) {
2292
        if (coolBarMgr != null) {
2291
        	coolBarMgr.refresh();
2293
        	coolBarMgr.refresh();
2292
			IMemento coolBarMem = memento
2294
			IMemento coolBarMem = memento
Lines 2705-2712 Link Here
2705
		if (currentPage == null)
2707
		if (currentPage == null)
2706
			getActionPresentation().clearActionSets();
2708
			getActionPresentation().clearActionSets();
2707
		else {
2709
		else {
2708
			if (getCoolBarManager2() != null) {
2710
			ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
2709
				getCoolBarManager2().refresh();
2711
			if (coolBarManager != null) {
2712
				coolBarManager.refresh();
2710
			}
2713
			}
2711
			getActionPresentation().setActionSets(currentPage.getActionSets());
2714
			getActionPresentation().setActionSets(currentPage.getActionSets());
2712
		}
2715
		}
Lines 2962-2968 Link Here
2962
	 * @param flags
2965
	 * @param flags
2963
	 *            indicate which bars to fill
2966
	 *            indicate which bars to fill
2964
	 */
2967
	 */
2965
	public void fillActionBars(IActionBarConfigurer proxyBars, int flags) {
2968
	public void fillActionBars(IActionBarConfigurer2 proxyBars, int flags) {
2966
		Assert.isNotNull(proxyBars);
2969
		Assert.isNotNull(proxyBars);
2967
		WorkbenchWindowConfigurer.WindowActionBarConfigurer wab = (WorkbenchWindowConfigurer.WindowActionBarConfigurer) getWindowConfigurer()
2970
		WorkbenchWindowConfigurer.WindowActionBarConfigurer wab = (WorkbenchWindowConfigurer.WindowActionBarConfigurer) getWindowConfigurer()
2968
				.getActionBarConfigurer();
2971
				.getActionBarConfigurer();
Lines 3272-3278 Link Here
3272
	 * @since 3.2
3275
	 * @since 3.2
3273
     */
3276
     */
3274
    protected Control createCoolBarControl(Composite parent) {
3277
    protected Control createCoolBarControl(Composite parent) {
3275
        return getActionBarPresentationFactory().createCoolBarControl(getCoolBarManager2(), parent);
3278
        return getActionBarPresentationFactory().createCoolBarControl((ICoolBarManager2) getCoolBarManager2(), parent);
3276
    }
3279
    }
3277
3280
3278
    /**
3281
    /**
Lines 3283-3289 Link Here
3283
     * @return a tool bar manager
3286
     * @return a tool bar manager
3284
	 * @since 3.2
3287
	 * @since 3.2
3285
     */
3288
     */
3286
    protected IToolBarManager2 createToolBarManager2(int style) {
3289
    protected IToolBarManager createToolBarManager2(int style) {
3287
        return getActionBarPresentationFactory().createToolBarManager();
3290
        return getActionBarPresentationFactory().createToolBarManager();
3288
    }
3291
    }
3289
3292
Lines 3296-3302 Link Here
3296
	 * @since 3.2
3299
	 * @since 3.2
3297
     */
3300
     */
3298
    protected Control createToolBarControl(Composite parent) {
3301
    protected Control createToolBarControl(Composite parent) {
3299
        return getActionBarPresentationFactory().createToolBarControl(getToolBarManager2(), parent);
3302
        return getActionBarPresentationFactory().createToolBarControl((IToolBarManager2) getToolBarManager2(), parent);
3300
    }
3303
    }
3301
    
3304
    
3302
    /**
3305
    /**
(-)Eclipse UI/org/eclipse/ui/internal/EditorActionBars.java (-2 / +2 lines)
Lines 18-29 Link Here
18
import org.eclipse.jface.action.IContributionManagerOverrides;
18
import org.eclipse.jface.action.IContributionManagerOverrides;
19
import org.eclipse.jface.action.ICoolBarManager;
19
import org.eclipse.jface.action.ICoolBarManager;
20
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.jface.action.IMenuManager;
21
import org.eclipse.jface.action.IToolBarContributionItem;
22
import org.eclipse.jface.action.IToolBarManager;
21
import org.eclipse.jface.action.IToolBarManager;
23
import org.eclipse.jface.action.SubContributionManager;
22
import org.eclipse.jface.action.SubContributionManager;
24
import org.eclipse.jface.action.SubMenuManager;
23
import org.eclipse.jface.action.SubMenuManager;
25
import org.eclipse.jface.action.SubStatusLineManager;
24
import org.eclipse.jface.action.SubStatusLineManager;
26
import org.eclipse.jface.action.SubToolBarManager;
25
import org.eclipse.jface.action.SubToolBarManager;
26
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
27
import org.eclipse.ui.IActionBars2;
27
import org.eclipse.ui.IActionBars2;
28
import org.eclipse.ui.IEditorActionBarContributor;
28
import org.eclipse.ui.IEditorActionBarContributor;
29
import org.eclipse.ui.IEditorPart;
29
import org.eclipse.ui.IEditorPart;
Lines 32-38 Link Here
32
import org.eclipse.ui.SubActionBars2;
32
import org.eclipse.ui.SubActionBars2;
33
import org.eclipse.ui.actions.RetargetAction;
33
import org.eclipse.ui.actions.RetargetAction;
34
import org.eclipse.ui.internal.misc.Policy;
34
import org.eclipse.ui.internal.misc.Policy;
35
import org.eclipse.ui.internal.presentations.IActionBarPresentationFactory;
35
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
36
import org.eclipse.ui.services.IServiceLocator;
36
import org.eclipse.ui.services.IServiceLocator;
37
37
38
/**
38
/**
(-)Eclipse UI/org/eclipse/ui/internal/ActionPresentation.java (-1 / +2 lines)
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
21
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
22
import org.eclipse.ui.SubActionBars;
22
import org.eclipse.ui.SubActionBars;
23
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
23
import org.eclipse.ui.internal.registry.IActionSet;
24
import org.eclipse.ui.internal.registry.IActionSet;
24
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
25
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
25
26
Lines 147-153 Link Here
147
                        IActionSet set = desc.createActionSet();
148
                        IActionSet set = desc.createActionSet();
148
                        SubActionBars bars = new ActionSetActionBars(window
149
                        SubActionBars bars = new ActionSetActionBars(window
149
								.getActionBars(), window,
150
								.getActionBars(), window,
150
								window.getWindowConfigurer()
151
								(IActionBarConfigurer2) window.getWindowConfigurer()
151
										.getActionBarConfigurer(), desc.getId());
152
										.getActionBarConfigurer(), desc.getId());
152
                        rec = new SetRec(desc, set, bars);
153
                        rec = new SetRec(desc, set, bars);
153
                        set.init(window, bars);
154
                        set.init(window, bars);
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-2 / +4 lines)
Lines 37-42 Link Here
37
import org.eclipse.jface.dialogs.IDialogConstants;
37
import org.eclipse.jface.dialogs.IDialogConstants;
38
import org.eclipse.jface.dialogs.MessageDialog;
38
import org.eclipse.jface.dialogs.MessageDialog;
39
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
39
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
40
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
40
import org.eclipse.jface.operation.IRunnableWithProgress;
41
import org.eclipse.jface.operation.IRunnableWithProgress;
41
import org.eclipse.jface.preference.IPreferenceStore;
42
import org.eclipse.jface.preference.IPreferenceStore;
42
import org.eclipse.jface.resource.ImageDescriptor;
43
import org.eclipse.jface.resource.ImageDescriptor;
Lines 345-352 Link Here
345
			String type = actionBars.getEditorType();
346
			String type = actionBars.getEditorType();
346
			actionCache.remove(type);
347
			actionCache.remove(type);
347
			// refresh the cool bar manager before disposing of a cool item
348
			// refresh the cool bar manager before disposing of a cool item
348
            if (window.getCoolBarManager2() != null) {
349
			ICoolBarManager2 coolBar = (ICoolBarManager2) window.getCoolBarManager2();
349
                window.getCoolBarManager2().refresh();
350
            if (coolBar != null) {
351
            	coolBar.refresh();
350
			}
352
			}
351
			actionBars.dispose();
353
			actionBars.dispose();
352
		}
354
		}
(-)Eclipse UI/org/eclipse/ui/application/IActionBarConfigurer.java (-24 lines)
Lines 14-21 Link Here
14
import org.eclipse.jface.action.ICoolBarManager;
14
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IStatusLineManager;
16
import org.eclipse.jface.action.IStatusLineManager;
17
import org.eclipse.jface.action.IToolBarContributionItem;
18
import org.eclipse.jface.action.IToolBarManager;
19
17
20
/**
18
/**
21
 * Interface providing special access for configuring the action bars
19
 * Interface providing special access for configuring the action bars
Lines 65-92 Link Here
65
    public ICoolBarManager getCoolBarManager();
63
    public ICoolBarManager getCoolBarManager();
66
    
64
    
67
    /**
65
    /**
68
     * Creates a tool bar manager for the workbench window's tool bar.
69
     * The action bar advisor should use this factory method rather than
70
     * creating a <code>ToolBarManager</code> directly. 
71
	 *
72
     * @return the tool bar manager
73
     * @since 3.2
74
     */
75
    public IToolBarManager createToolBarManager();
76
        
77
    /**
78
     * Creates a toolbar contribution item for the window's tool bar.
79
     * The action bar advisor should use this factory method rather than
80
     * creating a <code>ToolBarContributionItem</code> directly. 
81
	 * 
82
     * @param toolBarManager a tool bar manager for the workbench window's tool bar
83
     * @param id the id of the contribution
84
     * @return the tool bar contribution item
85
	 * @since 3.2
86
     */
87
    public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id);
88
89
    /**
90
     * Register the action as a global action with a workbench
66
     * Register the action as a global action with a workbench
91
     * window.
67
     * window.
92
     * <p>
68
     * <p>
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/CustomizePerspectiveDialog.java (-5 / +5 lines)
Lines 26-38 Link Here
26
import org.eclipse.jface.action.ICoolBarManager;
26
import org.eclipse.jface.action.ICoolBarManager;
27
import org.eclipse.jface.action.IMenuManager;
27
import org.eclipse.jface.action.IMenuManager;
28
import org.eclipse.jface.action.IStatusLineManager;
28
import org.eclipse.jface.action.IStatusLineManager;
29
import org.eclipse.jface.action.IToolBarContributionItem;
30
import org.eclipse.jface.action.IToolBarManager;
29
import org.eclipse.jface.action.IToolBarManager;
31
import org.eclipse.jface.action.MenuManager;
30
import org.eclipse.jface.action.MenuManager;
32
import org.eclipse.jface.action.StatusLineManager;
31
import org.eclipse.jface.action.StatusLineManager;
33
import org.eclipse.jface.action.ToolBarContributionItem;
34
import org.eclipse.jface.action.ToolBarManager;
32
import org.eclipse.jface.action.ToolBarManager;
35
import org.eclipse.jface.dialogs.TrayDialog;
33
import org.eclipse.jface.dialogs.TrayDialog;
34
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
35
import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2;
36
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.resource.ImageDescriptor;
37
import org.eclipse.jface.viewers.AbstractTreeViewer;
37
import org.eclipse.jface.viewers.AbstractTreeViewer;
38
import org.eclipse.jface.viewers.ArrayContentProvider;
38
import org.eclipse.jface.viewers.ArrayContentProvider;
Lines 86-92 Link Here
86
import org.eclipse.ui.PlatformUI;
86
import org.eclipse.ui.PlatformUI;
87
import org.eclipse.ui.activities.WorkbenchActivityHelper;
87
import org.eclipse.ui.activities.WorkbenchActivityHelper;
88
import org.eclipse.ui.application.ActionBarAdvisor;
88
import org.eclipse.ui.application.ActionBarAdvisor;
89
import org.eclipse.ui.application.IActionBarConfigurer;
90
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
89
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
91
import org.eclipse.ui.internal.ActionSetActionBars;
90
import org.eclipse.ui.internal.ActionSetActionBars;
92
import org.eclipse.ui.internal.ActionSetContributionItem;
91
import org.eclipse.ui.internal.ActionSetContributionItem;
Lines 102-107 Link Here
102
import org.eclipse.ui.internal.WorkbenchPlugin;
101
import org.eclipse.ui.internal.WorkbenchPlugin;
103
import org.eclipse.ui.internal.WorkbenchWindow;
102
import org.eclipse.ui.internal.WorkbenchWindow;
104
import org.eclipse.ui.internal.intro.IIntroConstants;
103
import org.eclipse.ui.internal.intro.IIntroConstants;
104
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
105
import org.eclipse.ui.internal.registry.ActionSetDescriptor;
105
import org.eclipse.ui.internal.registry.ActionSetDescriptor;
106
import org.eclipse.ui.internal.registry.ActionSetRegistry;
106
import org.eclipse.ui.internal.registry.ActionSetRegistry;
107
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
107
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
Lines 386-392 Link Here
386
     * window's hardwired menus and toolbars in order to display their
386
     * window's hardwired menus and toolbars in order to display their
387
     * structure properly in the preview panes.
387
     * structure properly in the preview panes.
388
     */
388
     */
389
    public class CustomizeActionBars implements IActionBarConfigurer,
389
    public class CustomizeActionBars implements IActionBarConfigurer2,
390
			IActionBars2 {
390
			IActionBars2 {
391
        
391
        
392
        IWorkbenchWindowConfigurer configurer;
392
        IWorkbenchWindowConfigurer configurer;
Lines 486-492 Link Here
486
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
486
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
487
		 */
487
		 */
488
		public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
488
		public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
489
			return new ToolBarContributionItem(toolBarManager, id);
489
			return new ToolBarContributionItem2(toolBarManager, id);
490
		}
490
		}
491
491
492
		/* (non-Javadoc)
492
		/* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/presentations/DefaultActionBarPresentationFactory.java (-12 / +13 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.presentations;
11
package org.eclipse.ui.internal.presentations;
12
12
13
import org.eclipse.jface.action.CoolBarManager;
14
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.jface.action.IToolBarContributionItem;
16
import org.eclipse.jface.action.IToolBarManager;
13
import org.eclipse.jface.action.IToolBarManager;
17
import org.eclipse.jface.action.IToolBarManager2;
14
import org.eclipse.jface.internal.provisional.action.CoolBarManager2;
18
import org.eclipse.jface.action.ToolBarContributionItem;
15
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
19
import org.eclipse.jface.action.ToolBarManager;
16
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
17
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
18
import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2;
19
import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
23
24
24
/**
25
/**
25
 * The intention of this class is to allow for replacing the implementation of
26
 * The intention of this class is to allow for replacing the implementation of
Lines 38-51 Link Here
38
	/* (non-Javadoc)
39
	/* (non-Javadoc)
39
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarManager()
40
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarManager()
40
	 */
41
	 */
41
	public ICoolBarManager createCoolBarManager() {
42
	public ICoolBarManager2 createCoolBarManager() {
42
		return new CoolBarManager(SWT.FLAT);
43
		return new CoolBarManager2(SWT.FLAT);
43
	}
44
	}
44
45
45
	/* (non-Javadoc)
46
	/* (non-Javadoc)
46
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarControl(org.eclipse.jface.action.ICoolBarManager, org.eclipse.swt.widgets.Composite)
47
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createCoolBarControl(org.eclipse.jface.action.ICoolBarManager, org.eclipse.swt.widgets.Composite)
47
	 */
48
	 */
48
	public Control createCoolBarControl(ICoolBarManager coolBarManager,
49
	public Control createCoolBarControl(ICoolBarManager2 coolBarManager,
49
			Composite parent) {
50
			Composite parent) {
50
		return coolBarManager.createControl2(parent);
51
		return coolBarManager.createControl2(parent);
51
	}
52
	}
Lines 54-60 Link Here
54
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarManager()
55
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createToolBarManager()
55
	 */
56
	 */
56
	public IToolBarManager2 createToolBarManager() {
57
	public IToolBarManager2 createToolBarManager() {
57
		return new ToolBarManager(SWT.FLAT | SWT.RIGHT);
58
		return new ToolBarManager2(SWT.FLAT | SWT.RIGHT);
58
	}
59
	}
59
60
60
	/* (non-Javadoc)
61
	/* (non-Javadoc)
Lines 69-75 Link Here
69
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createViewToolBarManager()
70
	 * @see org.eclipse.ui.internal.presentations.IActionBarPresentationFactory#createViewToolBarManager()
70
	 */
71
	 */
71
	public IToolBarManager2 createViewToolBarManager() {
72
	public IToolBarManager2 createViewToolBarManager() {
72
		return new ToolBarManager(SWT.FLAT | SWT.RIGHT);
73
		return new ToolBarManager2(SWT.FLAT | SWT.RIGHT);
73
	}
74
	}
74
75
75
	/* (non-Javadoc)
76
	/* (non-Javadoc)
Lines 85-90 Link Here
85
	 */
86
	 */
86
	public IToolBarContributionItem createToolBarContributionItem(
87
	public IToolBarContributionItem createToolBarContributionItem(
87
			IToolBarManager toolBarManager, String id) {
88
			IToolBarManager toolBarManager, String id) {
88
		return new ToolBarContributionItem(toolBarManager, id);
89
		return new ToolBarContributionItem2(toolBarManager, id);
89
	}
90
	}
90
}
91
}
(-)Eclipse UI/org/eclipse/ui/internal/presentations/IActionBarPresentationFactory.java (-105 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.ui.internal.presentations;
13
14
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.jface.action.IToolBarContributionItem;
16
import org.eclipse.jface.action.IToolBarManager;
17
import org.eclipse.jface.action.IToolBarManager2;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
21
/**
22
 * The intention of this class is to allow for replacing the implementation of
23
 * the cool bar and tool bars in the workbench.
24
 * <p>
25
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
26
 * part of a work in progress. There is a guarantee neither that this API will
27
 * work nor that it will remain the same. Please do not use this API without
28
 * consulting with the Platform/UI team.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public interface IActionBarPresentationFactory {
34
	
35
	/**
36
	 * Creates the cool bar manager for the window's tool bar area.
37
	 * 
38
	 * @return the cool bar manager
39
	 */
40
	public ICoolBarManager createCoolBarManager();
41
42
	/**
43
	 * Creates the control for the window's cool bar. Subclasses may override.
44
	 * 
45
	 * @param coolBarManager
46
	 *            the window's cool bar manager
47
	 * @param parent
48
	 *            the parent composite
49
	 * @return the window's cool bar control
50
	 */
51
	public Control createCoolBarControl(ICoolBarManager coolBarManager,
52
			Composite parent);
53
54
	/**
55
	 * Creates a tool bar manager for window's tool bar area.
56
	 * 
57
	 * @return the tool bar manager
58
	 */
59
	public IToolBarManager2 createToolBarManager();
60
61
	/**
62
	 * Creates the control for the window's tool bar. Subclasses may override.
63
	 * 
64
	 * @param toolBarManager
65
	 *            the window's toolbar manager
66
	 * @param parent
67
	 *            the parent composite
68
	 * @return the window's tool bar control
69
	 */
70
	public Control createToolBarControl(IToolBarManager2 toolBarManager,
71
			Composite parent);
72
73
	/**
74
	 * Creates a tool bar manager for a view's tool bar.
75
	 * 
76
	 * @return the tool bar manager
77
	 */
78
	public IToolBarManager2 createViewToolBarManager();
79
80
	/**
81
	 * Creates the control for a view tool bar. Subclasses may override.
82
	 * 
83
	 * @param toolBarManager
84
	 *            the view's tool bar manager
85
	 * @param parent
86
	 *            the parent composite
87
	 * @return the view's tool bar control
88
	 */
89
	public Control createViewToolBarControl(IToolBarManager2 toolBarManager,
90
			Composite parent);
91
92
	/**
93
	 * Creates a toolbar contribution item for a window toolbar manager to be
94
	 * added to the window's cool bar.
95
	 * 
96
	 * @param toolBarManager
97
	 *            the tool bar manager
98
	 * @param id
99
	 *            the id of the contribution
100
	 * @return the toolbar contribution item
101
	 */
102
	public IToolBarContributionItem createToolBarContributionItem(
103
			IToolBarManager toolBarManager, String id);
104
105
}
(-)META-INF/MANIFEST.MF (+3 lines)
Lines 35-40 Link Here
35
 org.eclipse.ui.internal.dnd;x-friends:="org.eclipse.ui.intro,org.eclipse.ui.presentations.r21",
35
 org.eclipse.ui.internal.dnd;x-friends:="org.eclipse.ui.intro,org.eclipse.ui.presentations.r21",
36
 org.eclipse.ui.internal.editorsupport;x-internal:=true,
36
 org.eclipse.ui.internal.editorsupport;x-internal:=true,
37
 org.eclipse.ui.internal.expressions;x-internal:=true,
37
 org.eclipse.ui.internal.expressions;x-internal:=true,
38
 org.eclipse.ui.internal.fieldassist;x-internal:=true,
38
 org.eclipse.ui.internal.handlers;x-internal:=true,
39
 org.eclipse.ui.internal.handlers;x-internal:=true,
39
 org.eclipse.ui.internal.help;x-internal:=true,
40
 org.eclipse.ui.internal.help;x-internal:=true,
40
 org.eclipse.ui.internal.intro;x-internal:=true,
41
 org.eclipse.ui.internal.intro;x-internal:=true,
Lines 49-54 Link Here
49
 org.eclipse.ui.internal.presentations.defaultpresentation;x-internal:=true,
50
 org.eclipse.ui.internal.presentations.defaultpresentation;x-internal:=true,
50
 org.eclipse.ui.internal.presentations.util;x-friends:="org.eclipse.ui.presentations.r21",
51
 org.eclipse.ui.internal.presentations.util;x-friends:="org.eclipse.ui.presentations.r21",
51
 org.eclipse.ui.internal.progress;x-internal:=true,
52
 org.eclipse.ui.internal.progress;x-internal:=true,
53
 org.eclipse.ui.internal.provisional.application,
54
 org.eclipse.ui.internal.provisional.presentations,
52
 org.eclipse.ui.internal.registry;x-internal:=true,
55
 org.eclipse.ui.internal.registry;x-internal:=true,
53
 org.eclipse.ui.internal.services;x-internal:=true,
56
 org.eclipse.ui.internal.services;x-internal:=true,
54
 org.eclipse.ui.internal.testing;x-internal:=true,
57
 org.eclipse.ui.internal.testing;x-internal:=true,
(-)Eclipse (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.ui.internal.provisional.application;
13
14
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
16
import org.eclipse.ui.application.IActionBarConfigurer;
17
18
/**
19
 * Extends <code>IActionBarConfigurer</code> with API to allow the advisor to
20
 * be decoupled from the implementation types for tool bar managers and tool bar
21
 * contribution items.
22
 * 
23
 * @since 3.2
24
 */
25
public interface IActionBarConfigurer2 extends IActionBarConfigurer {
26
	
27
	/**
28
	 * Creates a tool bar manager for the workbench window's tool bar. The
29
	 * action bar advisor should use this factory method rather than creating a
30
	 * <code>ToolBarManager</code> directly.
31
	 * 
32
	 * @return the tool bar manager
33
	 */
34
	public IToolBarManager createToolBarManager();
35
36
	/**
37
	 * Creates a toolbar contribution item for the window's tool bar. The action
38
	 * bar advisor should use this factory method rather than creating a
39
	 * <code>ToolBarContributionItem</code> directly.
40
	 * 
41
	 * @param toolBarManager
42
	 *            a tool bar manager for the workbench window's tool bar
43
	 * @param id
44
	 *            the id of the contribution
45
	 * @return the tool bar contribution item
46
	 */
47
	public IToolBarContributionItem createToolBarContributionItem(
48
			IToolBarManager toolBarManager, String id);
49
50
}
(-)Eclipse (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
12
package org.eclipse.ui.internal.provisional.presentations;
13
14
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
16
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
17
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
21
/**
22
 * The intention of this class is to allow for replacing the implementation of
23
 * the cool bar and tool bars in the workbench.
24
 * <p>
25
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
26
 * part of a work in progress. There is a guarantee neither that this API will
27
 * work nor that it will remain the same. Please do not use this API without
28
 * consulting with the Platform/UI team.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public interface IActionBarPresentationFactory {
34
	
35
	/**
36
	 * Creates the cool bar manager for the window's tool bar area.
37
	 * 
38
	 * @return the cool bar manager
39
	 */
40
	public ICoolBarManager2 createCoolBarManager();
41
42
	/**
43
	 * Creates the control for the window's cool bar. Subclasses may override.
44
	 * 
45
	 * @param coolBarManager
46
	 *            the window's cool bar manager
47
	 * @param parent
48
	 *            the parent composite
49
	 * @return the window's cool bar control
50
	 */
51
	public Control createCoolBarControl(ICoolBarManager2 coolBarManager,
52
			Composite parent);
53
54
	/**
55
	 * Creates a tool bar manager for window's tool bar area.
56
	 * 
57
	 * @return the tool bar manager
58
	 */
59
	public IToolBarManager2 createToolBarManager();
60
61
	/**
62
	 * Creates the control for the window's tool bar. Subclasses may override.
63
	 * 
64
	 * @param toolBarManager
65
	 *            the window's toolbar manager
66
	 * @param parent
67
	 *            the parent composite
68
	 * @return the window's tool bar control
69
	 */
70
	public Control createToolBarControl(IToolBarManager2 toolBarManager,
71
			Composite parent);
72
73
	/**
74
	 * Creates a tool bar manager for a view's tool bar.
75
	 * 
76
	 * @return the tool bar manager
77
	 */
78
	public IToolBarManager2 createViewToolBarManager();
79
80
	/**
81
	 * Creates the control for a view tool bar. Subclasses may override.
82
	 * 
83
	 * @param toolBarManager
84
	 *            the view's tool bar manager
85
	 * @param parent
86
	 *            the parent composite
87
	 * @return the view's tool bar control
88
	 */
89
	public Control createViewToolBarControl(IToolBarManager2 toolBarManager,
90
			Composite parent);
91
92
	/**
93
	 * Creates a toolbar contribution item for a window toolbar manager to be
94
	 * added to the window's cool bar.
95
	 * 
96
	 * @param toolBarManager
97
	 *            the tool bar manager
98
	 * @param id
99
	 *            the id of the contribution
100
	 * @return the toolbar contribution item
101
	 */
102
	public IToolBarContributionItem createToolBarContributionItem(
103
			IToolBarManager toolBarManager, String id);
104
105
}
(-)src/org/eclipse/ui/examples/rcp/browser/BrowserActionBarAdvisor.java (-3 / +4 lines)
Lines 18-23 Link Here
18
import org.eclipse.jface.action.IToolBarManager;
18
import org.eclipse.jface.action.IToolBarManager;
19
import org.eclipse.jface.action.MenuManager;
19
import org.eclipse.jface.action.MenuManager;
20
import org.eclipse.jface.action.Separator;
20
import org.eclipse.jface.action.Separator;
21
import org.eclipse.jface.action.ToolBarContributionItem;
22
import org.eclipse.jface.action.ToolBarManager;
21
import org.eclipse.ui.ISharedImages;
23
import org.eclipse.ui.ISharedImages;
22
import org.eclipse.ui.IViewPart;
24
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchPage;
Lines 155-163 Link Here
155
	}
157
	}
156
158
157
	protected void fillCoolBar(ICoolBarManager coolBar) {
159
	protected void fillCoolBar(ICoolBarManager coolBar) {
158
		IToolBarManager toolBar = getActionBarConfigurer().createToolBarManager();
160
		IToolBarManager toolBar = new ToolBarManager();
159
		coolBar.add(getActionBarConfigurer().createToolBarContributionItem(
161
		coolBar.add(new ToolBarContributionItem(toolBar, "standard")); //$NON-NLS-1$
160
				toolBar, "standard")); //$NON-NLS-1$
161
		
162
		
162
		// For the Back and Forward actions, force their text to be shown on the toolbar,
163
		// For the Back and Forward actions, force their text to be shown on the toolbar,
163
		// not just their image.  For the remaining actions, the ActionContributionItem
164
		// not just their image.  For the remaining actions, the ActionContributionItem
(-)src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java (-2 / +3 lines)
Lines 26-35 Link Here
26
import org.eclipse.jface.action.ICoolBarManager;
26
import org.eclipse.jface.action.ICoolBarManager;
27
import org.eclipse.jface.action.IMenuManager;
27
import org.eclipse.jface.action.IMenuManager;
28
import org.eclipse.jface.action.IStatusLineManager;
28
import org.eclipse.jface.action.IStatusLineManager;
29
import org.eclipse.jface.action.IToolBarContributionItem;
30
import org.eclipse.jface.action.IToolBarManager;
29
import org.eclipse.jface.action.IToolBarManager;
31
import org.eclipse.jface.action.MenuManager;
30
import org.eclipse.jface.action.MenuManager;
32
import org.eclipse.jface.action.Separator;
31
import org.eclipse.jface.action.Separator;
32
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
33
import org.eclipse.jface.preference.IPreferenceStore;
33
import org.eclipse.jface.preference.IPreferenceStore;
34
import org.eclipse.jface.util.IPropertyChangeListener;
34
import org.eclipse.jface.util.IPropertyChangeListener;
35
import org.eclipse.jface.util.PropertyChangeEvent;
35
import org.eclipse.jface.util.PropertyChangeEvent;
Lines 53-58 Link Here
53
import org.eclipse.ui.internal.ide.actions.BuildUtilities;
53
import org.eclipse.ui.internal.ide.actions.BuildUtilities;
54
import org.eclipse.ui.internal.ide.actions.QuickMenuAction;
54
import org.eclipse.ui.internal.ide.actions.QuickMenuAction;
55
import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault;
55
import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault;
56
import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
56
import org.eclipse.ui.internal.util.StatusLineContributionItem;
57
import org.eclipse.ui.internal.util.StatusLineContributionItem;
57
58
58
/**
59
/**
Lines 355-361 Link Here
355
     */
356
     */
356
    protected void fillCoolBar(ICoolBarManager coolBar) {
357
    protected void fillCoolBar(ICoolBarManager coolBar) {
357
358
358
    	IActionBarConfigurer actionBarConfigurer = getActionBarConfigurer();
359
    	IActionBarConfigurer2 actionBarConfigurer = (IActionBarConfigurer2) getActionBarConfigurer();
359
        { // Set up the context Menu
360
        { // Set up the context Menu
360
            IMenuManager popUpMenu = new MenuManager();
361
            IMenuManager popUpMenu = new MenuManager();
361
            popUpMenu.add(new ActionContributionItem(lockToolBarAction));
362
            popUpMenu.add(new ActionContributionItem(lockToolBarAction));

Return to bug 123257