Fix SourceLookupMessage constant.(SourceLookupMessages.DefaultSourceContainer_0 eclip...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / launchConfigurations / ExternalToolsRefreshTab.java
1 package net.sourceforge.phpdt.externaltools.launchConfigurations;
2
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  **********************************************************************/
9
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;
17
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;
31
32 public class ExternalToolsRefreshTab extends AbstractLaunchConfigurationTab
33                 implements IGroupDialogPage {
34
35         private ExternalToolVariableForm variableForm;
36
37         protected Button refreshField;
38
39         protected Button recursiveField;
40
41         /**
42          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
43          */
44         public void createControl(Composite parent) {
45                 Composite mainComposite = new Composite(parent, SWT.NONE);
46                 setControl(mainComposite);
47
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);
58         }
59
60         /**
61          * Creates the controls needed to edit the refresh recursive attribute of an
62          * external tool
63          * 
64          * @param parent
65          *            the composite to create the controls in
66          */
67         protected void createRecursiveComponent(Composite parent) {
68                 recursiveField = new Button(parent, SWT.CHECK);
69                 recursiveField
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();
78                         }
79                 });
80         }
81
82         /**
83          * Creates the controls needed to edit the refresh scope attribute of an
84          * external tool
85          * 
86          * @param parent
87          *            the composite to create the controls in
88          */
89         protected void createRefreshComponent(Composite parent) {
90                 refreshField = new Button(parent, SWT.CHECK);
91                 refreshField
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) {
99                                 updateEnabledState();
100                                 updateLaunchConfigurationDialog();
101                         }
102                 });
103         }
104
105         /**
106          * Creates the controls needed to edit the refresh scope variable attribute
107          * of an external tool
108          * 
109          * @param parent
110          *            the composite to create the controls in
111          */
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);
119         }
120
121         /**
122          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
123          */
124         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
125         }
126
127         /**
128          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
129          */
130         public void initializeFrom(ILaunchConfiguration configuration) {
131                 updateRefresh(configuration);
132                 updateRecursive(configuration);
133                 updateScope(configuration);
134         }
135
136         /**
137          * Method udpateScope.
138          * 
139          * @param configuration
140          */
141         private void updateScope(ILaunchConfiguration configuration) {
142                 String scope = null;
143                 try {
144                         scope = configuration.getAttribute(
145                                         IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
146                 } catch (CoreException ce) {
147                         ExternalToolsPlugin
148                                         .getDefault()
149                                         .log(
150                                                         ExternalToolsLaunchConfigurationMessages
151                                                                         .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
152                 }
153                 String varName = null;
154                 String varValue = null;
155                 if (scope != null) {
156                         ToolUtil.VariableDefinition varDef = ToolUtil.extractVariableTag(
157                                         scope, 0);
158                         varName = varDef.name;
159                         varValue = varDef.argument;
160                 }
161                 variableForm.selectVariable(varName, varValue);
162         }
163
164         /**
165          * Method updateRecursive.
166          * 
167          * @param configuration
168          */
169         private void updateRecursive(ILaunchConfiguration configuration) {
170                 boolean recursive = true;
171                 try {
172                         recursive = configuration.getAttribute(
173                                         IExternalToolConstants.ATTR_REFRESH_RECURSIVE, false);
174                 } catch (CoreException ce) {
175                         ExternalToolsPlugin
176                                         .getDefault()
177                                         .log(
178                                                         ExternalToolsLaunchConfigurationMessages
179                                                                         .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
180                 }
181                 recursiveField.setSelection(recursive);
182         }
183
184         /**
185          * Method updateRefresh.
186          * 
187          * @param configuration
188          */
189         private void updateRefresh(ILaunchConfiguration configuration) {
190                 String scope = null;
191                 try {
192                         scope = configuration.getAttribute(
193                                         IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
194                 } catch (CoreException ce) {
195                         ExternalToolsPlugin
196                                         .getDefault()
197                                         .log(
198                                                         ExternalToolsLaunchConfigurationMessages
199                                                                         .getString("ExternalToolsRefreshTab.Exception_reading_launch_configuration_3"), ce); //$NON-NLS-1$
200                 }
201                 refreshField.setSelection(scope != null);
202                 updateEnabledState();
203         }
204
205         /**
206          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
207          */
208         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
209
210                 if (refreshField.getSelection()) {
211                         configuration.setAttribute(
212                                         IExternalToolConstants.ATTR_REFRESH_SCOPE, variableForm
213                                                         .getSelectedVariable());
214                 } else {
215                         configuration.setAttribute(
216                                         IExternalToolConstants.ATTR_REFRESH_SCOPE, (String) null);
217                 }
218
219                 setAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE,
220                                 configuration, recursiveField.getSelection(), false);
221         }
222
223         /**
224          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
225          */
226         public String getName() {
227                 return ExternalToolsLaunchConfigurationMessages
228                                 .getString("ExternalToolsRefreshTab.Refres&h_6"); //$NON-NLS-1$
229         }
230
231         /**
232          * Updates the enablement state of the fields.
233          */
234         protected void updateEnabledState() {
235                 if (refreshField != null) {
236                         if (recursiveField != null) {
237                                 recursiveField.setEnabled(refreshField.getSelection());
238                         }
239                         if (variableForm != null) {
240                                 variableForm.setEnabled(refreshField.getSelection());
241                         }
242                 }
243         }
244
245         /**
246          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#convertHeightHint(int)
247          */
248         public int convertHeightHint(int chars) {
249                 return 0;
250         }
251
252         /**
253          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setButtonGridData(org.eclipse.swt.widgets.Button)
254          */
255         public GridData setButtonGridData(Button button) {
256                 return null;
257         }
258
259         /**
260          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setMessage(java.lang.String,
261          *      int)
262          */
263         public void setMessage(String newMessage, int newType) {
264                 setMessage(newMessage);
265         }
266
267         /**
268          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#updateValidState()
269          */
270         public void updateValidState() {
271                 updateLaunchConfigurationDialog();
272         }
273
274         /**
275          * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
276          */
277         public int getMessageType() {
278                 if (getErrorMessage() != null) {
279                         return IMessageProvider.ERROR;
280                 } else if (getMessage() != null) {
281                         return IMessageProvider.WARNING;
282                 }
283                 return IMessageProvider.NONE;
284         }
285
286         /**
287          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
288          */
289         public Image getImage() {
290                 return ExternalToolsImages
291                                 .getImage(IExternalToolConstants.IMG_ACTION_REFRESH);
292         }
293
294 }