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.ui.PHPDebugUiMessages;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.debug.core.DebugPlugin;
22 import org.eclipse.debug.core.ILaunchConfiguration;
23 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24 import org.eclipse.debug.core.ILaunchManager;
25 import org.eclipse.debug.internal.ui.DebugPluginImages;
26 import org.eclipse.debug.internal.ui.DebugUIPlugin;
27 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
28 import org.eclipse.debug.internal.ui.MultipleInputDialog;
29 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
30 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages;
31 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
32 import org.eclipse.debug.ui.IDebugUIConstants;
33 import org.eclipse.jface.dialogs.Dialog;
34 import org.eclipse.jface.dialogs.IDialogSettings;
35 import org.eclipse.jface.dialogs.MessageDialog;
36 import org.eclipse.jface.viewers.ColumnLayoutData;
37 import org.eclipse.jface.viewers.ColumnWeightData;
38 import org.eclipse.jface.viewers.DoubleClickEvent;
39 import org.eclipse.jface.viewers.IDoubleClickListener;
40 import org.eclipse.jface.viewers.ILabelProvider;
41 import org.eclipse.jface.viewers.ILabelProviderListener;
42 import org.eclipse.jface.viewers.ISelectionChangedListener;
43 import org.eclipse.jface.viewers.IStructuredContentProvider;
44 import org.eclipse.jface.viewers.IStructuredSelection;
45 import org.eclipse.jface.viewers.ITableLabelProvider;
46 import org.eclipse.jface.viewers.LabelProvider;
47 import org.eclipse.jface.viewers.SelectionChangedEvent;
48 import org.eclipse.jface.viewers.TableLayout;
49 import org.eclipse.jface.viewers.TableViewer;
50 import org.eclipse.jface.viewers.Viewer;
51 import org.eclipse.jface.viewers.ViewerSorter;
52 import org.eclipse.jface.window.Window;
53 import org.eclipse.swt.SWT;
54 import org.eclipse.swt.events.SelectionAdapter;
55 import org.eclipse.swt.events.SelectionEvent;
56 import org.eclipse.swt.graphics.Font;
57 import org.eclipse.swt.graphics.Image;
58 import org.eclipse.swt.layout.GridData;
59 import org.eclipse.swt.layout.GridLayout;
60 import org.eclipse.swt.widgets.Button;
61 import org.eclipse.swt.widgets.Composite;
62 import org.eclipse.swt.widgets.Label;
63 import org.eclipse.swt.widgets.Shell;
64 import org.eclipse.swt.widgets.Table;
65 import org.eclipse.swt.widgets.TableColumn;
66 import org.eclipse.swt.widgets.TableItem;
67 import org.eclipse.ui.PlatformUI;
68 import org.eclipse.ui.dialogs.ListSelectionDialog;
73 * TODO To change the template for this generated type comment go to Window -
74 * Preferences - Java - Code Style - Code Templates
76 public class PHPEnvironmentTab2 extends AbstractLaunchConfigurationTab {
78 protected TableViewer environmentTable;
80 protected String[] envTableColumnHeaders = {
81 LaunchConfigurationsMessages.EnvironmentTab_Variable_1, //$NON-NLS-1$
82 LaunchConfigurationsMessages.EnvironmentTab_Value_2 //$NON-NLS-1$
85 protected ColumnLayoutData[] envTableColumnLayouts = {
86 new ColumnWeightData(50), new ColumnWeightData(50) };
88 private static final String NAME_LABEL = LaunchConfigurationsMessages.EnvironmentTab_8; //$NON-NLS-1$
90 private static final String VALUE_LABEL = LaunchConfigurationsMessages.EnvironmentTab_9; //$NON-NLS-1$
92 protected static final String P_VARIABLE = "variable"; //$NON-NLS-1$
94 protected static final String P_VALUE = "value"; //$NON-NLS-1$
96 protected static String[] envTableColumnProperties = { P_VARIABLE, P_VALUE };
98 protected Button envAddButton;
100 protected Button envAddCGIButton;
102 protected Button envEditButton;
104 protected Button envRemoveButton;
106 protected Button appendEnvironment;
108 protected Button replaceEnvironment;
110 protected Button envSelectButton;
113 * Content provider for the environment table
115 protected class EnvironmentVariableContentProvider implements
116 IStructuredContentProvider {
117 public Object[] getElements(Object inputElement) {
118 EnvironmentVariable[] elements = new EnvironmentVariable[0];
119 ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
122 m = config.getAttribute(
123 ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
124 } catch (CoreException e) {
125 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin
126 .getUniqueIdentifier(), IStatus.ERROR,
127 "Error reading configuration", e)); //$NON-NLS-1$
130 if (m != null && !m.isEmpty()) {
131 elements = new EnvironmentVariable[m.size()];
132 String[] varNames = new String[m.size()];
133 m.keySet().toArray(varNames);
134 for (int i = 0; i < m.size(); i++) {
135 elements[i] = new EnvironmentVariable(varNames[i],
136 (String) m.get(varNames[i]));
142 public void dispose() {
145 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
146 if (newInput == null) {
149 if (viewer instanceof TableViewer) {
150 TableViewer tableViewer = (TableViewer) viewer;
151 if (tableViewer.getTable().isDisposed()) {
154 tableViewer.setSorter(new ViewerSorter() {
155 public int compare(Viewer iviewer, Object e1, Object e2) {
158 } else if (e2 == null) {
161 return ((EnvironmentVariable) e1).getName()
162 .compareToIgnoreCase(
163 ((EnvironmentVariable) e2)
173 * Label provider for the environment table
175 public class EnvironmentVariableLabelProvider extends LabelProvider
176 implements ITableLabelProvider {
177 public String getColumnText(Object element, int columnIndex) {
178 String result = null;
179 if (element != null) {
180 EnvironmentVariable var = (EnvironmentVariable) element;
181 switch (columnIndex) {
183 result = var.getName();
186 result = var.getValue();
193 public Image getColumnImage(Object element, int columnIndex) {
201 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
203 public void createControl(Composite parent) {
204 // Create main composite
205 Composite mainComposite = new Composite(parent, SWT.NONE);
206 setControl(mainComposite);
212 IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
213 GridLayout layout = new GridLayout();
214 layout.numColumns = 2;
215 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
216 mainComposite.setLayout(layout);
217 mainComposite.setLayoutData(gridData);
218 mainComposite.setFont(parent.getFont());
220 createEnvironmentTable(mainComposite);
221 createTableButtons(mainComposite);
222 createAppendReplace(mainComposite);
224 Dialog.applyDialogFont(mainComposite);
228 * Creates and configures the widgets which allow the user to choose whether
229 * the specified environment should be appended to the native environment or
230 * if it should completely replace it.
233 * the composite in which the widgets should be created
235 protected void createAppendReplace(Composite parent) {
236 Composite appendReplaceComposite = new Composite(parent, SWT.NONE);
237 GridData gridData = new GridData();
238 gridData.horizontalSpan = 2;
239 GridLayout layout = new GridLayout();
240 appendReplaceComposite.setLayoutData(gridData);
241 appendReplaceComposite.setLayout(layout);
242 appendReplaceComposite.setFont(parent.getFont());
244 appendEnvironment = createRadioButton(appendReplaceComposite,
245 LaunchConfigurationsMessages.EnvironmentTab_16); //$NON-NLS-1$
246 appendEnvironment.addSelectionListener(new SelectionAdapter() {
247 public void widgetSelected(SelectionEvent e) {
248 updateLaunchConfigurationDialog();
251 replaceEnvironment = createRadioButton(appendReplaceComposite,
252 LaunchConfigurationsMessages.EnvironmentTab_17); //$NON-NLS-1$
256 * Updates the enablement of the append/replace widgets. The widgets should
257 * disable when there are no environment variables specified.
259 protected void updateAppendReplace() {
260 boolean enable = environmentTable.getTable().getItemCount() > 0;
261 appendEnvironment.setEnabled(enable);
262 replaceEnvironment.setEnabled(enable);
266 * Creates and configures the table that displayed the key/value pairs that
267 * comprise the environment.
270 * the composite in which the table should be created
272 protected void createEnvironmentTable(Composite parent) {
273 Font font = parent.getFont();
274 // Create table composite
275 Composite tableComposite = new Composite(parent, SWT.NONE);
276 GridLayout layout = new GridLayout();
277 layout.marginHeight = 0;
278 layout.marginWidth = 0;
279 layout.numColumns = 1;
280 GridData gridData = new GridData(GridData.FILL_BOTH);
281 gridData.heightHint = 150;
282 tableComposite.setLayout(layout);
283 tableComposite.setLayoutData(gridData);
284 tableComposite.setFont(font);
286 Label label = new Label(tableComposite, SWT.NONE);
289 .setText(LaunchConfigurationsMessages.EnvironmentTab_Environment_variables_to_set__3); //$NON-NLS-1$
291 environmentTable = new TableViewer(tableComposite, SWT.BORDER
292 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
293 Table table = environmentTable.getTable();
294 TableLayout tableLayout = new TableLayout();
295 table.setLayout(tableLayout);
296 table.setHeaderVisible(true);
298 gridData = new GridData(GridData.FILL_BOTH);
299 environmentTable.getControl().setLayoutData(gridData);
301 .setContentProvider(new EnvironmentVariableContentProvider());
303 .setLabelProvider(new EnvironmentVariableLabelProvider());
304 environmentTable.setColumnProperties(envTableColumnProperties);
306 .addSelectionChangedListener(new ISelectionChangedListener() {
307 public void selectionChanged(SelectionChangedEvent event) {
308 handleTableSelectionChanged(event);
311 environmentTable.addDoubleClickListener(new IDoubleClickListener() {
312 public void doubleClick(DoubleClickEvent event) {
313 if (!environmentTable.getSelection().isEmpty()) {
314 handleEnvEditButtonSelected();
319 for (int i = 0; i < envTableColumnHeaders.length; i++) {
320 tableLayout.addColumnData(envTableColumnLayouts[i]);
321 TableColumn tc = new TableColumn(table, SWT.NONE, i);
322 tc.setResizable(envTableColumnLayouts[i].resizable);
323 tc.setText(envTableColumnHeaders[i]);
328 * Responds to a selection changed event in the environment table
331 * the selection change event
333 protected void handleTableSelectionChanged(SelectionChangedEvent event) {
334 int size = ((IStructuredSelection) event.getSelection()).size();
335 envEditButton.setEnabled(size == 1);
336 envRemoveButton.setEnabled(size > 0);
340 * Creates the add/edit/remove buttons for the environment table
343 * the composite in which the buttons should be created
345 protected void createTableButtons(Composite parent) {
346 // Create button composite
347 Composite buttonComposite = new Composite(parent, SWT.NONE);
348 GridLayout glayout = new GridLayout();
349 glayout.marginHeight = 0;
350 glayout.marginWidth = 0;
351 glayout.numColumns = 1;
352 GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
353 | GridData.HORIZONTAL_ALIGN_END);
354 buttonComposite.setLayout(glayout);
355 buttonComposite.setLayoutData(gdata);
356 buttonComposite.setFont(parent.getFont());
358 createVerticalSpacer(buttonComposite, 1);
360 envAddButton = createPushButton(buttonComposite,
361 LaunchConfigurationsMessages.EnvironmentTab_New_4, null); //$NON-NLS-1$
362 envAddButton.addSelectionListener(new SelectionAdapter() {
363 public void widgetSelected(SelectionEvent event) {
364 handleEnvAddButtonSelected();
367 envAddCGIButton = createPushButton(
370 .getString("LaunchConfigurationTab.PHPEnvironment2.CGIButton"), null); //$NON-NLS-1$
371 envAddCGIButton.addSelectionListener(new SelectionAdapter() {
372 public void widgetSelected(SelectionEvent event) {
373 handleEnvAddCGIButtonSelected();
377 envSelectButton = createPushButton(buttonComposite,
378 LaunchConfigurationsMessages.EnvironmentTab_18, null); //$NON-NLS-1$
379 envSelectButton.addSelectionListener(new SelectionAdapter() {
380 public void widgetSelected(SelectionEvent event) {
381 handleEnvSelectButtonSelected();
384 envEditButton = createPushButton(buttonComposite,
385 LaunchConfigurationsMessages.EnvironmentTab_Edit_5, null); //$NON-NLS-1$
386 envEditButton.addSelectionListener(new SelectionAdapter() {
387 public void widgetSelected(SelectionEvent event) {
388 handleEnvEditButtonSelected();
391 envEditButton.setEnabled(false);
392 envRemoveButton = createPushButton(buttonComposite,
393 LaunchConfigurationsMessages.EnvironmentTab_Remove_6, null); //$NON-NLS-1$
394 envRemoveButton.addSelectionListener(new SelectionAdapter() {
395 public void widgetSelected(SelectionEvent event) {
396 handleEnvRemoveButtonSelected();
399 envRemoveButton.setEnabled(false);
403 * Adds a new environment variable to the table.
405 protected void handleEnvAddButtonSelected() {
406 MultipleInputDialog dialog = new MultipleInputDialog(getShell(),
407 LaunchConfigurationsMessages.EnvironmentTab_22); //$NON-NLS-1$
408 dialog.addTextField(NAME_LABEL, null, false);
409 dialog.addVariablesField(VALUE_LABEL, null, true);
411 if (dialog.open() != Window.OK) {
415 String name = dialog.getStringValue(NAME_LABEL);
416 String value = dialog.getStringValue(VALUE_LABEL);
418 if (name != null && value != null && name.length() > 0
419 && value.length() > 0) {
420 addVariable(new EnvironmentVariable(name.trim(), value.trim()));
421 updateAppendReplace();
426 * Attempts to add the given variable. Returns whether the variable was
427 * added or not (as when the user answers not to overwrite an existing
431 * the variable to add
432 * @return whether the variable was added
434 protected boolean addVariable(EnvironmentVariable variable) {
435 String name = variable.getName();
436 TableItem[] items = environmentTable.getTable().getItems();
437 for (int i = 0; i < items.length; i++) {
438 EnvironmentVariable existingVariable = (EnvironmentVariable) items[i]
440 if (existingVariable.getName().equals(name)) {
441 boolean overWrite = MessageDialog.openQuestion(getShell(),
442 LaunchConfigurationsMessages.EnvironmentTab_12,
443 MessageFormat.format(
444 LaunchConfigurationsMessages.EnvironmentTab_13,
445 new String[] { name })); //$NON-NLS-1$ //$NON-NLS-2$
449 environmentTable.remove(existingVariable);
453 environmentTable.add(variable);
454 updateLaunchConfigurationDialog();
459 * Displays a dialog that allows user to select native environment variables
460 * to add to the table.
462 private void handleEnvSelectButtonSelected() {
463 // get Environment Variables from the OS
464 Map envVariables = getNativeEnvironment();
466 // get Environment Variables from the table
467 TableItem[] items = environmentTable.getTable().getItems();
468 for (int i = 0; i < items.length; i++) {
469 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
470 envVariables.remove(var.getName());
473 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(),
474 envVariables, createSelectionDialogContentProvider(),
475 createSelectionDialogLabelProvider(),
476 LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
477 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
479 int button = dialog.open();
480 if (button == Window.OK) {
481 Object[] selected = dialog.getResult();
482 for (int i = 0; i < selected.length; i++) {
483 environmentTable.add(selected[i]);
487 updateAppendReplace();
488 updateLaunchConfigurationDialog();
492 * Displays a dialog that allows user to select native environment variables
493 * to add to the table.
495 private void handleEnvAddCGIButtonSelected() {
497 Map envVariables = new HashMap();
499 envVariables.put("HTTP_COOKIE", new EnvironmentVariable("HTTP_COOKIE",
501 envVariables.put("REDIRECT_QUERY_STRING", new EnvironmentVariable(
502 "REDIRECT_QUERY_STRING", ""));
503 envVariables.put("REDIRECT_STATUS", new EnvironmentVariable(
504 "REDIRECT_STATUS", "200"));
505 envVariables.put("REDIRECT_URL", new EnvironmentVariable(
506 "REDIRECT_URL", ""));
507 envVariables.put("SERVER_SOFTWARE", new EnvironmentVariable(
508 "SERVER_SOFTWARE", "DBG / 2.1"));
509 envVariables.put("SERVER_NAME", new EnvironmentVariable("SERVER_NAME",
511 envVariables.put("SERVER_ADDR", new EnvironmentVariable("SERVER_ADDR",
513 envVariables.put("SERVER_PORT", new EnvironmentVariable("SERVER_PORT",
515 envVariables.put("REMOTE_ADDR", new EnvironmentVariable("REMOTE_ADDR",
517 envVariables.put("GATEWAY_INTERFACE", new EnvironmentVariable(
518 "GATEWAY_INTERFACE", "CGI / 1.1"));
519 envVariables.put("SERVER_PROTOCOL", new EnvironmentVariable(
520 "SERVER_PROTOCOL", "HTTP / 1.1"));
521 envVariables.put("REQUEST_METHOD", new EnvironmentVariable(
522 "REQUEST_METHOD", "GET"));
523 envVariables.put("QUERY_STRING", new EnvironmentVariable(
524 "QUERY_STRING", ""));
525 envVariables.put("REDIRECT_QUERY_STRING", new EnvironmentVariable(
526 "REDIRECT_QUERY_STRING", ""));
527 // envVariables.put("REQUEST_URI" + OSFilePath;
528 // envVariables.put("PATH_INFO=" + OSFilePath;
529 // envVariables.put("PATH_TRANSLATED=" + OSFilePath;
531 // get Environment Variables from the table
532 TableItem[] items = environmentTable.getTable().getItems();
533 for (int i = 0; i < items.length; i++) {
534 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
535 envVariables.remove(var.getName());
538 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(),
539 envVariables, createSelectionDialogContentProvider(),
540 createSelectionDialogLabelProvider(),
541 LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
542 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
544 int button = dialog.open();
545 if (button == Window.OK) {
546 Object[] selected = dialog.getResult();
547 for (int i = 0; i < selected.length; i++) {
548 environmentTable.add(selected[i]);
552 updateAppendReplace();
553 updateLaunchConfigurationDialog();
557 * Creates a label provider for the native native environment variable
560 * @return A label provider for the native native environment variable
563 private ILabelProvider createSelectionDialogLabelProvider() {
564 return new ILabelProvider() {
565 public Image getImage(Object element) {
569 public String getText(Object element) {
570 EnvironmentVariable var = (EnvironmentVariable) element;
571 return var.getName() + " [" + var.getValue() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
574 public void addListener(ILabelProviderListener listener) {
577 public void dispose() {
580 public boolean isLabelProperty(Object element, String property) {
584 public void removeListener(ILabelProviderListener listener) {
590 * Creates a content provider for the native native environment variable
593 * @return A content provider for the native native environment variable
596 private IStructuredContentProvider createSelectionDialogContentProvider() {
597 return new IStructuredContentProvider() {
598 public Object[] getElements(Object inputElement) {
599 EnvironmentVariable[] elements = null;
600 if (inputElement instanceof HashMap) {
601 Comparator comparator = new Comparator() {
602 public int compare(Object o1, Object o2) {
603 String s1 = (String) o1;
604 String s2 = (String) o2;
605 return s1.compareTo(s2);
609 TreeMap envVars = new TreeMap(comparator);
610 envVars.putAll((Map) inputElement);
611 elements = new EnvironmentVariable[envVars.size()];
613 for (Iterator iterator = envVars.keySet().iterator(); iterator
614 .hasNext(); index++) {
615 Object key = iterator.next();
616 elements[index] = (EnvironmentVariable) envVars
623 public void dispose() {
626 public void inputChanged(Viewer viewer, Object oldInput,
633 * Gets native environment variable from the LaunchManager. Creates
634 * EnvironmentVariable objects.
636 * @return Map of name - EnvironmentVariable pairs based on native
639 private Map getNativeEnvironment() {
640 Map stringVars = DebugPlugin.getDefault().getLaunchManager()
641 .getNativeEnvironment();
642 HashMap vars = new HashMap();
643 for (Iterator i = stringVars.keySet().iterator(); i.hasNext();) {
644 String key = (String) i.next();
645 String value = (String) stringVars.get(key);
646 vars.put(key, new EnvironmentVariable(key, value));
652 * Creates an editor for the value of the selected environment variable.
654 private void handleEnvEditButtonSelected() {
655 IStructuredSelection sel = (IStructuredSelection) environmentTable
657 EnvironmentVariable var = (EnvironmentVariable) sel.getFirstElement();
661 String originalName = var.getName();
662 String value = var.getValue();
663 MultipleInputDialog dialog = new MultipleInputDialog(getShell(),
664 LaunchConfigurationsMessages.EnvironmentTab_11); //$NON-NLS-1$
665 dialog.addTextField(NAME_LABEL, originalName, false);
666 dialog.addVariablesField(VALUE_LABEL, value, true);
668 if (dialog.open() != Window.OK) {
671 String name = dialog.getStringValue(NAME_LABEL);
672 value = dialog.getStringValue(VALUE_LABEL);
673 if (!originalName.equals(name)) {
674 if (addVariable(new EnvironmentVariable(name, value))) {
675 environmentTable.remove(var);
679 environmentTable.update(var, null);
680 updateLaunchConfigurationDialog();
685 * Removes the selected environment variable from the table.
687 private void handleEnvRemoveButtonSelected() {
688 IStructuredSelection sel = (IStructuredSelection) environmentTable
690 environmentTable.getControl().setRedraw(false);
691 for (Iterator i = sel.iterator(); i.hasNext();) {
692 EnvironmentVariable var = (EnvironmentVariable) i.next();
693 environmentTable.remove(var);
695 environmentTable.getControl().setRedraw(true);
696 updateAppendReplace();
697 updateLaunchConfigurationDialog();
701 * Updates the environment table for the given launch configuration
703 * @param configuration
705 protected void updateEnvironment(ILaunchConfiguration configuration) {
706 environmentTable.setInput(configuration);
712 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
714 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
720 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
722 public void initializeFrom(ILaunchConfiguration configuration) {
723 boolean append = true;
725 append = configuration.getAttribute(
726 ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
727 } catch (CoreException e) {
728 DebugUIPlugin.log(e.getStatus());
731 appendEnvironment.setSelection(true);
732 replaceEnvironment.setSelection(false);
734 replaceEnvironment.setSelection(true);
735 appendEnvironment.setSelection(false);
737 updateEnvironment(configuration);
738 updateAppendReplace();
742 * Stores the environment in the given configuration
744 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
746 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
747 // Convert the table's items into a Map so that this can be saved in the
748 // configuration's attributes.
749 TableItem[] items = environmentTable.getTable().getItems();
750 Map map = new HashMap(items.length);
751 for (int i = 0; i < items.length; i++) {
752 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
753 map.put(var.getName(), var.getValue());
755 if (map.size() == 0) {
756 configuration.setAttribute(
757 ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
759 configuration.setAttribute(
760 ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
762 configuration.setAttribute(
763 ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES,
764 appendEnvironment.getSelection());
770 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
772 public String getName() {
773 return LaunchConfigurationsMessages.EnvironmentTab_Environment_7; //$NON-NLS-1$
779 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
781 public Image getImage() {
782 return DebugPluginImages
783 .getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
789 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
791 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
792 // do nothing when activated
798 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
800 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
801 // do nothing when deactivated
804 private class NativeEnvironmentDialog extends ListSelectionDialog {
805 public NativeEnvironmentDialog(Shell parentShell, Object input,
806 IStructuredContentProvider contentProvider,
807 ILabelProvider labelProvider, String message) {
808 super(parentShell, input, contentProvider, labelProvider, message);
809 setShellStyle(getShellStyle() | SWT.RESIZE);
812 protected IDialogSettings getDialogSettings() {
813 IDialogSettings settings = DebugUIPlugin.getDefault()
814 .getDialogSettings();
815 IDialogSettings section = settings
816 .getSection(getDialogSettingsSectionName());
817 if (section == null) {
819 .addNewSection(getDialogSettingsSectionName());
825 * Returns the name of the section that this dialog stores its settings
830 protected String getDialogSettingsSectionName() {
831 return IDebugUIConstants.PLUGIN_ID
832 + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$