Call WIN_32 CHM files for "function help"
[phpeclipse.git] / net.sourceforge.phpeclipse / 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 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;
30
31 public class ExternalToolsRefreshTab extends AbstractLaunchConfigurationTab implements IGroupDialogPage {
32
33         private ExternalToolVariableForm variableForm;
34         
35         protected Button refreshField;
36         protected Button recursiveField;
37         
38         /**
39          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
40          */
41         public void createControl(Composite parent) {
42                 Composite mainComposite = new Composite(parent, SWT.NONE);
43                 setControl(mainComposite);
44                 
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);
55         }
56         
57         /**
58          * Creates the controls needed to edit the refresh recursive
59          * attribute of an external tool
60          * 
61          * @param parent the composite to create the controls in
62          */
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();
72                         }
73                 });
74         }
75         
76         /**
77          * Creates the controls needed to edit the refresh scope
78          * attribute of an external tool
79          * 
80          * @param parent the composite to create the controls in
81          */
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) {
90                                 updateEnabledState();
91                                 updateLaunchConfigurationDialog();
92                         }
93                 });
94         }
95         
96         /**
97          * Creates the controls needed to edit the refresh scope variable
98          * attribute of an external tool
99          * 
100          * @param parent the composite to create the controls in
101          */
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);
107         }
108         
109
110         /**
111          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
112          */
113         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
114         }
115
116         /**
117          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
118          */
119         public void initializeFrom(ILaunchConfiguration configuration) {
120                 updateRefresh(configuration);
121                 updateRecursive(configuration);
122                 updateScope(configuration);
123         }
124         /**
125          * Method udpateScope.
126          * @param configuration
127          */
128         private void updateScope(ILaunchConfiguration configuration) {
129                 String scope = null;
130                 try {
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$
134                 }
135                 String varName = null;
136                 String varValue = null;
137                 if (scope != null) {
138                         ToolUtil.VariableDefinition varDef = ToolUtil.extractVariableTag(scope, 0);
139                         varName = varDef.name;
140                         varValue = varDef.argument;
141                 }
142                 variableForm.selectVariable(varName, varValue);
143         }
144         /**
145          * Method updateRecursive.
146          * @param configuration
147          */
148         private void updateRecursive(ILaunchConfiguration configuration) {
149                 boolean recursive= true;
150                 try {
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$
154                 }
155                 recursiveField.setSelection(recursive);
156         }
157         /**
158          * Method updateRefresh.
159          * @param configuration
160          */
161         private void updateRefresh(ILaunchConfiguration configuration) {
162                 String scope= null;
163                 try {
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$
167                 }
168                 refreshField.setSelection(scope != null);
169                 updateEnabledState();           
170         }
171
172         /**
173          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
174          */
175         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
176
177                 if (refreshField.getSelection()) {
178                         configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, variableForm.getSelectedVariable());
179                 } else {
180                         configuration.setAttribute(IExternalToolConstants.ATTR_REFRESH_SCOPE, (String)null);
181                 }
182                 
183                 setAttribute(IExternalToolConstants.ATTR_REFRESH_RECURSIVE, configuration, recursiveField.getSelection(), false);
184         }
185
186         /**
187          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
188          */
189         public String getName() {
190                 return ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsRefreshTab.Refres&h_6"); //$NON-NLS-1$
191         }
192         
193         /**
194          * Updates the enablement state of the fields.
195          */
196         protected void updateEnabledState() {
197                 if (refreshField != null) {
198                         if (recursiveField != null) {
199                                 recursiveField.setEnabled(refreshField.getSelection());
200                         }
201                         if (variableForm != null) {
202                                 variableForm.setEnabled(refreshField.getSelection());
203                         }
204                 }
205         }
206         /**
207          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#convertHeightHint(int)
208          */
209         public int convertHeightHint(int chars) {
210                 return 0;
211         }
212
213         /**
214          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setButtonGridData(org.eclipse.swt.widgets.Button)
215          */
216         public GridData setButtonGridData(Button button) {
217                 return null;
218         }
219
220         /**
221          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#setMessage(java.lang.String, int)
222          */
223         public void setMessage(String newMessage, int newType) {
224                 setMessage(newMessage);
225         }
226
227         /**
228          * @see net.sourceforge.phpdt.externaltools.group.IGroupDialogPage#updateValidState()
229          */
230         public void updateValidState() {
231                 updateLaunchConfigurationDialog();
232         }
233
234         /**
235          * @see org.eclipse.jface.dialogs.IMessageProvider#getMessageType()
236          */
237         public int getMessageType() {
238                 if (getErrorMessage() != null) {
239                         return IMessageProvider.ERROR;
240                 } else if (getMessage() != null) {
241                         return IMessageProvider.WARNING;
242                 }
243                 return IMessageProvider.NONE;
244         }
245         /**
246          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
247          */
248         public Image getImage() {
249                 return ExternalToolsImages.getImage(IExternalToolConstants.IMG_ACTION_REFRESH);
250         }
251
252 }