~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/EnvironmentTab.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2007, 2009 Intel Corporation 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
 
 *     Intel Corporation - initial API and implementation
10
 
 *     IBM Corporation
11
 
 *******************************************************************************/
12
 
package org.eclipse.cdt.ui.newui;
13
 
 
14
 
import java.util.ArrayList;
15
 
import java.util.Arrays;
16
 
import java.util.Collections;
17
 
import java.util.Iterator;
18
 
import java.util.Map;
19
 
 
20
 
import org.eclipse.jface.resource.JFaceResources;
21
 
import org.eclipse.jface.viewers.IColorProvider;
22
 
import org.eclipse.jface.viewers.IFontProvider;
23
 
import org.eclipse.jface.viewers.IStructuredContentProvider;
24
 
import org.eclipse.jface.viewers.ITableFontProvider;
25
 
import org.eclipse.jface.viewers.ITableLabelProvider;
26
 
import org.eclipse.jface.viewers.LabelProvider;
27
 
import org.eclipse.jface.viewers.TableViewer;
28
 
import org.eclipse.jface.viewers.Viewer;
29
 
import org.eclipse.jface.window.Window;
30
 
import org.eclipse.osgi.util.TextProcessor;
31
 
import org.eclipse.swt.SWT;
32
 
import org.eclipse.swt.events.MouseAdapter;
33
 
import org.eclipse.swt.events.MouseEvent;
34
 
import org.eclipse.swt.events.SelectionAdapter;
35
 
import org.eclipse.swt.events.SelectionEvent;
36
 
import org.eclipse.swt.events.SelectionListener;
37
 
import org.eclipse.swt.graphics.Color;
38
 
import org.eclipse.swt.graphics.Font;
39
 
import org.eclipse.swt.graphics.Image;
40
 
import org.eclipse.swt.layout.GridData;
41
 
import org.eclipse.swt.layout.GridLayout;
42
 
import org.eclipse.swt.widgets.Button;
43
 
import org.eclipse.swt.widgets.Composite;
44
 
import org.eclipse.swt.widgets.Control;
45
 
import org.eclipse.swt.widgets.Label;
46
 
import org.eclipse.swt.widgets.Shell;
47
 
import org.eclipse.swt.widgets.Table;
48
 
import org.eclipse.swt.widgets.TableColumn;
49
 
import org.eclipse.ui.dialogs.ListSelectionDialog;
50
 
 
51
 
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
52
 
import org.eclipse.cdt.core.model.util.CDTListComparator;
53
 
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
54
 
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
55
 
import org.eclipse.cdt.utils.envvar.StorableEnvironment;
56
 
import org.eclipse.cdt.utils.spawner.EnvironmentReader;
57
 
 
58
 
import org.eclipse.cdt.internal.core.envvar.EnvVarDescriptor;
59
 
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
60
 
import org.eclipse.cdt.internal.core.envvar.UserDefinedEnvironmentSupplier;
61
 
 
62
 
/**
63
 
 * @noextend This class is not intended to be subclassed by clients.
64
 
 */
65
 
public class EnvironmentTab extends AbstractCPropertyTab {
66
 
        private static final String SEPARATOR = System.getProperty("path.separator", ";"); //$NON-NLS-1$ //$NON-NLS-2$
67
 
        private static final String LBR = " ["; //$NON-NLS-1$
68
 
        private static final String RBR = "]"; //$NON-NLS-1$
69
 
        private static final UserDefinedEnvironmentSupplier fUserSupplier = EnvironmentVariableManager.fUserSupplier;
70
 
        
71
 
        private final MultiCfgContributedEnvironment ce = new MultiCfgContributedEnvironment();
72
 
 
73
 
        private Table table;
74
 
        private TableViewer tv;
75
 
        private ArrayList<TabData> data = new ArrayList<TabData>();
76
 
        private Button b1, b2;
77
 
        private Label  lb1, lb2;
78
 
        
79
 
        private ICConfigurationDescription cfgd = null;
80
 
        private StorableEnvironment vars = null;
81
 
 
82
 
        private class TabData implements Comparable<TabData> {
83
 
                IEnvironmentVariable var;
84
 
                boolean changed;
85
 
                TabData(IEnvironmentVariable _var, boolean _changed) {
86
 
                        var = _var;
87
 
                        changed = _changed;
88
 
                }
89
 
                public int compareTo(TabData a) {
90
 
                        String s = var.getName();
91
 
                        if (a != null && s != null && a.var != null)
92
 
                                        return (s.compareTo(a.var.getName())); 
93
 
                        return 0;
94
 
                }
95
 
        }
96
 
        
97
 
        private class EnvironmentLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider , ITableFontProvider, IColorProvider{
98
 
                public EnvironmentLabelProvider(boolean user){
99
 
                }
100
 
                @Override
101
 
                public Image getImage(Object element) {
102
 
                        return null; // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_INFO);
103
 
                }
104
 
                @Override
105
 
                public String getText(Object element) {
106
 
                        return getColumnText(element, 0);
107
 
                }
108
 
                public Image getColumnImage(Object element, int columnIndex) {
109
 
                        return null;
110
 
                }
111
 
                public String getColumnText(Object element, int columnIndex) {
112
 
                        TabData td = (TabData)element;
113
 
                        switch(columnIndex){
114
 
                        case 0:
115
 
                                return td.var.getName();
116
 
                        case 1:
117
 
                                if(td.var.getOperation() == IEnvironmentVariable.ENVVAR_REMOVE)
118
 
                                        return UIMessages.getString(UIMessages.getString("EnvironmentTab.20")); //$NON-NLS-1$
119
 
                                return td.var.getValue();
120
 
                        case 2:
121
 
                                return ce.getOrigin(td.var);
122
 
                        }
123
 
                        return EMPTY_STR;
124
 
                }
125
 
 
126
 
                public Font getFont(Object element) {
127
 
                        return getFont(element, 0);
128
 
                }
129
 
 
130
 
                public Font getFont(Object element, int columnIndex) {
131
 
                        TabData td = (TabData)element;
132
 
                        switch(columnIndex){
133
 
                        case 0:
134
 
                                if (isUsers(td.var))
135
 
                                        return JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
136
 
                                break;
137
 
                        default:
138
 
                                break;
139
 
                        }
140
 
                        return null;
141
 
                }
142
 
                
143
 
            public Color getForeground(Object element){
144
 
                        return null;
145
 
            }
146
 
 
147
 
            public Color getBackground(Object element){
148
 
                        TabData td = (TabData)element;
149
 
                        if (isUsers(td.var))
150
 
                                return BACKGROUND_FOR_USER_VAR;
151
 
                        return null; 
152
 
            }
153
 
        }
154
 
        
155
 
        @Override
156
 
        public void createControls(Composite parent) {
157
 
                super.createControls(parent);
158
 
                usercomp.setLayout(new GridLayout(3, true));
159
 
                Label l1 = new Label(usercomp, SWT.LEFT);
160
 
                l1.setText(UIMessages.getString("EnvironmentTab.0")); //$NON-NLS-1$
161
 
                GridData gd = new GridData(GridData.FILL_HORIZONTAL);
162
 
                gd.horizontalSpan = 3;
163
 
                l1.setLayoutData(gd);
164
 
                table = new Table(usercomp, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.FULL_SELECTION);
165
 
                table.setHeaderVisible(true);
166
 
                table.setLinesVisible(true);
167
 
                table.addSelectionListener(new SelectionListener() {
168
 
                        public void widgetSelected(SelectionEvent e) {
169
 
                                updateButtons();
170
 
                        }
171
 
                        public void widgetDefaultSelected(SelectionEvent e) {
172
 
                        if (buttonIsEnabled(2) && table.getSelectionIndex() != -1)
173
 
                                buttonPressed(2);
174
 
                        }});
175
 
                
176
 
                tv = new TableViewer(table);
177
 
                tv.setContentProvider(new IStructuredContentProvider() {
178
 
 
179
 
                        @SuppressWarnings("unchecked")
180
 
                        public Object[] getElements(Object inputElement) {
181
 
                                if (inputElement != null && inputElement instanceof ArrayList) {
182
 
                                        ArrayList<Object> ar = (ArrayList)inputElement;
183
 
                                        return ar.toArray(new TabData[0]);
184
 
                                }
185
 
                                return null;
186
 
                        }
187
 
                        public void dispose() {}
188
 
                        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
189
 
                        });
190
 
                tv.setLabelProvider(new EnvironmentLabelProvider(true));
191
 
                // add headers
192
 
                TableColumn tc = new TableColumn(table, SWT.LEFT);
193
 
                tc.setText(UIMessages.getString("EnvironmentTab.1")); //$NON-NLS-1$
194
 
                tc.setWidth(150);
195
 
                tc = new TableColumn(table, SWT.LEFT);
196
 
                tc.setText(UIMessages.getString("EnvironmentTab.2")); //$NON-NLS-1$
197
 
                tc.setWidth(150);
198
 
                if (this.getResDesc() != null) {
199
 
                        tc = new TableColumn(table, SWT.LEFT);
200
 
                        tc.setText(UIMessages.getString("EnvironmentTab.16"));  //$NON-NLS-1$
201
 
                        tc.setWidth(100);
202
 
                }
203
 
                                    
204
 
                gd = new GridData(GridData.FILL_BOTH);
205
 
                gd.horizontalSpan = 3;
206
 
            table.setLayoutData(gd);
207
 
            
208
 
            b1 = new Button(usercomp, SWT.RADIO);
209
 
            b1.setText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$
210
 
            b1.setToolTipText(UIMessages.getString("EnvironmentTab.3")); //$NON-NLS-1$
211
 
            gd = new GridData(GridData.FILL_HORIZONTAL);
212
 
            gd.horizontalSpan = 3; 
213
 
            b1.setLayoutData(gd);
214
 
            b1.addSelectionListener(new SelectionAdapter() {
215
 
                        @Override
216
 
                        public void widgetSelected(SelectionEvent e) {
217
 
                                if (cfgd != null)
218
 
                                        ce.setAppendEnvironment(true, cfgd);
219
 
                                else
220
 
                                        vars.setAppendContributedEnvironment(true);
221
 
                                updateData();
222
 
                        }});
223
 
 
224
 
            b2 = new Button(usercomp, SWT.RADIO);
225
 
            b2.setText(UIMessages.getString("EnvironmentTab.4")); //$NON-NLS-1$
226
 
            b2.setToolTipText(UIMessages.getString("EnvironmentTab.4")); //$NON-NLS-1$
227
 
            gd = new GridData(GridData.FILL_HORIZONTAL);
228
 
            gd.horizontalSpan = 3; 
229
 
            b2.setLayoutData(gd);
230
 
            b2.addSelectionListener(new SelectionAdapter() {
231
 
                        @Override
232
 
                        public void widgetSelected(SelectionEvent e) {
233
 
                                if (cfgd != null)
234
 
                                        ce.setAppendEnvironment(false, cfgd);
235
 
                                else
236
 
                                        vars.setAppendContributedEnvironment(false);
237
 
                                updateData();
238
 
                        }});
239
 
 
240
 
            if (!page.isForPrefs()) {
241
 
                // dummy placeholder
242
 
                new Label(usercomp, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
243
 
                
244
 
                lb1 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
245
 
                lb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
246
 
                lb1.setToolTipText(UIMessages.getString("EnvironmentTab.15")); //$NON-NLS-1$
247
 
                lb1.addMouseListener(new MouseAdapter() {
248
 
                        @Override
249
 
                        public void mouseDoubleClick(MouseEvent e) {
250
 
                                CDTPrefUtil.spinDMode();
251
 
                                updateData();
252
 
                        }});
253
 
 
254
 
                lb2 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
255
 
                lb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
256
 
                lb2.setToolTipText(UIMessages.getString("EnvironmentTab.23")); //$NON-NLS-1$
257
 
                lb2.addMouseListener(new MouseAdapter() {
258
 
                        @Override
259
 
                        public void mouseDoubleClick(MouseEvent e) {
260
 
                                CDTPrefUtil.spinWMode();
261
 
                                updateLbs(null, lb2);
262
 
                        }});
263
 
            }
264
 
            initButtons(new String[] {UIMessages.getString("EnvironmentTab.5"),UIMessages.getString("EnvironmentTab.6"),UIMessages.getString("EnvironmentTab.7"),UIMessages.getString("EnvironmentTab.8"),UIMessages.getString("EnvironmentTab.9")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
265
 
        }
266
 
        
267
 
        @Override
268
 
        public void buttonPressed(int i) {
269
 
                switch (i) {
270
 
                case 0:
271
 
                        handleEnvAddButtonSelected();
272
 
                        break;
273
 
                case 1: // select
274
 
                        handleEnvSelectButtonSelected();
275
 
                        break;
276
 
                case 2: // edit
277
 
                        handleEnvEditButtonSelected(table.getSelectionIndex());
278
 
                        break;
279
 
                case 3: // remove
280
 
                        handleEnvDelButtonSelected(table.getSelectionIndex());
281
 
                        break;
282
 
                case 4: // Undefine
283
 
                        handleEnvUndefButtonSelected(table.getSelectionIndex());
284
 
                        break;
285
 
                }
286
 
                table.setFocus();
287
 
        }
288
 
        
289
 
        @Override
290
 
        protected void updateButtons() {
291
 
                if (table == null || table.isDisposed()) return;
292
 
                
293
 
                boolean canEdit = table.getSelectionCount() == 1;
294
 
                boolean canDel  = false;
295
 
                boolean canUndef = table.getSelectionCount() >= 1;
296
 
                if (canUndef) {
297
 
                        for (int i : table.getSelectionIndices()) {
298
 
                                IEnvironmentVariable var = ((TabData)tv.getElementAt(i)).var;
299
 
                                if (isUsers(var)) {
300
 
                                //      if (cfgd == null || !wse.getVariable(var.))
301
 
                                        canDel = true;
302
 
                                        break;
303
 
                                }
304
 
                        }
305
 
                }
306
 
                buttonSetEnabled(2, canEdit); // edit
307
 
                buttonSetEnabled(3, canDel); // delete
308
 
                buttonSetEnabled(4, canUndef); // undefine
309
 
        }
310
 
 
311
 
        @Override
312
 
        protected void updateData(ICResourceDescription _cfgd) {
313
 
                // null means preference configuration 
314
 
                cfgd = (_cfgd != null) ? _cfgd.getConfiguration() : null;
315
 
                if (cfgd == null && vars == null)
316
 
                        vars = fUserSupplier.getWorkspaceEnvironmentCopy();
317
 
                else
318
 
                        ce.setMulti(page.isMultiCfg());
319
 
                updateData();
320
 
        }
321
 
 
322
 
        private void updateData() {
323
 
                IEnvironmentVariable[] _vars = null;
324
 
                if (cfgd != null) {
325
 
                        b1.setSelection(ce.appendEnvironment(cfgd));
326
 
                        b2.setSelection(!ce.appendEnvironment(cfgd));
327
 
                         _vars = ce.getVariables(cfgd);
328
 
                } else {
329
 
                        if (vars == null)
330
 
                                vars = fUserSupplier.getWorkspaceEnvironmentCopy();
331
 
                        b1.setSelection(vars.appendContributedEnvironment());
332
 
                        b2.setSelection(!vars.appendContributedEnvironment());
333
 
                        _vars = vars.getVariables() ;
334
 
                }
335
 
                
336
 
                data.clear();
337
 
                if (_vars != null) {
338
 
                        for (IEnvironmentVariable _var : _vars) {
339
 
                                data.add(new TabData(_var, false));
340
 
                        }
341
 
                }
342
 
                Collections.sort(data);
343
 
                tv.setInput(data);
344
 
                
345
 
                updateLbs(lb1, lb2);
346
 
                updateButtons();
347
 
        }
348
 
 
349
 
        @Override
350
 
        protected void performApply(ICResourceDescription _src, ICResourceDescription _dst) {
351
 
                ICConfigurationDescription src = _src.getConfiguration();
352
 
                ICConfigurationDescription dst = _dst.getConfiguration();
353
 
                
354
 
                ce.setAppendEnvironment(ce.appendEnvironment(src), dst);
355
 
                IEnvironmentVariable[] v = ce.getVariables(dst);
356
 
                for (IEnvironmentVariable element : v)
357
 
                        ce.removeVariable(element.getName(), dst);
358
 
                v = ce.getVariables(src);
359
 
                for (IEnvironmentVariable element : v) {
360
 
                        if (ce.isUserVariable(src, element))
361
 
                                        ce.addVariable(element.getName(), element.getValue(), 
362
 
                                                        element.getOperation(), element.getDelimiter(), dst);
363
 
                }
364
 
        }
365
 
 
366
 
        /**
367
 
         * 
368
 
         */
369
 
        private class MyListSelectionDialog extends ListSelectionDialog {
370
 
                public boolean toAll = false;
371
 
            public MyListSelectionDialog(Shell parentShell, Object input, IStructuredContentProvider contentProvider) {
372
 
                super(parentShell, input, contentProvider, new LabelProvider() {}, UIMessages.getString("EnvironmentTab.12")); //$NON-NLS-1$
373
 
            }
374
 
            @Override
375
 
                protected Control createDialogArea(Composite parent) {
376
 
                Composite composite = (Composite) super.createDialogArea(parent);
377
 
                Button b = new Button(composite, SWT.CHECK);
378
 
                b.setText(UIMessages.getString("EnvironmentTab.13")); //$NON-NLS-1$
379
 
                b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
380
 
                if (cfgd == null)
381
 
                        b.setVisible(false);
382
 
                else
383
 
                        b.addSelectionListener(new SelectionAdapter() {
384
 
                                @Override
385
 
                                        public void widgetSelected(SelectionEvent e) {
386
 
                                        toAll = ((Button)e.widget).getSelection();
387
 
                                }});
388
 
                return composite;
389
 
            }
390
 
        }
391
 
        
392
 
        private void handleEnvEditButtonSelected(int n) {
393
 
                if (n == -1)
394
 
                        return;
395
 
                IEnvironmentVariable var = ((TabData)tv.getElementAt(n)).var;
396
 
                EnvDialog dlg = new EnvDialog(usercomp.getShell(), 
397
 
                                var, 
398
 
                                UIMessages.getString("EnvironmentTab.11"),  //$NON-NLS-1$ 
399
 
                                false,
400
 
                                page.isMultiCfg(),
401
 
                                cfgd);
402
 
                if (dlg.open() == Window.OK) {
403
 
                        if (cfgd != null)
404
 
                                ce.addVariable( var.getName(), dlg.t2.trim(), 
405
 
                                                IEnvironmentVariable.ENVVAR_REPLACE, 
406
 
                                                var.getDelimiter(), cfgd);
407
 
                        else
408
 
                                vars.createVariable(dlg.t1.trim(), dlg.t2.trim(),
409
 
                                                IEnvironmentVariable.ENVVAR_REPLACE, var.getDelimiter());
410
 
                        updateData();
411
 
                        table.setSelection(n);
412
 
                        updateButtons();
413
 
                }
414
 
        }
415
 
        
416
 
        private void handleEnvUndefButtonSelected(int n) {
417
 
                if (n == -1) 
418
 
                        return;
419
 
                for (int i : table.getSelectionIndices()) {
420
 
                        IEnvironmentVariable var = ((TabData)tv.getElementAt(i)).var;
421
 
                        if (cfgd == null)
422
 
                                vars.createVariable(
423
 
                                                var.getName(), 
424
 
                                                null, 
425
 
                                                IEnvironmentVariable.ENVVAR_REMOVE, 
426
 
                                                var.getDelimiter());
427
 
                        else 
428
 
                                ce.addVariable(
429
 
                                                var.getName(), 
430
 
                                                null, 
431
 
                                                IEnvironmentVariable.ENVVAR_REMOVE, 
432
 
                                                var.getDelimiter(), cfgd);
433
 
                }
434
 
                updateData();
435
 
                table.setSelection(n);
436
 
                updateButtons();
437
 
        }
438
 
        
439
 
        private void handleEnvDelButtonSelected(int n) {
440
 
                if (n == -1) 
441
 
                        return;
442
 
                for (int i : table.getSelectionIndices()) {
443
 
                        IEnvironmentVariable var = ((TabData)tv.getElementAt(i)).var;
444
 
                        if (cfgd == null) 
445
 
                                vars.deleteVariable(var.getName());
446
 
                        else
447
 
                                ce.removeVariable(var.getName(), cfgd);
448
 
                }
449
 
                updateData();
450
 
                int x = table.getItemCount() - 1;
451
 
                if (x >= 0) {
452
 
                        table.setSelection(Math.min(x, n));
453
 
                        updateButtons();
454
 
                }
455
 
        }
456
 
        
457
 
        private void handleEnvAddButtonSelected() {
458
 
                IEnvironmentVariable var = null;
459
 
                EnvDialog dlg = new EnvDialog(usercomp.getShell(), 
460
 
                                var, 
461
 
                                UIMessages.getString("EnvironmentTab.10"), //$NON-NLS-1$ 
462
 
                                true,
463
 
                                page.isMultiCfg(),
464
 
                                cfgd);
465
 
                if (dlg.open() == Window.OK) {
466
 
                        String name = dlg.t1.trim();
467
 
                        if (name.length() > 0) {
468
 
                                ICConfigurationDescription[] cfgs;
469
 
                                if (dlg.toAll)
470
 
                                        cfgs = page.getCfgsEditable();
471
 
                                else 
472
 
                                        cfgs = new ICConfigurationDescription[] {cfgd};
473
 
                                if (cfgd == null)
474
 
                                        vars.createVariable(name, dlg.t2.trim(), 
475
 
                                                        IEnvironmentVariable.ENVVAR_APPEND, SEPARATOR);
476
 
                                else
477
 
                                        for (ICConfigurationDescription cfg : cfgs) { 
478
 
                                                ce.addVariable(name, dlg.t2.trim(), 
479
 
                                                                IEnvironmentVariable.ENVVAR_APPEND, 
480
 
                                                                SEPARATOR, cfg);
481
 
                                        }
482
 
                                updateData();
483
 
                                setPos(name);
484
 
                        }
485
 
                }
486
 
        }
487
 
 
488
 
        private void setPos(String name) {
489
 
                if (name == null || name.length() == 0)
490
 
                        return;
491
 
                for (int i=0; i<table.getItemCount(); i++) {
492
 
                        if (name.equals(table.getItem(i).getText())) {
493
 
                                table.setSelection(i);
494
 
                                updateButtons();
495
 
                                break;
496
 
                        }
497
 
                }
498
 
        }
499
 
        
500
 
        private void handleEnvSelectButtonSelected() {
501
 
                // get Environment Variables from the OS
502
 
                Map<?,?> v = EnvironmentReader.getEnvVars();
503
 
                MyListSelectionDialog dialog = new MyListSelectionDialog(usercomp.getShell(), v, createSelectionDialogContentProvider());
504
 
                
505
 
                dialog.setTitle(UIMessages.getString("EnvironmentTab.14")); //$NON-NLS-1$
506
 
                if (dialog.open() == Window.OK) {
507
 
                        Object[] selected = dialog.getResult();
508
 
                        ICConfigurationDescription[] cfgs;
509
 
                        if (dialog.toAll)
510
 
                                cfgs = page.getCfgsEditable();
511
 
                        else 
512
 
                                cfgs = new ICConfigurationDescription[] {cfgd};
513
 
                        
514
 
                        String name = null;
515
 
                        for (Object element : selected) {
516
 
                                name = (String)element;
517
 
                                String value = EMPTY_STR;
518
 
                                int x = name.indexOf(LBR);
519
 
                                if (x >= 0) {
520
 
                                        value = name.substring(x + 2, name.length() - 1);
521
 
                                        name = name.substring(0, x);
522
 
                                }
523
 
                                
524
 
                                if (cfgd == null) 
525
 
                                        vars.createVariable(name, value);
526
 
                                else
527
 
                                        for (ICConfigurationDescription cfg : cfgs) { 
528
 
                                                ce.addVariable(
529
 
                                                                name, value, 
530
 
                                                                IEnvironmentVariable.ENVVAR_APPEND, 
531
 
                                                                SEPARATOR, cfg);
532
 
                                }
533
 
                        }
534
 
                        updateData();
535
 
                        setPos(name);
536
 
                }
537
 
        }
538
 
        
539
 
        private IStructuredContentProvider createSelectionDialogContentProvider() {
540
 
                return new IStructuredContentProvider() {
541
 
 
542
 
                        public Object[] getElements(Object inputElement) {
543
 
                                String[] els = null;
544
 
                                if (inputElement instanceof Map<?, ?>) {
545
 
                                        @SuppressWarnings("unchecked")
546
 
                                        Map<String,?> m = (Map)inputElement;
547
 
                                        els = new String[m.size()];  
548
 
                                        int index = 0;
549
 
                                        for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext(); index++) {
550
 
                                                String k = iterator.next();
551
 
                                                els[index] = TextProcessor.process(k + LBR + m.get(k) + RBR);  
552
 
                                        }
553
 
                                }
554
 
                                Arrays.sort(els, CDTListComparator.getInstance());
555
 
                                return els;
556
 
                        }
557
 
                        public void dispose() {}
558
 
                        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
559
 
                };
560
 
        }
561
 
        // This page can be displayed for project only
562
 
        @Override
563
 
        public boolean canBeVisible() {
564
 
                return page.isForProject() || page.isForPrefs();
565
 
        }
566
 
 
567
 
        @Override
568
 
        protected void performOK() {
569
 
                if (vars != null) {
570
 
                        if (fUserSupplier.setWorkspaceEnvironment(vars))
571
 
                                if (page instanceof PrefPage_Abstract)
572
 
                                        PrefPage_Abstract.isChanged = true;
573
 
                }
574
 
                vars = null;
575
 
                super.performOK();
576
 
        }
577
 
        
578
 
        @Override
579
 
        protected void performCancel() {
580
 
                vars = null;
581
 
                super.performCancel();
582
 
        }
583
 
        
584
 
        @Override
585
 
        protected void performDefaults() {
586
 
                ce.restoreDefaults(cfgd); // both for proj & prefs
587
 
                vars = null;
588
 
                updateData();
589
 
        }
590
 
        
591
 
        private boolean isUsers(IEnvironmentVariable var) {
592
 
                return cfgd == null || 
593
 
                      (ce.isUserVariable(cfgd, var) &&
594
 
                          ((EnvVarDescriptor)var).getContextInfo().getContext() != null);
595
 
 
596
 
        }
597
 
}