KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > preferences > StringVariablePreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.preferences;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.variables.IStringVariableManager;
19 import org.eclipse.core.variables.IValueVariable;
20 import org.eclipse.core.variables.VariablesPlugin;
21 import org.eclipse.debug.internal.ui.DebugUIPlugin;
22 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
23 import org.eclipse.debug.internal.ui.MultipleInputDialog;
24 import org.eclipse.debug.internal.ui.SWTFactory;
25 import org.eclipse.jface.dialogs.IDialogConstants;
26 import org.eclipse.jface.dialogs.MessageDialog;
27 import org.eclipse.jface.preference.PreferencePage;
28 import org.eclipse.jface.viewers.ColumnLayoutData;
29 import org.eclipse.jface.viewers.ColumnWeightData;
30 import org.eclipse.jface.viewers.DoubleClickEvent;
31 import org.eclipse.jface.viewers.IColorProvider;
32 import org.eclipse.jface.viewers.IDoubleClickListener;
33 import org.eclipse.jface.viewers.ISelectionChangedListener;
34 import org.eclipse.jface.viewers.IStructuredContentProvider;
35 import org.eclipse.jface.viewers.IStructuredSelection;
36 import org.eclipse.jface.viewers.ITableLabelProvider;
37 import org.eclipse.jface.viewers.LabelProvider;
38 import org.eclipse.jface.viewers.SelectionChangedEvent;
39 import org.eclipse.jface.viewers.TableLayout;
40 import org.eclipse.jface.viewers.TableViewer;
41 import org.eclipse.jface.viewers.Viewer;
42 import org.eclipse.jface.viewers.ViewerComparator;
43 import org.eclipse.jface.viewers.ViewerFilter;
44 import org.eclipse.jface.window.Window;
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.events.KeyAdapter;
47 import org.eclipse.swt.events.KeyEvent;
48 import org.eclipse.swt.events.SelectionAdapter;
49 import org.eclipse.swt.events.SelectionEvent;
50 import org.eclipse.swt.graphics.Color;
51 import org.eclipse.swt.graphics.Font;
52 import org.eclipse.swt.graphics.Image;
53 import org.eclipse.swt.layout.GridData;
54 import org.eclipse.swt.layout.GridLayout;
55 import org.eclipse.swt.widgets.Button;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Control;
58 import org.eclipse.swt.widgets.Display;
59 import org.eclipse.swt.widgets.Table;
60 import org.eclipse.swt.widgets.TableColumn;
61 import org.eclipse.ui.IWorkbench;
62 import org.eclipse.ui.IWorkbenchPreferencePage;
63 import org.eclipse.ui.PlatformUI;
64
65 import com.ibm.icu.text.MessageFormat;
66
67 /**
68  * Preference page for creating and configuring simple
69  * launch variables.
70  *
71  * @see org.eclipse.debug.core.variables.IValueVariable
72  * @see org.eclipse.debug.core.variables.ISimpleVariableRegistry
73  */

74 public class StringVariablePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
75     
76     private TableViewer variableTable;
77     protected Button envAddButton;
78     protected Button envEditButton;
79     protected Button envRemoveButton;
80     
81     protected SimpleVariableContentProvider variableContentProvider= new SimpleVariableContentProvider();
82     
83     protected static final String JavaDoc NAME_LABEL= DebugPreferencesMessages.SimpleVariablePreferencePage_10;
84     protected static final String JavaDoc VALUE_LABEL = DebugPreferencesMessages.SimpleVariablePreferencePage_11;
85     protected static final String JavaDoc DESCRIPTION_LABEL = DebugPreferencesMessages.SimpleVariablePreferencePage_12;
86     
87     protected static final String JavaDoc STRING_VARIABLE_PREFERENCE_KEY = "StringVariablePreferencePage"; //$NON-NLS-1$
88

89     protected static String JavaDoc[] variableTableColumnProperties= {
90         "variable", //$NON-NLS-1$
91
"value", //$NON-NLS-1$
92
"description" //$NON-NLS-1$
93
};
94     protected String JavaDoc[] variableTableColumnHeaders= {
95         DebugPreferencesMessages.SimpleVariablePreferencePage_3,
96         DebugPreferencesMessages.SimpleVariablePreferencePage_4,
97         DebugPreferencesMessages.SimpleVariablePreferencePage_5,
98         DebugPreferencesMessages.StringVariablePreferencePage_27
99     };
100     protected ColumnLayoutData[] variableTableColumnLayouts= {
101         new ColumnWeightData(30),
102         new ColumnWeightData(25),
103         new ColumnWeightData(25),
104         new ColumnWeightData(20)
105     };
106     
107     public StringVariablePreferencePage() {
108         setDescription(DebugPreferencesMessages.SimpleVariablePreferencePage_6);
109     }
110
111     /**
112      * @see PreferencePage#createControl(Composite)
113      */

114     public void createControl(Composite parent) {
115         super.createControl(parent);
116         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.SIMPLE_VARIABLE_PREFERENCE_PAGE);
117     }
118
119     protected Control createContents(Composite parent) {
120         noDefaultAndApplyButton();
121         Font font= parent.getFont();
122         //The main composite
123
Composite composite = new Composite(parent, SWT.NONE);
124         GridLayout layout = new GridLayout();
125         layout.marginHeight=0;
126         layout.marginWidth=0;
127         layout.numColumns= 2;
128         composite.setLayout(layout);
129         composite.setFont(font);
130         
131         createTable(composite);
132         createButtons(composite);
133                 
134         return composite;
135     }
136     
137     /**
138      * Creates and configures the table containing launch configuration variables
139      * and their associated value.
140      */

141     private void createTable(Composite parent) {
142         Font font= parent.getFont();
143         // Create table composite
144
Composite tableComposite = new Composite(parent, SWT.NONE);
145         GridLayout layout = new GridLayout();
146         layout.marginHeight = 0;
147         layout.marginWidth = 0;
148         layout.numColumns = 1;
149         GridData gridData = new GridData(GridData.FILL_BOTH);
150         gridData.heightHint = 150;
151         gridData.widthHint = 400;
152         tableComposite.setLayout(layout);
153         tableComposite.setLayoutData(gridData);
154         tableComposite.setFont(font);
155         // Create table
156
variableTable = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
157         Table table = variableTable.getTable();
158         table.setHeaderVisible(true);
159         table.setLinesVisible(true);
160         table.setFont(font);
161         gridData = new GridData(GridData.FILL_BOTH);
162         variableTable.getControl().setLayoutData(gridData);
163         variableTable.setContentProvider(variableContentProvider);
164         variableTable.setColumnProperties(variableTableColumnProperties);
165         variableTable.addFilter(new VariableFilter());
166         variableTable.setComparator(new ViewerComparator() {
167             public int compare(Viewer iViewer, Object JavaDoc e1, Object JavaDoc e2) {
168                 if (e1 == null) {
169                     return -1;
170                 } else if (e2 == null) {
171                     return 1;
172                 } else {
173                     return ((VariableWrapper)e1).getName().compareToIgnoreCase(((VariableWrapper)e2).getName());
174                 }
175             }
176         });
177         
178         variableTable.addSelectionChangedListener(new ISelectionChangedListener() {
179             public void selectionChanged(SelectionChangedEvent event) {
180                 handleTableSelectionChanged(event);
181             }
182         });
183         
184         variableTable.addDoubleClickListener(new IDoubleClickListener() {
185             public void doubleClick(DoubleClickEvent event) {
186                 if (!variableTable.getSelection().isEmpty()) {
187                     handleEditButtonPressed();
188                 }
189             }
190         });
191         variableTable.getTable().addKeyListener(new KeyAdapter() {
192             public void keyPressed(KeyEvent event) {
193                 if (event.character == SWT.DEL && event.stateMask == 0) {
194                     handleRemoveButtonPressed();
195                 }
196             }
197         });
198     
199         for (int i = 0; i < variableTableColumnHeaders.length; i++) {
200             TableColumn tc = new TableColumn(table, SWT.NONE, i);
201             tc.setResizable(variableTableColumnLayouts[i].resizable);
202             tc.setText(variableTableColumnHeaders[i]);
203         }
204         
205         // Try restoring column widths from preferences, if widths aren't stored, init columns to default
206
if (!restoreColumnWidths()){
207             restoreDefaultColumnWidths();
208         }
209         
210         variableTable.setInput(getVariableManager());
211         variableTable.setLabelProvider(new SimpleVariableLabelProvider());
212     }
213     
214     /**
215      * Creates the new/edit/remove buttons for the variable table
216      * @param parent the composite in which the buttons should be created
217      */

218     private void createButtons(Composite parent) {
219         // Create button composite
220
Composite buttonComposite = new Composite(parent, SWT.NONE);
221         GridLayout glayout = new GridLayout();
222         glayout.marginHeight = 0;
223         glayout.marginWidth = 0;
224         glayout.numColumns = 1;
225         GridData gdata = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
226         buttonComposite.setLayout(glayout);
227         buttonComposite.setLayoutData(gdata);
228         buttonComposite.setFont(parent.getFont());
229         
230         // Create buttons
231
envAddButton = SWTFactory.createPushButton(buttonComposite, DebugPreferencesMessages.SimpleVariablePreferencePage_7, null);
232         envAddButton.addSelectionListener(new SelectionAdapter()
233         {
234             public void widgetSelected(SelectionEvent event) {
235                 handleAddButtonPressed();
236             }
237         });
238         envEditButton = SWTFactory.createPushButton(buttonComposite, DebugPreferencesMessages.SimpleVariablePreferencePage_8, null);
239         envEditButton.addSelectionListener(new SelectionAdapter()
240         {
241             public void widgetSelected(SelectionEvent event) {
242                 handleEditButtonPressed();
243             }
244         });
245         envEditButton.setEnabled(false);
246         envRemoveButton = SWTFactory.createPushButton(buttonComposite, DebugPreferencesMessages.SimpleVariablePreferencePage_9, null);
247         envRemoveButton.addSelectionListener(new SelectionAdapter()
248         {
249             public void widgetSelected(SelectionEvent event) {
250                 handleRemoveButtonPressed();
251             }
252         });
253         envRemoveButton.setEnabled(false);
254     }
255     
256     private void handleAddButtonPressed() {
257         boolean done = false;
258         String JavaDoc name = null;
259         String JavaDoc description = null;
260         String JavaDoc value = null;
261         while (!done){
262             
263             MultipleInputDialog dialog= new MultipleInputDialog(getShell(), DebugPreferencesMessages.SimpleVariablePreferencePage_13);
264             dialog.addTextField(NAME_LABEL, name, false);
265             dialog.addBrowseField(VALUE_LABEL, value, true);
266             dialog.addTextField(DESCRIPTION_LABEL, description, true);
267     
268             if (dialog.open() != Window.OK) {
269                 done = true;
270             }
271             else {
272                 name= dialog.getStringValue(NAME_LABEL).trim();
273                 value = dialog.getStringValue(VALUE_LABEL);
274                 description= dialog.getStringValue(DESCRIPTION_LABEL);
275                 done = addVariable(name, description, value);
276             }
277         }
278     }
279
280     /**
281      * Attempts to create and add a new variable with the given properties. Returns
282      * whether the operation completed successfully (either the variable was added
283      * successfully, or the user cancelled the operation). Returns false if the name
284      * is null or the user chooses not to overwrite an existing variable.
285      *
286      * @param name name of the variable, cannot be <code>null</code> or empty.
287      * @param description description of the variable or <code>null</code>
288      * @param value value of the variable or <code>null</code>
289      * @return whether the operation completed successfully
290      */

291     private boolean addVariable(String JavaDoc name, String JavaDoc description, String JavaDoc value) {
292         if (name == null || name.length() == 0){
293             MessageDialog.openError(getShell(),DebugPreferencesMessages.StringVariablePreferencePage_21, DebugPreferencesMessages.StringVariablePreferencePage_20);
294             return false;
295         }
296         List JavaDoc editedVariables= variableContentProvider.getWorkingSetVariables();
297         Iterator JavaDoc iter= editedVariables.iterator();
298         while (iter.hasNext()) {
299             VariableWrapper currentVariable = (VariableWrapper) iter.next();
300             if (!currentVariable.isRemoved()) {
301                 String JavaDoc currentName = currentVariable.getName();
302                 if (currentName.equals(name)) {
303                     if (currentVariable.isReadOnly()){
304                         MessageDialog.openError(getShell(),DebugPreferencesMessages.StringVariablePreferencePage_23, MessageFormat.format(DebugPreferencesMessages.StringVariablePreferencePage_22, new String JavaDoc[] {name}));
305                         return false;
306                     }
307                     else {
308                         MessageDialog dialog = new MessageDialog(getShell(), DebugPreferencesMessages.SimpleVariablePreferencePage_15, null, MessageFormat.format(DebugPreferencesMessages.SimpleVariablePreferencePage_16, new String JavaDoc[] {name}), MessageDialog.QUESTION, new String JavaDoc[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
309                         int overWrite= dialog.open();
310                         if (overWrite == 0) {
311                             currentVariable.setValue(value);
312                             currentVariable.setDescription(description);
313                             variableTable.update(currentVariable, null);
314                             return true;
315                         } else if(overWrite == 1){
316                             return false;
317                         } else {
318                             return true; // Cancel was pressed, return true so operation is ended
319
}
320                     }
321                 }
322             }
323         }
324         VariableWrapper newVariable = new VariableWrapper(name, description, value);
325         variableContentProvider.addVariable(newVariable);
326         variableTable.refresh();
327         return true;
328     }
329     
330     private void handleEditButtonPressed() {
331         IStructuredSelection selection= (IStructuredSelection) variableTable.getSelection();
332         VariableWrapper variable= (VariableWrapper) selection.getFirstElement();
333         if (variable == null || variable.isReadOnly()) {
334             return;
335         }
336         String JavaDoc value= variable.getValue();
337         String JavaDoc description= variable.getDescription();
338         String JavaDoc name= variable.getName();
339         MultipleInputDialog dialog= new MultipleInputDialog(getShell(), MessageFormat.format(DebugPreferencesMessages.SimpleVariablePreferencePage_14, new String JavaDoc[] {name}));
340         dialog.addBrowseField(VALUE_LABEL, value, true);
341         dialog.addTextField(DESCRIPTION_LABEL, description, true);
342     
343         if (dialog.open() == Window.OK) {
344             value= dialog.getStringValue(VALUE_LABEL);
345             description= dialog.getStringValue(DESCRIPTION_LABEL);
346             if (value != null) {
347                 variable.setValue(value);
348             }
349             if (description != null) {
350                 variable.setDescription(description);
351             }
352             variableTable.update(variable, null);
353         }
354     }
355     
356     /**
357      * Remove the selection variables.
358      */

359     private void handleRemoveButtonPressed() {
360         IStructuredSelection selection= (IStructuredSelection) variableTable.getSelection();
361         List JavaDoc variablesToRemove= selection.toList();
362         StringBuffer JavaDoc contributedVariablesToRemove= new StringBuffer JavaDoc();
363         Iterator JavaDoc iter= variablesToRemove.iterator();
364         while (iter.hasNext()) {
365             VariableWrapper variable = (VariableWrapper) iter.next();
366             if (variable.isContributed()) {
367                 contributedVariablesToRemove.append('\t').append(variable.getName()).append('\n');
368             }
369         }
370         if (contributedVariablesToRemove.length() > 0) {
371             boolean remove= MessageDialog.openQuestion(getShell(), DebugPreferencesMessages.SimpleLaunchVariablePreferencePage_21, MessageFormat.format(DebugPreferencesMessages.SimpleLaunchVariablePreferencePage_22, new String JavaDoc[] {contributedVariablesToRemove.toString()})); //
372
if (!remove) {
373                 return;
374             }
375         }
376         VariableWrapper[] variables= (VariableWrapper[]) variablesToRemove.toArray(new VariableWrapper[0]);
377         for (int i = 0; i < variables.length; i++) {
378             variables[i].setRemoved(true);
379         }
380         variableTable.refresh();
381     }
382     
383     /**
384      * Responds to a selection changed event in the variable table
385      * @param event the selection change event
386      */

387     protected void handleTableSelectionChanged(SelectionChangedEvent event) {
388         IStructuredSelection selection = ((IStructuredSelection)event.getSelection());
389         VariableWrapper variable= (VariableWrapper) selection.getFirstElement();
390         if (variable == null || variable.isReadOnly()) {
391             envEditButton.setEnabled(false);
392             envRemoveButton.setEnabled(false);
393         }
394         else {
395             envEditButton.setEnabled(selection.size() == 1);
396             envRemoveButton.setEnabled(selection.size() > 0);
397         }
398     }
399
400     public void init(IWorkbench workbench) {
401     }
402
403     /**
404      * Clear the variables.
405      */

406     protected void performDefaults() {
407         variableContentProvider.init();
408         variableTable.refresh();
409         super.performDefaults();
410     }
411     
412     /**
413      * Sets the saved state for reversion.
414      */

415     public boolean performOk() {
416         variableContentProvider.saveChanges();
417         saveColumnWidths();
418         return super.performOk();
419     }
420
421     /**
422      * Returns the DebugPlugin's singleton instance of the
423      * launch variable manager
424      * @return the singleton instance of the simple variable registry.
425      */

426     private IStringVariableManager getVariableManager() {
427         return VariablesPlugin.getDefault().getStringVariableManager();
428     }
429     
430     public void saveColumnWidths() {
431         StringBuffer JavaDoc widthPreference = new StringBuffer JavaDoc();
432         for (int i = 0; i < variableTable.getTable().getColumnCount(); i++) {
433             widthPreference.append(variableTable.getTable().getColumn(i).getWidth());
434             widthPreference.append(',');
435         }
436         if (widthPreference.length() > 0){
437             DebugUIPlugin.getDefault().getPreferenceStore().setValue(STRING_VARIABLE_PREFERENCE_KEY, widthPreference.toString());
438         }
439     }
440     
441     private boolean restoreColumnWidths() {
442         String JavaDoc[] columnWidthStrings = DebugUIPlugin.getDefault().getPreferenceStore().getString(STRING_VARIABLE_PREFERENCE_KEY).split(","); //$NON-NLS-1$
443
int columnCount = variableTable.getTable().getColumnCount();
444         if (columnWidthStrings.length != columnCount){
445             return false; // Preferred column sizes not stored correctly.
446
}
447         for (int i = 0; i < columnCount; i++) {
448             try{
449                 int columnWidth = Integer.parseInt(columnWidthStrings[i]);
450                 variableTable.getTable().getColumn(i).setWidth(columnWidth);
451             } catch (NumberFormatException JavaDoc e){
452                 DebugUIPlugin.log(new Throwable JavaDoc("Problem loading persisted column sizes for StringVariablePreferencesPage",e)); //$NON-NLS-1$
453
}
454         }
455         return true;
456     }
457     
458     private void restoreDefaultColumnWidths(){
459         TableLayout layout = new TableLayout();
460         for (int i = 0; i < variableTableColumnLayouts.length; i++) {
461             layout.addColumnData(variableTableColumnLayouts[i]);
462         }
463         variableTable.getTable().setLayout(layout);
464     }
465     
466     private class SimpleVariableContentProvider implements IStructuredContentProvider {
467         /**
468          * The content provider stores variable wrappers for use during editing.
469          */

470         private List JavaDoc fWorkingSet = new ArrayList JavaDoc();
471         
472         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
473             return fWorkingSet.toArray();
474         }
475                 
476         /**
477          * Adds the given variable to the 'wrappers'
478          *
479          * @param variable variable to add
480          */

481         public void addVariable(VariableWrapper variable) {
482             fWorkingSet.add(variable);
483         }
484
485         public void dispose() {
486         }
487         
488         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
489             if (newInput == null || !(newInput instanceof IStringVariableManager)){
490                 return;
491             }
492             init();
493         }
494
495         /**
496          * Saves the edited variable state to the variable manager.
497          */

498         public void saveChanges() {
499             IStringVariableManager manager = getVariableManager();
500             Iterator JavaDoc iterator = fWorkingSet.iterator();
501             List JavaDoc remove = new ArrayList JavaDoc();
502             List JavaDoc add = new ArrayList JavaDoc();
503             while (iterator.hasNext()) {
504                 VariableWrapper variable = (VariableWrapper) iterator.next();
505                 if (!variable.isReadOnly()) {
506                     IValueVariable underlyingVariable = variable.getUnderlyingVariable();
507                     if (variable.isRemoved()) {
508                         if (underlyingVariable != null) {
509                             // if added and removed there is no underlying variable
510
remove.add(underlyingVariable);
511                         }
512                     } else if (variable.isAdded()) {
513                         IValueVariable vv = manager.newValueVariable(variable.getName(), variable.getDescription());
514                         vv.setValue(variable.getValue());
515                         add.add(vv);
516                     } else if (variable.isChanged()) {
517                         underlyingVariable.setValue(variable.getValue());
518                         underlyingVariable.setDescription(variable.getDescription());
519                     }
520                 }
521             }
522             // remove
523
if (!remove.isEmpty()) {
524                 manager.removeVariables((IValueVariable[]) remove.toArray(new IValueVariable[remove.size()]));
525             }
526             // add
527
if (!add.isEmpty()) {
528                 try {
529                     manager.addVariables((IValueVariable[]) add.toArray(new IValueVariable[add.size()]));
530                 } catch (CoreException e) {
531                 DebugUIPlugin.errorDialog(getShell(), DebugPreferencesMessages.StringVariablePreferencePage_24, DebugPreferencesMessages.StringVariablePreferencePage_25, e.getStatus()); //
532
}
533             }
534         }
535         
536         /**
537          * Re-initializes to the variables currently stored in the manager.
538          */

539         public void init() {
540             fWorkingSet.clear();
541             IStringVariableManager manager = getVariableManager();
542             IValueVariable[] variables = manager.getValueVariables();
543             for (int i = 0; i < variables.length; i++) {
544                 fWorkingSet.add(new VariableWrapper(variables[i]));
545             }
546         }
547         
548         /**
549          * Returns the 'working set' of variables
550          *
551          * @return the working set of variables (not yet saved)
552          */

553         public List JavaDoc getWorkingSetVariables() {
554             return fWorkingSet;
555         }
556         
557     }
558     
559     class VariableWrapper {
560         
561         protected IValueVariable fVariable;
562         protected String JavaDoc fNewName = null;
563         protected String JavaDoc fNewDesc = null;
564         protected String JavaDoc fNewValue = null;
565         boolean fRemoved = false;
566         boolean fAdded = false;
567         
568         public VariableWrapper(IValueVariable variable) {
569             fVariable = variable;
570         }
571         
572         public VariableWrapper(String JavaDoc name, String JavaDoc desc, String JavaDoc value) {
573             fNewName = name;
574             fNewDesc = desc;
575             fNewValue = value;
576             fAdded = true;
577         }
578         
579         public boolean isAdded() {
580             return fAdded;
581         }
582         
583         public String JavaDoc getName() {
584             if (fNewName == null) {
585                 return fVariable.getName();
586             }
587             return fNewName;
588         }
589         
590         public void setName(String JavaDoc name) {
591             fNewName = name;
592         }
593         
594         public String JavaDoc getDescription() {
595             if (fNewDesc == null) {
596                 return fVariable.getDescription();
597             }
598             return fNewDesc;
599         }
600         
601         public String JavaDoc getValue() {
602             if (fNewValue == null) {
603                 return fVariable.getValue();
604             }
605             return fNewValue;
606         }
607         
608         public void setValue(String JavaDoc value) {
609             fNewValue = value;
610         }
611         
612         public void setDescription(String JavaDoc desc) {
613             fNewDesc = desc;
614         }
615         
616         public boolean isChanged() {
617             return !fAdded && !fRemoved && (fNewValue != null || fNewDesc != null);
618         }
619         
620         public boolean isReadOnly() {
621             if (fVariable == null) {
622                 return false;
623             }
624             return fVariable.isReadOnly();
625         }
626         
627         public boolean isContributed() {
628             if (fVariable == null) {
629                 return false;
630             }
631             return fVariable.isContributed();
632         }
633         
634         public IValueVariable getUnderlyingVariable() {
635             return fVariable;
636         }
637         
638         public boolean isRemoved() {
639             return fRemoved;
640         }
641         
642         public void setRemoved(boolean removed) {
643             fRemoved = removed;
644         }
645     }
646     
647     private class SimpleVariableLabelProvider extends LabelProvider implements ITableLabelProvider, IColorProvider {
648         public Image getColumnImage(Object JavaDoc element, int columnIndex) {
649             return null;
650         }
651         public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
652             if (element instanceof VariableWrapper) {
653                 VariableWrapper variable= (VariableWrapper) element;
654                 switch (columnIndex) {
655                     case 0 :
656                         StringBuffer JavaDoc name = new StringBuffer JavaDoc();
657                         name.append(variable.getName());
658                         if (variable.isReadOnly()){
659                             name.append(DebugPreferencesMessages.StringVariablePreferencePage_26);
660                         }
661                         return name.toString();
662                     case 1:
663                         String JavaDoc value= variable.getValue();
664                         if (value == null) {
665                             value= ""; //$NON-NLS-1$
666
}
667                         return value;
668                     case 2:
669                         String JavaDoc description= variable.getDescription();
670                         if (description == null) {
671                             description= ""; //$NON-NLS-1$
672
}
673                         return description;
674                     case 3:
675                         String JavaDoc contribution = ""; //$NON-NLS-1$
676
if (variable.isContributed()) {
677                             String JavaDoc pluginId = getVariableManager().getContributingPluginId(variable.getUnderlyingVariable());
678                             if (pluginId != null) {
679                                 contribution = pluginId;
680                             } else {
681                                 contribution = DebugPreferencesMessages.SimpleLaunchVariablePreferencePage_23;
682                             }
683                         }
684                         return contribution;
685                         
686                 }
687             }
688             return null;
689         }
690         public Color getForeground(Object JavaDoc element) {
691             return null;
692         }
693         public Color getBackground(Object JavaDoc element) {
694             if (element instanceof VariableWrapper) {
695                 if (((VariableWrapper) element).isReadOnly()) {
696                     Display display= Display.getCurrent();
697                     return display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
698                 }
699             }
700             return null;
701         }
702     }
703
704     class VariableFilter extends ViewerFilter {
705
706         /* (non-Javadoc)
707          * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
708          */

709         public boolean select(Viewer viewer, Object JavaDoc parentElement, Object JavaDoc element) {
710             return !((VariableWrapper)element).isRemoved();
711         }
712         
713     }
714 }
715
Popular Tags