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 org.eclipse.core.runtime.CoreException;
11 import org.eclipse.debug.core.ILaunchConfiguration;
12 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
13 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
14 import org.eclipse.jface.dialogs.IMessageProvider;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import net.sourceforge.phpdt.externaltools.group.IGroupDialogPage;
24 import net.sourceforge.phpdt.externaltools.internal.dialog.ExternalToolVariableForm;
25 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
26 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
27 import net.sourceforge.phpdt.externaltools.internal.registry.ExternalToolVariable;
28 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
29 import net.sourceforge.phpdt.externaltools.model.ToolUtil;
31 public class ExternalToolsRefreshTab extends AbstractLaunchConfigurationTab implements IGroupDialogPage {
33 private ExternalToolVariableForm variableForm;
35 protected Button refreshField;
36 protected Button recursiveField;
39 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
41 public void createControl(Composite parent) {
42 Composite mainComposite = new Composite(parent, SWT.NONE);
43 setControl(mainComposite);
45 GridLayout layout = new GridLayout();
46 layout.numColumns = 1;
47 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
48 mainComposite.setLayout(layout);
49 mainComposite.setLayoutData(gridData);
50 mainComposite.setFont(parent.getFont());
51 createVerticalSpacer(mainComposite, 1);
52 createRefreshComponent(mainComposite);
53 createRecursiveComponent(mainComposite);
54 createScopeComponent(mainComposite);
58 * Creates the controls needed to edit the refresh recursive
59 * attribute of an external tool
61 * @param parent the composite to create the controls in
63 protected void createRecursiveComponent(Composite parent) {
64 recursiveField = new Button(parent, SWT.CHECK);
65 recursiveField.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Recursively_&include_sub-folders_1")); //$NON-NLS-1$
66 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
67 recursiveField.setLayoutData(data);
68 recursiveField.setFont(parent.getFont());
69 recursiveField.addSelectionListener(new SelectionAdapter() {
70 public void widgetSelected(SelectionEvent e) {
71 updateLaunchConfigurationDialog();
77 * Creates the controls needed to edit the refresh scope
78 * attribute of an external tool
80 * @param parent the composite to create the controls in
82 protected void createRefreshComponent(Composite parent) {
83 refreshField = new Button(parent, SWT.CHECK);
84 refreshField.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.&Refresh_resources_after_running_tool_1")); //$NON-NLS-1$
85 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
86 refreshField.setLayoutData(data);
87 refreshField.setFont(parent.getFont());
88 refreshField.addSelectionListener(new SelectionAdapter() {
89 public void widgetSelected(SelectionEvent e) {
91 updateLaunchConfigurationDialog();
97 * Creates the controls needed to edit the refresh scope variable
98 * attribute of an external tool
100 * @param parent the composite to create the controls in
102 protected void createScopeComponent(Composite parent) {
103 String label = ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Choose_scope_v&ariable___2"); //$NON-NLS-1$
104 ExternalToolVariable[] vars = ExternalToolsPlugin.getDefault().getRefreshVariableRegistry().getRefreshVariables();
105 variableForm = new ExternalToolVariableForm(label, vars);
106 variableForm.createContents(parent, this);
111 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
113 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
117 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
119 public void initializeFrom(ILaunchConfiguration configuration) {
120 updateRefresh(configuration);
121 updateRecursive(configuration);
122 updateScope(configuration);
125 * Method udpateScope.
126 * @param configuration
128 private void updateScope(ILaunchConfiguration configuration) {
131 scope= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
132 } catch (CoreException ce) {
133 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
135 String varName = null;
136 String varValue = null;
138 ToolUtil.VariableDefinition varDef = ToolUtil.extractVariableTag(scope, 0);
139 varName = varDef.name;
140 varValue = varDef.argument;
142 variableForm.selectVariable(varName, varValue);
145 * Method updateRecursive.
146 * @param configuration
148 private void updateRecursive(ILaunchConfiguration configuration) {
149 boolean recursive= true;
151 recursive= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE, false);
152 } catch (CoreException ce) {
153 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
155 recursiveField.setSelection(recursive);
158 * Method updateRefresh.
159 * @param configuration
161 private void updateRefresh(ILaunchConfiguration configuration) {
164 scope= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
165 } catch (CoreException ce) {
166 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
168 refreshField.setSelection(scope != null);
169 updateEnabledState();
173 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
175 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
177 if (refreshField.getSelection()) {
178 configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, variableForm.getSelectedVariable());
180 configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
183 setAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE, configuration, recursiveField.getSelection(), false);
187 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
189 public String getName() {
190 return ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Refres&h_6"); //$NON-NLS-1$
194 * Updates the enablement state of the fields.
196 protected void updateEnabledState() {
197 if (refreshField != null) {
198 if (recursiveField != null) {
199 recursiveField.setEnabled(refreshField.getSelection());
201 if (variableForm != null) {
202 variableForm.setEnabled(refreshField.getSelection());
207 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#convertHeightHint(int)
209 public int convertHeightHint(int chars) {
214 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setButtonGridData(org.eclipse.swt.widgets.Button)
216 public GridData setButtonGridData(Button button) {
221 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setMessage(java.lang.String, int)
223 public void setMessage(String newMessage, int newType) {
224 setMessage(newMessage);
228 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#updateValidState()
230 public void updateValidState() {
231 updateLaunchConfigurationDialog();
235 * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
237 public int getMessageType() {
238 if (getErrorMessage() != null) {
239 return IMessageProvider.ERROR;
240 } else if (getMessage() != null) {
241 return IMessageProvider.WARNING;
243 return IMessageProvider.NONE;
246 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
248 public Image getImage() {
249 return ExternalToolsImages.getImage(IExternalToolConstants.IMG_ACTION_REFRESH);