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.model.ExternalToolsPlugin;
14 import net.sourceforge.phpdt.externaltools.internal.registry.ExternalToolVariable;
15 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
16 import net.sourceforge.phpdt.externaltools.model.ToolUtil;
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 implements IGroupDialogPage {
34 private ExternalToolVariableForm variableForm;
36 protected Button refreshField;
37 protected Button recursiveField;
40 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
42 public void createControl(Composite parent) {
43 Composite mainComposite = new Composite(parent, SWT.NONE);
44 setControl(mainComposite);
46 GridLayout layout = new GridLayout();
47 layout.numColumns = 1;
48 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
49 mainComposite.setLayout(layout);
50 mainComposite.setLayoutData(gridData);
51 mainComposite.setFont(parent.getFont());
52 createVerticalSpacer(mainComposite, 1);
53 createRefreshComponent(mainComposite);
54 createRecursiveComponent(mainComposite);
55 createScopeComponent(mainComposite);
59 * Creates the controls needed to edit the refresh recursive
60 * attribute of an external tool
62 * @param parent the composite to create the controls in
64 protected void createRecursiveComponent(Composite parent) {
65 recursiveField = new Button(parent, SWT.CHECK);
66 recursiveField.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Recursively_&include_sub-folders_1")); //$NON-NLS-1$
67 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
68 recursiveField.setLayoutData(data);
69 recursiveField.setFont(parent.getFont());
70 recursiveField.addSelectionListener(new SelectionAdapter() {
71 public void widgetSelected(SelectionEvent e) {
72 updateLaunchConfigurationDialog();
78 * Creates the controls needed to edit the refresh scope
79 * attribute of an external tool
81 * @param parent the composite to create the controls in
83 protected void createRefreshComponent(Composite parent) {
84 refreshField = new Button(parent, SWT.CHECK);
85 refreshField.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.&Refresh_resources_after_running_tool_1")); //$NON-NLS-1$
86 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
87 refreshField.setLayoutData(data);
88 refreshField.setFont(parent.getFont());
89 refreshField.addSelectionListener(new SelectionAdapter() {
90 public void widgetSelected(SelectionEvent e) {
92 updateLaunchConfigurationDialog();
98 * Creates the controls needed to edit the refresh scope variable
99 * attribute of an external tool
101 * @param parent the composite to create the controls in
103 protected void createScopeComponent(Composite parent) {
104 String label = ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Choose_scope_v&ariable___2"); //$NON-NLS-1$
105 ExternalToolVariable[] vars = ExternalToolsPlugin.getDefault().getRefreshVariableRegistry().getRefreshVariables();
106 variableForm = new ExternalToolVariableForm(label, vars);
107 variableForm.createContents(parent, this);
112 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
114 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
118 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
120 public void initializeFrom(ILaunchConfiguration configuration) {
121 updateRefresh(configuration);
122 updateRecursive(configuration);
123 updateScope(configuration);
126 * Method udpateScope.
127 * @param configuration
129 private void updateScope(ILaunchConfiguration configuration) {
132 scope= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
133 } catch (CoreException ce) {
134 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
136 String varName = null;
137 String varValue = null;
139 ToolUtil.VariableDefinition varDef = ToolUtil.extractVariableTag(scope, 0);
140 varName = varDef.name;
141 varValue = varDef.argument;
143 variableForm.selectVariable(varName, varValue);
146 * Method updateRecursive.
147 * @param configuration
149 private void updateRecursive(ILaunchConfiguration configuration) {
150 boolean recursive= true;
152 recursive= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE, false);
153 } catch (CoreException ce) {
154 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
156 recursiveField.setSelection(recursive);
159 * Method updateRefresh.
160 * @param configuration
162 private void updateRefresh(ILaunchConfiguration configuration) {
165 scope= configuration.getAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
166 } catch (CoreException ce) {
167 ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
169 refreshField.setSelection(scope != null);
170 updateEnabledState();
174 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
176 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
178 if (refreshField.getSelection()) {
179 configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, variableForm.getSelectedVariable());
181 configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
184 setAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE, configuration, recursiveField.getSelection(), false);
188 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
190 public String getName() {
191 return ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Refres&h_6"); //$NON-NLS-1$
195 * Updates the enablement state of the fields.
197 protected void updateEnabledState() {
198 if (refreshField != null) {
199 if (recursiveField != null) {
200 recursiveField.setEnabled(refreshField.getSelection());
202 if (variableForm != null) {
203 variableForm.setEnabled(refreshField.getSelection());
208 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#convertHeightHint(int)
210 public int convertHeightHint(int chars) {
215 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setButtonGridData(org.eclipse.swt.widgets.Button)
217 public GridData setButtonGridData(Button button) {
222 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setMessage(java.lang.String, int)
224 public void setMessage(String newMessage, int newType) {
225 setMessage(newMessage);
229 * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#updateValidState()
231 public void updateValidState() {
232 updateLaunchConfigurationDialog();
236 * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
238 public int getMessageType() {
239 if (getErrorMessage() != null) {
240 return IMessageProvider.ERROR;
241 } else if (getMessage() != null) {
242 return IMessageProvider.WARNING;
244 return IMessageProvider.NONE;
247 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
249 public Image getImage() {
250 return ExternalToolsImages.getImage(IExternalToolConstants.IMG_ACTION_REFRESH);