KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > AbstractLaunchConfigurationTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.debug.ui;
12
13  
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.ILaunch;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18 import org.eclipse.debug.core.ILaunchManager;
19 import org.eclipse.debug.internal.ui.SWTFactory;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Shell;
28
29 /**
30  * Common function for launch configuration tabs.
31  * <p>
32  * Clients may subclass this class.
33  * </p>
34  * @see ILaunchConfigurationTab
35  * @since 2.0
36  */

37 public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigurationTab {
38 // TODO Add in access methods for createGroup, createLabel and createSingleText from SWTFactory post 3.2 API freeze
39

40     /**
41      * The control for this page, or <code>null</code>
42      */

43     private Control fControl;
44
45     /**
46      * The launch configuration dialog this tab is
47      * contained in.
48      */

49     private ILaunchConfigurationDialog fLaunchConfigurationDialog;
50     
51     /**
52      * Current error message, or <code>null</code>
53      */

54     private String JavaDoc fErrorMessage;
55     
56     /**
57      * Current message, or <code>null</code>
58      */

59     private String JavaDoc fMessage;
60     
61     /**
62      * Whether this tab needs to apply changes. This attribute is initialized to
63      * <code>true</code> to be backwards compatible. If clients want to take advantage
64      * of such a feature, they should set the flag to false, and check it before
65      * applying changes to the launch configuration working copy.
66      *
67      * @since 2.1
68      */

69     private boolean fDirty = true;
70         
71     /**
72      * Returns the dialog this tab is contained in, or
73      * <code>null</code> if not yet set.
74      *
75      * @return launch configuration dialog, or <code>null</code>
76      */

77     protected ILaunchConfigurationDialog getLaunchConfigurationDialog() {
78         return fLaunchConfigurationDialog;
79     }
80         
81     /**
82      * Updates the buttons and message in this page's launch
83      * configuration dialog.
84      */

85     protected void updateLaunchConfigurationDialog() {
86         if (getLaunchConfigurationDialog() != null) {
87             //order is important here due to the call to
88
//refresh the tab viewer in updateButtons()
89
//which ensures that the messages are up to date
90
getLaunchConfigurationDialog().updateButtons();
91             getLaunchConfigurationDialog().updateMessage();
92         }
93     }
94                 
95     /**
96      * @see ILaunchConfigurationTab#getControl()
97      */

98     public Control getControl() {
99         return fControl;
100     }
101
102     /**
103      * Sets the control to be displayed in this tab.
104      *
105      * @param control the control for this tab
106      */

107     protected void setControl(Control control) {
108         fControl = control;
109     }
110
111     /**
112      * @see ILaunchConfigurationTab#getErrorMessage()
113      */

114     public String JavaDoc getErrorMessage() {
115         return fErrorMessage;
116     }
117
118     /**
119      * @see ILaunchConfigurationTab#getMessage()
120      */

121     public String JavaDoc getMessage() {
122         return fMessage;
123     }
124
125     /**
126      * By default, do nothing.
127      *
128      * @see ILaunchConfigurationTab#launched(ILaunch)
129      * @deprecated
130      */

131     public void launched(ILaunch launch) {
132     }
133
134     /**
135      * @see ILaunchConfigurationTab#setLaunchConfigurationDialog(ILaunchConfigurationDialog)
136      */

137     public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
138         fLaunchConfigurationDialog = dialog;
139     }
140     
141     /**
142      * Sets this page's error message, possibly <code>null</code>.
143      *
144      * @param errorMessage the error message or <code>null</code>
145      */

146     protected void setErrorMessage(String JavaDoc errorMessage) {
147         fErrorMessage = errorMessage;
148     }
149
150     /**
151      * Sets this page's message, possibly <code>null</code>.
152      *
153      * @param message the message or <code>null</code>
154      */

155     protected void setMessage(String JavaDoc message) {
156         fMessage = message;
157     }
158     
159     /**
160      * Convenience method to return the launch manager.
161      *
162      * @return the launch manager
163      */

164     protected ILaunchManager getLaunchManager() {
165         return DebugPlugin.getDefault().getLaunchManager();
166     }
167     
168     /**
169      * By default, do nothing.
170      *
171      * @see ILaunchConfigurationTab#dispose()
172      */

173     public void dispose() {
174     }
175     
176     /**
177      * Returns the shell this tab is contained in, or <code>null</code>.
178      *
179      * @return the shell this tab is contained in, or <code>null</code>
180      */

181     protected Shell getShell() {
182         Control control = getControl();
183         if (control != null) {
184             return control.getShell();
185         }
186         return null;
187     }
188     
189     /**
190      * Creates and returns a new push button with the given
191      * label and/or image.
192      *
193      * @param parent parent control
194      * @param label button label or <code>null</code>
195      * @param image image of <code>null</code>
196      *
197      * @return a new push button
198      */

199     protected Button createPushButton(Composite parent, String JavaDoc label, Image image) {
200         return SWTFactory.createPushButton(parent, label, image);
201     }
202     
203     /**
204      * Creates and returns a new radio button with the given
205      * label and/or image.
206      *
207      * @param parent parent control
208      * @param label button label or <code>null</code>
209      *
210      * @return a new radio button
211      */

212     protected Button createRadioButton(Composite parent, String JavaDoc label) {
213         return SWTFactory.createRadioButton(parent, label);
214     }
215     
216     /**
217      * Creates and returns a new check button with the given
218      * label.
219      *
220      * @param parent the parent composite
221      * @param label the button label
222      * @return a new check button
223      * @since 3.0
224      */

225     protected Button createCheckButton(Composite parent, String JavaDoc label) {
226         Button button = new Button(parent, SWT.CHECK);
227         button.setText(label);
228         GridData data = new GridData();
229         button.setLayoutData(data);
230         button.setFont(parent.getFont());
231         SWTFactory.setButtonDimensionHint(button);
232         return button;
233     }
234     
235     /**
236      * @see ILaunchConfigurationTab#canSave()
237      */

238     public boolean canSave() {
239         return true;
240     }
241     
242     /**
243      * @see ILaunchConfigurationTab#isValid(ILaunchConfiguration)
244      */

245     public boolean isValid(ILaunchConfiguration launchConfig) {
246         return true;
247     }
248
249     /**
250      * Creates vertical space in the parent <code>Composite</code>
251      * @param comp the parent to add the vertical space to
252      * @param colSpan the number of line of vertical space to add
253      */

254     protected void createVerticalSpacer(Composite comp, int colSpan) {
255         Label label = new Label(comp, SWT.NONE);
256         GridData gd = new GridData();
257         gd.horizontalSpan = colSpan;
258         label.setLayoutData(gd);
259         label.setFont(comp.getFont());
260     }
261     
262     /**
263      * Create a horizontal separator.
264      *
265      * @param comp parent widget
266      * @param colSpan number of columns to span
267      * @since 3.0
268      */

269     protected void createSeparator(Composite comp, int colSpan) {
270         Label label = new Label(comp, SWT.SEPARATOR | SWT.HORIZONTAL);
271         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
272         gd.horizontalSpan = colSpan;
273         label.setLayoutData(gd);
274     }
275         
276     /**
277      * @see ILaunchConfigurationTab#getImage()
278      */

279     public Image getImage() {
280         return null;
281     }
282     
283     /**
284      * Returns this tab's unique identifier or <code>null</code> if none.
285      * By default, <code>null</code> is returned. Subclasses should override
286      * as necessary.
287      * <p>
288      * Tab identifiers allow contributed tabs to be ordered relative to one
289      * another.
290      * </p>
291      * @return tab id or <code>null</code>
292      * @since 3.3
293      */

294     public String JavaDoc getId() {
295         return null;
296     }
297     
298     /**
299      * Convenience method to set a boolean attribute of on a launch
300      * configuration. If the value being set is the default, the attribute's
301      * value is set to <code>null</code>.
302      *
303      * @param attribute attribute identifier
304      * @param configuration the configuration on which to set the attribute
305      * @param value the value of the attribute
306      * @param defaultValue the default value of the attribute
307      * @since 2.1
308      */

309     protected void setAttribute(String JavaDoc attribute, ILaunchConfigurationWorkingCopy configuration, boolean value, boolean defaultValue) {
310         if (value == defaultValue) {
311             configuration.setAttribute(attribute, (String JavaDoc)null);
312         } else {
313             configuration.setAttribute(attribute, value);
314         }
315     }
316
317
318
319     /**
320      * Returns whether this tab is dirty. It is up to clients to set/reset and consult
321      * this attribute as required. By default, a tab is initialized to dirty.
322      *
323      * @return whether this tab is dirty
324      * @since 2.1
325      */

326     protected boolean isDirty() {
327         return fDirty;
328     }
329
330     /**
331      * Sets the dirty state of the tab. It is up to clients to set/reset and consult
332      * this attribute as required. By default, a tab is initialized to dirty.
333      *
334      * @param dirty whether this tab is dirty
335      * @since 2.1
336      */

337     protected void setDirty(boolean dirty) {
338         fDirty = dirty;
339     }
340     
341     /**
342      * This method was added to the <code>ILaunchConfigurationTab</code> interface
343      * in the 3.0 release to allow tabs to distinguish between a tab being activated
344      * and a tab group be initialized for the first time, from a selected launch
345      * configuration. To maintain backwards compatible behavior, the default
346      * implementation provided, calls this tab's <code>initializeFrom</code> method.
347      * Tabs should override this method as required.
348      * <p>
349      * The launch tab framework was originally designed to take care of inter tab
350      * communication by applying attributes from the active tab to the launch configuration
351      * being edited, when a tab is exited, and by initializing a tab when activated.
352      * The addition of the methods <code>activated</code> and <code>deactivated</code>
353      * allow tabs to determine the appropriate course of action.
354      * </p>
355      *
356      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
357      * @since 3.0
358      */

359     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
360         initializeFrom(workingCopy);
361     }
362
363     /**
364      * This method was added to the <code>ILaunchConfigurationTab</code> interface
365      * in the 3.0 release to allow tabs to distinguish between a tab being deactivated
366      * and saving its attributes to a launch configuration. To maintain backwards
367      * compatible behavior, the default implementation provided, calls this tab's
368      * <code>performApply</code> method. Tabs should override this method as required.
369      * <p>
370      * The launch tab framework was originally designed to take care of inter tab
371      * communication by applying attributes from the active tab to the launch configuration
372      * being edited, when a tab is exited, and by initializing a tab when activated.
373      * The addition of the methods <code>activated</code> and <code>deactivated</code>
374      * allow tabs to determine the appropriate course of action.
375      * </p>
376      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
377      * @since 3.0
378      */

379     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
380         performApply(workingCopy);
381     }
382
383 }
384
385
Popular Tags