1 package net.sourceforge.phpdt.externaltools.launchConfigurations;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
10 import net.sourceforge.phpdt.externaltools.group.IGroupDialogPage;
11 import net.sourceforge.phpdt.externaltools.internal.dialog.ExternalToolVariableForm;
12 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
13 import net.sourceforge.phpdt.externaltools.internal.registry.ExternalToolVariable;
14 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
15 import net.sourceforge.phpdt.externaltools.model.ToolUtil;
16 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.ILaunchConfiguration;
20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
21 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
22 import org.eclipse.jface.dialogs.IMessageProvider;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
32 public class ExternalToolsRefreshTab extends AbstractLaunchConfigurationTab
33 implements IGroupDialogPage {
35 private ExternalToolVariableForm variableForm;
37 protected Button refreshField;
39 protected Button recursiveField;
42 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
44 public void createControl(Composite parent) {
45 Composite mainComposite = new Composite(parent, SWT.NONE);
46 setControl(mainComposite);
48 GridLayout layout = new GridLayout();
49 layout.numColumns = 1;
50 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
51 mainComposite.setLayout(layout);
52 mainComposite.setLayoutData(gridData);
53 mainComposite.setFont(parent.getFont());
54 createVerticalSpacer(mainComposite, 1);
55 createRefreshComponent(mainComposite);
56 createRecursiveComponent(mainComposite);
57 createScopeComponent(mainComposite);
61 * Creates the controls needed to edit the refresh recursive attribute of an
65 * the composite to create the controls in
67 protected void createRecursiveComponent(Composite parent) {
68 recursiveField = new Button(parent, SWT.CHECK);
70 .setText(ExternalToolsLaunchConfigurationMessages
71 .getString("ExternalToolsRefreshTab.Recursively_&include_sub-folders_1")); //$NON-NLS-1$
72 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
73 recursiveField.setLayoutData(data);
74 recursiveField.setFont(parent.getFont());
75 recursiveField.addSelectionListener(new SelectionAdapter() {
76 public void widgetSelected(SelectionEvent e) {
77 updateLaunchConfigurationDialog();
83 * Creates the controls needed to edit the refresh scope attribute of an
87 * the composite to create the controls in
89 protected void createRefreshComponent(Composite parent) {
90 refreshField = new Button(parent, SWT.CHECK);
92 .setText(ExternalToolsLaunchConfigurationMessages
93 .getString("ExternalToolsRefreshTab.&Refresh_resources_after_running_tool_1")); //$NON-NLS-1$
94 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
95 refreshField.setLayoutData(data);
96 refreshField.setFont(parent.getFont());
97 refreshField.addSelectionListener(new SelectionAdapter() {
98 public void widgetSelected(SelectionEvent e) {
100 updateLaunchConfigurationDialog();
106 * Creates the controls needed to edit the refresh scope variable attribute
107 * of an external tool
110 * the composite to create the controls in
112 protected void createScopeComponent(Composite parent) {
113 String label = ExternalToolsLaunchConfigurationMessages
114 .getString("ExternalToolsRefreshTab.Choose_scope_v&ariable___2"); //$NON-NLS-1$
115 ExternalToolVariable[] vars = ExternalToolsPlugin.getDefault()
116 .getRefreshVariableRegistry().getRefreshVariables();
117 variableForm = new ExternalToolVariableForm(label, vars);
118 variableForm.createContents(parent, this);
122 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
124 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
128 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
130 public void initializeFrom(ILaunchConfiguration configuration) {
131 updateRefresh(configuration);
132 updateRecursive(configuration);
133 updateScope(configuration);
137 * Method udpateScope.
139 * @param configuration
141 private void updateScope(ILaunchConfiguration configuration) {
144 scope = configuration.getAttribute(
145 IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
146 } catch (CoreException ce) {
150 ExternalToolsLaunchConfigurationMessages
151 .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
153 String varName = null;
154 String varValue = null;
156 ToolUtil.VariableDefinition varDef = ToolUtil.extractVariableTag(
158 varName = varDef.name;
159 varValue = varDef.argument;
161 variableForm.selectVariable(varName, varValue);
165 * Method updateRecursive.
167 * @param configuration
169 private void updateRecursive(ILaunchConfiguration configuration) {
170 boolean recursive = true;
172 recursive = configuration.getAttribute(
173 IExternalToolConstants.ATTR_REFRESH_RECURSIVE, false);
174 } catch (CoreException ce) {
178 ExternalToolsLaunchConfigurationMessages
179 .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
181 recursiveField.setSelection(recursive);
185 * Method updateRefresh.
187 * @param configuration
189 private void updateRefresh(ILaunchConfiguration configuration) {
192 scope = configuration.getAttribute(
193 IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
194 } catch (CoreException ce) {
198 ExternalToolsLaunchConfigurationMessages
199 .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
201 refreshField.setSelection(scope != null);
202 updateEnabledState();
206 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
208 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
210 if (refreshField.getSelection()) {
211 configuration.setAttribute(
212 IExternalToolConstants.ATTR_REFRESH_SCOPE, variableForm
213 .getSelectedVariable());
215 configuration.setAttribute(
216 IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
219 setAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE,
220 configuration, recursiveField.getSelection(), false);
224 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
226 public String getName() {
227 return ExternalToolsLaunchConfigurationMessages
228 .getString("ExternalToolsRefreshTab.Refres&h_6"); //$NON-NLS-1$
232 * Updates the enablement state of the fields.
234 protected void updateEnabledState() {
235 if (refreshField != null) {
236 if (recursiveField != null) {
237 recursiveField.setEnabled(refreshField.getSelection());
239 if (variableForm != null) {
240 variableForm.setEnabled(refreshField.getSelection());
246 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#convertHeightHint(int)
248 public int convertHeightHint(int chars) {
253 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setButtonGridData(org.eclipse.swt.widgets.Button)
255 public GridData setButtonGridData(Button button) {
260 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setMessage(java.lang.String,
263 public void setMessage(String newMessage, int newType) {
264 setMessage(newMessage);
268 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#updateValidState()
270 public void updateValidState() {
271 updateLaunchConfigurationDialog();
275 * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
277 public int getMessageType() {
278 if (getErrorMessage() != null) {
279 return IMessageProvider.ERROR;
280 } else if (getMessage() != null) {
281 return IMessageProvider.WARNING;
283 return IMessageProvider.NONE;
287 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
289 public Image getImage() {
290 return ExternalToolsImages
291 .getImage(IExternalToolConstants.IMG_ACTION_REFRESH);