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.graphics.Point;
59 import org.eclipse.swt.layout.GridData;
60 import org.eclipse.swt.layout.GridLayout;
61 import org.eclipse.swt.widgets.Button;
62 import org.eclipse.swt.widgets.Composite;
63 import org.eclipse.swt.widgets.Label;
64 import org.eclipse.swt.widgets.Shell;
65 import org.eclipse.swt.widgets.Table;
66 import org.eclipse.swt.widgets.TableColumn;
67 import org.eclipse.swt.widgets.TableItem;
68 import org.eclipse.ui.PlatformUI;
69 import org.eclipse.ui.dialogs.ListSelectionDialog;
74 * TODO To change the template for this generated type comment go to
75 * Window - Preferences - Java - Code Style - Code Templates
77 public class PHPEnvironmentTab2 extends AbstractLaunchConfigurationTab {
80 protected TableViewer environmentTable;
81 protected String[] envTableColumnHeaders =
83 LaunchConfigurationsMessages.EnvironmentTab_Variable_1, //$NON-NLS-1$
84 LaunchConfigurationsMessages.EnvironmentTab_Value_2 //$NON-NLS-1$
86 protected ColumnLayoutData[] envTableColumnLayouts =
88 new ColumnWeightData(50),
89 new ColumnWeightData(50)
91 private static final String NAME_LABEL= LaunchConfigurationsMessages.EnvironmentTab_8; //$NON-NLS-1$
92 private static final String VALUE_LABEL= LaunchConfigurationsMessages.EnvironmentTab_9; //$NON-NLS-1$
93 protected static final String P_VARIABLE = "variable"; //$NON-NLS-1$
94 protected static final String P_VALUE = "value"; //$NON-NLS-1$
95 protected static String[] envTableColumnProperties =
100 protected Button envAddButton;
101 protected Button envAddCGIButton;
102 protected Button envEditButton;
103 protected Button envRemoveButton;
104 protected Button appendEnvironment;
105 protected Button replaceEnvironment;
106 protected Button envSelectButton;
109 * Content provider for the environment table
111 protected class EnvironmentVariableContentProvider implements IStructuredContentProvider {
112 public Object[] getElements(Object inputElement) {
113 EnvironmentVariable[] elements = new EnvironmentVariable[0];
114 ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
117 m = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
118 } catch (CoreException e) {
119 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Error reading configuration", e)); //$NON-NLS-1$
122 if (m != null && !m.isEmpty()) {
123 elements = new EnvironmentVariable[m.size()];
124 String[] varNames = new String[m.size()];
125 m.keySet().toArray(varNames);
126 for (int i = 0; i < m.size(); i++) {
127 elements[i] = new EnvironmentVariable(varNames[i], (String) m.get(varNames[i]));
132 public void dispose() {
134 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
135 if (newInput == null){
138 if (viewer instanceof TableViewer){
139 TableViewer tableViewer= (TableViewer) viewer;
140 if (tableViewer.getTable().isDisposed()) {
143 tableViewer.setSorter(new ViewerSorter() {
144 public int compare(Viewer iviewer, Object e1, Object e2) {
147 } else if (e2 == null) {
150 return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
159 * Label provider for the environment table
161 public class EnvironmentVariableLabelProvider extends LabelProvider implements ITableLabelProvider {
162 public String getColumnText(Object element, int columnIndex) {
163 String result = null;
164 if (element != null) {
165 EnvironmentVariable var = (EnvironmentVariable) element;
166 switch (columnIndex) {
168 result = var.getName();
171 result = var.getValue();
177 public Image getColumnImage(Object element, int columnIndex) {
183 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
185 public void createControl(Composite parent) {
186 // Create main composite
187 Composite mainComposite = new Composite(parent, SWT.NONE);
188 setControl(mainComposite);
189 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
190 GridLayout layout = new GridLayout();
191 layout.numColumns = 2;
192 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
193 mainComposite.setLayout(layout);
194 mainComposite.setLayoutData(gridData);
195 mainComposite.setFont(parent.getFont());
197 createEnvironmentTable(mainComposite);
198 createTableButtons(mainComposite);
199 createAppendReplace(mainComposite);
201 Dialog.applyDialogFont(mainComposite);
205 * Creates and configures the widgets which allow the user to
206 * choose whether the specified environment should be appended
207 * to the native environment or if it should completely replace it.
208 * @param parent the composite in which the widgets should be created
210 protected void createAppendReplace(Composite parent) {
211 Composite appendReplaceComposite= new Composite(parent, SWT.NONE);
212 GridData gridData= new GridData();
213 gridData.horizontalSpan= 2;
214 GridLayout layout= new GridLayout();
215 appendReplaceComposite.setLayoutData(gridData);
216 appendReplaceComposite.setLayout(layout);
217 appendReplaceComposite.setFont(parent.getFont());
219 appendEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_16); //$NON-NLS-1$
220 appendEnvironment.addSelectionListener(new SelectionAdapter() {
221 public void widgetSelected(SelectionEvent e) {
222 updateLaunchConfigurationDialog();
225 replaceEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_17); //$NON-NLS-1$
229 * Updates the enablement of the append/replace widgets. The
230 * widgets should disable when there are no environment variables specified.
232 protected void updateAppendReplace() {
233 boolean enable= environmentTable.getTable().getItemCount() > 0;
234 appendEnvironment.setEnabled(enable);
235 replaceEnvironment.setEnabled(enable);
239 * Creates and configures the table that displayed the key/value
240 * pairs that comprise the environment.
241 * @param parent the composite in which the table should be created
243 protected void createEnvironmentTable(Composite parent) {
244 Font font= parent.getFont();
245 // Create table composite
246 Composite tableComposite = new Composite(parent, SWT.NONE);
247 GridLayout layout = new GridLayout();
248 layout.marginHeight = 0;
249 layout.marginWidth = 0;
250 layout.numColumns = 1;
251 GridData gridData = new GridData(GridData.FILL_BOTH);
252 gridData.heightHint = 150;
253 tableComposite.setLayout(layout);
254 tableComposite.setLayoutData(gridData);
255 tableComposite.setFont(font);
257 Label label = new Label(tableComposite, SWT.NONE);
259 label.setText(LaunchConfigurationsMessages.EnvironmentTab_Environment_variables_to_set__3); //$NON-NLS-1$
261 environmentTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
262 Table table = environmentTable.getTable();
263 TableLayout tableLayout = new TableLayout();
264 table.setLayout(tableLayout);
265 table.setHeaderVisible(true);
267 gridData = new GridData(GridData.FILL_BOTH);
268 environmentTable.getControl().setLayoutData(gridData);
269 environmentTable.setContentProvider(new EnvironmentVariableContentProvider());
270 environmentTable.setLabelProvider(new EnvironmentVariableLabelProvider());
271 environmentTable.setColumnProperties(envTableColumnProperties);
272 environmentTable.addSelectionChangedListener(new ISelectionChangedListener() {
273 public void selectionChanged(SelectionChangedEvent event) {
274 handleTableSelectionChanged(event);
277 environmentTable.addDoubleClickListener(new IDoubleClickListener() {
278 public void doubleClick(DoubleClickEvent event) {
279 if (!environmentTable.getSelection().isEmpty()) {
280 handleEnvEditButtonSelected();
285 for (int i = 0; i < envTableColumnHeaders.length; i++) {
286 tableLayout.addColumnData(envTableColumnLayouts[i]);
287 TableColumn tc = new TableColumn(table, SWT.NONE, i);
288 tc.setResizable(envTableColumnLayouts[i].resizable);
289 tc.setText(envTableColumnHeaders[i]);
294 * Responds to a selection changed event in the environment table
295 * @param event the selection change event
297 protected void handleTableSelectionChanged(SelectionChangedEvent event) {
298 int size = ((IStructuredSelection)event.getSelection()).size();
299 envEditButton.setEnabled(size == 1);
300 envRemoveButton.setEnabled(size > 0);
304 * Creates the add/edit/remove buttons for the environment table
305 * @param parent the composite in which the buttons should be created
307 protected void createTableButtons(Composite parent) {
308 // Create button composite
309 Composite buttonComposite = new Composite(parent, SWT.NONE);
310 GridLayout glayout = new GridLayout();
311 glayout.marginHeight = 0;
312 glayout.marginWidth = 0;
313 glayout.numColumns = 1;
314 GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
315 buttonComposite.setLayout(glayout);
316 buttonComposite.setLayoutData(gdata);
317 buttonComposite.setFont(parent.getFont());
319 createVerticalSpacer(buttonComposite, 1);
321 envAddButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_New_4, null); //$NON-NLS-1$
322 envAddButton.addSelectionListener(new SelectionAdapter()
324 public void widgetSelected(SelectionEvent event) {
325 handleEnvAddButtonSelected();
328 envAddCGIButton = createPushButton(buttonComposite, PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment2.CGIButton"), null); //$NON-NLS-1$
329 envAddCGIButton.addSelectionListener(new SelectionAdapter() {
330 public void widgetSelected(SelectionEvent event) {
331 handleEnvAddCGIButtonSelected();
335 envSelectButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_18, null); //$NON-NLS-1$
336 envSelectButton.addSelectionListener(new SelectionAdapter() {
337 public void widgetSelected(SelectionEvent event) {
338 handleEnvSelectButtonSelected();
341 envEditButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Edit_5, null); //$NON-NLS-1$
342 envEditButton.addSelectionListener(new SelectionAdapter()
344 public void widgetSelected(SelectionEvent event) {
345 handleEnvEditButtonSelected();
348 envEditButton.setEnabled(false);
349 envRemoveButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Remove_6, null); //$NON-NLS-1$
350 envRemoveButton.addSelectionListener(new SelectionAdapter()
352 public void widgetSelected(SelectionEvent event) {
353 handleEnvRemoveButtonSelected();
356 envRemoveButton.setEnabled(false);
360 * Adds a new environment variable to the table.
362 protected void handleEnvAddButtonSelected() {
363 MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_22); //$NON-NLS-1$
364 dialog.addTextField(NAME_LABEL, null, false);
365 dialog.addVariablesField(VALUE_LABEL, null, true);
367 if (dialog.open() != Window.OK) {
371 String name = dialog.getStringValue(NAME_LABEL);
372 String value = dialog.getStringValue(VALUE_LABEL);
374 if (name != null && value != null && name.length() > 0 && value.length() >0) {
375 addVariable(new EnvironmentVariable(name.trim(), value.trim()));
376 updateAppendReplace();
381 * Attempts to add the given variable. Returns whether the variable
382 * was added or not (as when the user answers not to overwrite an
383 * existing variable).
384 * @param variable the variable to add
385 * @return whether the variable was added
387 protected boolean addVariable(EnvironmentVariable variable) {
388 String name= variable.getName();
389 TableItem[] items = environmentTable.getTable().getItems();
390 for (int i = 0; i < items.length; i++) {
391 EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData();
392 if (existingVariable.getName().equals(name)) {
393 boolean overWrite= MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.EnvironmentTab_12, MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_13, new String[] {name})); //$NON-NLS-1$ //$NON-NLS-2$
397 environmentTable.remove(existingVariable);
401 environmentTable.add(variable);
402 updateLaunchConfigurationDialog();
407 * Displays a dialog that allows user to select native environment variables
408 * to add to the table.
410 private void handleEnvSelectButtonSelected() {
411 //get Environment Variables from the OS
412 Map envVariables = getNativeEnvironment();
414 //get Environment Variables from the table
415 TableItem[] items = environmentTable.getTable().getItems();
416 for (int i = 0; i < items.length; i++) {
417 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
418 envVariables.remove(var.getName());
421 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
422 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
424 int button = dialog.open();
425 if (button == Window.OK) {
426 Object[] selected = dialog.getResult();
427 for (int i = 0; i < selected.length; i++) {
428 environmentTable.add(selected[i]);
432 updateAppendReplace();
433 updateLaunchConfigurationDialog();
437 * Displays a dialog that allows user to select native environment variables
438 * to add to the table.
440 private void handleEnvAddCGIButtonSelected() {
442 Map envVariables = new HashMap();
445 envVariables.put("HTTP_COOKIE",new EnvironmentVariable("HTTP_COOKIE", "TestCookie=1"));
446 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING", ""));
447 envVariables.put("REDIRECT_STATUS",new EnvironmentVariable("REDIRECT_STATUS", "200"));
448 envVariables.put("REDIRECT_URL",new EnvironmentVariable("REDIRECT_URL", ""));
449 envVariables.put("SERVER_SOFTWARE",new EnvironmentVariable("SERVER_SOFTWARE","DBG / 2.1"));
450 envVariables.put("SERVER_NAME",new EnvironmentVariable("SERVER_NAME","localhost"));
451 envVariables.put("SERVER_ADDR",new EnvironmentVariable("SERVER_ADDR","127.0.0.1"));
452 envVariables.put("SERVER_PORT",new EnvironmentVariable("SERVER_PORT","80"));
453 envVariables.put("REMOTE_ADDR",new EnvironmentVariable("REMOTE_ADDR","127.0.0.1"));
454 envVariables.put("GATEWAY_INTERFACE",new EnvironmentVariable("GATEWAY_INTERFACE","CGI / 1.1"));
455 envVariables.put("SERVER_PROTOCOL",new EnvironmentVariable("SERVER_PROTOCOL","HTTP / 1.1"));
456 envVariables.put("REQUEST_METHOD",new EnvironmentVariable("REQUEST_METHOD","GET"));
457 envVariables.put("QUERY_STRING",new EnvironmentVariable("QUERY_STRING",""));
458 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING",""));
459 // envVariables.put("REQUEST_URI" + OSFilePath;
460 // envVariables.put("PATH_INFO=" + OSFilePath;
461 // envVariables.put("PATH_TRANSLATED=" + OSFilePath;
464 //get Environment Variables from the table
465 TableItem[] items = environmentTable.getTable().getItems();
466 for (int i = 0; i < items.length; i++) {
467 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
468 envVariables.remove(var.getName());
471 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
472 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
474 int button = dialog.open();
475 if (button == Window.OK) {
476 Object[] selected = dialog.getResult();
477 for (int i = 0; i < selected.length; i++) {
478 environmentTable.add(selected[i]);
482 updateAppendReplace();
483 updateLaunchConfigurationDialog();
488 * Creates a label provider for the native native environment variable selection dialog.
489 * @return A label provider for the native native environment variable selection dialog.
491 private ILabelProvider createSelectionDialogLabelProvider() {
492 return new ILabelProvider() {
493 public Image getImage(Object element) {
496 public String getText(Object element) {
497 EnvironmentVariable var = (EnvironmentVariable) element;
498 return var.getName() + " [" + var.getValue() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
500 public void addListener(ILabelProviderListener listener) {
502 public void dispose() {
504 public boolean isLabelProperty(Object element, String property) {
507 public void removeListener(ILabelProviderListener listener) {
513 * Creates a content provider for the native native environment variable selection dialog.
514 * @return A content provider for the native native environment variable selection dialog.
516 private IStructuredContentProvider createSelectionDialogContentProvider() {
517 return new IStructuredContentProvider() {
518 public Object[] getElements(Object inputElement) {
519 EnvironmentVariable[] elements = null;
520 if (inputElement instanceof HashMap) {
521 Comparator comparator = new Comparator() {
522 public int compare(Object o1, Object o2) {
523 String s1 = (String)o1;
524 String s2 = (String)o2;
525 return s1.compareTo(s2);
529 TreeMap envVars = new TreeMap(comparator);
530 envVars.putAll((Map)inputElement);
531 elements = new EnvironmentVariable[envVars.size()];
533 for (Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); index++) {
534 Object key = iterator.next();
535 elements[index] = (EnvironmentVariable) envVars.get(key);
540 public void dispose() {
542 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
548 * Gets native environment variable from the LaunchManager. Creates EnvironmentVariable objects.
549 * @return Map of name - EnvironmentVariable pairs based on native environment.
551 private Map getNativeEnvironment() {
552 Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
553 HashMap vars = new HashMap();
554 for (Iterator i = stringVars.keySet().iterator(); i.hasNext(); ) {
555 String key = (String) i.next();
556 String value = (String) stringVars.get(key);
557 vars.put(key, new EnvironmentVariable(key, value));
563 * Creates an editor for the value of the selected environment variable.
565 private void handleEnvEditButtonSelected() {
566 IStructuredSelection sel= (IStructuredSelection) environmentTable.getSelection();
567 EnvironmentVariable var= (EnvironmentVariable) sel.getFirstElement();
571 String originalName= var.getName();
572 String value= var.getValue();
573 MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_11); //$NON-NLS-1$
574 dialog.addTextField(NAME_LABEL, originalName, false);
575 dialog.addVariablesField(VALUE_LABEL, value, true);
577 if (dialog.open() != Window.OK) {
580 String name= dialog.getStringValue(NAME_LABEL);
581 value= dialog.getStringValue(VALUE_LABEL);
582 if (!originalName.equals(name)) {
583 if (addVariable(new EnvironmentVariable(name, value))) {
584 environmentTable.remove(var);
588 environmentTable.update(var, null);
589 updateLaunchConfigurationDialog();
594 * Removes the selected environment variable from the table.
596 private void handleEnvRemoveButtonSelected() {
597 IStructuredSelection sel = (IStructuredSelection) environmentTable.getSelection();
598 environmentTable.getControl().setRedraw(false);
599 for (Iterator i = sel.iterator(); i.hasNext(); ) {
600 EnvironmentVariable var = (EnvironmentVariable) i.next();
601 environmentTable.remove(var);
603 environmentTable.getControl().setRedraw(true);
604 updateAppendReplace();
605 updateLaunchConfigurationDialog();
609 * Updates the environment table for the given launch configuration
610 * @param configuration
612 protected void updateEnvironment(ILaunchConfiguration configuration) {
613 environmentTable.setInput(configuration);
617 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
619 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
623 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
625 public void initializeFrom(ILaunchConfiguration configuration) {
626 boolean append= true;
628 append = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
629 } catch (CoreException e) {
630 DebugUIPlugin.log(e.getStatus());
633 appendEnvironment.setSelection(true);
634 replaceEnvironment.setSelection(false);
636 replaceEnvironment.setSelection(true);
637 appendEnvironment.setSelection(false);
639 updateEnvironment(configuration);
640 updateAppendReplace();
644 * Stores the environment in the given configuration
645 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
647 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
648 // Convert the table's items into a Map so that this can be saved in the
649 // configuration's attributes.
650 TableItem[] items = environmentTable.getTable().getItems();
651 Map map = new HashMap(items.length);
652 for (int i = 0; i < items.length; i++)
654 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
655 map.put(var.getName(), var.getValue());
657 if (map.size() == 0) {
658 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
660 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
662 configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, appendEnvironment.getSelection());
666 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
668 public String getName() {
669 return LaunchConfigurationsMessages.EnvironmentTab_Environment_7; //$NON-NLS-1$
673 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
675 public Image getImage() {
676 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
680 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
682 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
683 // do nothing when activated
687 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
689 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
690 // do nothing when deactivated
693 private class NativeEnvironmentDialog extends ListSelectionDialog {
694 public NativeEnvironmentDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String message) {
695 super(parentShell, input, contentProvider, labelProvider, message);
696 setShellStyle(getShellStyle() | SWT.RESIZE);
699 protected IDialogSettings getDialogSettings() {
700 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
701 IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
702 if (section == null) {
703 section = settings.addNewSection(getDialogSettingsSectionName());
709 * Returns the name of the section that this dialog stores its settings in
713 protected String getDialogSettingsSectionName() {
714 return IDebugUIConstants.PLUGIN_ID + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$