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.DialogSettingsHelper;
28 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
29 import org.eclipse.debug.internal.ui.MultipleInputDialog;
30 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
31 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages;
32 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
33 import org.eclipse.debug.ui.IDebugUIConstants;
34 import org.eclipse.jface.dialogs.Dialog;
35 import org.eclipse.jface.dialogs.IDialogSettings;
36 import org.eclipse.jface.dialogs.MessageDialog;
37 import org.eclipse.jface.viewers.ColumnLayoutData;
38 import org.eclipse.jface.viewers.ColumnWeightData;
39 import org.eclipse.jface.viewers.DoubleClickEvent;
40 import org.eclipse.jface.viewers.IDoubleClickListener;
41 import org.eclipse.jface.viewers.ILabelProvider;
42 import org.eclipse.jface.viewers.ILabelProviderListener;
43 import org.eclipse.jface.viewers.ISelectionChangedListener;
44 import org.eclipse.jface.viewers.IStructuredContentProvider;
45 import org.eclipse.jface.viewers.IStructuredSelection;
46 import org.eclipse.jface.viewers.ITableLabelProvider;
47 import org.eclipse.jface.viewers.LabelProvider;
48 import org.eclipse.jface.viewers.SelectionChangedEvent;
49 import org.eclipse.jface.viewers.TableLayout;
50 import org.eclipse.jface.viewers.TableViewer;
51 import org.eclipse.jface.viewers.Viewer;
52 import org.eclipse.jface.viewers.ViewerSorter;
53 import org.eclipse.jface.window.Window;
54 import org.eclipse.swt.SWT;
55 import org.eclipse.swt.events.SelectionAdapter;
56 import org.eclipse.swt.events.SelectionEvent;
57 import org.eclipse.swt.graphics.Font;
58 import org.eclipse.swt.graphics.Image;
59 import org.eclipse.swt.graphics.Point;
60 import org.eclipse.swt.layout.GridData;
61 import org.eclipse.swt.layout.GridLayout;
62 import org.eclipse.swt.widgets.Button;
63 import org.eclipse.swt.widgets.Composite;
64 import org.eclipse.swt.widgets.Label;
65 import org.eclipse.swt.widgets.Shell;
66 import org.eclipse.swt.widgets.Table;
67 import org.eclipse.swt.widgets.TableColumn;
68 import org.eclipse.swt.widgets.TableItem;
69 import org.eclipse.ui.PlatformUI;
70 import org.eclipse.ui.dialogs.ListSelectionDialog;
75 * TODO To change the template for this generated type comment go to
76 * Window - Preferences - Java - Code Style - Code Templates
78 public class PHPEnvironmentTab2 extends AbstractLaunchConfigurationTab {
81 protected TableViewer environmentTable;
82 protected String[] envTableColumnHeaders =
84 LaunchConfigurationsMessages.EnvironmentTab_Variable_1, //$NON-NLS-1$
85 LaunchConfigurationsMessages.EnvironmentTab_Value_2 //$NON-NLS-1$
87 protected ColumnLayoutData[] envTableColumnLayouts =
89 new ColumnWeightData(50),
90 new ColumnWeightData(50)
92 private static final String NAME_LABEL= LaunchConfigurationsMessages.EnvironmentTab_8; //$NON-NLS-1$
93 private static final String VALUE_LABEL= LaunchConfigurationsMessages.EnvironmentTab_9; //$NON-NLS-1$
94 protected static final String P_VARIABLE = "variable"; //$NON-NLS-1$
95 protected static final String P_VALUE = "value"; //$NON-NLS-1$
96 protected static String[] envTableColumnProperties =
101 protected Button envAddButton;
102 protected Button envAddCGIButton;
103 protected Button envEditButton;
104 protected Button envRemoveButton;
105 protected Button appendEnvironment;
106 protected Button replaceEnvironment;
107 protected Button envSelectButton;
110 * Content provider for the environment table
112 protected class EnvironmentVariableContentProvider implements IStructuredContentProvider {
113 public Object[] getElements(Object inputElement) {
114 EnvironmentVariable[] elements = new EnvironmentVariable[0];
115 ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
118 m = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
119 } catch (CoreException e) {
120 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Error reading configuration", e)); //$NON-NLS-1$
123 if (m != null && !m.isEmpty()) {
124 elements = new EnvironmentVariable[m.size()];
125 String[] varNames = new String[m.size()];
126 m.keySet().toArray(varNames);
127 for (int i = 0; i < m.size(); i++) {
128 elements[i] = new EnvironmentVariable(varNames[i], (String) m.get(varNames[i]));
133 public void dispose() {
135 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
136 if (newInput == null){
139 if (viewer instanceof TableViewer){
140 TableViewer tableViewer= (TableViewer) viewer;
141 if (tableViewer.getTable().isDisposed()) {
144 tableViewer.setSorter(new ViewerSorter() {
145 public int compare(Viewer iviewer, Object e1, Object e2) {
148 } else if (e2 == null) {
151 return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
160 * Label provider for the environment table
162 public class EnvironmentVariableLabelProvider extends LabelProvider implements ITableLabelProvider {
163 public String getColumnText(Object element, int columnIndex) {
164 String result = null;
165 if (element != null) {
166 EnvironmentVariable var = (EnvironmentVariable) element;
167 switch (columnIndex) {
169 result = var.getName();
172 result = var.getValue();
178 public Image getColumnImage(Object element, int columnIndex) {
184 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
186 public void createControl(Composite parent) {
187 // Create main composite
188 Composite mainComposite = new Composite(parent, SWT.NONE);
189 setControl(mainComposite);
190 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
191 GridLayout layout = new GridLayout();
192 layout.numColumns = 2;
193 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
194 mainComposite.setLayout(layout);
195 mainComposite.setLayoutData(gridData);
196 mainComposite.setFont(parent.getFont());
198 createEnvironmentTable(mainComposite);
199 createTableButtons(mainComposite);
200 createAppendReplace(mainComposite);
202 Dialog.applyDialogFont(mainComposite);
206 * Creates and configures the widgets which allow the user to
207 * choose whether the specified environment should be appended
208 * to the native environment or if it should completely replace it.
209 * @param parent the composite in which the widgets should be created
211 protected void createAppendReplace(Composite parent) {
212 Composite appendReplaceComposite= new Composite(parent, SWT.NONE);
213 GridData gridData= new GridData();
214 gridData.horizontalSpan= 2;
215 GridLayout layout= new GridLayout();
216 appendReplaceComposite.setLayoutData(gridData);
217 appendReplaceComposite.setLayout(layout);
218 appendReplaceComposite.setFont(parent.getFont());
220 appendEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_16); //$NON-NLS-1$
221 appendEnvironment.addSelectionListener(new SelectionAdapter() {
222 public void widgetSelected(SelectionEvent e) {
223 updateLaunchConfigurationDialog();
226 replaceEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_17); //$NON-NLS-1$
230 * Updates the enablement of the append/replace widgets. The
231 * widgets should disable when there are no environment variables specified.
233 protected void updateAppendReplace() {
234 boolean enable= environmentTable.getTable().getItemCount() > 0;
235 appendEnvironment.setEnabled(enable);
236 replaceEnvironment.setEnabled(enable);
240 * Creates and configures the table that displayed the key/value
241 * pairs that comprise the environment.
242 * @param parent the composite in which the table should be created
244 protected void createEnvironmentTable(Composite parent) {
245 Font font= parent.getFont();
246 // Create table composite
247 Composite tableComposite = new Composite(parent, SWT.NONE);
248 GridLayout layout = new GridLayout();
249 layout.marginHeight = 0;
250 layout.marginWidth = 0;
251 layout.numColumns = 1;
252 GridData gridData = new GridData(GridData.FILL_BOTH);
253 gridData.heightHint = 150;
254 tableComposite.setLayout(layout);
255 tableComposite.setLayoutData(gridData);
256 tableComposite.setFont(font);
258 Label label = new Label(tableComposite, SWT.NONE);
260 label.setText(LaunchConfigurationsMessages.EnvironmentTab_Environment_variables_to_set__3); //$NON-NLS-1$
262 environmentTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
263 Table table = environmentTable.getTable();
264 TableLayout tableLayout = new TableLayout();
265 table.setLayout(tableLayout);
266 table.setHeaderVisible(true);
268 gridData = new GridData(GridData.FILL_BOTH);
269 environmentTable.getControl().setLayoutData(gridData);
270 environmentTable.setContentProvider(new EnvironmentVariableContentProvider());
271 environmentTable.setLabelProvider(new EnvironmentVariableLabelProvider());
272 environmentTable.setColumnProperties(envTableColumnProperties);
273 environmentTable.addSelectionChangedListener(new ISelectionChangedListener() {
274 public void selectionChanged(SelectionChangedEvent event) {
275 handleTableSelectionChanged(event);
278 environmentTable.addDoubleClickListener(new IDoubleClickListener() {
279 public void doubleClick(DoubleClickEvent event) {
280 if (!environmentTable.getSelection().isEmpty()) {
281 handleEnvEditButtonSelected();
286 for (int i = 0; i < envTableColumnHeaders.length; i++) {
287 tableLayout.addColumnData(envTableColumnLayouts[i]);
288 TableColumn tc = new TableColumn(table, SWT.NONE, i);
289 tc.setResizable(envTableColumnLayouts[i].resizable);
290 tc.setText(envTableColumnHeaders[i]);
295 * Responds to a selection changed event in the environment table
296 * @param event the selection change event
298 protected void handleTableSelectionChanged(SelectionChangedEvent event) {
299 int size = ((IStructuredSelection)event.getSelection()).size();
300 envEditButton.setEnabled(size == 1);
301 envRemoveButton.setEnabled(size > 0);
305 * Creates the add/edit/remove buttons for the environment table
306 * @param parent the composite in which the buttons should be created
308 protected void createTableButtons(Composite parent) {
309 // Create button composite
310 Composite buttonComposite = new Composite(parent, SWT.NONE);
311 GridLayout glayout = new GridLayout();
312 glayout.marginHeight = 0;
313 glayout.marginWidth = 0;
314 glayout.numColumns = 1;
315 GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
316 buttonComposite.setLayout(glayout);
317 buttonComposite.setLayoutData(gdata);
318 buttonComposite.setFont(parent.getFont());
320 createVerticalSpacer(buttonComposite, 1);
322 envAddButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_New_4, null); //$NON-NLS-1$
323 envAddButton.addSelectionListener(new SelectionAdapter()
325 public void widgetSelected(SelectionEvent event) {
326 handleEnvAddButtonSelected();
329 envAddCGIButton = createPushButton(buttonComposite, PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment2.CGIButton"), null); //$NON-NLS-1$
330 envAddCGIButton.addSelectionListener(new SelectionAdapter() {
331 public void widgetSelected(SelectionEvent event) {
332 handleEnvAddCGIButtonSelected();
336 envSelectButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_18, null); //$NON-NLS-1$
337 envSelectButton.addSelectionListener(new SelectionAdapter() {
338 public void widgetSelected(SelectionEvent event) {
339 handleEnvSelectButtonSelected();
342 envEditButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Edit_5, null); //$NON-NLS-1$
343 envEditButton.addSelectionListener(new SelectionAdapter()
345 public void widgetSelected(SelectionEvent event) {
346 handleEnvEditButtonSelected();
349 envEditButton.setEnabled(false);
350 envRemoveButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Remove_6, null); //$NON-NLS-1$
351 envRemoveButton.addSelectionListener(new SelectionAdapter()
353 public void widgetSelected(SelectionEvent event) {
354 handleEnvRemoveButtonSelected();
357 envRemoveButton.setEnabled(false);
361 * Adds a new environment variable to the table.
363 protected void handleEnvAddButtonSelected() {
364 MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_22); //$NON-NLS-1$
365 dialog.addTextField(NAME_LABEL, null, false);
366 dialog.addVariablesField(VALUE_LABEL, null, true);
368 if (dialog.open() != Window.OK) {
372 String name = dialog.getStringValue(NAME_LABEL);
373 String value = dialog.getStringValue(VALUE_LABEL);
375 if (name != null && value != null && name.length() > 0 && value.length() >0) {
376 addVariable(new EnvironmentVariable(name.trim(), value.trim()));
377 updateAppendReplace();
382 * Attempts to add the given variable. Returns whether the variable
383 * was added or not (as when the user answers not to overwrite an
384 * existing variable).
385 * @param variable the variable to add
386 * @return whether the variable was added
388 protected boolean addVariable(EnvironmentVariable variable) {
389 String name= variable.getName();
390 TableItem[] items = environmentTable.getTable().getItems();
391 for (int i = 0; i < items.length; i++) {
392 EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData();
393 if (existingVariable.getName().equals(name)) {
394 boolean overWrite= MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.EnvironmentTab_12, MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_13, new String[] {name})); //$NON-NLS-1$ //$NON-NLS-2$
398 environmentTable.remove(existingVariable);
402 environmentTable.add(variable);
403 updateLaunchConfigurationDialog();
408 * Displays a dialog that allows user to select native environment variables
409 * to add to the table.
411 private void handleEnvSelectButtonSelected() {
412 //get Environment Variables from the OS
413 Map envVariables = getNativeEnvironment();
415 //get Environment Variables from the table
416 TableItem[] items = environmentTable.getTable().getItems();
417 for (int i = 0; i < items.length; i++) {
418 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
419 envVariables.remove(var.getName());
422 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
423 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
425 int button = dialog.open();
426 if (button == Window.OK) {
427 Object[] selected = dialog.getResult();
428 for (int i = 0; i < selected.length; i++) {
429 environmentTable.add(selected[i]);
433 updateAppendReplace();
434 updateLaunchConfigurationDialog();
438 * Displays a dialog that allows user to select native environment variables
439 * to add to the table.
441 private void handleEnvAddCGIButtonSelected() {
443 Map envVariables = new HashMap();
446 envVariables.put("HTTP_COOKIE",new EnvironmentVariable("HTTP_COOKIE", "TestCookie=1"));
447 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING", ""));
448 envVariables.put("REDIRECT_STATUS",new EnvironmentVariable("REDIRECT_STATUS", "200"));
449 envVariables.put("REDIRECT_URL",new EnvironmentVariable("REDIRECT_URL", ""));
450 envVariables.put("SERVER_SOFTWARE",new EnvironmentVariable("SERVER_SOFTWARE","DBG / 2.1"));
451 envVariables.put("SERVER_NAME",new EnvironmentVariable("SERVER_NAME","localhost"));
452 envVariables.put("SERVER_ADDR",new EnvironmentVariable("SERVER_ADDR","127.0.0.1"));
453 envVariables.put("SERVER_PORT",new EnvironmentVariable("SERVER_PORT","80"));
454 envVariables.put("REMOTE_ADDR",new EnvironmentVariable("REMOTE_ADDR","127.0.0.1"));
455 envVariables.put("GATEWAY_INTERFACE",new EnvironmentVariable("GATEWAY_INTERFACE","CGI / 1.1"));
456 envVariables.put("SERVER_PROTOCOL",new EnvironmentVariable("SERVER_PROTOCOL","HTTP / 1.1"));
457 envVariables.put("REQUEST_METHOD",new EnvironmentVariable("REQUEST_METHOD","GET"));
458 envVariables.put("QUERY_STRING",new EnvironmentVariable("QUERY_STRING",""));
459 envVariables.put("REDIRECT_QUERY_STRING",new EnvironmentVariable("REDIRECT_QUERY_STRING",""));
460 // envVariables.put("REQUEST_URI" + OSFilePath;
461 // envVariables.put("PATH_INFO=" + OSFilePath;
462 // envVariables.put("PATH_TRANSLATED=" + OSFilePath;
465 //get Environment Variables from the table
466 TableItem[] items = environmentTable.getTable().getItems();
467 for (int i = 0; i < items.length; i++) {
468 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
469 envVariables.remove(var.getName());
472 ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19); //$NON-NLS-1$
473 dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); //$NON-NLS-1$
475 int button = dialog.open();
476 if (button == Window.OK) {
477 Object[] selected = dialog.getResult();
478 for (int i = 0; i < selected.length; i++) {
479 environmentTable.add(selected[i]);
483 updateAppendReplace();
484 updateLaunchConfigurationDialog();
489 * Creates a label provider for the native native environment variable selection dialog.
490 * @return A label provider for the native native environment variable selection dialog.
492 private ILabelProvider createSelectionDialogLabelProvider() {
493 return new ILabelProvider() {
494 public Image getImage(Object element) {
497 public String getText(Object element) {
498 EnvironmentVariable var = (EnvironmentVariable) element;
499 return var.getName() + " [" + var.getValue() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
501 public void addListener(ILabelProviderListener listener) {
503 public void dispose() {
505 public boolean isLabelProperty(Object element, String property) {
508 public void removeListener(ILabelProviderListener listener) {
514 * Creates a content provider for the native native environment variable selection dialog.
515 * @return A content provider for the native native environment variable selection dialog.
517 private IStructuredContentProvider createSelectionDialogContentProvider() {
518 return new IStructuredContentProvider() {
519 public Object[] getElements(Object inputElement) {
520 EnvironmentVariable[] elements = null;
521 if (inputElement instanceof HashMap) {
522 Comparator comparator = new Comparator() {
523 public int compare(Object o1, Object o2) {
524 String s1 = (String)o1;
525 String s2 = (String)o2;
526 return s1.compareTo(s2);
530 TreeMap envVars = new TreeMap(comparator);
531 envVars.putAll((Map)inputElement);
532 elements = new EnvironmentVariable[envVars.size()];
534 for (Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); index++) {
535 Object key = iterator.next();
536 elements[index] = (EnvironmentVariable) envVars.get(key);
541 public void dispose() {
543 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
549 * Gets native environment variable from the LaunchManager. Creates EnvironmentVariable objects.
550 * @return Map of name - EnvironmentVariable pairs based on native environment.
552 private Map getNativeEnvironment() {
553 Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
554 HashMap vars = new HashMap();
555 for (Iterator i = stringVars.keySet().iterator(); i.hasNext(); ) {
556 String key = (String) i.next();
557 String value = (String) stringVars.get(key);
558 vars.put(key, new EnvironmentVariable(key, value));
564 * Creates an editor for the value of the selected environment variable.
566 private void handleEnvEditButtonSelected() {
567 IStructuredSelection sel= (IStructuredSelection) environmentTable.getSelection();
568 EnvironmentVariable var= (EnvironmentVariable) sel.getFirstElement();
572 String originalName= var.getName();
573 String value= var.getValue();
574 MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_11); //$NON-NLS-1$
575 dialog.addTextField(NAME_LABEL, originalName, false);
576 dialog.addVariablesField(VALUE_LABEL, value, true);
578 if (dialog.open() != Window.OK) {
581 String name= dialog.getStringValue(NAME_LABEL);
582 value= dialog.getStringValue(VALUE_LABEL);
583 if (!originalName.equals(name)) {
584 if (addVariable(new EnvironmentVariable(name, value))) {
585 environmentTable.remove(var);
589 environmentTable.update(var, null);
590 updateLaunchConfigurationDialog();
595 * Removes the selected environment variable from the table.
597 private void handleEnvRemoveButtonSelected() {
598 IStructuredSelection sel = (IStructuredSelection) environmentTable.getSelection();
599 environmentTable.getControl().setRedraw(false);
600 for (Iterator i = sel.iterator(); i.hasNext(); ) {
601 EnvironmentVariable var = (EnvironmentVariable) i.next();
602 environmentTable.remove(var);
604 environmentTable.getControl().setRedraw(true);
605 updateAppendReplace();
606 updateLaunchConfigurationDialog();
610 * Updates the environment table for the given launch configuration
611 * @param configuration
613 protected void updateEnvironment(ILaunchConfiguration configuration) {
614 environmentTable.setInput(configuration);
618 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
620 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
624 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
626 public void initializeFrom(ILaunchConfiguration configuration) {
627 boolean append= true;
629 append = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
630 } catch (CoreException e) {
631 DebugUIPlugin.log(e.getStatus());
634 appendEnvironment.setSelection(true);
635 replaceEnvironment.setSelection(false);
637 replaceEnvironment.setSelection(true);
638 appendEnvironment.setSelection(false);
640 updateEnvironment(configuration);
641 updateAppendReplace();
645 * Stores the environment in the given configuration
646 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
648 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
649 // Convert the table's items into a Map so that this can be saved in the
650 // configuration's attributes.
651 TableItem[] items = environmentTable.getTable().getItems();
652 Map map = new HashMap(items.length);
653 for (int i = 0; i < items.length; i++)
655 EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
656 map.put(var.getName(), var.getValue());
658 if (map.size() == 0) {
659 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);
661 configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
663 configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, appendEnvironment.getSelection());
667 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
669 public String getName() {
670 return LaunchConfigurationsMessages.EnvironmentTab_Environment_7; //$NON-NLS-1$
674 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
676 public Image getImage() {
677 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
681 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
683 public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
684 // do nothing when activated
688 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
690 public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
691 // do nothing when deactivated
694 private class NativeEnvironmentDialog extends ListSelectionDialog {
695 public NativeEnvironmentDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String message) {
696 super(parentShell, input, contentProvider, labelProvider, message);
697 setShellStyle(getShellStyle() | SWT.RESIZE);
700 protected IDialogSettings getDialogSettings() {
701 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
702 IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
703 if (section == null) {
704 section = settings.addNewSection(getDialogSettingsSectionName());
710 * Returns the name of the section that this dialog stores its settings in
714 protected String getDialogSettingsSectionName() {
715 return IDebugUIConstants.PLUGIN_ID + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$
720 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
722 protected Point getInitialLocation(Point initialSize) {
723 Point initialLocation= DialogSettingsHelper.getInitialLocation(getDialogSettingsSectionName());
724 if (initialLocation != null) {
725 return initialLocation;
727 return super.getInitialLocation(initialSize);
731 * @see org.eclipse.jface.window.Window#getInitialSize()
733 protected Point getInitialSize() {
734 Point size = super.getInitialSize();
735 return DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(), size);
739 * @see org.eclipse.jface.window.Window#close()
741 public boolean close() {
742 DialogSettingsHelper.persistShellGeometry(getShell(), getDialogSettingsSectionName());
743 return super.close();