KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > EnvironmentTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 Keith Seitz and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Keith Seitz (keiths@redhat.com) - initial implementation
10  * IBM Corporation - integration and code cleanup
11  *******************************************************************************/

12 package org.eclipse.debug.ui;
13
14 import java.util.Comparator JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.TreeMap JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.debug.core.DebugPlugin;
24 import org.eclipse.debug.core.ILaunchConfiguration;
25 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26 import org.eclipse.debug.core.ILaunchManager;
27 import org.eclipse.debug.internal.ui.DebugPluginImages;
28 import org.eclipse.debug.internal.ui.DebugUIPlugin;
29 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
30 import org.eclipse.debug.internal.ui.MultipleInputDialog;
31 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
32 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages;
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.ViewerComparator;
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;
69
70 import com.ibm.icu.text.MessageFormat;
71
72 /**
73  * Launch configuration tab for configuring the environment passed
74  * into Runtime.exec(...) when a config is launched.
75  * <p>
76  * This class may be instantiated; this class is not intended
77  * to be subclassed.
78  * </p>
79  * @since 3.0
80  */

81 public class EnvironmentTab extends AbstractLaunchConfigurationTab {
82
83     protected TableViewer environmentTable;
84     protected String JavaDoc[] envTableColumnHeaders =
85     {
86         LaunchConfigurationsMessages.EnvironmentTab_Variable_1,
87         LaunchConfigurationsMessages.EnvironmentTab_Value_2,
88     };
89     protected ColumnLayoutData[] envTableColumnLayouts =
90     {
91         new ColumnWeightData(50),
92         new ColumnWeightData(50)
93     };
94     private static final String JavaDoc NAME_LABEL= LaunchConfigurationsMessages.EnvironmentTab_8;
95     private static final String JavaDoc VALUE_LABEL= LaunchConfigurationsMessages.EnvironmentTab_9;
96     protected static final String JavaDoc P_VARIABLE = "variable"; //$NON-NLS-1$
97
protected static final String JavaDoc P_VALUE = "value"; //$NON-NLS-1$
98
protected static String JavaDoc[] envTableColumnProperties =
99     {
100         P_VARIABLE,
101         P_VALUE
102     };
103     protected Button envAddButton;
104     protected Button envEditButton;
105     protected Button envRemoveButton;
106     protected Button appendEnvironment;
107     protected Button replaceEnvironment;
108     protected Button envSelectButton;
109     
110     /**
111      * Content provider for the environment table
112      */

113     protected class EnvironmentVariableContentProvider implements IStructuredContentProvider {
114         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
115             EnvironmentVariable[] elements = new EnvironmentVariable[0];
116             ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
117             Map JavaDoc m;
118             try {
119                 m = config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map JavaDoc) null);
120             } catch (CoreException e) {
121                 DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, "Error reading configuration", e)); //$NON-NLS-1$
122
return elements;
123             }
124             if (m != null && !m.isEmpty()) {
125                 elements = new EnvironmentVariable[m.size()];
126                 String JavaDoc[] varNames = new String JavaDoc[m.size()];
127                 m.keySet().toArray(varNames);
128                 for (int i = 0; i < m.size(); i++) {
129                     elements[i] = new EnvironmentVariable(varNames[i], (String JavaDoc) m.get(varNames[i]));
130                 }
131             }
132             return elements;
133         }
134         public void dispose() {
135         }
136         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
137             if (newInput == null){
138                 return;
139             }
140             if (viewer instanceof TableViewer){
141                 TableViewer tableViewer= (TableViewer) viewer;
142                 if (tableViewer.getTable().isDisposed()) {
143                     return;
144                 }
145                 tableViewer.setComparator(new ViewerComparator() {
146                     public int compare(Viewer iviewer, Object JavaDoc e1, Object JavaDoc e2) {
147                         if (e1 == null) {
148                             return -1;
149                         } else if (e2 == null) {
150                             return 1;
151                         } else {
152                             return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
153                         }
154                     }
155                 });
156             }
157         }
158     }
159     
160     /**
161      * Label provider for the environment table
162      */

163     public class EnvironmentVariableLabelProvider extends LabelProvider implements ITableLabelProvider {
164         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
165             String JavaDoc result = null;
166             if (element != null) {
167                 EnvironmentVariable var = (EnvironmentVariable) element;
168                 switch (columnIndex) {
169                     case 0: // variable
170
result = var.getName();
171                         break;
172                     case 1: // value
173
result = var.getValue();
174                         break;
175                 }
176             }
177             return result;
178         }
179         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
180             if (columnIndex == 0) {
181                 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENV_VAR);
182             }
183             return null;
184         }
185     }
186
187     /* (non-Javadoc)
188      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
189      */

190     public void createControl(Composite parent) {
191         // Create main composite
192
Composite mainComposite = new Composite(parent, SWT.NONE);
193         setControl(mainComposite);
194         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
195         GridLayout layout = new GridLayout();
196         layout.numColumns = 2;
197         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
198         mainComposite.setLayout(layout);
199         mainComposite.setLayoutData(gridData);
200         mainComposite.setFont(parent.getFont());
201         
202         createEnvironmentTable(mainComposite);
203         createTableButtons(mainComposite);
204         createAppendReplace(mainComposite);
205         
206         Dialog.applyDialogFont(mainComposite);
207     }
208     
209     /**
210      * Creates and configures the widgets which allow the user to
211      * choose whether the specified environment should be appended
212      * to the native environment or if it should completely replace it.
213      * @param parent the composite in which the widgets should be created
214      */

215     protected void createAppendReplace(Composite parent) {
216         Composite appendReplaceComposite= new Composite(parent, SWT.NONE);
217         GridData gridData= new GridData();
218         gridData.horizontalSpan= 2;
219         GridLayout layout= new GridLayout();
220         appendReplaceComposite.setLayoutData(gridData);
221         appendReplaceComposite.setLayout(layout);
222         appendReplaceComposite.setFont(parent.getFont());
223         
224         appendEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_16);
225         appendEnvironment.addSelectionListener(new SelectionAdapter() {
226             public void widgetSelected(SelectionEvent e) {
227                 updateLaunchConfigurationDialog();
228             }
229         });
230         replaceEnvironment= createRadioButton(appendReplaceComposite, LaunchConfigurationsMessages.EnvironmentTab_17);
231     }
232     
233     /**
234      * Updates the enablement of the append/replace widgets. The
235      * widgets should disable when there are no environment variables specified.
236      */

237     protected void updateAppendReplace() {
238         boolean enable= environmentTable.getTable().getItemCount() > 0;
239         appendEnvironment.setEnabled(enable);
240         replaceEnvironment.setEnabled(enable);
241     }
242     
243     /**
244      * Creates and configures the table that displayed the key/value
245      * pairs that comprise the environment.
246      * @param parent the composite in which the table should be created
247      */

248     protected void createEnvironmentTable(Composite parent) {
249         Font font= parent.getFont();
250         // Create table composite
251
Composite tableComposite = new Composite(parent, SWT.NONE);
252         GridLayout layout = new GridLayout();
253         layout.marginHeight = 0;
254         layout.marginWidth = 0;
255         layout.numColumns = 1;
256         GridData gridData = new GridData(GridData.FILL_BOTH);
257         gridData.heightHint = 150;
258         tableComposite.setLayout(layout);
259         tableComposite.setLayoutData(gridData);
260         tableComposite.setFont(font);
261         // Create label
262
Label label = new Label(tableComposite, SWT.NONE);
263         label.setFont(font);
264         label.setText(LaunchConfigurationsMessages.EnvironmentTab_Environment_variables_to_set__3);
265         // Create table
266
environmentTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
267         Table table = environmentTable.getTable();
268         TableLayout tableLayout = new TableLayout();
269         table.setLayout(tableLayout);
270         table.setHeaderVisible(true);
271         table.setFont(font);
272         gridData = new GridData(GridData.FILL_BOTH);
273         environmentTable.getControl().setLayoutData(gridData);
274         environmentTable.setContentProvider(new EnvironmentVariableContentProvider());
275         environmentTable.setLabelProvider(new EnvironmentVariableLabelProvider());
276         environmentTable.setColumnProperties(envTableColumnProperties);
277         environmentTable.addSelectionChangedListener(new ISelectionChangedListener() {
278             public void selectionChanged(SelectionChangedEvent event) {
279                 handleTableSelectionChanged(event);
280             }
281         });
282         environmentTable.addDoubleClickListener(new IDoubleClickListener() {
283             public void doubleClick(DoubleClickEvent event) {
284                 if (!environmentTable.getSelection().isEmpty()) {
285                     handleEnvEditButtonSelected();
286                 }
287             }
288         });
289         // Create columns
290
for (int i = 0; i < envTableColumnHeaders.length; i++) {
291             tableLayout.addColumnData(envTableColumnLayouts[i]);
292             TableColumn tc = new TableColumn(table, SWT.NONE, i);
293             tc.setResizable(envTableColumnLayouts[i].resizable);
294             tc.setText(envTableColumnHeaders[i]);
295         }
296     }
297     
298     /**
299      * Responds to a selection changed event in the environment table
300      * @param event the selection change event
301      */

302     protected void handleTableSelectionChanged(SelectionChangedEvent event) {
303         int size = ((IStructuredSelection)event.getSelection()).size();
304         envEditButton.setEnabled(size == 1);
305         envRemoveButton.setEnabled(size > 0);
306     }
307     
308     /**
309      * Creates the add/edit/remove buttons for the environment table
310      * @param parent the composite in which the buttons should be created
311      */

312     protected void createTableButtons(Composite parent) {
313         // Create button composite
314
Composite buttonComposite = new Composite(parent, SWT.NONE);
315         GridLayout glayout = new GridLayout();
316         glayout.marginHeight = 0;
317         glayout.marginWidth = 0;
318         glayout.numColumns = 1;
319         GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
320         buttonComposite.setLayout(glayout);
321         buttonComposite.setLayoutData(gdata);
322         buttonComposite.setFont(parent.getFont());
323
324         createVerticalSpacer(buttonComposite, 1);
325         // Create buttons
326
envAddButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_New_4, null);
327         envAddButton.addSelectionListener(new SelectionAdapter()
328         {
329             public void widgetSelected(SelectionEvent event) {
330                 handleEnvAddButtonSelected();
331             }
332                 });
333         envSelectButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_18, null);
334         envSelectButton.addSelectionListener(new SelectionAdapter() {
335             public void widgetSelected(SelectionEvent event) {
336                 handleEnvSelectButtonSelected();
337             }
338         });
339         envEditButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Edit_5, null);
340         envEditButton.addSelectionListener(new SelectionAdapter()
341         {
342             public void widgetSelected(SelectionEvent event) {
343                 handleEnvEditButtonSelected();
344             }
345         });
346         envEditButton.setEnabled(false);
347         envRemoveButton = createPushButton(buttonComposite, LaunchConfigurationsMessages.EnvironmentTab_Remove_6, null);
348         envRemoveButton.addSelectionListener(new SelectionAdapter()
349         {
350             public void widgetSelected(SelectionEvent event) {
351                 handleEnvRemoveButtonSelected();
352             }
353         });
354         envRemoveButton.setEnabled(false);
355     }
356     
357     /**
358      * Adds a new environment variable to the table.
359      */

360     protected void handleEnvAddButtonSelected() {
361         MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_22);
362         dialog.addTextField(NAME_LABEL, null, false);
363         dialog.addVariablesField(VALUE_LABEL, null, true);
364         
365         if (dialog.open() != Window.OK) {
366             return;
367         }
368         
369         String JavaDoc name = dialog.getStringValue(NAME_LABEL);
370         String JavaDoc value = dialog.getStringValue(VALUE_LABEL);
371         
372         if (name != null && value != null && name.length() > 0 && value.length() >0) {
373             addVariable(new EnvironmentVariable(name.trim(), value.trim()));
374             updateAppendReplace();
375         }
376     }
377     
378     /**
379      * Attempts to add the given variable. Returns whether the variable
380      * was added or not (as when the user answers not to overwrite an
381      * existing variable).
382      * @param variable the variable to add
383      * @return whether the variable was added
384      */

385     protected boolean addVariable(EnvironmentVariable variable) {
386         String JavaDoc name= variable.getName();
387         TableItem[] items = environmentTable.getTable().getItems();
388         for (int i = 0; i < items.length; i++) {
389             EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData();
390             if (existingVariable.getName().equals(name)) {
391                 boolean overWrite= MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.EnvironmentTab_12, MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_13, new String JavaDoc[] {name})); //
392
if (!overWrite) {
393                     return false;
394                 }
395                 environmentTable.remove(existingVariable);
396                 break;
397             }
398         }
399         environmentTable.add(variable);
400         updateLaunchConfigurationDialog();
401         return true;
402     }
403     
404     /**
405      * Displays a dialog that allows user to select native environment variables
406      * to add to the table.
407      */

408     private void handleEnvSelectButtonSelected() {
409         //get Environment Variables from the OS
410
Map JavaDoc envVariables = getNativeEnvironment();
411         
412         //get Environment Variables from the table
413
TableItem[] items = environmentTable.getTable().getItems();
414         for (int i = 0; i < items.length; i++) {
415             EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
416             envVariables.remove(var.getName());
417         }
418         
419         ListSelectionDialog dialog = new NativeEnvironmentDialog(getShell(), envVariables, createSelectionDialogContentProvider(), createSelectionDialogLabelProvider(), LaunchConfigurationsMessages.EnvironmentTab_19);
420         dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20);
421         
422         int button = dialog.open();
423         if (button == Window.OK) {
424             Object JavaDoc[] selected = dialog.getResult();
425             for (int i = 0; i < selected.length; i++) {
426                 environmentTable.add(selected[i]);
427             }
428         }
429         
430         updateAppendReplace();
431         updateLaunchConfigurationDialog();
432     }
433
434     /**
435      * Creates a label provider for the native native environment variable selection dialog.
436      * @return A label provider for the native native environment variable selection dialog.
437      */

438     private ILabelProvider createSelectionDialogLabelProvider() {
439         return new ILabelProvider() {
440             public Image getImage(Object JavaDoc element) {
441                 return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
442             }
443             public String JavaDoc getText(Object JavaDoc element) {
444                 EnvironmentVariable var = (EnvironmentVariable) element;
445                 return MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_7, new String JavaDoc[] {var.getName(), var.getValue()});
446             }
447             public void addListener(ILabelProviderListener listener) {
448             }
449             public void dispose() {
450             }
451             public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
452                 return false;
453             }
454             public void removeListener(ILabelProviderListener listener) {
455             }
456         };
457     }
458
459     /**
460      * Creates a content provider for the native native environment variable selection dialog.
461      * @return A content provider for the native native environment variable selection dialog.
462      */

463     private IStructuredContentProvider createSelectionDialogContentProvider() {
464         return new IStructuredContentProvider() {
465             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
466                 EnvironmentVariable[] elements = null;
467                 if (inputElement instanceof HashMap JavaDoc) {
468                     Comparator JavaDoc comparator = new Comparator JavaDoc() {
469                         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
470                             String JavaDoc s1 = (String JavaDoc)o1;
471                             String JavaDoc s2 = (String JavaDoc)o2;
472                             return s1.compareTo(s2);
473                         }
474                     };
475                     TreeMap JavaDoc envVars = new TreeMap JavaDoc(comparator);
476                     envVars.putAll((Map JavaDoc)inputElement);
477                     elements = new EnvironmentVariable[envVars.size()];
478                     int index = 0;
479                     for (Iterator JavaDoc iterator = envVars.keySet().iterator(); iterator.hasNext(); index++) {
480                         Object JavaDoc key = iterator.next();
481                         elements[index] = (EnvironmentVariable) envVars.get(key);
482                     }
483                 }
484                 return elements;
485             }
486             public void dispose() {
487             }
488             public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
489             }
490         };
491     }
492
493     /**
494      * Gets native environment variable from the LaunchManager. Creates EnvironmentVariable objects.
495      * @return Map of name - EnvironmentVariable pairs based on native environment.
496      */

497     private Map JavaDoc getNativeEnvironment() {
498         Map JavaDoc stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
499         HashMap JavaDoc vars = new HashMap JavaDoc();
500         for (Iterator JavaDoc i = stringVars.keySet().iterator(); i.hasNext(); ) {
501             String JavaDoc key = (String JavaDoc) i.next();
502             String JavaDoc value = (String JavaDoc) stringVars.get(key);
503             vars.put(key, new EnvironmentVariable(key, value));
504         }
505         return vars;
506     }
507
508     /**
509      * Creates an editor for the value of the selected environment variable.
510      */

511     private void handleEnvEditButtonSelected() {
512         IStructuredSelection sel= (IStructuredSelection) environmentTable.getSelection();
513         EnvironmentVariable var= (EnvironmentVariable) sel.getFirstElement();
514         if (var == null) {
515             return;
516         }
517         String JavaDoc originalName= var.getName();
518         String JavaDoc value= var.getValue();
519         MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_11);
520         dialog.addTextField(NAME_LABEL, originalName, false);
521         dialog.addVariablesField(VALUE_LABEL, value, true);
522         
523         if (dialog.open() != Window.OK) {
524             return;
525         }
526         String JavaDoc name= dialog.getStringValue(NAME_LABEL);
527         value= dialog.getStringValue(VALUE_LABEL);
528         if (!originalName.equals(name)) {
529             if (addVariable(new EnvironmentVariable(name, value))) {
530                 environmentTable.remove(var);
531             }
532         } else {
533             var.setValue(value);
534             environmentTable.update(var, null);
535             updateLaunchConfigurationDialog();
536         }
537     }
538
539     /**
540      * Removes the selected environment variable from the table.
541      */

542     private void handleEnvRemoveButtonSelected() {
543         IStructuredSelection sel = (IStructuredSelection) environmentTable.getSelection();
544         environmentTable.getControl().setRedraw(false);
545         for (Iterator JavaDoc i = sel.iterator(); i.hasNext(); ) {
546             EnvironmentVariable var = (EnvironmentVariable) i.next();
547         environmentTable.remove(var);
548         }
549         environmentTable.getControl().setRedraw(true);
550         updateAppendReplace();
551         updateLaunchConfigurationDialog();
552     }
553
554     /**
555      * Updates the environment table for the given launch configuration
556      * @param configuration
557      */

558     protected void updateEnvironment(ILaunchConfiguration configuration) {
559         environmentTable.setInput(configuration);
560     }
561
562     /* (non-Javadoc)
563      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
564      */

565     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
566         configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
567     }
568
569     /* (non-Javadoc)
570      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
571      */

572     public void initializeFrom(ILaunchConfiguration configuration) {
573         boolean append= true;
574         try {
575             append = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
576         } catch (CoreException e) {
577             DebugUIPlugin.log(e.getStatus());
578         }
579         if (append) {
580             appendEnvironment.setSelection(true);
581             replaceEnvironment.setSelection(false);
582         } else {
583             replaceEnvironment.setSelection(true);
584             appendEnvironment.setSelection(false);
585         }
586         updateEnvironment(configuration);
587         updateAppendReplace();
588     }
589
590     /**
591      * Stores the environment in the given configuration
592      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
593      */

594     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
595         // Convert the table's items into a Map so that this can be saved in the
596
// configuration's attributes.
597
TableItem[] items = environmentTable.getTable().getItems();
598         Map JavaDoc map = new HashMap JavaDoc(items.length);
599         for (int i = 0; i < items.length; i++)
600         {
601             EnvironmentVariable var = (EnvironmentVariable) items[i].getData();
602             map.put(var.getName(), var.getValue());
603         }
604         if (map.size() == 0) {
605             configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map JavaDoc) null);
606         } else {
607             configuration.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
608         }
609         configuration.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, appendEnvironment.getSelection());
610     }
611
612     /* (non-Javadoc)
613      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
614      */

615     public String JavaDoc getName() {
616         return LaunchConfigurationsMessages.EnvironmentTab_Environment_7;
617     }
618     
619     /**
620      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId()
621      *
622      * @since 3.3
623      */

624     public String JavaDoc getId() {
625         return "org.eclipse.debug.ui.environmentTab"; //$NON-NLS-1$
626
}
627     
628     /* (non-Javadoc)
629      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
630      */

631     public Image getImage() {
632         return DebugPluginImages.getImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT);
633     }
634
635     /* (non-Javadoc)
636      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
637      */

638     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
639         // do nothing when activated
640
}
641
642     /* (non-Javadoc)
643      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
644      */

645     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
646         // do nothing when de-activated
647
}
648     
649     private class NativeEnvironmentDialog extends ListSelectionDialog {
650         public NativeEnvironmentDialog(Shell parentShell, Object JavaDoc input, IStructuredContentProvider contentProvider, ILabelProvider labelProvider, String JavaDoc message) {
651             super(parentShell, input, contentProvider, labelProvider, message);
652             setShellStyle(getShellStyle() | SWT.RESIZE);
653         }
654         
655         /**
656          * Returns the name of the section that this dialog stores its settings in
657          *
658          * @return String
659          */

660         protected String JavaDoc getDialogSettingsSectionName() {
661             return IDebugUIConstants.PLUGIN_ID + ".ENVIRONMENT_TAB.NATIVE_ENVIROMENT_DIALOG"; //$NON-NLS-1$
662
}
663         
664          /* (non-Javadoc)
665          * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
666          */

667         protected IDialogSettings getDialogBoundsSettings() {
668              IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
669              IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
670              if (section == null) {
671                  section = settings.addNewSection(getDialogSettingsSectionName());
672              }
673              return section;
674         }
675     }
676 }
677
Popular Tags