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

(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-4 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
2
 * Copyright (c) 2006 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 Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-27 Link Here
21
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.layout.FillLayout;
22
import org.eclipse.swt.layout.FillLayout;
23
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.ui.IActionBars2;
25
import org.eclipse.ui.IEditorInput;
24
import org.eclipse.ui.IEditorInput;
26
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IEditorPart;
27
import org.eclipse.ui.IEditorReference;
26
import org.eclipse.ui.IEditorReference;
Lines 401-408 Link Here
401
            
400
            
402
            EditorSite site = new EditorSite(this, part, manager.page, descr);
401
            EditorSite site = new EditorSite(this, part, manager.page, descr);
403
            
402
            
404
            site.setActionBars(new EditorActionBars((IActionBars2) manager.page
403
            site.setActionBars(new EditorActionBars(manager.page, site, getId()));
405
					.getActionBars(), site, getId()));
406
            try {
404
            try {
407
                part.init(site, input);
405
                part.init(site, input);
408
            } catch (PartInitException e) {
406
            } catch (PartInitException e) {
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindowConfigurer.java (-3 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
2
 * Copyright (c) 2003, 2006 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 20-25 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.IToolBarManager;
23
import org.eclipse.jface.window.Window;
24
import org.eclipse.jface.window.Window;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.dnd.DropTarget;
26
import org.eclipse.swt.dnd.DropTarget;
Lines 37-42 Link Here
37
import org.eclipse.ui.application.IWorkbenchConfigurer;
38
import org.eclipse.ui.application.IWorkbenchConfigurer;
38
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
39
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
39
import org.eclipse.ui.application.WorkbenchAdvisor;
40
import org.eclipse.ui.application.WorkbenchAdvisor;
41
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
40
import org.eclipse.ui.presentations.AbstractPresentationFactory;
42
import org.eclipse.ui.presentations.AbstractPresentationFactory;
41
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
43
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
42
44
Lines 205-211 Link Here
205
            if (proxy != null) {
207
            if (proxy != null) {
206
                return proxy.getCoolBarManager();
208
                return proxy.getCoolBarManager();
207
            }
209
            }
208
            return window.getCoolBarManager();
210
            return window.getCoolBarManager2();
209
        }
211
        }
210
212
211
        /* (non-Javadoc)
213
        /* (non-Javadoc)
Lines 217-222 Link Here
217
            }
219
            }
218
            window.registerGlobalAction(action);
220
            window.registerGlobalAction(action);
219
        }
221
        }
222
223
		private ActionBarPresentation getActionBarPresentation() {
224
			WorkbenchWindow window = (WorkbenchWindow)getWindowConfigurer().getWindow();
225
			return window.getActionBarPresentation();
226
		}
227
228
		/* (non-Javadoc)
229
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarManager(int)
230
		 */
231
		public IToolBarManager createToolBarManager(int style) {
232
			return getActionBarPresentation().createToolBarManager();
233
		}
234
235
		/* (non-Javadoc)
236
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
237
		 */
238
		public IContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
239
			return getActionBarPresentation().createToolBarContributionItem(toolBarManager, id);
240
		}
220
    }
241
    }
221
242
222
    /**
243
    /**
Lines 588-594 Link Here
588
     * @see org.eclipse.ui.application.IWorkbenchWindowConfigurer
609
     * @see org.eclipse.ui.application.IWorkbenchWindowConfigurer
589
     */
610
     */
590
    public Control createCoolBarControl(Composite parent) {
611
    public Control createCoolBarControl(Composite parent) {
591
        return window.getCoolBarManager().createControl(parent);
612
        return actionBarConfigurer.getActionBarPresentation().createCoolBarControl(
613
        		window.getCoolBarManager2(), parent);
592
    }
614
    }
593
615
594
    /* (non-Javadoc)
616
    /* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java (-38 / +113 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 36-47 Link Here
36
import org.eclipse.jface.action.IAction;
36
import org.eclipse.jface.action.IAction;
37
import org.eclipse.jface.action.IContributionItem;
37
import org.eclipse.jface.action.IContributionItem;
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.IMenuManager;
40
import org.eclipse.jface.action.IMenuManager;
41
import org.eclipse.jface.action.IToolBarContributionItem;
42
import org.eclipse.jface.action.IToolBarManager2;
40
import org.eclipse.jface.action.MenuManager;
43
import org.eclipse.jface.action.MenuManager;
41
import org.eclipse.jface.action.Separator;
44
import org.eclipse.jface.action.Separator;
42
import org.eclipse.jface.action.StatusLineManager;
45
import org.eclipse.jface.action.StatusLineManager;
43
import org.eclipse.jface.action.ToolBarContributionItem;
44
import org.eclipse.jface.action.ToolBarManager;
45
import org.eclipse.jface.commands.ActionHandler;
46
import org.eclipse.jface.commands.ActionHandler;
46
import org.eclipse.jface.operation.IRunnableWithProgress;
47
import org.eclipse.jface.operation.IRunnableWithProgress;
47
import org.eclipse.jface.window.ApplicationWindow;
48
import org.eclipse.jface.window.ApplicationWindow;
Lines 121-126 Link Here
121
import org.eclipse.ui.internal.misc.Policy;
122
import org.eclipse.ui.internal.misc.Policy;
122
import org.eclipse.ui.internal.misc.UIListenerLogging;
123
import org.eclipse.ui.internal.misc.UIListenerLogging;
123
import org.eclipse.ui.internal.misc.UIStats;
124
import org.eclipse.ui.internal.misc.UIStats;
125
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
126
import org.eclipse.ui.internal.presentations.InternalPresentationFactory;
124
import org.eclipse.ui.internal.progress.ProgressRegion;
127
import org.eclipse.ui.internal.progress.ProgressRegion;
125
import org.eclipse.ui.internal.registry.ActionSetRegistry;
128
import org.eclipse.ui.internal.registry.ActionSetRegistry;
126
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
129
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
Lines 129-134 Link Here
129
import org.eclipse.ui.internal.services.ISourceProviderService;
132
import org.eclipse.ui.internal.services.ISourceProviderService;
130
import org.eclipse.ui.internal.services.ServiceLocator;
133
import org.eclipse.ui.internal.services.ServiceLocator;
131
import org.eclipse.ui.internal.util.PrefUtil;
134
import org.eclipse.ui.internal.util.PrefUtil;
135
import org.eclipse.ui.presentations.AbstractPresentationFactory;
132
136
133
/**
137
/**
134
 * A window within the workbench.
138
 * A window within the workbench.
Lines 322-329 Link Here
322
		addCoolBar(SWT.FLAT);
326
		addCoolBar(SWT.FLAT);
323
		addStatusLine();
327
		addStatusLine();
324
328
325
		actionPresentation = new ActionPresentation(this);
326
327
		// register with the tracker
329
		// register with the tracker
328
		getExtensionTracker()
330
		getExtensionTracker()
329
				.registerHandler(
331
				.registerHandler(
Lines 704-710 Link Here
704
	 * Return whether or not the coolbar layout is locked.
706
	 * Return whether or not the coolbar layout is locked.
705
	 */
707
	 */
706
	protected boolean isCoolBarLocked() {
708
	protected boolean isCoolBarLocked() {
707
		CoolBarManager cbm = getCoolBarManager();
709
        ICoolBarManager cbm = getCoolBarManager2(); 
708
		return cbm != null && cbm.getLockLayout();
710
		return cbm != null && cbm.getLockLayout();
709
	}
711
	}
710
712
Lines 1427-1433 Link Here
1427
		boolean result;
1429
		boolean result;
1428
		try {
1430
		try {
1429
			// Clear the action sets, fix for bug 27416.
1431
			// Clear the action sets, fix for bug 27416.
1430
			actionPresentation.clearActionSets();
1432
            getActionPresentation().clearActionSets();
1431
1433
1432
			// Remove the handler submissions. Bug 64024.
1434
			// Remove the handler submissions. Bug 64024.
1433
			final IWorkbench workbench = getWorkbench();
1435
			final IWorkbench workbench = getWorkbench();
Lines 1492-1498 Link Here
1492
	 */
1494
	 */
1493
	/* package */
1495
	/* package */
1494
	void lockCoolBar(boolean lock) {
1496
	void lockCoolBar(boolean lock) {
1495
		getCoolBarManager().setLockLayout(lock);
1497
        getCoolBarManager2().setLockLayout(lock);
1496
	}
1498
	}
1497
1499
1498
	/**
1500
	/**
Lines 1658-1665 Link Here
1658
		// This needs to be done before pages are created to ensure proper
1660
		// This needs to be done before pages are created to ensure proper
1659
		// canonical creation
1661
		// canonical creation
1660
		// of cool items
1662
		// of cool items
1661
		if (getCoolBarManager() != null) {
1663
		ICoolBarManager coolBarMgr = getCoolBarManager2();
1662
			CoolBarManager coolBarMgr = getCoolBarManager();
1664
        if (coolBarMgr != null) {
1663
			IMemento coolBarMem = memento
1665
			IMemento coolBarMem = memento
1664
					.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
1666
					.getChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
1665
			if (coolBarMem != null) {
1667
			if (coolBarMem != null) {
Lines 1727-1738 Link Here
1727
							if (oldItem != null) {
1729
							if (oldItem != null) {
1728
								newItem = oldItem;
1730
								newItem = oldItem;
1729
							} else {
1731
							} else {
1730
								newItem = new ToolBarContributionItem(
1732
								ActionBarPresentation actionBarPresentation = getActionBarPresentation();
1731
										new ToolBarManager(coolBarMgr
1733
								newItem = actionBarPresentation.createToolBarContributionItem(
1732
												.getStyle()), id);
1734
										actionBarPresentation.createToolBarManager(), id);
1733
								if (type
1735
								if (type
1734
										.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1736
										.equals(IWorkbenchConstants.TAG_TYPE_PLACEHOLDER)) {
1735
									ToolBarContributionItem newToolBarItem = (ToolBarContributionItem) newItem;
1737
									IToolBarContributionItem newToolBarItem = (IToolBarContributionItem) newItem;
1736
									if (height != null) {
1738
									if (height != null) {
1737
										newToolBarItem.setCurrentHeight(height
1739
										newToolBarItem.setCurrentHeight(height
1738
												.intValue());
1740
												.intValue());
Lines 1760-1772 Link Here
1760
							}
1762
							}
1761
							// Set the current height and width
1763
							// Set the current height and width
1762
							if ((width != null)
1764
							if ((width != null)
1763
									&& (newItem instanceof ToolBarContributionItem)) {
1765
									&& (newItem instanceof IToolBarContributionItem)) {
1764
								((ToolBarContributionItem) newItem)
1766
								((IToolBarContributionItem) newItem)
1765
										.setCurrentWidth(width.intValue());
1767
										.setCurrentWidth(width.intValue());
1766
							}
1768
							}
1767
							if ((height != null)
1769
							if ((height != null)
1768
									&& (newItem instanceof ToolBarContributionItem)) {
1770
									&& (newItem instanceof IToolBarContributionItem)) {
1769
								((ToolBarContributionItem) newItem)
1771
								((IToolBarContributionItem) newItem)
1770
										.setCurrentHeight(height.intValue());
1772
										.setCurrentHeight(height.intValue());
1771
							}
1773
							}
1772
						}
1774
						}
Lines 1951-1957 Link Here
1951
		if (coolbarMem == null) {
1953
		if (coolbarMem == null) {
1952
			return false;
1954
			return false;
1953
		}
1955
		}
1954
		CoolBarManager coolBarMgr = getCoolBarManager();
1956
        ICoolBarManager coolBarMgr = getCoolBarManager2();
1955
		// Check to see if layout is locked
1957
		// Check to see if layout is locked
1956
		Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
1958
		Integer locked = coolbarMem.getInteger(IWorkbenchConstants.TAG_LOCKED);
1957
		boolean state = (locked != null) && (locked.intValue() == 1);
1959
		boolean state = (locked != null) && (locked.intValue() == 1);
Lines 2043-2053 Link Here
2043
				}
2045
				}
2044
				// If a tool bar contribution item already exists for this id
2046
				// If a tool bar contribution item already exists for this id
2045
				// then use the old object
2047
				// then use the old object
2046
				if (oldItem instanceof ToolBarContributionItem) {
2048
				if (oldItem instanceof IToolBarContributionItem) {
2047
					newItem = oldItem;
2049
					newItem = oldItem;
2048
				} else {
2050
				} else {
2049
					newItem = new ToolBarContributionItem(new ToolBarManager(
2051
					ActionBarPresentation actionBarPresentaiton = getActionBarPresentation();
2050
							coolBarMgr.getStyle()), id);
2052
					newItem = actionBarPresentaiton.createToolBarContributionItem(
2053
									actionBarPresentaiton.createToolBarManager(), id);
2051
					// make it invisible by default
2054
					// make it invisible by default
2052
					newItem.setVisible(false);
2055
					newItem.setVisible(false);
2053
					// Need to add the item to the cool bar manager so that its
2056
					// Need to add the item to the cool bar manager so that its
Lines 2283-2298 Link Here
2283
		}
2286
		}
2284
2287
2285
		// / Save the order of the cool bar contribution items
2288
		// / Save the order of the cool bar contribution items
2286
		if (getCoolBarManager() != null) {
2289
        ICoolBarManager coolBarMgr = getCoolBarManager2();
2287
			getCoolBarManager().refresh();
2290
        if (coolBarMgr != null) {
2291
        	coolBarMgr.refresh();
2288
			IMemento coolBarMem = memento
2292
			IMemento coolBarMem = memento
2289
					.createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
2293
					.createChild(IWorkbenchConstants.TAG_COOLBAR_LAYOUT);
2290
			if (getCoolBarManager().getLockLayout() == true) {
2294
            if (coolBarMgr.getLockLayout() == true) {
2291
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 1);
2295
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 1);
2292
			} else {
2296
			} else {
2293
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 0);
2297
				coolBarMem.putInteger(IWorkbenchConstants.TAG_LOCKED, 0);
2294
			}
2298
			}
2295
			IContributionItem[] items = getCoolBarManager().getItems();
2299
            IContributionItem[] items = coolBarMgr.getItems();
2296
			for (int i = 0; i < items.length; i++) {
2300
			for (int i = 0; i < items.length; i++) {
2297
				IMemento coolItemMem = coolBarMem
2301
				IMemento coolItemMem = coolBarMem
2298
						.createChild(IWorkbenchConstants.TAG_COOLITEM);
2302
						.createChild(IWorkbenchConstants.TAG_COOLITEM);
Lines 2328-2335 Link Here
2328
					 */
2332
					 */
2329
					final int height;
2333
					final int height;
2330
					final int width;
2334
					final int width;
2331
					if (item instanceof ToolBarContributionItem) {
2335
					if (item instanceof IToolBarContributionItem) {
2332
						ToolBarContributionItem toolBarItem = (ToolBarContributionItem) item;
2336
						IToolBarContributionItem toolBarItem = (IToolBarContributionItem) item;
2333
						toolBarItem.saveWidgetState();
2337
						toolBarItem.saveWidgetState();
2334
						height = toolBarItem.getCurrentHeight();
2338
						height = toolBarItem.getCurrentHeight();
2335
						width = toolBarItem.getCurrentWidth();
2339
						width = toolBarItem.getCurrentWidth();
Lines 2635-2641 Link Here
2635
		}
2639
		}
2636
		// updateAll required in order to enable accelerators on pull-down menus
2640
		// updateAll required in order to enable accelerators on pull-down menus
2637
		getMenuBarManager().updateAll(false);
2641
		getMenuBarManager().updateAll(false);
2638
		getCoolBarManager().update(false);
2642
        getCoolBarManager2().update(false);
2639
		getStatusLineManager().update(false);
2643
		getStatusLineManager().update(false);
2640
	}
2644
	}
2641
2645
Lines 2699-2710 Link Here
2699
2703
2700
		WorkbenchPage currentPage = getActiveWorkbenchPage();
2704
		WorkbenchPage currentPage = getActiveWorkbenchPage();
2701
		if (currentPage == null)
2705
		if (currentPage == null)
2702
			actionPresentation.clearActionSets();
2706
			getActionPresentation().clearActionSets();
2703
		else {
2707
		else {
2704
			if (getCoolBarManager() != null) {
2708
			if (getCoolBarManager2() != null) {
2705
				getCoolBarManager().refresh();
2709
				getCoolBarManager2().refresh();
2706
			}
2710
			}
2707
			actionPresentation.setActionSets(currentPage.getActionSets());
2711
			getActionPresentation().setActionSets(currentPage.getActionSets());
2708
		}
2712
		}
2709
		fireActionSetsChanged();
2713
		fireActionSetsChanged();
2710
		updateActionBars();
2714
		updateActionBars();
Lines 3211-3221 Link Here
3211
				.getPerspectiveBar();
3215
				.getPerspectiveBar();
3212
	}
3216
	}
3213
3217
3214
	// for dynamic UI
3218
    /**
3215
	public ActionPresentation getActionPresentation() {
3219
     * Returns the action presentation for dynamic UI
3216
		return actionPresentation;
3220
     * @return action presentation
3217
	}
3221
     */
3218
3222
    public ActionPresentation getActionPresentation() {
3223
        if (actionPresentation == null) {
3224
        	actionPresentation = new ActionPresentation(this);
3225
        }
3226
        return actionPresentation;
3227
    }
3228
    
3229
    /*package*/ ActionBarPresentation getActionBarPresentation() {
3230
    	// allow replacement of the actionbar presentation
3231
    	ActionBarPresentation actionBarPresentation;        	
3232
    	AbstractPresentationFactory presentationFactory = 
3233
    		getWindowConfigurer().getPresentationFactory();
3234
    	if (presentationFactory instanceof InternalPresentationFactory) {
3235
        	actionBarPresentation = ((InternalPresentationFactory) presentationFactory)
3236
					.createActionBarPresentation(this);
3237
    	}
3238
    	else 
3239
    		actionBarPresentation = new ActionBarPresentation();      
3240
    	
3241
    	return actionBarPresentation;        	
3242
    }
3243
    
3219
	/*
3244
	/*
3220
	 * (non-Javadoc)
3245
	 * (non-Javadoc)
3221
	 * 
3246
	 * 
Lines 3226-3231 Link Here
3226
	}
3251
	}
3227
3252
3228
	/**
3253
	/**
3254
     * Returns a new cool bar manager for the window.
3255
     * <p>
3256
     * Subclasses may override this method to customize the cool bar manager.
3257
     * </p>
3258
     * 
3259
     * @return a cool bar manager
3260
	 * @since 3.2
3261
     */
3262
    protected ICoolBarManager createCoolBarManager2(int style) {
3263
        return getActionBarPresentation().createCoolBarManager(style);
3264
    }
3265
    
3266
    /**
3267
     * Creates the control for the cool bar manager.
3268
     * <p>
3269
     * Subclasses may override this method to customize the cool bar manager.
3270
     * </p>
3271
     * 
3272
     * @return an instance of <code>CoolBar</code>\
3273
	 * @since 3.2
3274
     */
3275
    protected Control createCoolBarControl(Composite parent) {
3276
        return getActionBarPresentation().createCoolBarControl(getCoolBarManager2(), parent);
3277
    }
3278
3279
    /**
3280
     * Returns a new tool bar manager for the window.
3281
     * <p>
3282
     * Subclasses may override this method to customize the tool bar manager.
3283
     * </p>
3284
     * @return a tool bar manager
3285
	 * @since 3.2
3286
     */
3287
    protected IToolBarManager2 createToolBarManager2(int style) {
3288
        return getActionBarPresentation().createToolBarManager();
3289
    }
3290
3291
    /**
3292
     * Creates the control for the tool bar manager.
3293
     * <p>
3294
     * Subclasses may override this method to customize the tool bar manager.
3295
     * </p>
3296
     * @return a Control
3297
	 * @since 3.2
3298
     */
3299
    protected Control createToolBarControl(Composite parent) {
3300
        return getActionBarPresentation().createToolBarControl(getToolBarManager2(), parent);
3301
    }
3302
    
3303
    /**
3229
	 * Delegate to the presentation factory.
3304
	 * Delegate to the presentation factory.
3230
	 * 
3305
	 * 
3231
	 * @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager
3306
	 * @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager
(-)Eclipse UI/org/eclipse/ui/internal/PluginActionSetBuilder.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 375-381 Link Here
375
            }
375
            }
376
376
377
            PluginAction action = ad.getAction();
377
            PluginAction action = ad.getAction();
378
            PluginActionCoolBarContributionItem actionContribution = new PluginActionCoolBarContributionItem(
378
            ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
379
                    action);
379
                    action);
380
380
381
            bars.addAdjunctContribution(actionContribution);
381
            bars.addAdjunctContribution(actionContribution);
Lines 430-436 Link Here
430
430
431
            // Create the action
431
            // Create the action
432
            PluginAction action = ad.getAction();
432
            PluginAction action = ad.getAction();
433
            PluginActionCoolBarContributionItem actionContribution = new PluginActionCoolBarContributionItem(
433
            ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
434
                    action);
434
                    action);
435
435
436
            // retreive the toolbar from the action bars.
436
            // retreive the toolbar from the action bars.
Lines 562-568 Link Here
562
            //			if (menuMgr != null) 
562
            //			if (menuMgr != null) 
563
            //				revokeActionSetFromMenu(menuMgr, id);
563
            //				revokeActionSetFromMenu(menuMgr, id);
564
564
565
            revokeActionSetFromCoolbar(window.getCoolBarManager(), id);
565
            revokeActionSetFromCoolbar(window.getCoolBarManager2(), id);
566
            //			IToolBarManager toolBarMgr = bars.getToolBarManager();
566
            //			IToolBarManager toolBarMgr = bars.getToolBarManager();
567
            //			if (toolBarMgr != null && toolBarMgr instanceof CoolItemToolBarManager) 
567
            //			if (toolBarMgr != null && toolBarMgr instanceof CoolItemToolBarManager) 
568
            //				revokeActionSetFromToolbar(toolBarMgr, id);
568
            //				revokeActionSetFromToolbar(toolBarMgr, id);
(-)Eclipse UI/org/eclipse/ui/internal/WWinActionBars.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 41-47 Link Here
41
     * 
41
     * 
42
     */
42
     */
43
    public ICoolBarManager getCoolBarManager() {
43
    public ICoolBarManager getCoolBarManager() {
44
        return window.getCoolBarManager();
44
        return window.getCoolBarManager2();
45
    }
45
    }
46
46
47
    /**
47
    /**
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-7 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 37-43 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.CoolBarManager;
40
import org.eclipse.jface.action.ICoolBarManager;
41
import org.eclipse.jface.dialogs.ErrorDialog;
41
import org.eclipse.jface.dialogs.ErrorDialog;
42
import org.eclipse.jface.dialogs.IDialogConstants;
42
import org.eclipse.jface.dialogs.IDialogConstants;
43
import org.eclipse.jface.dialogs.MessageDialog;
43
import org.eclipse.jface.dialogs.MessageDialog;
Lines 2539-2545 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
        CoolBarManager mgr = window.getCoolBarManager();
2542
        ICoolBarManager mgr = window.getCoolBarManager2();
2543
        try {
2543
        try {
2544
            mgr.getControl().setRedraw(false);
2544
            mgr.getControl().setRedraw(false);
2545
            BusyIndicator.showWhile(null, new Runnable() {
2545
            BusyIndicator.showWhile(null, new Runnable() {
Lines 3148-3156 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
        CoolBarManager mgr = window.getCoolBarManager();
3151
        ICoolBarManager mgr = window.getCoolBarManager2();
3152
        try {
3152
        try {
3153
            mgr.getControl().setRedraw(false);
3153
            mgr.getControl2().setRedraw(false);
3154
            getClientComposite().setRedraw(false);
3154
            getClientComposite().setRedraw(false);
3155
            // Run op in busy cursor.
3155
            // Run op in busy cursor.
3156
            BusyIndicator.showWhile(null, new Runnable() {
3156
            BusyIndicator.showWhile(null, new Runnable() {
Lines 3160-3166 Link Here
3160
            });
3160
            });
3161
        } finally {
3161
        } finally {
3162
            getClientComposite().setRedraw(true);
3162
            getClientComposite().setRedraw(true);
3163
            mgr.getControl().setRedraw(true);
3163
            mgr.getControl2().setRedraw(true);
3164
            IWorkbenchPart part = getActivePart();
3164
            IWorkbenchPart part = getActivePart();
3165
            if (part != null)
3165
            if (part != null)
3166
                part.setFocus();
3166
                part.setFocus();
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.getCoolBarManager().resetItemOrder();
3183
        window.getCoolBarManager2().resetItemOrder();
3184
    }
3184
    }
3185
3185
3186
    /**
3186
    /**
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-9 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 52-59 Link Here
52
import org.eclipse.swt.widgets.Display;
52
import org.eclipse.swt.widgets.Display;
53
import org.eclipse.swt.widgets.Shell;
53
import org.eclipse.swt.widgets.Shell;
54
import org.eclipse.ui.ActiveShellExpression;
54
import org.eclipse.ui.ActiveShellExpression;
55
import org.eclipse.ui.ISaveableModel;
56
import org.eclipse.ui.ISaveableModelSource;
57
import org.eclipse.ui.IEditorActionBarContributor;
55
import org.eclipse.ui.IEditorActionBarContributor;
58
import org.eclipse.ui.IEditorDescriptor;
56
import org.eclipse.ui.IEditorDescriptor;
59
import org.eclipse.ui.IEditorInput;
57
import org.eclipse.ui.IEditorInput;
Lines 67-72 Link Here
67
import org.eclipse.ui.IPathEditorInput;
65
import org.eclipse.ui.IPathEditorInput;
68
import org.eclipse.ui.IPersistableElement;
66
import org.eclipse.ui.IPersistableElement;
69
import org.eclipse.ui.IReusableEditor;
67
import org.eclipse.ui.IReusableEditor;
68
import org.eclipse.ui.ISaveableModel;
69
import org.eclipse.ui.ISaveableModelSource;
70
import org.eclipse.ui.ISaveablePart;
70
import org.eclipse.ui.ISaveablePart;
71
import org.eclipse.ui.ISaveablePart2;
71
import org.eclipse.ui.ISaveablePart2;
72
import org.eclipse.ui.IViewPart;
72
import org.eclipse.ui.IViewPart;
Lines 296-303 Link Here
296
		}
296
		}
297
297
298
		// Create a new action bar set.
298
		// Create a new action bar set.
299
		actionBars = new EditorActionBars(
299
		actionBars = new EditorActionBars(page, site, type);
300
				(WWinActionBars) page.getActionBars(), site, type);
301
		actionBars.addRef();
300
		actionBars.addRef();
302
		actionCache.put(type, actionBars);
301
		actionCache.put(type, actionBars);
303
302
Lines 329-336 Link Here
329
328
330
		// Create a new action bar set.
329
		// Create a new action bar set.
331
		// Note: It is an empty set.
330
		// Note: It is an empty set.
332
		EditorActionBars actionBars = new EditorActionBars(
331
		EditorActionBars actionBars = new EditorActionBars(page, site, type);
333
				(WWinActionBars) page.getActionBars(), site, type);
334
		actionBars.addRef();
332
		actionBars.addRef();
335
		actionCache.put(type, actionBars);
333
		actionCache.put(type, actionBars);
336
334
Lines 347-354 Link Here
347
			String type = actionBars.getEditorType();
345
			String type = actionBars.getEditorType();
348
			actionCache.remove(type);
346
			actionCache.remove(type);
349
			// refresh the cool bar manager before disposing of a cool item
347
			// refresh the cool bar manager before disposing of a cool item
350
			if (window.getCoolBarManager() != null) {
348
            if (window.getCoolBarManager2() != null) {
351
				window.getCoolBarManager().refresh();
349
                window.getCoolBarManager2().refresh();
352
			}
350
			}
353
			actionBars.dispose();
351
			actionBars.dispose();
354
		}
352
		}
(-)Eclipse UI/org/eclipse/ui/internal/PlaceholderContributionItem.java (-25 / +26 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 13-20 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.ToolBarContributionItem;
16
import org.eclipse.jface.action.IToolBarContributionItem;
17
import org.eclipse.jface.action.ToolBarManager;
18
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.CoolBar;
18
import org.eclipse.swt.widgets.CoolBar;
20
import org.eclipse.swt.widgets.Menu;
19
import org.eclipse.swt.widgets.Menu;
Lines 65-71 Link Here
65
     * @param item
64
     * @param item
66
     *            The item to be replaced; must not be <code>null</code>.
65
     *            The item to be replaced; must not be <code>null</code>.
67
     */
66
     */
68
    PlaceholderContributionItem(final ToolBarContributionItem item) {
67
    PlaceholderContributionItem(final IToolBarContributionItem item) {
69
        item.saveWidgetState();
68
        item.saveWidgetState();
70
        id = item.getId();
69
        id = item.getId();
71
        storedHeight = item.getCurrentHeight();
70
        storedHeight = item.getCurrentHeight();
Lines 74-100 Link Here
74
        storedUseChevron = item.getUseChevron();
73
        storedUseChevron = item.getUseChevron();
75
    }
74
    }
76
75
77
    /**
78
     * Creates a new tool bar contribution item on the given manager -- using
79
     * the stored data to initialize some of its properties.
80
     * 
81
     * @param manager
82
     *            The manager for which the contribution item should be
83
     *            created; must not be <code>null</code>
84
     * @return A new tool bar contribution item equivalent to the contribution
85
     *         item this placeholder was intended to replace; never <code>null</code>.
86
     */
87
    ToolBarContributionItem createToolBarContributionItem(
88
            final ToolBarManager manager) {
89
        ToolBarContributionItem toolBarContributionItem = new ToolBarContributionItem(
90
                manager, id);
91
        toolBarContributionItem.setCurrentHeight(storedHeight);
92
        toolBarContributionItem.setCurrentWidth(storedWidth);
93
        toolBarContributionItem.setMinimumItemsToShow(storedMinimumItems);
94
        toolBarContributionItem.setUseChevron(storedUseChevron);
95
        return toolBarContributionItem;
96
    }
97
98
    /*
76
    /*
99
     * (non-Javadoc)
77
     * (non-Javadoc)
100
     * 
78
     * 
Lines 172-177 Link Here
172
    int getWidth() {
150
    int getWidth() {
173
        return storedWidth;
151
        return storedWidth;
174
    }
152
    }
153
    
154
    /**
155
     * Returns the minimum number of tool items to show in the cool item.
156
     * 
157
     * @return the minimum number of tool items to show, or <code>SHOW_ALL_ITEMS</code>
158
     *         if a value was not set
159
     * @see #setMinimumItemsToShow(int)
160
	 * @since 3.2
161
     */
162
    int getMinimumItemsToShow() {
163
    	return storedMinimumItems;
164
    }
165
    
166
    /**
167
     * Returns whether chevron support is enabled.
168
     * 
169
     * @return <code>true</code> if chevron support is enabled, <code>false</code>
170
     *         otherwise
171
	 * @since 3.2
172
     */
173
    boolean getUseChevron() {
174
        return storedUseChevron;
175
    }
175
176
176
    /*
177
    /*
177
     * (non-Javadoc)
178
     * (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/internal/EditorActionBars.java (-19 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 18-30 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;
21
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.action.SubContributionManager;
23
import org.eclipse.jface.action.SubContributionManager;
23
import org.eclipse.jface.action.SubMenuManager;
24
import org.eclipse.jface.action.SubMenuManager;
24
import org.eclipse.jface.action.SubStatusLineManager;
25
import org.eclipse.jface.action.SubStatusLineManager;
25
import org.eclipse.jface.action.SubToolBarManager;
26
import org.eclipse.jface.action.SubToolBarManager;
26
import org.eclipse.jface.action.ToolBarContributionItem;
27
import org.eclipse.jface.action.ToolBarManager;
28
import org.eclipse.ui.IActionBars2;
27
import org.eclipse.ui.IActionBars2;
29
import org.eclipse.ui.IEditorActionBarContributor;
28
import org.eclipse.ui.IEditorActionBarContributor;
30
import org.eclipse.ui.IEditorPart;
29
import org.eclipse.ui.IEditorPart;
Lines 33-38 Link Here
33
import org.eclipse.ui.SubActionBars2;
32
import org.eclipse.ui.SubActionBars2;
34
import org.eclipse.ui.actions.RetargetAction;
33
import org.eclipse.ui.actions.RetargetAction;
35
import org.eclipse.ui.internal.misc.Policy;
34
import org.eclipse.ui.internal.misc.Policy;
35
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
36
import org.eclipse.ui.services.IServiceLocator;
36
import org.eclipse.ui.services.IServiceLocator;
37
37
38
/**
38
/**
Lines 82-98 Link Here
82
82
83
	private int refCount;
83
	private int refCount;
84
84
85
	private ToolBarContributionItem toolBarContributionItem = null;
85
	private IToolBarContributionItem toolBarContributionItem = null;
86
86
87
	private String type;
87
	private String type;
88
	
89
	private ActionBarPresentation actionBarPresentation;
88
90
89
	/**
91
	/**
90
	 * Constructs the EditorActionBars for an editor.
92
	 * Constructs the EditorActionBars for an editor.
91
	 */
93
	 */
92
	public EditorActionBars(IActionBars2 parent,
94
	public EditorActionBars(WorkbenchPage page,
93
			final IServiceLocator serviceLocator, String type) {
95
			final IServiceLocator serviceLocator, String type) {
94
		super(parent, serviceLocator);
96
		super((IActionBars2)page.getActionBars(), serviceLocator);
95
		this.type = type;
97
		this.type = type;
98
		this.actionBarPresentation = ((WorkbenchWindow) page
99
				.getWorkbenchWindow()).getActionBarPresentation();
96
	}
100
	}
97
101
98
	/**
102
	/**
Lines 243-256 Link Here
243
		}
247
		}
244
		if (toolBarContributionItem == null) {
248
		if (toolBarContributionItem == null) {
245
			IContributionItem foundItem = coolBarManager.find(type);
249
			IContributionItem foundItem = coolBarManager.find(type);
246
			if ((foundItem instanceof ToolBarContributionItem)) {
250
			if ((foundItem instanceof IToolBarContributionItem)) {
247
				toolBarContributionItem = (ToolBarContributionItem) foundItem;
251
				toolBarContributionItem = (IToolBarContributionItem) foundItem;
248
				coolItemToolBarMgr = toolBarContributionItem
252
				coolItemToolBarMgr = toolBarContributionItem.getToolBarManager();
249
						.getToolBarManager();
250
				if (coolItemToolBarMgr == null) {
253
				if (coolItemToolBarMgr == null) {
251
					coolItemToolBarMgr = new ToolBarManager(coolBarManager
254
					coolItemToolBarMgr = actionBarPresentation.createToolBarManager();
252
							.getStyle());
255
					toolBarContributionItem = actionBarPresentation.createToolBarContributionItem(
253
					toolBarContributionItem = new ToolBarContributionItem(
254
							coolItemToolBarMgr, type);
256
							coolItemToolBarMgr, type);
255
					// Add editor item to group
257
					// Add editor item to group
256
					coolBarManager.prependToGroup(
258
					coolBarManager.prependToGroup(
Lines 258-275 Link Here
258
							toolBarContributionItem);
260
							toolBarContributionItem);
259
				}
261
				}
260
			} else {
262
			} else {
261
				coolItemToolBarMgr = new ToolBarManager(coolBarManager
263
				coolItemToolBarMgr = actionBarPresentation.createToolBarManager();
262
						.getStyle());
263
				if ((coolBarManager instanceof ContributionManager)
264
				if ((coolBarManager instanceof ContributionManager)
264
						&& (foundItem instanceof PlaceholderContributionItem)) {
265
						&& (foundItem instanceof PlaceholderContributionItem)) {
265
					PlaceholderContributionItem placeholder = (PlaceholderContributionItem) foundItem;
266
					PlaceholderContributionItem placeholder = (PlaceholderContributionItem) foundItem;
266
					toolBarContributionItem = placeholder
267
					toolBarContributionItem = createToolBarContributionItem(coolItemToolBarMgr, placeholder);
267
							.createToolBarContributionItem((ToolBarManager) coolItemToolBarMgr);
268
					// Restore from a placeholder
268
					// Restore from a placeholder
269
					((ContributionManager) coolBarManager).replaceItem(type,
269
					((ContributionManager) coolBarManager).replaceItem(type,
270
							toolBarContributionItem);
270
							toolBarContributionItem);
271
				} else {
271
				} else {
272
					toolBarContributionItem = new ToolBarContributionItem(
272
					toolBarContributionItem = actionBarPresentation.createToolBarContributionItem(
273
							coolItemToolBarMgr, type);
273
							coolItemToolBarMgr, type);
274
					// Add editor item to group
274
					// Add editor item to group
275
					coolBarManager.prependToGroup(
275
					coolBarManager.prependToGroup(
Lines 277-289 Link Here
277
							toolBarContributionItem);
277
							toolBarContributionItem);
278
				}
278
				}
279
			}
279
			}
280
			((ToolBarManager) coolItemToolBarMgr).setOverrides(new Overrides());
280
			((ContributionManager)coolItemToolBarMgr).setOverrides(new Overrides());
281
			toolBarContributionItem.setVisible(getActive());
281
			toolBarContributionItem.setVisible(getActive());
282
			coolItemToolBarMgr.markDirty();
282
			coolItemToolBarMgr.markDirty();
283
		}
283
		}
284
284
285
		return coolItemToolBarMgr;
285
		return coolItemToolBarMgr;
286
	}
286
	}
287
	
288
    /*
289
     * Creates a new tool bar contribution item on the given manager -- using
290
     * the stored data to initialize some of its properties.
291
     */
292
    IToolBarContributionItem createToolBarContributionItem(
293
			final IToolBarManager manager, PlaceholderContributionItem item) {
294
		IToolBarContributionItem toolBarContributionItem = actionBarPresentation
295
				.createToolBarContributionItem(manager, item.getId());
296
		toolBarContributionItem.setCurrentHeight(item.getHeight());
297
		toolBarContributionItem.setCurrentWidth(item.getWidth());
298
		toolBarContributionItem.setMinimumItemsToShow(item.getMinimumItemsToShow());
299
		toolBarContributionItem.setUseChevron(item.getUseChevron());
300
		return toolBarContributionItem;
301
	}
287
302
288
	/**
303
	/**
289
	 * Returns whether the contribution list is visible. If the visibility is
304
	 * Returns whether the contribution list is visible. If the visibility is
(-)Eclipse UI/org/eclipse/ui/internal/ActionSetActionBars.java (-20 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 18-37 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;
21
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.action.IToolBarManager;
22
import org.eclipse.jface.action.SubMenuManager;
23
import org.eclipse.jface.action.SubMenuManager;
23
import org.eclipse.jface.action.SubToolBarManager;
24
import org.eclipse.jface.action.SubToolBarManager;
24
import org.eclipse.jface.action.ToolBarContributionItem;
25
import org.eclipse.jface.action.ToolBarManager;
26
import org.eclipse.ui.IActionBars2;
25
import org.eclipse.ui.IActionBars2;
27
import org.eclipse.ui.IWorkbenchActionConstants;
26
import org.eclipse.ui.IWorkbenchActionConstants;
28
import org.eclipse.ui.SubActionBars2;
27
import org.eclipse.ui.SubActionBars2;
29
import org.eclipse.ui.services.IServiceLocator;
28
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
30
29
31
/**
30
/**
32
 * This class represents the action bars for an action set.
31
 * This class represents the action bars for an action set.
33
 */
32
 */
34
public class ActionSetActionBars extends SubActionBars2 {
33
public class ActionSetActionBars extends SubActionBars2 {
34
	
35
	private ActionBarPresentation actionBarPresentation = null;
35
36
36
	private String actionSetId;
37
	private String actionSetId;
37
38
Lines 39-54 Link Here
39
40
40
	private IToolBarManager coolItemToolBarMgr = null;
41
	private IToolBarManager coolItemToolBarMgr = null;
41
42
42
	private ToolBarContributionItem toolBarContributionItem = null;
43
	private IToolBarContributionItem toolBarContributionItem = null;
43
44
44
	/**
45
	/**
45
	 * Constructs a new action bars object
46
     * Constructs a new action bars object
46
	 */
47
     */
47
	public ActionSetActionBars(IActionBars2 parent,
48
    public ActionSetActionBars(IActionBars2 parent, String actionSetId, WorkbenchWindow window) {
48
			final IServiceLocator serviceLocator, String actionSetId) {
49
    	super(parent, window);
49
		super(parent, serviceLocator);
50
		this.actionSetId = actionSetId;		
50
		this.actionSetId = actionSetId;
51
        this.actionBarPresentation = window.getActionBarPresentation();
51
	}
52
    }
52
53
53
	/**
54
	/**
54
	 * Adds to the list all the actions that are part of this action set but
55
	 * Adds to the list all the actions that are part of this action set but
Lines 107-113 Link Here
107
		for (int i = 0; i < adjunctContributions.size(); i++) {
108
		for (int i = 0; i < adjunctContributions.size(); i++) {
108
			ContributionItem item = (ContributionItem) adjunctContributions
109
			ContributionItem item = (ContributionItem) adjunctContributions
109
					.get(i);
110
					.get(i);
110
			ToolBarManager parent = (ToolBarManager) item.getParent();
111
			IContributionManager parent = item.getParent();
111
			if (parent != null) {
112
			if (parent != null) {
112
				parent.remove(item);
113
				parent.remove(item);
113
				item.dispose();
114
				item.dispose();
Lines 181-187 Link Here
181
		if (coolBarManager == null) {
182
		if (coolBarManager == null) {
182
			return null;
183
			return null;
183
		}
184
		}
184
		return new ToolBarManager(coolBarManager.getStyle());
185
        return actionBarPresentation.createToolBarManager();
185
	}
186
	}
186
187
187
	/**
188
	/**
Lines 221-229 Link Here
221
		// tool bar
222
		// tool bar
222
		// id then create one. Otherwise retrieve the tool bar contribution
223
		// id then create one. Otherwise retrieve the tool bar contribution
223
		// item
224
		// item
224
		if (cbItem instanceof ToolBarContributionItem) {
225
		if (cbItem instanceof IToolBarContributionItem) {
225
226
226
			ToolBarContributionItem tbcbItem = (ToolBarContributionItem) cbItem;
227
			IToolBarContributionItem tbcbItem = (IToolBarContributionItem) cbItem;
227
			coolItemToolBarMgr = tbcbItem.getToolBarManager();
228
			coolItemToolBarMgr = tbcbItem.getToolBarManager();
228
			// If this not an adjuct type then we can cashe the tool bar
229
			// If this not an adjuct type then we can cashe the tool bar
229
			// contribution type
230
			// contribution type
Lines 231-245 Link Here
231
				toolBarContributionItem = tbcbItem;
232
				toolBarContributionItem = tbcbItem;
232
			}
233
			}
233
		} else {
234
		} else {
234
235
			
235
			coolItemToolBarMgr = new ToolBarManager(coolBarManager.getStyle());
236
			coolItemToolBarMgr = actionBarPresentation.createToolBarManager();
237
           
236
			// If this is not an adjunct type then create a tool bar
238
			// If this is not an adjunct type then create a tool bar
237
			// contribution item
239
			// contribution item
238
			// we don't create one for an adjunct type because another action
240
			// we don't create one for an adjunct type because another action
239
			// set action bars contains one
241
			// set action bars contains one
242
            
243
            IContributionItem toolBarContributionItem = actionBarPresentation
244
					.createToolBarContributionItem(coolItemToolBarMgr,
245
							toolBarId);
240
246
241
			toolBarContributionItem = new ToolBarContributionItem(
242
					coolItemToolBarMgr, toolBarId);
243
			toolBarContributionItem.setParent(coolItemToolBarMgr);
247
			toolBarContributionItem.setParent(coolItemToolBarMgr);
244
			toolBarContributionItem.setVisible(getActive());
248
			toolBarContributionItem.setVisible(getActive());
245
			coolItemToolBarMgr.markDirty();
249
			coolItemToolBarMgr.markDirty();
(-)Eclipse UI/org/eclipse/ui/internal/ActionPresentation.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 146-152 Link Here
146
                    } else {
146
                    } else {
147
                        IActionSet set = desc.createActionSet();
147
                        IActionSet set = desc.createActionSet();
148
                        SubActionBars bars = new ActionSetActionBars(window
148
                        SubActionBars bars = new ActionSetActionBars(window
149
                                .getActionBars(), window, desc.getId());
149
                                .getActionBars(), desc.getId(), window);
150
                        rec = new SetRec(desc, set, bars);
150
                        rec = new SetRec(desc, set, bars);
151
                        set.init(window, bars);
151
                        set.init(window, bars);
152
                        sets.add(set);
152
                        sets.add(set);
(-)Eclipse UI/org/eclipse/ui/internal/ViewPane.java (-24 / +47 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 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;
16
import org.eclipse.jface.action.MenuManager;
17
import org.eclipse.jface.action.MenuManager;
17
import org.eclipse.jface.action.ToolBarManager;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
18
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.MouseAdapter;
21
import org.eclipse.swt.events.MouseAdapter;
20
import org.eclipse.swt.events.MouseEvent;
22
import org.eclipse.swt.events.MouseEvent;
Lines 28-33 Link Here
28
import org.eclipse.ui.IViewReference;
30
import org.eclipse.ui.IViewReference;
29
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPart;
30
import org.eclipse.ui.internal.dnd.DragUtil;
32
import org.eclipse.ui.internal.dnd.DragUtil;
33
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
31
import org.eclipse.ui.presentations.IPresentablePart;
34
import org.eclipse.ui.presentations.IPresentablePart;
32
import org.eclipse.ui.presentations.StackPresentation;
35
import org.eclipse.ui.presentations.StackPresentation;
33
36
Lines 41-48 Link Here
41
44
42
    // create initially toolbarless bar manager so that actions may be added in the 
45
    // create initially toolbarless bar manager so that actions may be added in the 
43
    // init method of the view.
46
    // init method of the view.
44
    private ToolBarManager isvToolBarMgr = new PaneToolBarManager(SWT.FLAT
47
    private IToolBarManager2 isvToolBarMgr = null;
45
            | SWT.WRAP);
46
48
47
    private MenuManager isvMenuMgr;
49
    private MenuManager isvMenuMgr;
48
50
Lines 56-71 Link Here
56
    /**
58
    /**
57
     * Toolbar manager for the ISV toolbar.
59
     * Toolbar manager for the ISV toolbar.
58
     */
60
     */
59
    class PaneToolBarManager extends ToolBarManager {
61
    private class ISVPropListener implements IPropertyChangeListener {    	
60
        public PaneToolBarManager(int style) {
62
    	private Control toolBar;    	
61
            super(style);
63
    	
62
        }
64
    	/**
63
65
    	 * Constructor
64
        protected void relayout(ToolBar toolBar, int oldCount, int newCount) {
66
    	 * @param toolBar
65
            toolBarResized(toolBar, newCount);
67
    	 */
66
68
    	public ISVPropListener (Control toolBar) {
67
            toolBar.layout();
69
    		this.toolBar = toolBar;
68
        }
70
    	}
71
    	
72
    	/* (non-Javadoc)
73
    	 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
74
    	 */
75
    	public void propertyChange(PropertyChangeEvent event) {    		
76
    		String property = event.getProperty();
77
    		Integer newValue = (Integer)event.getNewValue();
78
	       	if (IToolBarManager2.PROP_LAYOUT.equals(property)) {
79
	       		toolBarResized(toolBar, newValue != null ? newValue.intValue() : 0);	
80
	       		if (toolBar instanceof Composite)
81
	       			((Composite)toolBar).layout();
82
	       		else
83
	       			toolBar.getParent().layout();
84
	       	}
85
	    }
69
    }
86
    }
70
87
71
    /**
88
    /**
Lines 92-97 Link Here
92
     */
109
     */
93
    public ViewPane(IViewReference ref, WorkbenchPage page) {
110
    public ViewPane(IViewReference ref, WorkbenchPage page) {
94
        super(ref, page);
111
        super(ref, page);
112
        ActionBarPresentation actionBarPresentation = ((WorkbenchWindow) page
113
				.getWorkbenchWindow()).getActionBarPresentation();
114
        
115
        isvToolBarMgr = actionBarPresentation.createViewToolBarManager();
95
    }
116
    }
96
117
97
    /**
118
    /**
Lines 123-131 Link Here
123
144
124
    }
145
    }
125
146
126
    private void toolBarResized(ToolBar toolBar, int newSize) {
147
    private void toolBarResized(Control toolBar, int newSize) {
127
        
148
        
128
        Control toolbar = isvToolBarMgr.getControl();
149
        Control toolbar = isvToolBarMgr.getControl2();
129
        if (toolbar != null) {
150
        if (toolbar != null) {
130
            Control ctrl = getControl();
151
            Control ctrl = getControl();
131
152
Lines 146-152 Link Here
146
        
167
        
147
        // ISV toolbar.
168
        // ISV toolbar.
148
        //			// 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom
169
        //			// 1GD0ISU: ITPUI:ALL - Dbl click on view tool cause zoom
149
        final ToolBar isvToolBar = isvToolBarMgr.createControl(parentControl.getParent());
170
        final Control isvToolBar = isvToolBarMgr.createControl2(parentControl.getParent());
171
        
172
        isvToolBarMgr.addPropertyChangeListener(new ISVPropListener(isvToolBar));
150
        
173
        
151
        isvToolBar.addMouseListener(new MouseAdapter() {
174
        isvToolBar.addMouseListener(new MouseAdapter() {
152
            public void mouseDoubleClick(MouseEvent event) {
175
            public void mouseDoubleClick(MouseEvent event) {
Lines 301-307 Link Here
301
    /**
324
    /**
302
     * @see ViewActionBars
325
     * @see ViewActionBars
303
     */
326
     */
304
    public ToolBarManager getToolBarManager() {
327
    public IToolBarManager2 getToolBarManager() {
305
        return isvToolBarMgr;
328
        return isvToolBarMgr;
306
    }
329
    }
307
330
Lines 463-469 Link Here
463
        super.reparent(newParent);
486
        super.reparent(newParent);
464
487
465
        if (isvToolBarMgr != null) {
488
        if (isvToolBarMgr != null) {
466
            ToolBar bar = isvToolBarMgr.getControl();
489
            Control bar = isvToolBarMgr.getControl2();
467
            if (bar != null) {
490
            if (bar != null) {
468
                bar.setParent(newParent);
491
                bar.setParent(newParent);
469
                bar.moveAbove(control);
492
                bar.moveAbove(control);
Lines 499-517 Link Here
499
    }
522
    }
500
523
501
    public boolean toolbarIsVisible() {
524
    public boolean toolbarIsVisible() {
502
        ToolBarManager toolbarManager = getToolBarManager();
525
        IToolBarManager2 toolbarManager = getToolBarManager();
503
526
504
        if (toolbarManager == null) {
527
        if (toolbarManager == null) {
505
            return false;
528
            return false;
506
        }
529
        }
507
530
508
        ToolBar control = toolbarManager.getControl();
531
        Control control = toolbarManager.getControl2();
509
532
510
        if (control == null || control.isDisposed()) {
533
        if (control == null || control.isDisposed()) {
511
            return false;
534
            return false;
512
        }
535
        }
513
536
514
        return control.getItemCount() > 0;
537
        return toolbarManager.getItemCount() > 0;
515
    }
538
    }
516
539
517
    /*
540
    /*
Lines 559-570 Link Here
559
        return internalGetToolbar();
582
        return internalGetToolbar();
560
    }
583
    }
561
    
584
    
562
    private ToolBar internalGetToolbar() {
585
    private Control internalGetToolbar() {
563
        if (isvToolBarMgr == null) {
586
        if (isvToolBarMgr == null) {
564
            return null;
587
            return null;
565
        }
588
        }
566
        
589
        
567
        return isvToolBarMgr.getControl();        
590
        return isvToolBarMgr.getControl2();        
568
    }
591
    }
569
592
570
    /* (non-Javadoc)
593
    /* (non-Javadoc)
(-)Eclipse UI/org/eclipse/ui/application/IActionBarConfigurer.java (+21 lines)
Lines 11-19 Link Here
11
package org.eclipse.ui.application;
11
package org.eclipse.ui.application;
12
12
13
import org.eclipse.jface.action.IAction;
13
import org.eclipse.jface.action.IAction;
14
import org.eclipse.jface.action.IContributionItem;
14
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.jface.action.ICoolBarManager;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IStatusLineManager;
17
import org.eclipse.jface.action.IStatusLineManager;
18
import org.eclipse.jface.action.IToolBarManager;
17
19
18
/**
20
/**
19
 * Interface providing special access for configuring the action bars
21
 * Interface providing special access for configuring the action bars
Lines 61-66 Link Here
61
     * @return the cool bar manager
63
     * @return the cool bar manager
62
     */
64
     */
63
    public ICoolBarManager getCoolBarManager();
65
    public ICoolBarManager getCoolBarManager();
66
    
67
    /**
68
     * Creates tool bar manager for the workbench window's tool bar.
69
	 *
70
     * @param style
71
     * @return toolBarManager
72
     * @since 3.2
73
     */
74
    public IToolBarManager createToolBarManager(int style);
75
        
76
    /**
77
     * Creates a toolbar contribution item for the window's tool bar.
78
	 * 
79
     * @param toolBarManager the window's tool bar manager
80
     * @param id the id of the contribution
81
     * @return the contribution item
82
	 * @since 3.2
83
     */
84
    public IContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id);
64
85
65
    /**
86
    /**
66
     * Register the action as a global action with a workbench
87
     * Register the action as a global action with a workbench
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/CustomizePerspectiveDialog.java (-2 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 479-484 Link Here
479
		public final IServiceLocator getServiceLocator() {
479
		public final IServiceLocator getServiceLocator() {
480
			return configurer.getWindow();
480
			return configurer.getWindow();
481
		}
481
		}
482
483
		/* (non-Javadoc)
484
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
485
		 */
486
		public IContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
487
			return null;
488
		}
489
490
		/* (non-Javadoc)
491
		 * @see org.eclipse.ui.application.IActionBarConfigurer#createToolBarManager(int)
492
		 */
493
		public IToolBarManager createToolBarManager(int style) {
494
			return null;
495
		}
482
    }
496
    }
483
497
484
    class ShortcutMenuItemContentProvider implements IStructuredContentProvider {
498
    class ShortcutMenuItemContentProvider implements IStructuredContentProvider {
Lines 942-948 Link Here
942
    private void buildMenusAndToolbarsFor(CustomizeActionBars customizeActionBars, ActionSetDescriptor actionSetDesc) {
956
    private void buildMenusAndToolbarsFor(CustomizeActionBars customizeActionBars, ActionSetDescriptor actionSetDesc) {
943
        String id = actionSetDesc.getId();
957
        String id = actionSetDesc.getId();
944
        ActionSetActionBars bars = new ActionSetActionBars(
958
        ActionSetActionBars bars = new ActionSetActionBars(
945
        		customizeActionBars, window, id);
959
        		customizeActionBars, id, window);
946
        PluginActionSetBuilder builder = new PluginActionSetBuilder();
960
        PluginActionSetBuilder builder = new PluginActionSetBuilder();
947
        PluginActionSet actionSet = null;
961
        PluginActionSet actionSet = null;
948
        try {
962
        try {
(-)Eclipse UI/org/eclipse/ui/internal/activities/ws/WorkbenchActivitySupport.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
2
 * Copyright (c) 2003, 2006 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 210-220 Link Here
210
                                            if (manager != null)
210
                                            if (manager != null)
211
                                                updateManager(manager);
211
                                                updateManager(manager);
212
                                            manager = window
212
                                            manager = window
213
                                                    .getCoolBarManager();
213
                                                    .getCoolBarManager2();
214
                                            if (manager != null)
214
                                            if (manager != null)
215
                                                updateManager(manager);
215
                                                updateManager(manager);
216
                                            manager = window
216
                                            manager = window
217
                                                    .getToolBarManager();
217
                                                    .getToolBarManager2();
218
                                            if (manager != null)
218
                                            if (manager != null)
219
                                                updateManager(manager);
219
                                                updateManager(manager);
220
                                            manager = window
220
                                            manager = window
(-)Eclipse (+115 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.internal.presentations;
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;
17
import org.eclipse.jface.action.IToolBarManager2;
18
import org.eclipse.jface.action.ToolBarContributionItem;
19
import org.eclipse.jface.action.ToolBarManager;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
24
/**
25
 * The intention of this class is to allow for replacing the implementation
26
 * of the toolbars in the workbench.  
27
 * <p>
28
 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
29
 * part of a work in progress. There is a guarantee neither that this API will
30
 * work nor that it will remain the same. Please do not use this API without
31
 * consulting with the Platform/UI team.
32
 * </p>
33
 * 
34
 * @since 3.2
35
 */
36
public class ActionBarPresentation  {
37
    
38
    /**
39
     * Creates CoolBarManager for WorkbenchWindow's tool bar
40
     * 
41
     * @return coolBarManager
42
     */
43
    public ICoolBarManager createCoolBarManager(int style) {
44
        CoolBarManager coolBarManager = new CoolBarManager(style);
45
        return coolBarManager;
46
    }
47
    
48
    /**
49
     * Creates the control for the window's cool bar.
50
     * Subclasses may override.
51
     * 
52
     * @param coolBarManager the window's status line manager
53
     * @param parent the parent composite
54
     * @return the window's cool bar control
55
     */
56
    public Control createCoolBarControl(ICoolBarManager coolBarManager, Composite parent) {
57
    	return coolBarManager.createControl2(parent);
58
    }
59
    
60
    /**
61
     * Creates ToolBarManager for WorkbenchWindow's tool bar
62
     * 
63
     * @param style
64
     * @return toolBarManager
65
     */
66
    public IToolBarManager2 createToolBarManager() {
67
        return new ToolBarManager(SWT.FLAT|SWT.RIGHT);
68
    }
69
    
70
    /**
71
     * Creates the control for the window's tool bar.
72
     * Subclasses may override.
73
     * 
74
     * @param toolBarManager the window's toolbar manager
75
     * @param parent the parent composite
76
     * @return the window's tool bar control
77
     */
78
    public Control createToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
79
    	return toolBarManager.createControl2(parent);
80
    }
81
    
82
    /**
83
     * Creates ToolBarManager for a view part tool bar
84
     * 
85
     * @param style
86
     * @return toolBarManager
87
     */
88
    public IToolBarManager2 createViewToolBarManager() {
89
        return new ToolBarManager(SWT.FLAT|SWT.RIGHT);
90
    }
91
    
92
    /**
93
     * Creates the control for a view part tool bar.
94
     * Subclasses may override.
95
     * 
96
     * @param toolBarManager the view part's toolbar manager
97
     * @param parent the parent composite
98
     * @return the window's tool bar control
99
     */
100
    public Control createViewToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
101
    	return toolBarManager.createControl2(parent);
102
    }
103
    
104
    /**
105
     * Creates a toolbar contribution.  
106
     * This is to support custom coolbar managers.
107
     * 
108
     * @param toolBarManager the toolbar manager
109
     * @param id the id of the contribution 
110
     * @return the toolbar contribution item
111
     */
112
    public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
113
    	return new ToolBarContributionItem(toolBarManager, id);
114
    }   
115
}
(-)Eclipse (+40 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.presentations;
13
14
import org.eclipse.ui.IWorkbenchWindow;
15
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
16
17
/**
18
 * The intention of this class is to allow for replacing the implementation
19
 * of the toolbars in the workbench by providing a subclass of this presentation 
20
 * factory.
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 abstract class InternalPresentationFactory extends WorkbenchPresentationFactory {
32
33
    /**
34
     * Creates an action presentation for a window
35
     * @param window 
36
     * @return ActionPresentation
37
     */
38
    public abstract ActionBarPresentation createActionBarPresentation(IWorkbenchWindow window);
39
40
}
(-)src/org/eclipse/ui/examples/rcp/browser/BrowserActionBarAdvisor.java (-6 / +4 lines)
Lines 18-25 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;
23
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
24
import org.eclipse.ui.ISharedImages;
22
import org.eclipse.ui.ISharedImages;
25
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.IViewPart;
Lines 158-165 Link Here
158
	}
156
	}
159
157
160
	protected void fillCoolBar(ICoolBarManager coolBar) {
158
	protected void fillCoolBar(ICoolBarManager coolBar) {
161
		IToolBarManager toolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
159
		IToolBarManager toolBar = getActionBarConfigurer().createToolBarManager(SWT.NONE);
162
		coolBar.add(new ToolBarContributionItem(toolBar, "standard")); //$NON-NLS-1$
160
		coolBar.add(toolBar); //$NON-NLS-1$
163
		
161
		
164
		// For the Back and Forward actions, force their text to be shown on the toolbar,
162
		// For the Back and Forward actions, force their text to be shown on the toolbar,
165
		// not just their image.  For the remaining actions, the ActionContributionItem
163
		// not just their image.  For the remaining actions, the ActionContributionItem
Lines 172-178 Link Here
172
		forwardCI.setMode(ActionContributionItem.MODE_FORCE_TEXT);
170
		forwardCI.setMode(ActionContributionItem.MODE_FORCE_TEXT);
173
		toolBar.add(forwardCI);
171
		toolBar.add(forwardCI);
174
172
175
        toolBar.add(stopAction);
173
		toolBar.add(stopAction);
176
        toolBar.add(refreshAction);
174
		toolBar.add(refreshAction);
177
	}
175
	}
178
}
176
}
(-)plugin_customization.ini (+1 lines)
Lines 1-2 Link Here
1
org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight
1
org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight
2
org.eclipse.ui/KEY_CONFIGURATION_ID=org.eclipse.ui.examples.rcp.browser.keyConfiguration
2
org.eclipse.ui/KEY_CONFIGURATION_ID=org.eclipse.ui.examples.rcp.browser.keyConfiguration
3
org.eclipse.ui/presentationFactoryId=org.eclipse.ui.examples.presentation.customtoolbar
(-)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/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
}
(-)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/SCoolBarManager.java (+1035 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.util.Assert;
18
import org.eclipse.jface.util.Policy;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.CoolBar;
23
import org.eclipse.swt.widgets.Menu;
24
25
public class SCoolBarManager extends ContributionManager implements ICoolBarManager {
26
27
    /**
28
     * A separator created by the end user.
29
     */
30
    public final static String USER_SEPARATOR = "UserSeparator"; //$NON-NLS-1$
31
32
    /**
33
     * The original creation order of the contribution items.
34
     */
35
    private ArrayList cbItemsCreationOrder = new ArrayList();
36
37
    /**
38
     * MenuManager for cool bar pop-up menu, or null if none.
39
     */
40
    private MenuManager contextMenuManager = null;
41
42
    /**
43
     * The cool bar control; <code>null</code> before creation and after
44
     * disposal.
45
     */
46
    private SCoolBar coolBar = null;
47
48
    /**
49
     * The cool bar items style; <code>SWT.NONE</code> by default.
50
     */
51
    private int itemStyle = SWT.NONE;
52
53
    /**
54
     * Creates a new cool bar manager with the default style. Equivalent to
55
     * <code>CoolBarManager(SWT.NONE)</code>.
56
     */
57
    public SCoolBarManager() {
58
        // do nothing
59
    }
60
61
    /**
62
     * Creates a cool bar manager for an existing cool bar control. This
63
     * manager becomes responsible for the control, and will dispose of it when
64
     * the manager is disposed.
65
     * 
66
     * @param coolBar
67
     *            the cool bar control
68
     */
69
    public SCoolBarManager(SCoolBar coolBar) {
70
        this();
71
        Assert.isNotNull(coolBar);
72
        this.coolBar = coolBar;
73
        itemStyle = coolBar.getStyle();
74
    }
75
76
    /**
77
     * Creates a cool bar manager with the given SWT style. Calling <code>createControl</code>
78
     * will create the cool bar control.
79
     * 
80
     * @param style
81
     *            the cool bar item style; see
82
     *            {@link org.eclipse.swt.widgets.CoolBar CoolBar}for for valid
83
     *            style bits
84
     */
85
    public SCoolBarManager(int style) {
86
        itemStyle = style;
87
    }
88
89
    /*
90
     * (non-Javadoc)
91
     * 
92
     * @see org.eclipse.jface.action.ICoolBarManager#add(org.eclipse.jface.action.IToolBarManager)
93
     */
94
    public void add(IToolBarManager toolBarManager) {
95
        Assert.isNotNull(toolBarManager);
96
        SToolBarContributionItem2 toolBarContributionItem = new SToolBarContributionItem2(toolBarManager);
97
        super.add(toolBarContributionItem);
98
    }
99
    
100
    public void add(IContributionItem item) {
101
    	super.add(item);
102
    }
103
104
    /**
105
     * Collapses consecutive separators and removes a separator from the
106
     * beginning and end of the list.
107
     * 
108
     * @param contributionList
109
     *            the list of contributions; must not be <code>null</code>.
110
     * @return The contribution list provided with extraneous separators
111
     *         removed; this value is never <code>null</code>, but may be
112
     *         empty.
113
     */
114
    private ArrayList adjustContributionList(ArrayList contributionList) {
115
        IContributionItem item;
116
        // Fist remove a separator if it is the first element of the list
117
        if (contributionList.size() != 0) {
118
            item = (IContributionItem) contributionList.get(0);
119
            if (item.isSeparator()) {
120
                contributionList.remove(0);
121
            }
122
123
            ListIterator iterator = contributionList.listIterator();
124
            // collapse consecutive separators
125
            while (iterator.hasNext()) {
126
                item = (IContributionItem) iterator.next();
127
                if (item.isSeparator()) {
128
                    while (iterator.hasNext()) {
129
                        item = (IContributionItem) iterator.next();
130
                        if (item.isSeparator()) {
131
                            iterator.remove();
132
                        } else {
133
                            break;
134
                        }
135
                    }
136
137
                }
138
            }
139
            // Now check last element to see if there is a separator
140
            item = (IContributionItem) contributionList.get(contributionList
141
                    .size() - 1);
142
            if (item.isSeparator()) {
143
                contributionList.remove(contributionList.size() - 1);
144
            }
145
        }
146
        return contributionList;
147
148
    }
149
150
    /* (non-Javadoc)
151
     * @see org.eclipse.jface.action.ContributionManager#checkDuplication(org.eclipse.jface.action.IContributionItem)
152
     */
153
    protected boolean allowItem(IContributionItem itemToAdd) {
154
        /* We will allow as many null entries as they like, though there should
155
         * be none.
156
         */
157
        if (itemToAdd == null) {
158
            return true;
159
        }
160
161
        /* Null identifiers can be expected in generic contribution items.
162
         */
163
        String firstId = itemToAdd.getId();
164
        if (firstId == null) {
165
            return true;
166
        }
167
168
        // Cycle through the current list looking for duplicates.
169
        IContributionItem[] currentItems = getItems();
170
        for (int i = 0; i < currentItems.length; i++) {
171
            IContributionItem currentItem = currentItems[i];
172
173
            // We ignore null entries.
174
            if (currentItem == null) {
175
                continue;
176
            }
177
178
            String secondId = currentItem.getId();
179
            if (firstId.equals(secondId)) {
180
                if (Policy.TRACE_TOOLBAR) { //$NON-NLS-1$
181
                    System.out.println("Trying to add a duplicate item."); //$NON-NLS-1$
182
                    new Exception().printStackTrace(System.out);
183
                    System.out.println("DONE --------------------------"); //$NON-NLS-1$
184
                }
185
                return false;
186
            }
187
        }
188
189
        return true;
190
    }
191
192
    /**
193
     * Positions the list iterator to the end of all the separators. Calling
194
     * <code>next()</code> the iterator should return the immediate object
195
     * following the last separator.
196
     * 
197
     * @param iterator
198
     *            the list iterator.
199
     */
200
    private void collapseSeparators(ListIterator iterator) {
201
202
        while (iterator.hasNext()) {
203
            IContributionItem item = (IContributionItem) iterator.next();
204
            if (!item.isSeparator()) {
205
                iterator.previous();
206
                return;
207
            }
208
        }
209
    }
210
211
    /**
212
     * Returns whether the cool bar control has been created and not yet
213
     * disposed.
214
     * 
215
     * @return <code>true</code> if the control has been created and not yet
216
     *         disposed, <code>false</code> otherwise
217
     */
218
    private boolean coolBarExist() {
219
        return coolBar != null && !coolBar.isDisposed();
220
    }
221
222
    /**
223
     * Creates and returns this manager's cool bar control. Does not create a
224
     * new control if one already exists.
225
     * 
226
     * @param parent
227
     *            the parent control
228
     * @return the cool bar control
229
     */
230
    public Control createControl2(Composite parent) {
231
        Assert.isNotNull(parent);
232
        if (!coolBarExist()) {
233
       		coolBar = new SCoolBar(parent, itemStyle);
234
       		((SCoolBar)coolBar).setSkin(new HannoverGlobalCoolBarSkin());
235
            coolBar.setMenu(getContextMenuControl());
236
            coolBar.setLocked(false);
237
            coolBar.setSkin(new HannoverGlobalCoolBarSkin());
238
            update(false);
239
        }
240
        return coolBar;
241
    }
242
243
    /**
244
     * Disposes of this cool bar manager and frees all allocated SWT resources.
245
     * Notifies all contribution items of the dispose. Note that this method
246
     * does not clean up references between this cool bar manager and its
247
     * associated contribution items. Use <code>removeAll</code> for that
248
     * purpose.
249
     */
250
    public void dispose() {
251
        if (coolBarExist()) {
252
            IContributionItem[] items = getItems();
253
            for (int i = 0; i < items.length; i++) {
254
                // Disposes of the contribution item.
255
                // If Contribution Item is a toolbar then it will dispose of
256
                // all the nested
257
                // contribution items.
258
                items[i].dispose();
259
            }
260
            coolBar.dispose();
261
            coolBar = null;
262
        }
263
        // If a context menu existed then dispose of it.
264
        if (contextMenuManager != null) {
265
            contextMenuManager.dispose();
266
            contextMenuManager = null;
267
        }
268
269
    }
270
271
    /**
272
     * Disposes the given cool item.
273
     * 
274
     * @param item
275
     *            the cool item to dispose
276
     */
277
    private void dispose(SCoolItem item) {
278
        if ((item != null) && !item.isDisposed()) {
279
280
            item.setData(null);
281
            Control control = item.getControl();
282
            // if the control is already disposed, setting the coolitem
283
            // control to null will cause an SWT exception, workaround
284
            // for 19630
285
            if ((control != null) && !control.isDisposed()) {
286
                item.setControl(null);
287
            }
288
            item.dispose();
289
        }
290
    }
291
292
    /**
293
     * Finds the cool item associated with the given contribution item.
294
     * 
295
     * @param item
296
     *            the contribution item
297
     * @return the associated cool item, or <code>null</code> if not found
298
     */
299
    private SCoolItem findCoolItem(IContributionItem item) {
300
        if (coolBar == null)
301
            return null;
302
        SCoolItem[] items = coolBar.getItems();
303
        for (int i = 0; i < items.length; i++) {
304
            SCoolItem coolItem = items[i];
305
            IContributionItem data = (IContributionItem) coolItem.getData();
306
            if (data != null && data.equals(item))
307
                return coolItem;
308
        }
309
        return null;
310
    }
311
312
    /**
313
     * Return a consistent set of wrap indices. The return value will always
314
     * include at least one entry and the first entry will always be zero.
315
     * CoolBar.getWrapIndices() is inconsistent in whether or not it returns an
316
     * index for the first row.
317
     * 
318
     * @param wraps
319
     *            the wrap indicies from the cool bar widget
320
     * @return the adjusted wrap indicies.
321
     */
322
    private int[] getAdjustedWrapIndices(int[] wraps) {
323
        int[] adjustedWrapIndices;
324
        if (wraps.length == 0) {
325
            adjustedWrapIndices = new int[] { 0 };
326
        } else {
327
            if (wraps[0] != 0) {
328
                adjustedWrapIndices = new int[wraps.length + 1];
329
                adjustedWrapIndices[0] = 0;
330
                for (int i = 0; i < wraps.length; i++) {
331
                    adjustedWrapIndices[i + 1] = wraps[i];
332
                }
333
            } else {
334
                adjustedWrapIndices = wraps;
335
            }
336
        }
337
        return adjustedWrapIndices;
338
    }
339
340
    /**
341
     * Returns the control of the Menu Manager. If the menu manager does not
342
     * have a control then one is created.
343
     * 
344
     * @return menu control associated with manager, or null if none
345
     */
346
    private Menu getContextMenuControl() {
347
        if ((contextMenuManager != null) && (coolBar != null)) {
348
            Menu menuWidget = contextMenuManager.getMenu();
349
            if ((menuWidget == null) || (menuWidget.isDisposed())) {
350
                menuWidget = contextMenuManager.createContextMenu(coolBar);
351
            }
352
            return menuWidget;
353
        }
354
        return null;
355
    }
356
357
    /*
358
     * (non-Javadoc)
359
     * 
360
     * @see org.eclipse.jface.action.ICoolBarManager#isLayoutLocked()
361
     */
362
    public IMenuManager getContextMenuManager() {
363
        return contextMenuManager;
364
    }
365
366
    /**
367
     * Returns the cool bar control for this manager.
368
     * 
369
     * @return the cool bar control, or <code>null</code> if none
370
     */
371
    public CoolBar getControl() {
372
        return null;
373
    }
374
375
    /**
376
     * Returns an array list of all the contribution items in the manager.
377
     * 
378
     * @return an array list of contribution items.
379
     */
380
    private ArrayList getItemList() {
381
        IContributionItem[] cbItems = getItems();
382
        ArrayList list = new ArrayList(cbItems.length);
383
        for (int i = 0; i < cbItems.length; i++) {
384
            list.add(cbItems[i]);
385
        }
386
        return list;
387
    }
388
389
    /*
390
     * (non-Javadoc)
391
     * 
392
     * @see org.eclipse.jface.action.ICoolBarManager#isLayoutLocked()
393
     */
394
    public boolean getLockLayout() {
395
        if (!coolBarExist()) {
396
            return false;
397
        }
398
        return coolBar.getLocked();
399
    }
400
401
    /**
402
     * Returns the number of rows that should be displayed visually.
403
     * 
404
     * @param items
405
     *            the array of contributin items
406
     * @return the number of rows
407
     */
408
    private int getNumRows(IContributionItem[] items) {
409
        int numRows = 1;
410
        boolean separatorFound = false;
411
        for (int i = 0; i < items.length; i++) {
412
            if (items[i].isSeparator()) {
413
                separatorFound = true;
414
            }
415
            if ((separatorFound) && (items[i].isVisible())
416
                    && (!items[i].isGroupMarker()) && (!items[i].isSeparator())) {
417
                numRows++;
418
                separatorFound = false;
419
            }
420
        }
421
        return numRows;
422
    }
423
424
    /*
425
     * (non-Javadoc)
426
     * 
427
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
428
     */
429
    public int getStyle() {
430
        return itemStyle;
431
    }
432
433
    /**
434
     * Subclasses may extend this <code>ContributionManager</code> method,
435
     * but must call <code>super.itemAdded</code>.
436
     * 
437
     * @see org.eclipse.jface.action.ContributionManager#itemAdded(org.eclipse.jface.action.IContributionItem)
438
     */
439
    protected void itemAdded(IContributionItem item) {
440
        Assert.isNotNull(item);
441
        super.itemAdded(item);
442
        int insertedAt = indexOf(item);
443
        boolean replaced = false;
444
        final int size = cbItemsCreationOrder.size();
445
        for (int i = 0; i < size; i++) {
446
            IContributionItem created = (IContributionItem) cbItemsCreationOrder
447
                    .get(i);
448
            if (created.getId() != null && created.getId().equals(item.getId())) {
449
                cbItemsCreationOrder.set(i, item);
450
                replaced = true;
451
                break;
452
            }
453
        }
454
455
        if (!replaced) {
456
            cbItemsCreationOrder.add(Math.min(Math.max(insertedAt, 0),
457
                    cbItemsCreationOrder.size()), item);
458
        }
459
    }
460
461
    /**
462
     * Subclasses may extend this <code>ContributionManager</code> method,
463
     * but must call <code>super.itemRemoved</code>.
464
     * 
465
     * @see org.eclipse.jface.action.ContributionManager#itemRemoved(org.eclipse.jface.action.IContributionItem)
466
     */
467
    protected void itemRemoved(IContributionItem item) {
468
        Assert.isNotNull(item);
469
        super.itemRemoved(item);
470
        SCoolItem coolItem = findCoolItem(item);
471
        if (coolItem != null) {
472
            coolItem.setData(null);
473
        }
474
    }
475
476
    /**
477
     * Positions the list iterator to the starting of the next row. By calling
478
     * next on the returned iterator, it will return the first element of the
479
     * next row.
480
     * 
481
     * @param iterator
482
     *            the list iterator of contribution items
483
     * @param ignoreCurrentItem
484
     *            Whether the current item in the iterator should be considered
485
     *            (as well as subsequent items).
486
     */
487
    private void nextRow(ListIterator iterator, boolean ignoreCurrentItem) {
488
489
        IContributionItem currentElement = null;
490
        if (!ignoreCurrentItem && iterator.hasPrevious()) {
491
            currentElement = (IContributionItem) iterator.previous();
492
            iterator.next();
493
        }
494
495
        if ((currentElement != null) && (currentElement.isSeparator())) {
496
            collapseSeparators(iterator);
497
            return;
498
        } else {
499
            //Find next separator
500
            while (iterator.hasNext()) {
501
                IContributionItem item = (IContributionItem) iterator.next();
502
                if (item.isSeparator()) {
503
                    // we we find a separator, collapse any consecutive
504
                    // separators
505
                    // and return
506
                    collapseSeparators(iterator);
507
                    return;
508
                }
509
            }
510
        }
511
    }
512
513
    /*
514
     * Used for debuging. Prints all the items in the internal structures.
515
     */
516
    //    private void printContributions(ArrayList contributionList) {
517
    //        int index = 0;
518
    //        System.out.println("----------------------------------\n"); //$NON-NLS-1$
519
    //        for (Iterator i = contributionList.iterator(); i.hasNext(); index++) {
520
    //            IContributionItem item = (IContributionItem) i.next();
521
    //            if (item.isSeparator()) {
522
    //                System.out.println("Separator"); //$NON-NLS-1$
523
    //            } else {
524
    //                System.out.println(index + ". Item id: " + item.getId() //$NON-NLS-1$
525
    //                        + " - is Visible: " //$NON-NLS-1$
526
    //                        + item.isVisible());
527
    //            }
528
    //        }
529
    //    }
530
    /**
531
     * Synchronizes the visual order of the cool items in the control with this
532
     * manager's internal data structures. This method should be called before
533
     * requesting the order of the contribution items to ensure that the order
534
     * is accurate.
535
     * <p>
536
     * Note that <code>update()</code> and <code>refresh()</code> are
537
     * converses: <code>update()</code> changes the visual order to match the
538
     * internal structures, and <code>refresh</code> changes the internal
539
     * structures to match the visual order.
540
     * </p>
541
     */
542
    public void refresh() {
543
        if (!coolBarExist()) {
544
            return;
545
        }
546
547
        // Retreives the list of contribution items as an array list
548
        ArrayList contributionList = getItemList();
549
550
        // Check the size of the list
551
        if (contributionList.size() == 0)
552
            return;
553
554
        // The list of all the cool items in their visual order
555
        SCoolItem[] coolItems = coolBar.getItems();
556
        // The wrap indicies of the coolbar
557
        int[] wrapIndicies = getAdjustedWrapIndices(coolBar.getWrapIndices());
558
559
        int row = 0;
560
        int coolItemIndex = 0;
561
562
        // Traverse through all cool items in the coolbar add them to a new
563
        // data structure
564
        // in the correct order
565
        ArrayList displayedItems = new ArrayList(coolBar.getItemCount());
566
        for (int i = 0; i < coolItems.length; i++) {
567
            SCoolItem coolItem = coolItems[i];
568
            if (coolItem.getData() instanceof IContributionItem) {
569
                IContributionItem cbItem = (IContributionItem) coolItem
570
                        .getData();
571
                displayedItems.add(Math.min(i, displayedItems.size()), cbItem);
572
            }
573
        }
574
575
        // Add separators to the displayed Items data structure
576
        int offset = 0;
577
        for (int i = 1; i < wrapIndicies.length; i++) {
578
            int insertAt = wrapIndicies[i] + offset;
579
            displayedItems.add(insertAt, new Separator(USER_SEPARATOR));
580
            offset++;
581
        }
582
583
        // Determine which rows are invisible
584
        ArrayList existingVisibleRows = new ArrayList(4);
585
        ListIterator rowIterator = contributionList.listIterator();
586
        collapseSeparators(rowIterator);
587
        int numRow = 0;
588
        while (rowIterator.hasNext()) {
589
            // Scan row
590
            while (rowIterator.hasNext()) {
591
                IContributionItem cbItem = (IContributionItem) rowIterator
592
                        .next();
593
                if (displayedItems.contains(cbItem)) {
594
                    existingVisibleRows.add(new Integer(numRow));
595
                    break;
596
                }
597
                if (cbItem.isSeparator()) {
598
                    break;
599
                }
600
            }
601
            nextRow(rowIterator, false);
602
            numRow++;
603
        }
604
605
        Iterator existingRows = existingVisibleRows.iterator();
606
        // Adjust row number to the first visible
607
        if (existingRows.hasNext()) {
608
            row = ((Integer) existingRows.next()).intValue();
609
        }
610
611
        HashMap itemLocation = new HashMap();
612
        for (ListIterator locationIterator = displayedItems.listIterator(); locationIterator
613
                .hasNext();) {
614
            IContributionItem item = (IContributionItem) locationIterator
615
                    .next();
616
            if (item.isSeparator()) {
617
                if (existingRows.hasNext()) {
618
                    Integer value = (Integer) existingRows.next();
619
                    row = value.intValue();
620
                } else {
621
                    row++;
622
                }
623
            } else {
624
                itemLocation.put(item, new Integer(row));
625
            }
626
627
        }
628
629
        // Insert the contribution items in their correct location
630
        for (ListIterator iterator = displayedItems.listIterator(); iterator
631
                .hasNext();) {
632
            IContributionItem cbItem = (IContributionItem) iterator.next();
633
            if (cbItem.isSeparator()) {
634
                coolItemIndex = 0;
635
            } else {
636
                relocate(cbItem, coolItemIndex, contributionList, itemLocation);
637
                cbItem.saveWidgetState();
638
                coolItemIndex++;
639
            }
640
        }
641
642
        if (contributionList.size() != 0) {
643
            contributionList = adjustContributionList(contributionList);
644
            IContributionItem[] array = new IContributionItem[contributionList
645
                    .size() - 1];
646
            array = (IContributionItem[]) contributionList.toArray(array);
647
            internalSetItems(array);
648
        }
649
650
    }
651
652
    /**
653
     * Relocates the given contribution item to the specified index.
654
     * 
655
     * @param cbItem
656
     *            the conribution item to relocate
657
     * @param index
658
     *            the index to locate this item
659
     * @param contributionList
660
     *            the current list of conrtributions
661
     * @param itemLocation
662
     */
663
    private void relocate(IContributionItem cbItem, int index,
664
            ArrayList contributionList, HashMap itemLocation) {
665
666
        if (!(itemLocation.get(cbItem) instanceof Integer))
667
            return;
668
        int targetRow = ((Integer) itemLocation.get(cbItem)).intValue();
669
670
        int cbInternalIndex = contributionList.indexOf(cbItem);
671
672
        //	by default add to end of list
673
        int insertAt = contributionList.size();
674
        // Find the row to place this item in.
675
        ListIterator iterator = contributionList.listIterator();
676
        // bypass any separators at the begining
677
        collapseSeparators(iterator);
678
        int currentRow = -1;
679
        while (iterator.hasNext()) {
680
681
            currentRow++;
682
            if (currentRow == targetRow) {
683
                // We found the row to insert the item
684
                int virtualIndex = 0;
685
                insertAt = iterator.nextIndex();
686
                // first check the position of the current element (item)
687
                // then get the next element
688
                while (iterator.hasNext()) {
689
                    IContributionItem item = (IContributionItem) iterator
690
                            .next();
691
                    Integer itemRow = (Integer) itemLocation.get(item);
692
                    if (item.isSeparator())
693
                        break;
694
                    // if the item has an associate widget
695
                    if ((itemRow != null) && (itemRow.intValue() == targetRow)) {
696
                        // if the next element is the index we are looking for
697
                        // then break
698
                        if (virtualIndex >= index)
699
                            break;
700
                        virtualIndex++;
701
702
                    }
703
                    insertAt++;
704
                }
705
                // If we don't need to move it then we return
706
                if (cbInternalIndex == insertAt)
707
                    return;
708
                break;
709
            }
710
            nextRow(iterator, true);
711
        }
712
        contributionList.remove(cbItem);
713
714
        // Adjust insertAt index
715
        if (cbInternalIndex < insertAt) {
716
            insertAt--;
717
        }
718
719
        // if we didn't find the row then add a new row
720
        if (currentRow != targetRow) {
721
            contributionList.add(new Separator(USER_SEPARATOR));
722
            insertAt = contributionList.size();
723
        }
724
        insertAt = Math.min(insertAt, contributionList.size());
725
        contributionList.add(insertAt, cbItem);
726
727
    }
728
729
    /**
730
     * Restores the canonical order of this cool bar manager. The canonical
731
     * order is the order in which the contribution items where added.
732
     */
733
    public void resetItemOrder() {
734
        for (ListIterator iterator = cbItemsCreationOrder.listIterator(); iterator
735
                .hasNext();) {
736
            IContributionItem item = (IContributionItem) iterator.next();
737
            // if its a user separator then do not include in original order.
738
            if ((item.getId() != null) && (item.getId().equals(USER_SEPARATOR))) {
739
                iterator.remove();
740
            }
741
        }
742
        IContributionItem[] itemsToSet = new IContributionItem[cbItemsCreationOrder
743
                .size()];
744
        cbItemsCreationOrder.toArray(itemsToSet);
745
        setItems(itemsToSet);
746
    }
747
748
    /*
749
     * (non-Javadoc)
750
     * 
751
     * @see org.eclipse.jface.action.ICoolBarManager#setContextMenuManager(org.eclipse.jface.action.IMenuManager)
752
     */
753
    public void setContextMenuManager(IMenuManager contextMenuManager) {
754
        this.contextMenuManager = (MenuManager) contextMenuManager;
755
        if (coolBar != null) {
756
            coolBar.setMenu(getContextMenuControl());
757
        }
758
    }
759
760
    /**
761
     * Replaces the current items with the given items.
762
     * Forces an update.
763
     * 
764
     * @param newItems the items with which to replace the current items
765
     */
766
    public void setItems(IContributionItem[] newItems) {
767
        // dispose of all the cool items on the cool bar manager
768
/* FIXME TFS
769
 *	This is disposing of the coolItems but references are still hanging around. Might
770
 *	be a problem with SCoolBar and or SCoolItem. [Terry Smith 12/9/2005]
771
 * 
772
        if (coolBar != null) {
773
            SCoolItem[] coolItems = coolBar.getItems();
774
           for (int i = 0; i < coolItems.length; i++) {
775
              dispose(coolItems[i]);
776
            }
777
        }
778
        // Set the internal structure to this order
779
        internalSetItems(newItems);
780
*/
781
        // Force and update
782
        update(true);
783
    }
784
785
    /*
786
     * (non-Javadoc)
787
     * 
788
     * @see org.eclipse.jface.action.ICoolBarManager#lockLayout(boolean)
789
     */
790
    public void setLockLayout(boolean value) {
791
        if (!coolBarExist()) {
792
            return;
793
        }
794
        coolBar.setLocked(value);
795
    }
796
797
    /**
798
     * Subclasses may extend this <code>IContributionManager</code> method,
799
     * but must call <code>super.update</code>.
800
     * 
801
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
802
     */
803
    public void update(boolean force) {
804
        if ((!isDirty() && !force) || (!coolBarExist())) {
805
            return;
806
        }
807
808
        boolean relock = false;
809
        boolean changed = false;
810
811
        try {
812
            coolBar.setRedraw(false);
813
814
            // Refresh the widget data with the internal data structure.
815
            refresh();
816
817
            if (coolBar.getLocked()) {
818
                coolBar.setLocked(false);
819
                relock = true;
820
            }
821
822
            /*
823
             * Make a list of items including only those items that are
824
             * visible. Separators should stay because they mark line breaks in
825
             * a cool bar.
826
             */
827
            final IContributionItem[] items = getItems();
828
            final List visibleItems = new ArrayList(items.length);
829
            for (int i = 0; i < items.length; i++) {
830
                final IContributionItem item = items[i];
831
                if (item.isVisible()) {
832
                    visibleItems.add(item);
833
                }
834
            }
835
836
            /*
837
             * Make a list of CoolItem widgets in the cool bar for which there
838
             * is no current visible contribution item. These are the widgets
839
             * to be disposed. Dynamic items are also removed.
840
             */
841
            SCoolItem[] coolItems = coolBar.getItems();
842
            final ArrayList coolItemsToRemove = new ArrayList(coolItems.length);
843
            for (int i = 0; i < coolItems.length; i++) {
844
                final Object data = coolItems[i].getData();
845
                if ((data == null)
846
                        || (!visibleItems.contains(data))
847
                        || ((data instanceof IContributionItem) && ((IContributionItem) data)
848
                                .isDynamic())) {
849
                    coolItemsToRemove.add(coolItems[i]);
850
                }
851
            }
852
853
            // Dispose of any items in the list to be removed.
854
            for (int i = coolItemsToRemove.size() - 1; i >= 0; i--) {
855
                SCoolItem coolItem = (SCoolItem) coolItemsToRemove.get(i);
856
                if (!coolItem.isDisposed()) {
857
                    Control control = coolItem.getControl();
858
                    if (control != null) {
859
                        coolItem.setControl(null);
860
                        control.dispose();
861
                    }
862
                    coolItem.dispose();
863
                }
864
            }
865
866
            // Add any new items by telling them to fill.
867
            coolItems = coolBar.getItems();
868
            IContributionItem sourceItem;
869
            IContributionItem destinationItem;
870
            int sourceIndex = 0;
871
            int destinationIndex = 0;
872
            final Iterator visibleItemItr = visibleItems.iterator();
873
            while (visibleItemItr.hasNext()) {
874
                sourceItem = (IContributionItem) visibleItemItr.next();
875
876
                // Retrieve the corresponding contribution item from SWT's
877
                // data.
878
                if (sourceIndex < coolItems.length) {
879
                    destinationItem = (IContributionItem) coolItems[sourceIndex]
880
                            .getData();
881
                } else {
882
                    destinationItem = null;
883
                }
884
885
                // The items match is they are equal or both separators.
886
                if (destinationItem != null) {
887
                    if (sourceItem.equals(destinationItem)) {
888
                        sourceIndex++;
889
                        destinationIndex++;
890
                        sourceItem.update();
891
                        continue;
892
893
                    } else if ((destinationItem.isSeparator())
894
                            && (sourceItem.isSeparator())) {
895
                        coolItems[sourceIndex].setData(sourceItem);
896
                        sourceIndex++;
897
                        destinationIndex++;
898
                        sourceItem.update();
899
                        continue;
900
901
                    }
902
                }
903
904
                // Otherwise, a new item has to be added.
905
                final int start = coolBar.getItemCount();
906
                if (sourceItem instanceof ISContributionItem)
907
                	((ISContributionItem)sourceItem).fill(coolBar, destinationIndex);
908
                final int newItems = coolBar.getItemCount() - start;
909
                for (int i = 0; i < newItems; i++) {
910
                    coolBar.getItem(destinationIndex++).setData(sourceItem);
911
                }
912
                changed = true;
913
            }
914
915
            // Remove any old widgets not accounted for.
916
            for (int i = coolItems.length - 1; i >= sourceIndex; i--) {
917
                final SCoolItem item = coolItems[i];
918
                if (!item.isDisposed()) {
919
                    Control control = item.getControl();
920
                    if (control != null) {
921
                        item.setControl(null);
922
                        control.dispose();
923
                    }
924
                    item.dispose();
925
                    changed = true;
926
                }
927
            }
928
929
            // Update wrap indices.
930
            updateWrapIndices();
931
932
            // Update the sizes.
933
            for (int i = 0; i < items.length; i++) {
934
                IContributionItem item = items[i];
935
                item.update(SIZE);
936
            }
937
938
            // if the coolBar was previously locked then lock it
939
            if (relock) {
940
                coolBar.setLocked(true);
941
            }
942
943
            if (changed) {
944
                updateTabOrder();
945
            }
946
947
            // We are no longer dirty.
948
            setDirty(false);
949
        } finally {
950
            coolBar.setRedraw(true);
951
        }
952
    }
953
954
    /**
955
     * Sets the tab order of the coolbar to the visual order of its items.
956
     */
957
    /* package */void updateTabOrder() {
958
        if (coolBar != null) {
959
            SCoolItem[] items = coolBar.getItems();
960
            if (items != null) {
961
                ArrayList children = new ArrayList(items.length);
962
                for (int i = 0; i < items.length; i++) {
963
                    if ((items[i].getControl() != null)
964
                            && (!items[i].getControl().isDisposed())) {
965
                        children.add(items[i].getControl());
966
                    }
967
                }
968
                // Convert array
969
                Control[] childrenArray = new Control[0];
970
                childrenArray = (Control[]) children.toArray(childrenArray);
971
972
                if (childrenArray != null) {
973
                    coolBar.setTabList(childrenArray);
974
                }
975
976
            }
977
        }
978
    }
979
980
    /**
981
     * Updates the indices at which the cool bar should wrap.
982
     */
983
    private void updateWrapIndices() {
984
        final IContributionItem[] items = getItems();
985
        final int numRows = getNumRows(items) - 1;
986
987
        // Generate the list of wrap indices.
988
        final int[] wrapIndices = new int[numRows];
989
        boolean foundSeparator = false;
990
        int j = 0;
991
        for (int i = 0; i < items.length; i++) {
992
            IContributionItem item = items[i];
993
            SCoolItem coolItem = findCoolItem(item);
994
            if (item.isSeparator()) {
995
                foundSeparator = true;
996
            }
997
            if ((!item.isSeparator()) && (!item.isGroupMarker())
998
                    && (item.isVisible()) && (coolItem != null)
999
                    && (foundSeparator)) {
1000
                wrapIndices[j] = coolBar.indexOf(coolItem);
1001
                j++;
1002
                foundSeparator = false;
1003
            }
1004
        }
1005
1006
        /*
1007
         * Check to see if these new wrap indices are different than the old
1008
         * ones.
1009
         */
1010
        final int[] oldIndices = coolBar.getWrapIndices();
1011
        boolean shouldUpdate = false;
1012
        if (oldIndices.length == wrapIndices.length) {
1013
            for (int i = 0; i < oldIndices.length; i++) {
1014
                if (oldIndices[i] != wrapIndices[i]) {
1015
                    shouldUpdate = true;
1016
                    break;
1017
                }
1018
            }
1019
        } else {
1020
            shouldUpdate = true;
1021
        }
1022
1023
        if (shouldUpdate) {
1024
            coolBar.setWrapIndices(wrapIndices);
1025
        }
1026
    }
1027
1028
	public CoolBar createControl(Composite parent) {
1029
		return null;
1030
	}
1031
1032
	public Control getControl2() {
1033
		return coolBar;
1034
	}
1035
}
(-)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/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/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/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.IToolBarContributionItem;
11
import org.eclipse.jface.action.IToolBarManager;
12
import org.eclipse.jface.action.MenuManager;
13
import org.eclipse.jface.action.Separator;
14
import org.eclipse.jface.action.SubContributionItem;
15
import org.eclipse.jface.action.ToolBarContributionItem;
16
import org.eclipse.jface.action.ToolBarManager;
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).getControl();
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/CustomToolBarPresentation.java (+71 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.IToolBarContributionItem;
5
import org.eclipse.jface.action.IToolBarManager;
6
import org.eclipse.jface.action.IToolBarManager2;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.widgets.Composite;
9
import org.eclipse.swt.widgets.Control;
10
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SCoolBarManager;
11
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SToolBarContributionItem2;
12
import org.eclipse.ui.examples.presentation.customtoolbar.widgets.SToolBarManager2;
13
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
14
15
/**
16
 * Demonstrates how to customize the tool bars in an RCP application.
17
 *
18
 */
19
class CustomToolBarPresentation extends ActionBarPresentation {
20
			
21
	/* (non-Javadoc)
22
	 * @see org.eclipse.ui.presentations.ToolBarPresentation#createCoolBarManager(int)
23
	 */
24
	public ICoolBarManager createCoolBarManager(int style) {
25
		SCoolBarManager coolBarManager = new SCoolBarManager(style);
26
		return coolBarManager;
27
	}
28
	
29
	public IToolBarManager2 createToolBarManager() {
30
		SToolBarManager2 toolBarManager = new SToolBarManager2(SWT.FLAT);
31
		return toolBarManager;
32
	}
33
	
34
    /* (non-Javadoc)
35
     * @see org.eclipse.ui.internal.presentations.ActionBarPresentation#createToolBarContributionItem(org.eclipse.jface.action.IToolBarManager, java.lang.String)
36
     */
37
    public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) {
38
    	return new SToolBarContributionItem2(toolBarManager, id);
39
    }
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.ui.presentations.ToolBarPresentation#createCoolBarControl(org.eclipse.jface.action.ICoolBarManager, org.eclipse.swt.widgets.Composite)
43
	 */
44
	public Control createCoolBarControl(ICoolBarManager coolBarManager, Composite parent) {
45
		return super.createCoolBarControl(coolBarManager, parent);
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.ui.presentations.ToolBarPresentation#createToolBarControl(org.eclipse.jface.action.IToolBarManager2, org.eclipse.swt.widgets.Composite)
50
	 */
51
	public Control createToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
52
		return super.createToolBarControl(toolBarManager, parent);
53
	}
54
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.ui.internal.presentations.ActionBarPresentation#createViewToolBarControl(org.eclipse.jface.action.IToolBarManager2, org.eclipse.swt.widgets.Composite)
57
	 */
58
	public Control createViewToolBarControl(IToolBarManager2 toolBarManager, Composite parent) {
59
		return super.createViewToolBarControl(toolBarManager, parent);
60
	}
61
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.ui.internal.presentations.ActionBarPresentation#createViewToolBarManager()
64
	 */
65
	public IToolBarManager2 createViewToolBarManager() {
66
		SToolBarManager2 toolBarManager = new SToolBarManager2(SWT.FLAT);
67
		return toolBarManager;
68
	}
69
		
70
	
71
}
(-)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.IToolBarManager2;
15
import org.eclipse.jface.action.MenuManager;
16
import org.eclipse.jface.action.SubContributionItem;
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/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/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/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 (+13 lines)
Added Link Here
1
package org.eclipse.ui.examples.presentation.customtoolbar;
2
3
import org.eclipse.ui.IWorkbenchWindow;
4
import org.eclipse.ui.internal.presentations.ActionBarPresentation;
5
import org.eclipse.ui.internal.presentations.InternalPresentationFactory;
6
7
public class CustomToolBarPresentationFactory extends InternalPresentationFactory {
8
9
	public ActionBarPresentation createActionBarPresentation(IWorkbenchWindow window) {
10
		return new CustomToolBarPresentation();
11
	}
12
	
13
}
(-)src/org/eclipse/jface/window/ApplicationWindow.java (-8 / +96 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 15-20 Link Here
15
15
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;
19
import org.eclipse.jface.action.IToolBarManager2;
18
import org.eclipse.jface.action.MenuManager;
20
import org.eclipse.jface.action.MenuManager;
19
import org.eclipse.jface.action.StatusLineManager;
21
import org.eclipse.jface.action.StatusLineManager;
20
import org.eclipse.jface.action.ToolBarManager;
22
import org.eclipse.jface.action.ToolBarManager;
Lines 77-83 Link Here
77
     *
79
     *
78
     * @see #addToolBar
80
     * @see #addToolBar
79
     */
81
     */
80
    private ToolBarManager toolBarManager = null;
82
    protected IToolBarManager2 toolBarManager = null;
81
83
82
    /**
84
    /**
83
     * Status line manager, or <code>null</code> if none (default).
85
     * Status line manager, or <code>null</code> if none (default).
Lines 92-98 Link Here
92
     * @see #addCoolBar
94
     * @see #addCoolBar
93
     * @since 3.0
95
     * @since 3.0
94
     */
96
     */
95
    private CoolBarManager coolBarManager = null;
97
    protected ICoolBarManager coolBarManager = null;
96
98
97
    /**
99
    /**
98
     * The seperator between the menu bar and the rest of the window.
100
     * The seperator between the menu bar and the rest of the window.
Lines 255-261 Link Here
255
    protected void addToolBar(int style) {
257
    protected void addToolBar(int style) {
256
        if ((getShell() == null) && (toolBarManager == null)
258
        if ((getShell() == null) && (toolBarManager == null)
257
                && (coolBarManager == null)) {
259
                && (coolBarManager == null)) {
258
            toolBarManager = createToolBarManager(style);
260
            toolBarManager = createToolBarManager2(style);
259
        }
261
        }
260
    }
262
    }
261
263
Lines 270-277 Link Here
270
    protected void addCoolBar(int style) {
272
    protected void addCoolBar(int style) {
271
        if ((getShell() == null) && (toolBarManager == null)
273
        if ((getShell() == null) && (toolBarManager == null)
272
                && (coolBarManager == null)) {
274
                && (coolBarManager == null)) {
273
            coolBarManager = createCoolBarManager(style);
275
            coolBarManager = createCoolBarManager2(style);
274
        }
276
        }	
275
    }
277
    }
276
278
277
    /* (non-Javadoc)
279
    /* (non-Javadoc)
Lines 404-409 Link Here
404
    protected ToolBarManager createToolBarManager(int style) {
406
    protected ToolBarManager createToolBarManager(int style) {
405
        return new ToolBarManager(style);
407
        return new ToolBarManager(style);
406
    }
408
    }
409
    
410
    /**
411
     * Returns a new tool bar manager for the window. 
412
     * <p> 
413
     * By default this method calls <code>createToolBarManager</code>.  Subclasses
414
     * may override this method to provide an alternative implementation for the
415
     * tool bar manager.
416
     * </p>
417
     * 
418
	 * <p>
419
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
420
	 * 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
422
	 * consulting with the Platform/UI team.
423
	 * </p>
424
     * 
425
     * @return a tool bar manager
426
     * @since 3.2
427
     */
428
    protected IToolBarManager2 createToolBarManager2(int style) {
429
        return createToolBarManager(style);
430
    }
407
431
408
    /**
432
    /**
409
     * Returns a new cool bar manager for the window.
433
     * Returns a new cool bar manager for the window.
Lines 417-422 Link Here
417
    protected CoolBarManager createCoolBarManager(int style) {
441
    protected CoolBarManager createCoolBarManager(int style) {
418
        return new CoolBarManager(style);
442
        return new CoolBarManager(style);
419
    }
443
    }
444
    
445
    /**
446
     * Returns a new cool bar manager for the window.
447
     * <p>
448
     * By default this method calls <code>createCoolBarManager</code>.  Subclasses
449
     * may override this method to provide an alternative implementation for the
450
     * cool bar manager.
451
     * </p>
452
     * 
453
	 * <p>
454
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
455
	 * 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
457
	 * consulting with the Platform/UI team.
458
	 * </p>
459
     * 
460
     * @return a cool bar manager
461
     * @since 3.2
462
     */
463
    protected ICoolBarManager createCoolBarManager2(int style) {
464
        return createCoolBarManager(style);
465
    }
420
466
421
    /**
467
    /**
422
     * Creates the control for the tool bar manager.
468
     * Creates the control for the tool bar manager.
Lines 427-433 Link Here
427
     */
473
     */
428
    protected Control createToolBarControl(Composite parent) {
474
    protected Control createToolBarControl(Composite parent) {
429
        if (toolBarManager != null) {
475
        if (toolBarManager != null) {
430
            return toolBarManager.createControl(parent);
476
            return toolBarManager.createControl2(parent);
431
        }
477
        }
432
        return null;
478
        return null;
433
    }
479
    }
Lines 443-449 Link Here
443
     */
489
     */
444
    protected Control createCoolBarControl(Composite composite) {
490
    protected Control createCoolBarControl(Composite composite) {
445
        if (coolBarManager != null) {
491
        if (coolBarManager != null) {
446
            return coolBarManager.createControl(composite);
492
            return coolBarManager.createControl2(composite);
447
        }
493
        }
448
        return null;
494
        return null;
449
    }
495
    }
Lines 510-515 Link Here
510
     * @see #addToolBar(int)
556
     * @see #addToolBar(int)
511
     */
557
     */
512
    public ToolBarManager getToolBarManager() {
558
    public ToolBarManager getToolBarManager() {
559
    	if (toolBarManager instanceof ToolBarManager)
560
        	return (ToolBarManager)toolBarManager;
561
        return null;
562
    }
563
    
564
    /**
565
     * Returns the tool bar manager for this window (if it has one).
566
     * 
567
	 * <p>
568
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
569
	 * part of a work in progress. There is a guarantee neither that this API will
570
	 * work nor that it will remain the same. Please do not use this API without
571
	 * consulting with the Platform/UI team.
572
	 * </p>
573
     * 
574
     * @return the tool bar manager, or <code>null</code> if
575
     *   this window does not have a tool bar
576
     * @see #addToolBar(int)
577
	 * @since 3.2
578
     */
579
    public IToolBarManager2 getToolBarManager2() {
513
        return toolBarManager;
580
        return toolBarManager;
514
    }
581
    }
515
582
Lines 522-527 Link Here
522
     * @since 3.0
589
     * @since 3.0
523
     */
590
     */
524
    public CoolBarManager getCoolBarManager() {
591
    public CoolBarManager getCoolBarManager() {
592
    	if (coolBarManager instanceof CoolBarManager)
593
        	return (CoolBarManager)coolBarManager;
594
        return null;
595
    }
596
    
597
    /**
598
     * Returns the cool bar manager for this window.
599
     * 
600
	 * <p>
601
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
602
	 * part of a work in progress. There is a guarantee neither that this API will
603
	 * work nor that it will remain the same. Please do not use this API without
604
	 * consulting with the Platform/UI team.
605
	 * </p>
606
     * 
607
     * @return the cool bar manager, or <code>null</code> if
608
     *   this window does not have a cool bar
609
     * @see #addCoolBar(int)
610
     * @since 3.2
611
     */
612
    public ICoolBarManager getCoolBarManager2() {
525
        return coolBarManager;
613
        return coolBarManager;
526
    }
614
    }
527
615
(-)src/org/eclipse/jface/action/CoolBarManager.java (-1 / +38 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
2
 * Copyright (c) 2003, 2006 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 245-250 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
    }
248
268
249
    /**
269
    /**
250
     * Disposes of this cool bar manager and frees all allocated SWT resources.
270
     * Disposes of this cool bar manager and frees all allocated SWT resources.
Lines 382-387 Link Here
382
    public CoolBar getControl() {
402
    public CoolBar getControl() {
383
        return coolBar;
403
        return coolBar;
384
    }
404
    }
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
    }
385
422
386
    /**
423
    /**
387
     * Returns an array list of all the contribution items in the manager.
424
     * Returns an array list of all the contribution items in the manager.
(-)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 {
46
public class ToolBarContributionItem extends ContributionItem implements IToolBarContributionItem {
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 (-1 / +144 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
2
 * Copyright (c) 2003, 2006 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-15 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;
13
import org.eclipse.swt.widgets.CoolBar;
15
import org.eclipse.swt.widgets.CoolBar;
14
16
15
/**
17
/**
Lines 50-55 Link Here
50
     * @see ToolBarContributionItem
52
     * @see ToolBarContributionItem
51
     */
53
     */
52
    public void add(IToolBarManager toolBarManager);
54
    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);
53
91
54
    /**
92
    /**
55
     * Returns the context menu manager used by this cool bar manager. This
93
     * Returns the context menu manager used by this cool bar manager. This
Lines 62-67 Link Here
62
    public IMenuManager getContextMenuManager();
100
    public IMenuManager getContextMenuManager();
63
101
64
    /**
102
    /**
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
    /**
65
     * Returns whether the layout of the underlying cool bar widget is locked.
133
     * Returns whether the layout of the underlying cool bar widget is locked.
66
     * 
134
     * 
67
     * @return <code>true</code> if cool bar layout is locked, <code>false</code>
135
     * @return <code>true</code> if cool bar layout is locked, <code>false</code>
Lines 87-92 Link Here
87
    public void setContextMenuManager(IMenuManager menuManager);
155
    public void setContextMenuManager(IMenuManager menuManager);
88
156
89
    /**
157
    /**
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
    /**
90
     * Locks or unlocks the layout of the underlying cool bar widget. Once the
226
     * Locks or unlocks the layout of the underlying cool bar widget. Once the
91
     * cool bar is locked, cool items cannot be repositioned by the user.
227
     * cool bar is locked, cool items cannot be repositioned by the user.
92
     * <p>
228
     * <p>
Lines 94-99 Link Here
94
     * cool bar is locked.
230
     * cool bar is locked.
95
     * </p>
231
     * </p>
96
     * 
232
     * 
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
     *  
97
     * @param value
240
     * @param value
98
     *            <code>true</code> to lock the cool bar, <code>false</code>
241
     *            <code>true</code> to lock the cool bar, <code>false</code>
99
     *            to unlock
242
     *            to unlock
(-)src/org/eclipse/jface/action/ToolBarManager.java (-2 / +98 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 13-18 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;
16
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.accessibility.ACC;
20
import org.eclipse.swt.accessibility.ACC;
18
import org.eclipse.swt.accessibility.AccessibleAdapter;
21
import org.eclipse.swt.accessibility.AccessibleAdapter;
Lines 33-39 Link Here
33
 * </p>
36
 * </p>
34
 */
37
 */
35
public class ToolBarManager extends ContributionManager implements
38
public class ToolBarManager extends ContributionManager implements
36
		IToolBarManager {
39
		IToolBarManager2 {
37
40
38
	/**
41
	/**
39
	 * The tool bar items style; <code>SWT.NONE</code> by default.
42
	 * The tool bar items style; <code>SWT.NONE</code> by default.
Lines 54-59 Link Here
54
	private MenuManager contextMenuManager = null;
57
	private MenuManager contextMenuManager = null;
55
58
56
	/**
59
	/**
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
	/**
57
	 * Creates a new tool bar manager with the default SWT button style. Use the
66
	 * Creates a new tool bar manager with the default SWT button style. Use the
58
	 * <code>createControl</code> method to create the tool bar control.
67
	 * <code>createControl</code> method to create the tool bar control.
59
	 */
68
	 */
Lines 182-187 Link Here
182
	protected void relayout(ToolBar layoutBar, int oldCount, int newCount) {
191
	protected void relayout(ToolBar layoutBar, int oldCount, int newCount) {
183
		if ((oldCount == 0) != (newCount == 0))
192
		if ((oldCount == 0) != (newCount == 0))
184
			layoutBar.getParent().layout();
193
			layoutBar.getParent().layout();
194
		firePropertyChange(PROP_LAYOUT, new Integer(oldCount), new Integer(newCount));
185
	}
195
	}
186
196
187
	/**
197
	/**
Lines 396-399 Link Here
396
		}
406
		}
397
	}
407
	}
398
408
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
399
}
495
}
(-)src/org/eclipse/jface/action/SubCoolBarManager.java (-1 / +73 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2004 IBM Corporation and others.
2
 * Copyright (c) 2003, 2006 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-16 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;
14
17
15
/**
18
/**
16
 * A <code>SubCoolBarManager</code> monitors the additional and removal of 
19
 * A <code>SubCoolBarManager</code> monitors the additional and removal of 
Lines 42-47 Link Here
42
        super.add(new ToolBarContributionItem(toolBarManager));
45
        super.add(new ToolBarContributionItem(toolBarManager));
43
    }
46
    }
44
47
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
    
45
    /* (non-Javadoc)
80
    /* (non-Javadoc)
46
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
81
     * @see org.eclipse.jface.action.ICoolBarManager#getStyle()
47
     */
82
     */
Lines 82-87 Link Here
82
        return null;
117
        return null;
83
    }
118
    }
84
119
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
    
85
    /* (non-Javadoc)
136
    /* (non-Javadoc)
86
     * In SubCoolBarManager we do nothing.
137
     * In SubCoolBarManager we do nothing.
87
     */
138
     */
Lines 89-94 Link Here
89
        // do nothing
140
        // do nothing
90
    }
141
    }
91
142
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
92
    /* (non-Javadoc)
151
    /* (non-Javadoc)
93
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
152
     * @see org.eclipse.jface.action.IContributionManager#update(boolean)
94
     */
153
     */
Lines 99-102 Link Here
99
        getParentCoolBarManager().update(force);
158
        getParentCoolBarManager().update(force);
100
    }
159
    }
101
160
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
102
}
174
}
(-)src/org/eclipse/jface/action/IToolBarManager2.java (+111 lines)
Added 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)
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.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
}

Return to bug 123257