blob: 7ffacde550a700d38169146a084b1eca9a2771f8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.views.editor.pages;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ContributionManager;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.te.ui.forms.CustomFormToolkit;
import org.eclipse.tcf.te.ui.forms.FormLayoutFactory;
import org.eclipse.tcf.te.ui.views.activator.UIPlugin;
import org.eclipse.tcf.te.ui.views.interfaces.ImageConsts;
import org.eclipse.tcf.te.ui.views.nls.Messages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.menus.IMenuService;
/**
* Abstract details editor page implementation managing
* an custom form toolkit instance.
*/
public abstract class AbstractCustomFormToolkitEditorPage extends AbstractEditorPage {
// Reference to the form toolkit instance
private CustomFormToolkit toolkit = null;
// Reference to the toolbar manager to release menu contributions for
private IToolBarManager manager = null;
// The default help action class definition
static protected class HelpAction extends Action {
/* default */ final String helpID;
/**
* Constructor.
*
* @param helpID The context help id. Must not be <code>null</code>.
*/
public HelpAction(String helpID) {
super(Messages.AbstractCustomFormToolkitEditorPage_HelpAction_label, IAction.AS_PUSH_BUTTON);
Assert.isNotNull(helpID);
this.helpID = helpID;
setToolTipText(Messages.AbstractCustomFormToolkitEditorPage_HelpAction_tooltip);
setImageDescriptor(UIPlugin.getImageDescriptor(ImageConsts.HELP));
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpID);
}
});
}
}
/**
* Returns the custom form toolkit instance.
*
* @return The custom form toolkit instance or <code>null</code>.
*/
protected final CustomFormToolkit getFormToolkit() {
return toolkit;
}
/**
* Sets the custom form toolkit instance.
*
* @param toolkit The custom form toolkit instance or <code>null</code>.
*/
protected final void setFormToolkit(CustomFormToolkit toolkit) {
this.toolkit = toolkit;
}
/* (non-Javadoc)
* @see org.eclipse.ui.forms.editor.FormPage#dispose()
*/
@Override
public void dispose() {
// Get the menu service and release the toolbar manager
if (manager instanceof ContributionManager) {
IMenuService service = (IMenuService) getSite().getService(IMenuService.class);
if (service != null) {
service.releaseContributions((ContributionManager)manager);
}
}
// Dispose the custom form toolkit
if (toolkit != null) { toolkit.dispose(); toolkit = null; }
// Dispose all the rest
super.dispose();
}
/* (non-Javadoc)
* @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
*/
@Override
protected void createFormContent(IManagedForm managedForm) {
super.createFormContent(managedForm);
Assert.isNotNull(managedForm);
// Create the toolkit instance
toolkit = new CustomFormToolkit(managedForm.getToolkit());
// Configure the managed form
configureManagedForm(managedForm);
// Do create the content of the form now
doCreateFormContent(managedForm.getForm().getBody(), getFormToolkit());
// Re-arrange the controls
managedForm.reflow(true);
}
/**
* Configure the managed form to be ready for usage.
*
* @param managedForm The managed form. Must not be <code>null</code>.
*/
protected void configureManagedForm(IManagedForm managedForm) {
Assert.isNotNull(managedForm);
// Configure main layout
Composite body = managedForm.getForm().getBody();
body.setLayout(FormLayoutFactory.createFormGridLayout(false, 1));
// Set context help id
if (getContextHelpId() != null) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(managedForm.getForm(), getContextHelpId());
}
// Decorate the form header
getFormToolkit().getFormToolkit().decorateFormHeading(managedForm.getForm().getForm());
// And set the header text and image
if (getFormTitle() != null) managedForm.getForm().getForm().setText(getFormTitle());
managedForm.getForm().getForm().setImage(getFormImage());
// Add the toolbar items which will appear in the form header
manager = managedForm.getForm().getForm().getToolBarManager();
// Add the default "additions" separator
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
// Create fixed toolbar contribution items
createToolbarContributionItems(manager);
// Get the menu service and populate contributed toolbar actions
IMenuService service = (IMenuService) getSite().getService(IMenuService.class);
if (service != null && manager instanceof ContributionManager) {
service.populateContributionManager((ContributionManager)manager, "toolbar:" + getId()); //$NON-NLS-1$
}
// Trigger an update of the toolbar widget
manager.update(true);
}
/**
* Returns the context help id to associate with the page form.
*
* @return The context help id.
*/
protected String getContextHelpId() {
return null;
}
/**
* Returns the form title to set to the top form header.
*
* @return The form title.
*/
protected String getFormTitle() {
return null;
}
/**
* Returns the image to be set to the top form header.
*
* @return The image or <code>null</code> to use no image.
*/
protected Image getFormImage() {
return null;
}
/**
* Create the toolbar contribution items.
*
* @param manager The toolbar manager. Must not be <code>null</code>.
*/
protected void createToolbarContributionItems(IToolBarManager manager) {
Assert.isNotNull(manager);
// If the page is associated with a context help id, add a default
// help action button into the toolbar
if (getContextHelpId() != null) {
manager.add(new Separator());
Action helpAction = doCreateHelpAction(getContextHelpId());
if(helpAction != null) manager.add(helpAction);
}
}
/**
* Create the help action.
*
* @param contextHelpId The context help id. Must not be <code>null</code>.
* @return The help action or <code>null</code>.
*/
protected Action doCreateHelpAction(String contextHelpId) {
Assert.isNotNull(contextHelpId);
return new HelpAction(contextHelpId);
}
/**
* Do create the managed form content.
*
* @param parent The parent composite. Must not be <code>null</code>
* @param toolkit The {@link CustomFormToolkit} instance. Must not be <code>null</code>.
*/
protected abstract void doCreateFormContent(Composite parent, CustomFormToolkit toolkit);
}
|