2 * Created on 14.07.2004
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
7 package net.sourceforge.phpdt.internal.debug.ui.launcher;
9 import java.text.MessageFormat;
10 import java.util.Comparator;
11 import java.util.HashMap;
12 import java.util.Iterator;
14 import java.util.TreeMap;
16 //import net.sourceforge.phpdt.internal.debug.core.Environment;
18 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.debug.core.DebugPlugin;
24 import org.eclipse.debug.core.ILaunchConfiguration;
25 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26 import org.eclipse.debug.core.ILaunchManager;
27 import org.eclipse.debug.internal.ui.DebugPluginImages;
28 import org.eclipse.debug.internal.ui.DebugUIPlugin;
29 import org.eclipse.debug.internal.ui.DialogSettingsHelper;
30 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
31 import org.eclipse.debug.internal.ui.MultipleInputDialog;
32 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
33 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages;
34 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
35 import org.eclipse.debug.ui.IDebugUIConstants;
36 //import org.eclipse.debug.ui.EnvironmentTab.EnvironmentVariableContentProvider;
37 //import org.eclipse.debug.ui.EnvironmentTab.EnvironmentVariableLabelProvider;
38 //import org.eclipse.debug.ui.EnvironmentTab.NativeEnvironmentDialog;
39 import org.eclipse.jface.dialogs.Dialog;
40 import org.eclipse.jface.dialogs.IDialogSettings;
41 import org.eclipse.jface.dialogs.MessageDialog;
42 import org.eclipse.jface.viewers.ColumnLayoutData;
43 import org.eclipse.jface.viewers.ColumnWeightData;
44 import org.eclipse.jface.viewers.DoubleClickEvent;
45 import org.eclipse.jface.viewers.IDoubleClickListener;
46 import org.eclipse.jface.viewers.ILabelProvider;
47 import org.eclipse.jface.viewers.ILabelProviderListener;
48 import org.eclipse.jface.viewers.ISelectionChangedListener;
49 import org.eclipse.jface.viewers.IStructuredContentProvider;
50 import org.eclipse.jface.viewers.IStructuredSelection;
51 import org.eclipse.jface.viewers.ITableLabelProvider;
52 import org.eclipse.jface.viewers.LabelProvider;
53 import org.eclipse.jface.viewers.SelectionChangedEvent;
54 import org.eclipse.jface.viewers.TableLayout;
55 import org.eclipse.jface.viewers.TableViewer;
56 import org.eclipse.jface.viewers.Viewer;
57 import org.eclipse.jface.viewers.ViewerSorter;
58 import org.eclipse.jface.window.Window;
59 import org.eclipse.swt.SWT;
60 import org.eclipse.swt.events.SelectionAdapter;
61 import org.eclipse.swt.events.SelectionEvent;
62 import org.eclipse.swt.graphics.Font;
63 import org.eclipse.swt.graphics.Image;
64 import org.eclipse.swt.graphics.Point;
65 import org.eclipse.swt.layout.GridData;
66 import org.eclipse.swt.layout.GridLayout;
67 import org.eclipse.swt.widgets.Button;
68 import org.eclipse.swt.widgets.Composite;
69 import org.eclipse.swt.widgets.Label;
70 import org.eclipse.swt.widgets.Shell;
71 import org.eclipse.swt.widgets.Table;
72 import org.eclipse.swt.widgets.TableColumn;
73 import org.eclipse.swt.widgets.TableItem;
74 import org.eclipse.ui.dialogs.ListSelectionDialog;
75 import org.eclipse.ui.help.WorkbenchHelp;
80 * TODO To change the template for this generated type comment go to
81 * Window - Preferences - Java - Code Style - Code Templates
83 public class PHPEnvironmentTab2 extends AbstractLaunchConfigurationTab {
86 protected TableViewer environmentTable;
87 protected String[] envTableColumnHeaders =
89 LaunchConfigurationsMessages.getString("EnvironmentTab.Variable_1"), //$NON-NLS-1$
90 LaunchConfigurationsMessages.getString("EnvironmentTab.Value_2"), //$NON-NLS-1$
92 protected ColumnLayoutData[] envTableColumnLayouts =
94 new ColumnWeightData(50),
95 new ColumnWeightData(50)
97 private static final String NAME_LABEL= LaunchConfigurationsMessages.getString("EnvironmentTab.8"); //$NON-NLS-1$
98 private static final String VALUE_LABEL= LaunchConfigurationsMessages.getString("EnvironmentTab.9"); //$NON-NLS-1$
99 protected static final String P_VARIABLE = "variable"; //$NON-NLS-1$
100 protected static final String P_VALUE = "value"; //$NON-NLS-1$
101 protected static String[] envTableColumnProperties =
106 protected Button envAddButton;
107 protected Button envAddCGIButton;
108 protected Button envEditButton;
109 protected Button envRemoveButton;
110 protected Button appendEnvironment;
111 protected Button replaceEnvironment;
112 protected Button envSelectButton;
115 * Content provider for the environment table
117 protected class EnvironmentVariableContentProvider implements IStructuredContentProvider {
118 public Object[] getElements(Object inputElement) {
119 EnvironmentVariable[] elements = new EnvironmentVariable[0];
120 ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
123 m = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
124 } catch (CoreException e) {
125 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Error reading configuration", e)); //$NON-NLS-1$
128 if (m != null && !m.isEmpty()) {
129 elements = new EnvironmentVariable[m.size()];
130 String[] varNames = new String[m.size()];
131 m.keySet().toArray(varNames);
132 for (int i = 0; i < m.size(); i++) {
133 elements[i] = new EnvironmentVariable(varNames[i], (String) m.get(varNames[i]));
138 public void dispose() {
140 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
141 if (newInput == null){
144 if (viewer instanceof TableViewer){
145 TableViewer tableViewer= (TableViewer) viewer;
146 if (tableViewer.getTable().isDisposed()) {
149 tableViewer.setSorter(new ViewerSorter() {
150 public int compare(Viewer iviewer, Object e1, Object e2) {
153 } else if (e2 == null) {
156 return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
165 * Label provider for the environment table
167 public class EnvironmentVariableLabelProvider extends LabelProvider implements ITableLabelProvider {
168 public String getColumnText(Object element, int columnIndex) {
169 String result = null;
170 if (element != null) {
171 EnvironmentVariable var = (EnvironmentVariable) element;
172 switch (columnIndex) {
174 result = var.getName();
177 result = var.getValue();
183 public Image getColumnImage(Object element, int columnIndex) {
189 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
191 public void createControl(Composite parent) {
192 // Create main composite
193 Composite mainComposite = new Composite(parent, SWT.NONE);
194 setControl(mainComposite);
195 WorkbenchHelp.setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
196 GridLayout layout = new GridLayout();
197 layout.numColumns = 2;
198 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
199 mainComposite.setLayout(layout);
200 mainComposite.setLayoutData(gridData);
201 mainComposite.setFont(parent.getFont());
203 createEnvironmentTable(mainComposite);
204 createTableButtons(mainComposite);
205 createAppendReplace(mainComposite);
207 Dialog.applyDialogFont(mainComposite);
211 * Creates and configures the widgets which allow the user to
212 * choose whether the specified environment should be appended
213 * to the native environment or if it should completely replace it.
214 * @param parent the composite in which the widgets should be created
216 protected void createAppendReplace(Composite parent) {
217 Composite appendReplaceComposite= new Composite(parent, SWT.NONE);
218 GridData gridData= new GridData();
219 gridData.horizontalSpan= 2;
220 GridLayout layout= new GridLayout();
221 appendReplaceComposite.setLayoutData(gridData);
222 appendReplaceComposite.setLayout(layout);
223 appendReplaceComposite.setFont(parent.getFont());
225 appendEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.16")); //$NON-NLS-1$
226 appendEnvironment.addSelectionListener(new SelectionAdapter() {
227 public void widgetSelected(SelectionEvent e) {
228 updateLaunchConfigurationDialog();
231 replaceEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.17")); //$NON-NLS-1$
235 * Updates the enablement of the append/replace widgets. The
236 * widgets should disable when there are no environment variables specified.
238 protected void updateAppendReplace() {
239 boolean enable= environmentTable.getTable().getItemCount() > 0;
240 appendEnvironment.setEnabled(enable);
241 replaceEnvironment.setEnabled(enable);
245 * Creates and configures the table that displayed the key/value
246 * pairs that comprise the environment.
247 * @param parent the composite in which the table should be created
249 protected void createEnvironmentTable(Composite parent) {
250 Font font= parent.getFont();
251 // Create table composite
252 Composite tableComposite = new Composite(parent, SWT.NONE);
253 GridLayout layout = new GridLayout();
254 layout.marginHeight = 0;
255 layout.marginWidth = 0;
256 layout.numColumns = 1;
257 GridData gridData = new GridData(GridData.FILL_BOTH);
258 gridData.heightHint = 150;
259 tableComposite.setLayout(layout);
260 tableComposite.setLayoutData(gridData);
261 tableComposite.setFont(font);
263 Label label = new Label(tableComposite, SWT.NONE);
265 label.setText(LaunchConfigurationsMessages.getString("EnvironmentTab.Environment_variables_to_set__3")); //$NON-NLS-1$
267 environmentTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
268 Table table = environmentTable.getTable();
269 TableLayout tableLayout = new TableLayout();
270 table.setLayout(tableLayout);
271 table.setHeaderVisible(true);
273 gridData = new GridData(GridData.FILL_BOTH);
274 environmentTable.getControl().setLayoutData(gridData);
275 environmentTable.setContentProvider(new EnvironmentVariableContentProvider());
276 environmentTable.setLabelProvider(new EnvironmentVariableLabelProvider());
277 environmentTable.setColumnProperties(envTableColumnProperties);
278 environmentTable.addSelectionChangedListener(new ISelectionChangedListener() {
279 public void selectionChanged(SelectionChangedEvent event) {
280 handleTableSelectionChanged(event);
283 environmentTable.addDoubleClickListener(new IDoubleClickListener() {
284 public void doubleClick(DoubleClickEvent event) {
285 if (!environmentTable.getSelection().isEmpty()) {
286 handleEnvEditButtonSelected();
291 for (int i = 0; i < envTableColumnHeaders.length; i++) {
292 tableLayout.addColumnData(envTableColumnLayouts[i]);
293 TableColumn tc = new TableColumn(table, SWT.NONE, i);
294 tc.setResizable(envTableColumnLayouts[i].resizable);
295 tc.setText(envTableColumnHeaders[i]);
300 * Responds to a selection changed event in the environment table
301 * @param event the selection change event
303 protected void handleTableSelectionChanged(SelectionChangedEvent event) {
304 int size = ((IStructuredSelection)event.getSelection()).size();
305 envEditButton.setEnabled(size == 1);
306 envRemoveButton.setEnabled(size > 0);
310 * Creates the add/edit/remove buttons for the environment table
311 * @param parent the composite in which the buttons should be created
313 protected void createTableButtons(Composite parent) {
314 // Create button composite
315 Composite buttonComposite = new Composite(parent, SWT.NONE);
316 GridLayout glayout = new GridLayout();
317 glayout.marginHeight = 0;
318 glayout.marginWidth = 0;
319 glayout.numColumns = 1;
320 GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
321 buttonComposite.setLayout(glayout);
322 buttonComposite.setLayoutData(gdata);
323 buttonComposite.setFont(parent.getFont());
325 createVerticalSpacer(buttonComposite, 1);
327 envAddButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.New_4"), null); //$NON-NLS-1$
328 envAddButton.addSelectionListener(new SelectionAdapter()
330 public void widgetSelected(SelectionEvent event) {
331 handleEnvAddButtonSelected();
334 envAddCGIButton = createPushButton(buttonComposite, PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment2.CGIButton"), null); //$NON-NLS-1$
335 envAddCGIButton.addSelectionListener(new SelectionAdapter() {
336 public void widgetSelected(SelectionEvent event) {
337 handleEnvAddCGIButtonSelected();
341 envSelectButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.18"), null); //$NON-NLS-1$
342 envSelectButton.addSelectionListener(new SelectionAdapter() {
343 public void widgetSelected(SelectionEvent event) {
344 handleEnvSelectButtonSelected();
347 envEditButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.Edit_5"), null); //$NON-NLS-1$
348 envEditButton.addSelectionListener(new SelectionAdapter()
350 public void widgetSelected(SelectionEvent event) {
351 handleEnvEditButtonSelected();
354 envEditButton.setEnabled(false);
355 envRemoveButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.getString("EnvironmentTab.Remove_6"), null); //$NON-NLS-1$
356 envRemoveButton.addSelectionListener(new SelectionAdapter()
358 public void widgetSelected(SelectionEvent event) {
359 handleEnvRemoveButtonSelected();
362 envRemoveButton.setEnabled(false);
366 * Adds a new environment variable to the table.
368 protected void handleEnvAddButtonSelected() {
369 MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.getString("EnvironmentTab.22")); //$NON-NLS-1$
370 dialog.addTextField(NAME_LABEL, null, false);
371 dialog.addVariablesField(VALUE_LABEL, null, true);
373 if (dialog.open() != Window.OK) {
377 String name = dialog.getStringValue(NAME_LABEL);
378 String value = dialog.getStringValue(VALUE_LABEL);
380 if (name != null && value != null && name.length() > 0 && value.length() >0) {
381 addVariable(new EnvironmentVariable(name.trim(), value.trim()));
382 updateAppendReplace();
387 * Attempts to add the given variable. Returns whether the variable
388 * was added or not (as when the user answers not to overwrite an
389 * existing variable).
390 * @param variable the variable to add
391 * @return whether the variable was added
393 protected boolean addVariable(EnvironmentVariable variable) {
394 String name= variable.getName();
395 TableItem[] items = environmentTable.getTable().getItems();
396 for (int i = 0; i < items.length; i++) {
397 EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData();
398 if (existingVariable.getName().equals(name)) {
399 boolean overWrite= MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.getString("EnvironmentTab.12"), MessageFormat.format(LaunchConfigurationsMessages.getString("EnvironmentTab.13"), new String[] {name})); //$NON-NLS-1$ //$NON-NLS-2$
403 environmentTable.remove(existingVariable);
407 environmentTable.add(variable);
408 updateLaunchConfigurationDialog();
413 * Displays a dialog that allows user to select native environment variables
414 * to add to the table.
416 private void handleEnvSelectButtonSelected() {
417 //get Environment Variables from the OS
418 Map envVariables = getNativeEnvironment();
420 //get Environment Variables from the table
421 TableItem[] items = environmentTable.getTable().getItems();
422 for (int i = 0; i < items.length; i++) {
423 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
424 envVariables.remove(var.getName());
427 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.getString("EnvironmentTab.19")); //$NON-NLS-1$
428 dialog.setTitle(LaunchConfigurationsMessages.getString("EnvironmentTab.20")); //$NON-NLS-1$
430 int button = dialog.open();
431 if (button == Window.OK) {
432 Object[] selected = dialog.getResult();
433 for (int i = 0; i < selected.length; i++) {
434 environmentTable.add(selected[i]);
438 updateAppendReplace();
439 updateLaunchConfigurationDialog();
443 * Displays a dialog that allows user to select native environment variables
444 * to add to the table.
446 private void handleEnvAddCGIButtonSelected() {
448 Map envVariables = new HashMap();
451 envVariables.put("HTTP_COOKIE",new EnvironmentVariable("HTTP_COOKIE", "TestCookie=1"));
452 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING", ""));
453 envVariables.put("REDIRECT_STATUS",new EnvironmentVariable("REDIRECT_STATUS", "200"));
454 envVariables.put("REDIRECT_URL",new EnvironmentVariable("REDIRECT_URL", ""));
455 envVariables.put("SERVER_SOFTWARE",new EnvironmentVariable("SERVER_SOFTWARE","DBG / 2.1"));
456 envVariables.put("SERVER_NAME",new EnvironmentVariable("SERVER_NAME","localhost"));
457 envVariables.put("SERVER_ADDR",new EnvironmentVariable("SERVER_ADDR","127.0.0.1"));
458 envVariables.put("SERVER_PORT",new EnvironmentVariable("SERVER_PORT","80"));
459 envVariables.put("REMOTE_ADDR",new EnvironmentVariable("REMOTE_ADDR","127.0.0.1"));
460 envVariables.put("GATEWAY_INTERFACE",new EnvironmentVariable("GATEWAY_INTERFACE","CGI / 1.1"));
461 envVariables.put("SERVER_PROTOCOL",new EnvironmentVariable("SERVER_PROTOCOL","HTTP / 1.1"));
462 envVariables.put("REQUEST_METHOD",new EnvironmentVariable("REQUEST_METHOD","GET"));
463 envVariables.put("QUERY_STRING",new EnvironmentVariable("QUERY_STRING",""));
464 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING",""));
465 // envVariables.put("REQUEST_URI" + OSFilePath;
466 // envVariables.put("PATH_INFO=" + OSFilePath;
467 // envVariables.put("PATH_TRANSLATED=" + OSFilePath;
470 //get Environment Variables from the table
471 TableItem[] items = environmentTable.getTable().getItems();
472 for (int i = 0; i < items.length; i++) {
473 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
474 envVariables.remove(var.getName());
477 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.getString("EnvironmentTab.19")); //$NON-NLS-1$
478 dialog.setTitle(LaunchConfigurationsMessages.getString("EnvironmentTab.20")); //$NON-NLS-1$
480 int button = dialog.open();
481 if (button == Window.OK) {
482 Object[] selected = dialog.getResult();
483 for (int i = 0; i < selected.length; i++) {
484 environmentTable.add(selected[i]);
488 updateAppendReplace();
489 updateLaunchConfigurationDialog();
494 * Creates a label provider for the native native environment variable selection dialog.
495 * @return A label provider for the native native environment variable selection dialog.
497 private ILabelProvider createSelectionDialogLabelProvider() {
498 return new ILabelProvider() {
499 public Image getImage(Object element) {
502 public String getText(Object element) {
503 EnvironmentVariable var = (EnvironmentVariable) element;
504 return var.getName() + " [" + var.getValue() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
506 public void addListener(ILabelProviderListener listener) {
508 public void dispose() {
510 public boolean isLabelProperty(Object element, String property) {
513 public void removeListener(ILabelProviderListener listener) {
519 * Creates a content provider for the native native environment variable selection dialog.
520 * @return A content provider for the native native environment variable selection dialog.
522 private IStructuredContentProvider createSelectionDialogContentProvider() {
523 return new IStructuredContentProvider() {
524 public Object[] getElements(Object inputElement) {
525 EnvironmentVariable[] elements = null;
526 if (inputElement instanceof HashMap) {
527 Comparator comparator = new Comparator() {
528 public int compare(Object o1, Object o2) {
529 String s1 = (String)o1;
530 String s2 = (String)o2;
531 return s1.compareTo(s2);
535 TreeMap envVars = new TreeMap(comparator);
536 envVars.putAll((Map)inputElement);
537 elements = new EnvironmentVariable[envVars.size()];
539 for (Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); index++) {
540 Object key = iterator.next();
541 elements[index] = (EnvironmentVariable) envVars.get(key);
546 public void dispose() {
548 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
554 * Gets native environment variable from the LaunchManager. Creates EnvironmentVariable objects.
555 * @return Map of name - EnvironmentVariable pairs based on native environment.
557 private Map getNativeEnvironment() {
558 Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
559 HashMap vars = new HashMap();
560 for (Iterator i = stringVars.keySet().iterator(); i.hasNext(); ) {
561 String key = (String) i.next();
562 String value = (String) stringVars.get(key);
563 vars.put(key, new EnvironmentVariable(key, value));
569 * Creates an editor for the value of the selected environment variable.
571 private void handleEnvEditButtonSelected() {
572 IStructuredSelection sel= (IStructuredSelection) environmentTable.getSelection();
573 EnvironmentVariable var= (EnvironmentVariable) sel.getFirstElement();
577 String originalName= var.getName();
578 String value= var.getValue();
579 MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.getString("EnvironmentTab.11")); //$NON-NLS-1$
580 dialog.addTextField(NAME_LABEL, originalName, false);
581 dialog.addVariablesField(VALUE_LABEL, value, true);
583 if (dialog.open() != Window.OK) {
586 String name= dialog.getStringValue(NAME_LABEL);
587 value= dialog.getStringValue(VALUE_LABEL);
588 if (!originalName.equals(name)) {
589 if (addVariable(new EnvironmentVariable(name, value))) {
590 environmentTable.remove(var);
594 environmentTable.update(var, null);
595 updateLaunchConfigurationDialog();
600 * Removes the selected environment variable from the table.
602 private void handleEnvRemoveButtonSelected() {
603 IStructuredSelection sel = (IStructuredSelection) environmentTable.getSelection();
604 environmentTable.getControl().setRedraw(false);
605 for (Iterator i = sel.iterator(); i.hasNext(); ) {
606 EnvironmentVariable var = (EnvironmentVariable) i.next();
607 environmentTable.remove(var);
609 environmentTable.getControl().setRedraw(true);
610 updateAppendReplace();
611 updateLaunchConfigurationDialog();
615 * Updates the environment table for the given launch configuration
616 * @param configuration
618 protected void updateEnvironment(ILaunchConfiguration configuration) {
619 environmentTable.setInput(configuration);
623 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
625 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
629 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
631 public void initializeFrom(ILaunchConfiguration configuration) {
632 boolean append= true;
634 append = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
635 } catch (CoreException e) {
636 DebugUIPlugin.log(e.getStatus());
639 appendEnvironment.setSelection(true);
640 replaceEnvironment.setSelection(false);
642 replaceEnvironment.setSelection(true);
643 appendEnvironment.setSelection(false);
645 updateEnvironment(configuration);
646 updateAppendReplace();
650 * Stores the environment in the given configuration
651 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
653 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
654 // Convert the table's items into a Map so that this can be saved in the
655 // configuration's attributes.
656 TableItem[] items = environmentTable.getTable().getItems();
657 Map map = new HashMap(items.length);
658 for (int i = 0; i < items.length; i++)
660 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
661 map.put(var.getName(), var.getValue());
663 if (map.size() == 0) {
664 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
666 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
668 configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, appendEnvironment.getSelection());
672 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
674 public String getName() {
675 return LaunchConfigurationsMessages.getString("EnvironmentTab.Environment_7"); //$NON-NLS-1$
679 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
681 public Image getImage() {
682 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
686 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
688 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
689 // do nothing when activated
693 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
695 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
696 // do nothing when deactivated
699 private class NativeEnvironmentDialog extends ListSelectionDialog {
700 public NativeEnvironmentDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String message) {
701 super(parentShell, input, contentProvider, labelProvider, message);
702 setShellStyle(getShellStyle() | SWT.RESIZE);
705 protected IDialogSettings getDialogSettings() {
706 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
707 IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
708 if (section == null) {
709 section = settings.addNewSection(getDialogSettingsSectionName());
715 * Returns the name of the section that this dialog stores its settings in
719 protected String getDialogSettingsSectionName() {
720 return IDebugUIConstants.PLUGIN_ID + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$
725 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
727 protected Point getInitialLocation(Point initialSize) {
728 Point initialLocation= DialogSettingsHelper.getInitialLocation(getDialogSettingsSectionName());
729 if (initialLocation != null) {
730 return initialLocation;
732 return super.getInitialLocation(initialSize);
736 * @see org.eclipse.jface.window.Window#getInitialSize()
738 protected Point getInitialSize() {
739 Point size = super.getInitialSize();
740 return DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), size);
744 * @see org.eclipse.jface.window.Window#close()
746 public boolean close() {
747 DialogSettingsHelper.persistShellGeometry(getShell(), getDialogSettingsSectionName());
748 return super.close();