Mercurial > projects > dwt-addons
annotate dwtx/jface/action/ControlContribution.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | ea8ff534f622 |
children |
rev | line source |
---|---|
24 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.action.ControlContribution; | |
14 | |
15 import dwtx.jface.action.ContributionItem; | |
16 | |
17 import dwt.DWT; | |
18 import dwt.widgets.Composite; | |
19 import dwt.widgets.Control; | |
20 import dwt.widgets.Menu; | |
21 import dwt.widgets.ToolBar; | |
22 import dwt.widgets.ToolItem; | |
23 import dwtx.core.runtime.Assert; | |
24 | |
25 import dwt.dwthelper.utils; | |
26 | |
27 /** | |
28 * An abstract contribution item implementation for adding an arbitrary | |
29 * DWT control to a tool bar. | |
30 * Note, however, that these items cannot be contributed to menu bars. | |
31 * <p> | |
32 * The <code>createControl</code> framework method must be implemented | |
33 * by concrete subclasses. | |
34 * </p> | |
35 */ | |
36 public abstract class ControlContribution : ContributionItem { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
37 alias ContributionItem.fill fill; |
24 | 38 /** |
39 * Creates a control contribution item with the given id. | |
40 * | |
41 * @param id the contribution item id | |
42 */ | |
43 protected this(String id) { | |
44 super(id); | |
45 } | |
46 | |
47 /** | |
48 * Computes the width of the given control which is being added | |
49 * to a tool bar. This is needed to determine the width of the tool bar item | |
50 * containing the given control. | |
51 * <p> | |
52 * The default implementation of this framework method returns | |
53 * <code>control.computeSize(DWT.DEFAULT, DWT.DEFAULT, true).x</code>. | |
54 * Subclasses may override if required. | |
55 * </p> | |
56 * | |
57 * @param control the control being added | |
58 * @return the width of the control | |
59 */ | |
60 protected int computeWidth(Control control) { | |
61 return control.computeSize(DWT.DEFAULT, DWT.DEFAULT, true).x; | |
62 } | |
63 | |
64 /** | |
65 * Creates and returns the control for this contribution item | |
66 * under the given parent composite. | |
67 * <p> | |
68 * This framework method must be implemented by concrete | |
69 * subclasses. | |
70 * </p> | |
71 * | |
72 * @param parent the parent composite | |
73 * @return the new control | |
74 */ | |
75 protected abstract Control createControl(Composite parent); | |
76 | |
77 /** | |
78 * The control item implementation of this <code>IContributionItem</code> | |
79 * method calls the <code>createControl</code> framework method. | |
80 * Subclasses must implement <code>createControl</code> rather than | |
81 * overriding this method. | |
82 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
83 public override final void fill(Composite parent) { |
24 | 84 createControl(parent); |
85 } | |
86 | |
87 /** | |
88 * The control item implementation of this <code>IContributionItem</code> | |
89 * method throws an exception since controls cannot be added to menus. | |
90 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
91 public override final void fill(Menu parent, int index) { |
24 | 92 Assert.isTrue(false, "Can't add a control to a menu");//$NON-NLS-1$ |
93 } | |
94 | |
95 /** | |
96 * The control item implementation of this <code>IContributionItem</code> | |
97 * method calls the <code>createControl</code> framework method to | |
98 * create a control under the given parent, and then creates | |
99 * a new tool item to hold it. | |
100 * Subclasses must implement <code>createControl</code> rather than | |
101 * overriding this method. | |
102 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
103 public override final void fill(ToolBar parent, int index) { |
24 | 104 Control control = createControl(parent); |
105 ToolItem ti = new ToolItem(parent, DWT.SEPARATOR, index); | |
106 ti.setControl(control); | |
107 ti.setWidth(computeWidth(control)); | |
108 } | |
109 } |