KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.StringReader JavaDoc;
16 import java.io.StringWriter JavaDoc;
17 import com.ibm.icu.text.MessageFormat;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IAdaptable;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.MultiStatus;
25 import org.eclipse.core.runtime.NullProgressMonitor;
26 import org.eclipse.core.runtime.Path;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.debug.core.DebugPlugin;
29 import org.eclipse.debug.core.ILaunchConfiguration;
30 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
31 import org.eclipse.debug.internal.ui.DebugPluginImages;
32 import org.eclipse.debug.internal.ui.DebugUIPlugin;
33 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
34 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
35 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
36 import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
37 import org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages;
38 import org.eclipse.jface.window.Window;
39 import org.eclipse.jface.wizard.WizardDialog;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.events.SelectionAdapter;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.graphics.Image;
44 import org.eclipse.swt.layout.GridData;
45 import org.eclipse.swt.layout.GridLayout;
46 import org.eclipse.swt.widgets.Button;
47 import org.eclipse.swt.widgets.Composite;
48 import org.eclipse.swt.widgets.Group;
49 import org.eclipse.ui.IWorkingSet;
50 import org.eclipse.ui.IWorkingSetManager;
51 import org.eclipse.ui.PlatformUI;
52 import org.eclipse.ui.WorkbenchException;
53 import org.eclipse.ui.XMLMemento;
54 import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
55
56 /**
57  * A launch configuration tab which allows the user to specify
58  * which resources should be refreshed when the launch
59  * terminates.
60  * <p>
61  * This class may be instantiated; this class is not intended
62  * to be subclassed.
63  * </p>
64  * @since 3.0
65  */

66 public class RefreshTab extends AbstractLaunchConfigurationTab {
67
68     /**
69      * Boolean attribute indicating if a refresh scope is recursive. Default
70      * value is <code>false</code>.
71      */

72     public static final String JavaDoc ATTR_REFRESH_RECURSIVE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_RECURSIVE"; //$NON-NLS-1$
73

74     /**
75      * String attribute identifying the scope of resources that should be
76      * refreshed after an external tool is run. The value is either a refresh
77      * variable or the default value, <code>null</code>, indicating no refresh.
78      */

79     public static final String JavaDoc ATTR_REFRESH_SCOPE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_SCOPE"; //$NON-NLS-1$
80

81     // indicates no working set has been selected
82
private static final String JavaDoc NO_WORKING_SET = "NONE"; //$NON-NLS-1$
83

84     // Check Buttons
85
private Button fRefreshButton;
86     private Button fRecursiveButton;
87     
88     // Group box
89
private Group fGroup;
90     
91     // Radio Buttons
92
private Button fContainerButton;
93     private Button fProjectButton;
94     private Button fResourceButton;
95     private Button fWorkingSetButton;
96     private Button fWorkspaceButton;
97     
98     // Push Button
99
private Button fSelectButton;
100     
101     // Working set
102
private IWorkingSet fWorkingSet;
103
104     /**
105      * XML tag used to designate the root of the persisted IWorkingSet
106      */

107     private static final String JavaDoc TAG_LAUNCH_CONFIGURATION_WORKING_SET= "launchConfigurationWorkingSet"; //$NON-NLS-1$
108

109     /**
110      * XML tag used for setting / getting the factory ID of the persisted IWorkingSet
111      * Bug 37143
112      */

113     private static final String JavaDoc TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
114

115     /**
116      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
117      */

118     public void createControl(Composite parent) {
119         Composite mainComposite = new Composite(parent, SWT.NONE);
120         setControl(mainComposite);
121         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_REFRESH_TAB);
122         
123         GridLayout layout = new GridLayout();
124         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
125         mainComposite.setLayout(layout);
126         mainComposite.setLayoutData(gd);
127         mainComposite.setFont(parent.getFont());
128         
129         fRefreshButton = createCheckButton(mainComposite, StringSubstitutionMessages.RefreshTab_31);
130         fRefreshButton.addSelectionListener(new SelectionAdapter() {
131             public void widgetSelected(SelectionEvent e) {
132                 updateEnabledState();
133                 updateLaunchConfigurationDialog();
134             }
135         });
136         
137         fGroup = new Group(mainComposite, SWT.NONE);
138         fGroup.setFont(mainComposite.getFont());
139         layout = new GridLayout();
140         layout.numColumns = 2;
141         layout.makeColumnsEqualWidth = false;
142         fGroup.setLayout(layout);
143         gd = new GridData(GridData.FILL_HORIZONTAL);
144         gd.horizontalSpan = 2;
145         fGroup.setLayoutData(gd);
146
147         SelectionAdapter adapter = new SelectionAdapter() {
148             public void widgetSelected(SelectionEvent e) {
149                 if (((Button)e.getSource()).getSelection()) {
150                     updateEnabledState();
151                     updateLaunchConfigurationDialog();
152                 }
153             }
154         };
155         
156         fWorkspaceButton = createRadioButton(fGroup, StringSubstitutionMessages.RefreshTab_32);
157         gd = new GridData(GridData.FILL_HORIZONTAL);
158         gd.horizontalSpan = 2;
159         fWorkspaceButton.setLayoutData(gd);
160         fWorkspaceButton.addSelectionListener(adapter);
161
162         fResourceButton = createRadioButton(fGroup, StringSubstitutionMessages.RefreshTab_33);
163         gd = new GridData(GridData.FILL_HORIZONTAL);
164         gd.horizontalSpan = 2;
165         fResourceButton.setLayoutData(gd);
166         fResourceButton.addSelectionListener(adapter);
167
168         fProjectButton = createRadioButton(fGroup, StringSubstitutionMessages.RefreshTab_34);
169         gd = new GridData(GridData.FILL_HORIZONTAL);
170         gd.horizontalSpan = 2;
171         fProjectButton.setLayoutData(gd);
172         fProjectButton.addSelectionListener(adapter);
173
174         fContainerButton = createRadioButton(fGroup, StringSubstitutionMessages.RefreshTab_35);
175         gd = new GridData(GridData.FILL_HORIZONTAL);
176         gd.horizontalSpan = 2;
177         fContainerButton.setLayoutData(gd);
178         fContainerButton.addSelectionListener(adapter);
179                 
180         fWorkingSetButton = createRadioButton(fGroup, StringSubstitutionMessages.RefreshTab_36);
181         gd = new GridData(GridData.FILL_HORIZONTAL);
182         gd.horizontalSpan = 1;
183         fWorkingSetButton.setLayoutData(gd);
184         fWorkingSetButton.addSelectionListener(adapter);
185         
186         fSelectButton = createPushButton(fGroup, StringSubstitutionMessages.RefreshTab_37, null);
187         gd = (GridData)fSelectButton.getLayoutData();
188         gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
189         fSelectButton.addSelectionListener(new SelectionAdapter() {
190             public void widgetSelected(SelectionEvent e) {
191                 selectResources();
192             }
193         });
194         
195         createVerticalSpacer(fGroup, 2);
196         createRecursiveComponent(fGroup);
197     }
198
199     /**
200      * Prompts the user to select the resources to refresh.
201      */

202     private void selectResources() {
203         IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
204         
205         if (fWorkingSet == null){
206             fWorkingSet = workingSetManager.createWorkingSet(StringSubstitutionMessages.RefreshTab_40, new IAdaptable[0]);
207         }
208         IWorkingSetEditWizard wizard = workingSetManager.createWorkingSetEditWizard(fWorkingSet);
209         WizardDialog dialog = new WizardDialog(((LaunchConfigurationsDialog)LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog()).getShell(), wizard);
210         dialog.create();
211         
212         if (dialog.open() == Window.CANCEL) {
213             return;
214         }
215         fWorkingSet = wizard.getSelection();
216         updateLaunchConfigurationDialog();
217     }
218     
219     /**
220      * Creates the controls needed to edit the refresh recursive
221      * attribute of a launch configuration
222      *
223      * @param parent the composite to create the controls in
224      */

225     private void createRecursiveComponent(Composite parent) {
226         fRecursiveButton = createCheckButton(parent, StringSubstitutionMessages.RefreshTab_0);
227         GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
228         data.horizontalSpan = 2;
229         fRecursiveButton.setLayoutData(data);
230         fRecursiveButton.addSelectionListener(new SelectionAdapter() {
231             public void widgetSelected(SelectionEvent e) {
232                 updateLaunchConfigurationDialog();
233             }
234         });
235     }
236
237     /**
238      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
239      */

240     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
241     }
242
243     /**
244      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
245      */

246     public void initializeFrom(ILaunchConfiguration configuration) {
247         updateRefresh(configuration);
248         updateRecursive(configuration);
249         updateScope(configuration);
250         updateEnabledState();
251     }
252     
253     /**
254      * Updates the tab to display the refresh scope specified by the launch config
255      */

256     private void updateScope(ILaunchConfiguration configuration) {
257         String JavaDoc scope = null;
258         try {
259             scope= configuration.getAttribute(ATTR_REFRESH_SCOPE, (String JavaDoc)null);
260         } catch (CoreException ce) {
261             DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception reading launch configuration", ce)); //$NON-NLS-1$
262
}
263         fWorkspaceButton.setSelection(false);
264         fResourceButton.setSelection(false);
265         fContainerButton.setSelection(false);
266         fProjectButton.setSelection(false);
267         fWorkingSetButton.setSelection(false);
268         if (scope == null) {
269             // select the workspace by default
270
fWorkspaceButton.setSelection(true);
271         } else {
272             if (scope.equals("${workspace}")) { //$NON-NLS-1$
273
fWorkspaceButton.setSelection(true);
274             } else if (scope.equals("${resource}")) { //$NON-NLS-1$
275
fResourceButton.setSelection(true);
276             } else if (scope.equals("${container}")) { //$NON-NLS-1$
277
fContainerButton.setSelection(true);
278             } else if (scope.equals("${project}")) { //$NON-NLS-1$
279
fProjectButton.setSelection(true);
280             } else if (scope.startsWith("${resource:")) { //$NON-NLS-1$
281
fWorkingSetButton.setSelection(true);
282                 try {
283                     IResource[] resources = getRefreshResources(scope);
284                     IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
285                     fWorkingSet = workingSetManager.createWorkingSet(StringSubstitutionMessages.RefreshTab_40, resources);
286                 } catch (CoreException e) {
287                     fWorkingSet = null;
288                 }
289             } else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
290
fWorkingSetButton.setSelection(true);
291                 String JavaDoc memento = scope.substring(14, scope.length() - 1);
292                 fWorkingSet = restoreWorkingSet(memento);
293             }
294         }
295     }
296     /**
297      * Method updateRecursive.
298      * @param configuration
299      */

300     private void updateRecursive(ILaunchConfiguration configuration) {
301         boolean recursive= true;
302         try {
303             recursive= configuration.getAttribute(ATTR_REFRESH_RECURSIVE, true);
304         } catch (CoreException ce) {
305             DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception reading launch configuration", ce)); //$NON-NLS-1$
306
}
307         fRecursiveButton.setSelection(recursive);
308     }
309     /**
310      * Method updateRefresh.
311      * @param configuration
312      */

313     private void updateRefresh(ILaunchConfiguration configuration) {
314         String JavaDoc scope= null;
315         try {
316             scope= configuration.getAttribute(ATTR_REFRESH_SCOPE, (String JavaDoc)null);
317         } catch (CoreException ce) {
318             DebugUIPlugin.log(DebugUIPlugin.newErrorStatus("Exception reading launch configuration", ce)); //$NON-NLS-1$
319
}
320         fRefreshButton.setSelection(scope != null);
321     }
322
323     /**
324      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
325      */

326     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
327         if (fRefreshButton.getSelection()) {
328             String JavaDoc scope = generateScopeMemento();
329             configuration.setAttribute(ATTR_REFRESH_SCOPE, scope);
330             setAttribute(ATTR_REFRESH_RECURSIVE, configuration, fRecursiveButton.getSelection(), true);
331         } else {
332             //clear the refresh attributes
333
configuration.setAttribute(ATTR_REFRESH_SCOPE, (String JavaDoc)null);
334             setAttribute(ATTR_REFRESH_RECURSIVE, configuration, true, true);
335         }
336     }
337
338     /**
339      * Generates a memento for the refresh scope. This is based on old refresh
340      * variables.
341      *
342      * @return a memento
343      */

344     private String JavaDoc generateScopeMemento() {
345         if (fWorkspaceButton.getSelection()) {
346             return "${workspace}"; //$NON-NLS-1$
347
}
348         if (fResourceButton.getSelection()) {
349             return "${resource}"; //$NON-NLS-1$
350
}
351         if (fContainerButton.getSelection()) {
352             return "${container}"; //$NON-NLS-1$
353
}
354         if (fProjectButton.getSelection()) {
355             return "${project}"; //$NON-NLS-1$
356
}
357         if (fWorkingSetButton.getSelection()) {
358             return getRefreshAttribute(fWorkingSet);
359         }
360         return null;
361     }
362
363     /**
364      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
365      */

366     public String JavaDoc getName() {
367         return StringSubstitutionMessages.RefreshTab_6;
368     }
369     
370     /**
371      * Updates the enablement state of the fields.
372      */

373     private void updateEnabledState() {
374         boolean enabled= fRefreshButton.getSelection();
375         fRecursiveButton.setEnabled(enabled);
376         fGroup.setEnabled(enabled);
377         fWorkspaceButton.setEnabled(enabled);
378         fResourceButton.setEnabled(enabled);
379         fContainerButton.setEnabled(enabled);
380         fProjectButton.setEnabled(enabled);
381         fWorkingSetButton.setEnabled(enabled);
382         fSelectButton.setEnabled(enabled && fWorkingSetButton.getSelection());
383         if (!enabled) {
384             super.setErrorMessage(null);
385         }
386     }
387     
388     /**
389      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
390      */

391     public Image getImage() {
392         return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJS_REFRESH_TAB);
393     }
394
395     public boolean isValid(ILaunchConfiguration launchConfig) {
396         setErrorMessage(null);
397         setMessage(null);
398         if (fRefreshButton.getSelection() && (fWorkingSetButton.getSelection() && (fWorkingSet == null || fWorkingSet.getElements().length == 0))) {
399             setErrorMessage(StringSubstitutionMessages.RefreshTab_42);
400             return false;
401         }
402         return true;
403     }
404     
405     /**
406      * Refreshes the resources as specified by the given launch configuration.
407      *
408      * @param configuration launch configuration
409      * @param monitor progress monitor which may be <code>null</code>
410      * @throws CoreException if an exception occurs while refreshing resources
411      */

412     public static void refreshResources(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
413         if (monitor == null) {
414             monitor = new NullProgressMonitor();
415         }
416         String JavaDoc scope = getRefreshScope(configuration);
417         IResource[] resources= null;
418         if (scope != null) {
419             resources = getRefreshResources(scope);
420         }
421         if (resources == null || resources.length == 0){
422             return;
423         }
424         int depth = IResource.DEPTH_ONE;
425         if (isRefreshRecursive(configuration))
426             depth = IResource.DEPTH_INFINITE;
427     
428         if (monitor.isCanceled()) {
429             return;
430         }
431     
432         monitor.beginTask(StringSubstitutionMessages.RefreshTab_7,
433             resources.length);
434     
435         MultiStatus status = new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), 0, StringSubstitutionMessages.RefreshTab_8, null);
436         for (int i = 0; i < resources.length; i++) {
437             if (monitor.isCanceled())
438                 break;
439             if (resources[i] != null && resources[i].isAccessible()) {
440                 try {
441                     resources[i].refreshLocal(depth, null);
442                 } catch (CoreException e) {
443                     status.merge(e.getStatus());
444                 }
445             }
446             monitor.worked(1);
447         }
448     
449         monitor.done();
450         if (!status.isOK()) {
451             throw new CoreException(status);
452         }
453     }
454
455     /**
456      * Returns a collection of resources referred to by a refresh scope attribute.
457      *
458      * @param scope refresh scope attribute (<code>ATTR_REFRESH_SCOPE</code>)
459      * @return collection of resources referred to by the refresh scope attribute
460      * @throws CoreException if unable to resolve a set of resources
461      */

462     public static IResource[] getRefreshResources(String JavaDoc scope) throws CoreException {
463         if (scope.startsWith("${resource:")) { //$NON-NLS-1$
464
// This is an old format that is replaced with 'working_set'
465
String JavaDoc pathString = scope.substring(11, scope.length() - 1);
466             Path path = new Path(pathString);
467             IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
468             if (resource == null) {
469                 throw new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR, MessageFormat.format(StringSubstitutionMessages.RefreshTab_38, new String JavaDoc[]{pathString}), null));
470             }
471             return new IResource[]{resource};
472         } else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
473
IWorkingSet workingSet = getWorkingSet(scope);
474             if (workingSet == null) {
475                 throw new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR, StringSubstitutionMessages.RefreshTab_39, null));
476             }
477             IAdaptable[] elements = workingSet.getElements();
478             IResource[] resources = new IResource[elements.length];
479             for (int i = 0; i < elements.length; i++) {
480                 IAdaptable adaptable = elements[i];
481                 if (adaptable instanceof IResource) {
482                     resources[i] = (IResource) adaptable;
483                 } else {
484                     resources[i] = (IResource) adaptable.getAdapter(IResource.class);
485                 }
486             }
487             return resources;
488         } else if(scope.equals("${workspace}")) { //$NON-NLS-1$
489
return new IResource[]{ResourcesPlugin.getWorkspace().getRoot()};
490         } else {
491             IResource resource = SelectedResourceManager.getDefault().getSelectedResource();
492             if (resource == null) {
493                 // empty selection
494
return new IResource[]{};
495             }
496             if (scope.equals("${resource}")) { //$NON-NLS-1$
497
// resource = resource
498
} else if (scope.equals("${container}")) { //$NON-NLS-1$
499
resource = resource.getParent();
500             } else if (scope.equals("${project}")) { //$NON-NLS-1$
501
resource = resource.getProject();
502             }
503             return new IResource[]{resource};
504         }
505     }
506     
507     /**
508      * Restores a working set based on the XMLMemento represented within
509      * the mementoString.
510      *
511      * @param mementoString The string memento of the working set
512      * @return the restored working set or <code>null</code> if problems occurred restoring the
513      * working set.
514      */

515     private static IWorkingSet restoreWorkingSet(String JavaDoc mementoString) {
516         if (NO_WORKING_SET.equals(mementoString)) {
517             return null;
518         }
519         StringReader JavaDoc reader= new StringReader JavaDoc(mementoString);
520         XMLMemento memento= null;
521         try {
522             memento = XMLMemento.createReadRoot(reader);
523         } catch (WorkbenchException e) {
524             DebugUIPlugin.log(e);
525             return null;
526         }
527
528         IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
529         return workingSetManager.createWorkingSet(memento);
530     }
531     
532     /**
533      * Returns the refresh scope attribute specified by the given launch configuration
534      * or <code>null</code> if none.
535      *
536      * @param configuration launch configuration
537      * @return refresh scope attribute (<code>ATTR_REFRESH_SCOPE</code>)
538      * @throws CoreException if unable to access the associated attribute
539      */

540     public static String JavaDoc getRefreshScope(ILaunchConfiguration configuration) throws CoreException {
541         return configuration.getAttribute(ATTR_REFRESH_SCOPE, (String JavaDoc) null);
542     }
543
544     /**
545      * Returns whether the refresh scope specified by the given launch
546      * configuration is recursive.
547      *
548      * @param configuration
549      * @return whether the refresh scope is recursive
550      * @throws CoreException if unable to access the associated attribute
551      */

552     public static boolean isRefreshRecursive(ILaunchConfiguration configuration) throws CoreException {
553         return configuration.getAttribute(ATTR_REFRESH_RECURSIVE, true);
554     }
555     
556     /**
557      * Creates and returns a memento for the given working set, to be used as a
558      * refresh attribute.
559      *
560      * @param workingSet a working set, or <code>null</code>
561      * @return an equivalent refresh attribute
562      */

563     public static String JavaDoc getRefreshAttribute(IWorkingSet workingSet) {
564         String JavaDoc set = null;
565         if (workingSet == null || workingSet.getElements().length == 0) {
566             set = NO_WORKING_SET;
567         } else {
568             XMLMemento workingSetMemento = XMLMemento.createWriteRoot(TAG_LAUNCH_CONFIGURATION_WORKING_SET);
569             workingSetMemento.putString(RefreshTab.TAG_FACTORY_ID, workingSet.getFactoryId());
570             workingSet.saveState(workingSetMemento);
571             StringWriter JavaDoc writer= new StringWriter JavaDoc();
572             try {
573                 workingSetMemento.save(writer);
574             } catch (IOException JavaDoc e) {
575                 DebugUIPlugin.log(e);
576             }
577             set = writer.toString();
578         }
579         if (set != null) {
580             StringBuffer JavaDoc memento = new StringBuffer JavaDoc();
581             memento.append("${working_set:"); //$NON-NLS-1$
582
memento.append(set);
583             memento.append("}"); //$NON-NLS-1$
584
return memento.toString();
585         }
586         return null;
587     }
588     
589     /**
590      * Creates and returns a working set from the given refresh attribute created by
591      * the method <code>getRefreshAttribute(IWorkingSet)</code>, or <code>null</code>
592      * if none.
593      *
594      * @param refreshAttribute a refresh attribute that represents a working set
595      * @return equivalent working set, or <code>null</code>
596      */

597     public static IWorkingSet getWorkingSet(String JavaDoc refreshAttribute) {
598         if (refreshAttribute.startsWith("${working_set:")) { //$NON-NLS-1$
599
String JavaDoc memento = refreshAttribute.substring(14, refreshAttribute.length() - 1);
600             return restoreWorkingSet(memento);
601         }
602         return null;
603     }
604     /* (non-Javadoc)
605      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
606      */

607     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
608         // do nothing on activation
609
}
610
611     /* (non-Javadoc)
612      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
613      */

614     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
615         // do nothing on deactivation
616
}
617 }
618
Popular Tags