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
74 * Window - Preferences - Java - Code Style - Code Templates
76 public class PHPEnvironmentTab2 extends AbstractLaunchConfigurationTab {
79 protected TableViewer environmentTable;
80 protected String[] envTableColumnHeaders =
82 LaunchConfigurationsMessages.EnvironmentTab_Variable_1, //$NON-NLS-1$
83 LaunchConfigurationsMessages.EnvironmentTab_Value_2 //$NON-NLS-1$
85 protected ColumnLayoutData[] envTableColumnLayouts =
87 new ColumnWeightData(50),
88 new ColumnWeightData(50)
90 private static final String NAME_LABEL= LaunchConfigurationsMessages.EnvironmentTab_8; //$NON-NLS-1$
91 private static final String VALUE_LABEL= LaunchConfigurationsMessages.EnvironmentTab_9; //$NON-NLS-1$
92 protected static final String P_VARIABLE = "variable"; //$NON-NLS-1$
93 protected static final String P_VALUE = "value"; //$NON-NLS-1$
94 protected static String[] envTableColumnProperties =
99 protected Button envAddButton;
100 protected Button envAddCGIButton;
101 protected Button envEditButton;
102 protected Button envRemoveButton;
103 protected Button appendEnvironment;
104 protected Button replaceEnvironment;
105 protected Button envSelectButton;
108 * Content provider for the environment table
110 protected class EnvironmentVariableContentProvider implements IStructuredContentProvider {
111 public Object[] getElements(Object inputElement) {
112 EnvironmentVariable[] elements = new EnvironmentVariable[0];
113 ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
116 m = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
117 } catch (CoreException e) {
118 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Error reading configuration", e)); //$NON-NLS-1$
121 if (m != null && !m.isEmpty()) {
122 elements = new EnvironmentVariable[m.size()];
123 String[] varNames = new String[m.size()];
124 m.keySet().toArray(varNames);
125 for (int i = 0; i < m.size(); i++) {
126 elements[i] = new EnvironmentVariable(varNames[i], (String) m.get(varNames[i]));
131 public void dispose() {
133 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
134 if (newInput == null){
137 if (viewer instanceof TableViewer){
138 TableViewer tableViewer= (TableViewer) viewer;
139 if (tableViewer.getTable().isDisposed()) {
142 tableViewer.setSorter(new ViewerSorter() {
143 public int compare(Viewer iviewer, Object e1, Object e2) {
146 } else if (e2 == null) {
149 return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
158 * Label provider for the environment table
160 public class EnvironmentVariableLabelProvider extends LabelProvider implements ITableLabelProvider {
161 public String getColumnText(Object element, int columnIndex) {
162 String result = null;
163 if (element != null) {
164 EnvironmentVariable var = (EnvironmentVariable) element;
165 switch (columnIndex) {
167 result = var.getName();
170 result = var.getValue();
176 public Image getColumnImage(Object element, int columnIndex) {
182 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
184 public void createControl(Composite parent) {
185 // Create main composite
186 Composite mainComposite = new Composite(parent, SWT.NONE);
187 setControl(mainComposite);
188 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
189 GridLayout layout = new GridLayout();
190 layout.numColumns = 2;
191 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
192 mainComposite.setLayout(layout);
193 mainComposite.setLayoutData(gridData);
194 mainComposite.setFont(parent.getFont());
196 createEnvironmentTable(mainComposite);
197 createTableButtons(mainComposite);
198 createAppendReplace(mainComposite);
200 Dialog.applyDialogFont(mainComposite);
204 * Creates and configures the widgets which allow the user to
205 * choose whether the specified environment should be appended
206 * to the native environment or if it should completely replace it.
207 * @param parent the composite in which the widgets should be created
209 protected void createAppendReplace(Composite parent) {
210 Composite appendReplaceComposite= new Composite(parent, SWT.NONE);
211 GridData gridData= new GridData();
212 gridData.horizontalSpan= 2;
213 GridLayout layout= new GridLayout();
214 appendReplaceComposite.setLayoutData(gridData);
215 appendReplaceComposite.setLayout(layout);
216 appendReplaceComposite.setFont(parent.getFont());
218 appendEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_16); //$NON-NLS-1$
219 appendEnvironment.addSelectionListener(new SelectionAdapter() {
220 public void widgetSelected(SelectionEvent e) {
221 updateLaunchConfigurationDialog();
224 replaceEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_17); //$NON-NLS-1$
228 * Updates the enablement of the append/replace widgets. The
229 * widgets should disable when there are no environment variables specified.
231 protected void updateAppendReplace() {
232 boolean enable= environmentTable.getTable().getItemCount() > 0;
233 appendEnvironment.setEnabled(enable);
234 replaceEnvironment.setEnabled(enable);
238 * Creates and configures the table that displayed the key/value
239 * pairs that comprise the environment.
240 * @param parent the composite in which the table should be created
242 protected void createEnvironmentTable(Composite parent) {
243 Font font= parent.getFont();
244 // Create table composite
245 Composite tableComposite = new Composite(parent, SWT.NONE);
246 GridLayout layout = new GridLayout();
247 layout.marginHeight = 0;
248 layout.marginWidth = 0;
249 layout.numColumns = 1;
250 GridData gridData = new GridData(GridData.FILL_BOTH);
251 gridData.heightHint = 150;
252 tableComposite.setLayout(layout);
253 tableComposite.setLayoutData(gridData);
254 tableComposite.setFont(font);
256 Label label = new Label(tableComposite, SWT.NONE);
258 label.setText(LaunchConfigurationsMessages.EnvironmentTab_Environment_variables_to_set__3); //$NON-NLS-1$
260 environmentTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
261 Table table = environmentTable.getTable();
262 TableLayout tableLayout = new TableLayout();
263 table.setLayout(tableLayout);
264 table.setHeaderVisible(true);
266 gridData = new GridData(GridData.FILL_BOTH);
267 environmentTable.getControl().setLayoutData(gridData);
268 environmentTable.setContentProvider(new EnvironmentVariableContentProvider());
269 environmentTable.setLabelProvider(new EnvironmentVariableLabelProvider());
270 environmentTable.setColumnProperties(envTableColumnProperties);
271 environmentTable.addSelectionChangedListener(new ISelectionChangedListener() {
272 public void selectionChanged(SelectionChangedEvent event) {
273 handleTableSelectionChanged(event);
276 environmentTable.addDoubleClickListener(new IDoubleClickListener() {
277 public void doubleClick(DoubleClickEvent event) {
278 if (!environmentTable.getSelection().isEmpty()) {
279 handleEnvEditButtonSelected();
284 for (int i = 0; i < envTableColumnHeaders.length; i++) {
285 tableLayout.addColumnData(envTableColumnLayouts[i]);
286 TableColumn tc = new TableColumn(table, SWT.NONE, i);
287 tc.setResizable(envTableColumnLayouts[i].resizable);
288 tc.setText(envTableColumnHeaders[i]);
293 * Responds to a selection changed event in the environment table
294 * @param event the selection change event
296 protected void handleTableSelectionChanged(SelectionChangedEvent event) {
297 int size = ((IStructuredSelection)event.getSelection()).size();
298 envEditButton.setEnabled(size == 1);
299 envRemoveButton.setEnabled(size > 0);
303 * Creates the add/edit/remove buttons for the environment table
304 * @param parent the composite in which the buttons should be created
306 protected void createTableButtons(Composite parent) {
307 // Create button composite
308 Composite buttonComposite = new Composite(parent, SWT.NONE);
309 GridLayout glayout = new GridLayout();
310 glayout.marginHeight = 0;
311 glayout.marginWidth = 0;
312 glayout.numColumns = 1;
313 GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
314 buttonComposite.setLayout(glayout);
315 buttonComposite.setLayoutData(gdata);
316 buttonComposite.setFont(parent.getFont());
318 createVerticalSpacer(buttonComposite, 1);
320 envAddButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_New_4, null); //$NON-NLS-1$
321 envAddButton.addSelectionListener(new SelectionAdapter()
323 public void widgetSelected(SelectionEvent event) {
324 handleEnvAddButtonSelected();
327 envAddCGIButton = createPushButton(buttonComposite, PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment2.CGIButton"), null); //$NON-NLS-1$
328 envAddCGIButton.addSelectionListener(new SelectionAdapter() {
329 public void widgetSelected(SelectionEvent event) {
330 handleEnvAddCGIButtonSelected();
334 envSelectButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_18, null); //$NON-NLS-1$
335 envSelectButton.addSelectionListener(new SelectionAdapter() {
336 public void widgetSelected(SelectionEvent event) {
337 handleEnvSelectButtonSelected();
340 envEditButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Edit_5, null); //$NON-NLS-1$
341 envEditButton.addSelectionListener(new SelectionAdapter()
343 public void widgetSelected(SelectionEvent event) {
344 handleEnvEditButtonSelected();
347 envEditButton.setEnabled(false);
348 envRemoveButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Remove_6, null); //$NON-NLS-1$
349 envRemoveButton.addSelectionListener(new SelectionAdapter()
351 public void widgetSelected(SelectionEvent event) {
352 handleEnvRemoveButtonSelected();
355 envRemoveButton.setEnabled(false);
359 * Adds a new environment variable to the table.
361 protected void handleEnvAddButtonSelected() {
362 MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_22); //$NON-NLS-1$
363 dialog.addTextField(NAME_LABEL, null, false);
364 dialog.addVariablesField(VALUE_LABEL, null, true);
366 if (dialog.open() != Window.OK) {
370 String name = dialog.getStringValue(NAME_LABEL);
371 String value = dialog.getStringValue(VALUE_LABEL);
373 if (name != null && value != null && name.length() > 0 && value.length() >0) {
374 addVariable(new EnvironmentVariable(name.trim(), value.trim()));
375 updateAppendReplace();
380 * Attempts to add the given variable. Returns whether the variable
381 * was added or not (as when the user answers not to overwrite an
382 * existing variable).
383 * @param variable the variable to add
384 * @return whether the variable was added
386 protected boolean addVariable(EnvironmentVariable variable) {
387 String name= variable.getName();
388 TableItem[] items = environmentTable.getTable().getItems();
389 for (int i = 0; i < items.length; i++) {
390 EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData();
391 if (existingVariable.getName().equals(name)) {
392 boolean overWrite= MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.EnvironmentTab_12, MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_13, new String[] {name})); //$NON-NLS-1$ //$NON-NLS-2$
396 environmentTable.remove(existingVariable);
400 environmentTable.add(variable);
401 updateLaunchConfigurationDialog();
406 * Displays a dialog that allows user to select native environment variables
407 * to add to the table.
409 private void handleEnvSelectButtonSelected() {
410 //get Environment Variables from the OS
411 Map envVariables = getNativeEnvironment();
413 //get Environment Variables from the table
414 TableItem[] items = environmentTable.getTable().getItems();
415 for (int i = 0; i < items.length; i++) {
416 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
417 envVariables.remove(var.getName());
420 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
421 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
423 int button = dialog.open();
424 if (button == Window.OK) {
425 Object[] selected = dialog.getResult();
426 for (int i = 0; i < selected.length; i++) {
427 environmentTable.add(selected[i]);
431 updateAppendReplace();
432 updateLaunchConfigurationDialog();
436 * Displays a dialog that allows user to select native environment variables
437 * to add to the table.
439 private void handleEnvAddCGIButtonSelected() {
441 Map envVariables = new HashMap();
444 envVariables.put("HTTP_COOKIE",new EnvironmentVariable("HTTP_COOKIE", "TestCookie=1"));
445 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING", ""));
446 envVariables.put("REDIRECT_STATUS",new EnvironmentVariable("REDIRECT_STATUS", "200"));
447 envVariables.put("REDIRECT_URL",new EnvironmentVariable("REDIRECT_URL", ""));
448 envVariables.put("SERVER_SOFTWARE",new EnvironmentVariable("SERVER_SOFTWARE","DBG / 2.1"));
449 envVariables.put("SERVER_NAME",new EnvironmentVariable("SERVER_NAME","localhost"));
450 envVariables.put("SERVER_ADDR",new EnvironmentVariable("SERVER_ADDR","127.0.0.1"));
451 envVariables.put("SERVER_PORT",new EnvironmentVariable("SERVER_PORT","80"));
452 envVariables.put("REMOTE_ADDR",new EnvironmentVariable("REMOTE_ADDR","127.0.0.1"));
453 envVariables.put("GATEWAY_INTERFACE",new EnvironmentVariable("GATEWAY_INTERFACE","CGI / 1.1"));
454 envVariables.put("SERVER_PROTOCOL",new EnvironmentVariable("SERVER_PROTOCOL","HTTP / 1.1"));
455 envVariables.put("REQUEST_METHOD",new EnvironmentVariable("REQUEST_METHOD","GET"));
456 envVariables.put("QUERY_STRING",new EnvironmentVariable("QUERY_STRING",""));
457 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING",""));
458 // envVariables.put("REQUEST_URI" + OSFilePath;
459 // envVariables.put("PATH_INFO=" + OSFilePath;
460 // envVariables.put("PATH_TRANSLATED=" + OSFilePath;
463 //get Environment Variables from the table
464 TableItem[] items = environmentTable.getTable().getItems();
465 for (int i = 0; i < items.length; i++) {
466 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
467 envVariables.remove(var.getName());
470 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
471 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
473 int button = dialog.open();
474 if (button == Window.OK) {
475 Object[] selected = dialog.getResult();
476 for (int i = 0; i < selected.length; i++) {
477 environmentTable.add(selected[i]);
481 updateAppendReplace();
482 updateLaunchConfigurationDialog();
487 * Creates a label provider for the native native environment variable selection dialog.
488 * @return A label provider for the native native environment variable selection dialog.
490 private ILabelProvider createSelectionDialogLabelProvider() {
491 return new ILabelProvider() {
492 public Image getImage(Object element) {
495 public String getText(Object element) {
496 EnvironmentVariable var = (EnvironmentVariable) element;
497 return var.getName() + " [" + var.getValue() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
499 public void addListener(ILabelProviderListener listener) {
501 public void dispose() {
503 public boolean isLabelProperty(Object element, String property) {
506 public void removeListener(ILabelProviderListener listener) {
512 * Creates a content provider for the native native environment variable selection dialog.
513 * @return A content provider for the native native environment variable selection dialog.
515 private IStructuredContentProvider createSelectionDialogContentProvider() {
516 return new IStructuredContentProvider() {
517 public Object[] getElements(Object inputElement) {
518 EnvironmentVariable[] elements = null;
519 if (inputElement instanceof HashMap) {
520 Comparator comparator = new Comparator() {
521 public int compare(Object o1, Object o2) {
522 String s1 = (String)o1;
523 String s2 = (String)o2;
524 return s1.compareTo(s2);
528 TreeMap envVars = new TreeMap(comparator);
529 envVars.putAll((Map)inputElement);
530 elements = new EnvironmentVariable[envVars.size()];
532 for (Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); index++) {
533 Object key = iterator.next();
534 elements[index] = (EnvironmentVariable) envVars.get(key);
539 public void dispose() {
541 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
547 * Gets native environment variable from the LaunchManager. Creates EnvironmentVariable objects.
548 * @return Map of name - EnvironmentVariable pairs based on native environment.
550 private Map getNativeEnvironment() {
551 Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
552 HashMap vars = new HashMap();
553 for (Iterator i = stringVars.keySet().iterator(); i.hasNext(); ) {
554 String key = (String) i.next();
555 String value = (String) stringVars.get(key);
556 vars.put(key, new EnvironmentVariable(key, value));
562 * Creates an editor for the value of the selected environment variable.
564 private void handleEnvEditButtonSelected() {
565 IStructuredSelection sel= (IStructuredSelection) environmentTable.getSelection();
566 EnvironmentVariable var= (EnvironmentVariable) sel.getFirstElement();
570 String originalName= var.getName();
571 String value= var.getValue();
572 MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_11); //$NON-NLS-1$
573 dialog.addTextField(NAME_LABEL, originalName, false);
574 dialog.addVariablesField(VALUE_LABEL, value, true);
576 if (dialog.open() != Window.OK) {
579 String name= dialog.getStringValue(NAME_LABEL);
580 value= dialog.getStringValue(VALUE_LABEL);
581 if (!originalName.equals(name)) {
582 if (addVariable(new EnvironmentVariable(name, value))) {
583 environmentTable.remove(var);
587 environmentTable.update(var, null);
588 updateLaunchConfigurationDialog();
593 * Removes the selected environment variable from the table.
595 private void handleEnvRemoveButtonSelected() {
596 IStructuredSelection sel = (IStructuredSelection) environmentTable.getSelection();
597 environmentTable.getControl().setRedraw(false);
598 for (Iterator i = sel.iterator(); i.hasNext(); ) {
599 EnvironmentVariable var = (EnvironmentVariable) i.next();
600 environmentTable.remove(var);
602 environmentTable.getControl().setRedraw(true);
603 updateAppendReplace();
604 updateLaunchConfigurationDialog();
608 * Updates the environment table for the given launch configuration
609 * @param configuration
611 protected void updateEnvironment(ILaunchConfiguration configuration) {
612 environmentTable.setInput(configuration);
616 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
618 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
622 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
624 public void initializeFrom(ILaunchConfiguration configuration) {
625 boolean append= true;
627 append = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
628 } catch (CoreException e) {
629 DebugUIPlugin.log(e.getStatus());
632 appendEnvironment.setSelection(true);
633 replaceEnvironment.setSelection(false);
635 replaceEnvironment.setSelection(true);
636 appendEnvironment.setSelection(false);
638 updateEnvironment(configuration);
639 updateAppendReplace();
643 * Stores the environment in the given configuration
644 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
646 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
647 // Convert the table's items into a Map so that this can be saved in the
648 // configuration's attributes.
649 TableItem[] items = environmentTable.getTable().getItems();
650 Map map = new HashMap(items.length);
651 for (int i = 0; i < items.length; i++)
653 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
654 map.put(var.getName(), var.getValue());
656 if (map.size() == 0) {
657 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
659 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
661 configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, appendEnvironment.getSelection());
665 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
667 public String getName() {
668 return LaunchConfigurationsMessages.EnvironmentTab_Environment_7; //$NON-NLS-1$
672 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
674 public Image getImage() {
675 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
679 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
681 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
682 // do nothing when activated
686 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
688 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
689 // do nothing when deactivated
692 private class NativeEnvironmentDialog extends ListSelectionDialog {
693 public NativeEnvironmentDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String message) {
694 super(parentShell, input, contentProvider, labelProvider, message);
695 setShellStyle(getShellStyle() | SWT.RESIZE);
698 protected IDialogSettings getDialogSettings() {
699 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
700 IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
701 if (section == null) {
702 section = settings.addNewSection(getDialogSettingsSectionName());
708 * Returns the name of the section that this dialog stores its settings in
712 protected String getDialogSettingsSectionName() {
713 return IDebugUIConstants.PLUGIN_ID + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$