KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > views > ConfigurationView


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.update.internal.ui.views;
12 import java.io.*;
13 import java.lang.reflect.*;
14 import java.net.*;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Hashtable JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
18
19 import org.eclipse.core.runtime.*;
20 import org.eclipse.jface.action.*;
21 import org.eclipse.jface.operation.*;
22 import org.eclipse.jface.resource.*;
23 import org.eclipse.jface.viewers.*;
24 import org.eclipse.osgi.util.NLS;
25 import org.eclipse.swt.*;
26 import org.eclipse.swt.custom.*;
27 import org.eclipse.swt.graphics.*;
28 import org.eclipse.swt.layout.*;
29 import org.eclipse.swt.widgets.*;
30 import org.eclipse.ui.*;
31 import org.eclipse.ui.branding.*;
32 import org.eclipse.ui.dialogs.*;
33 import org.eclipse.ui.model.IWorkbenchAdapter;
34 import org.eclipse.ui.part.*;
35 import org.eclipse.update.configuration.*;
36 import org.eclipse.update.core.*;
37 import org.eclipse.update.internal.core.LocalSite;
38 import org.eclipse.update.internal.operations.*;
39 import org.eclipse.update.internal.ui.*;
40 import org.eclipse.update.internal.ui.model.*;
41 import org.eclipse.update.internal.ui.parts.*;
42 import org.eclipse.update.operations.*;
43 import org.osgi.framework.*;
44 import org.eclipse.core.runtime.Path;
45
46
47 /**
48  * Insert the type's description here.
49  * @see ViewPart
50  */

51 public class ConfigurationView
52     implements
53         IInstallConfigurationChangedListener,
54         IConfiguredSiteChangedListener,
55         ILocalSiteChangedListener {
56     private TreeViewer treeViewer;
57     private DrillDownAdapter drillDownAdapter;
58     private Action collapseAllAction;
59     private static final String JavaDoc STATE_SHOW_UNCONF = "ConfigurationView.showUnconf"; //$NON-NLS-1$
60
private static final String JavaDoc STATE_SHOW_SITES = "ConfigurationView.showSites"; //$NON-NLS-1$
61
private static final String JavaDoc STATE_SHOW_NESTED_FEATURES =
62         "ConfigurationView.showNestedFeatures"; //$NON-NLS-1$
63

64     private Action showSitesAction;
65     private Action showNestedFeaturesAction;
66     private ReplaceVersionAction swapVersionAction;
67     private FeatureStateAction featureStateAction;
68     private UninstallFeatureAction uninstallFeatureAction;
69     private UnconfigureAndUninstallFeatureAction unconfigureAndUninstallFeatureAction;
70     private FeaturesStateAction featuresStateAction;
71     private UninstallFeaturesAction uninstallFeaturesAction;
72     private UnconfigureAndUninstallFeaturesAction unconfigureAndUninstallFeaturesAction;
73     private InstallOptionalFeatureAction installOptFeatureAction;
74     private Action showUnconfFeaturesAction;
75     private RevertConfigurationAction revertAction;
76     private ShowActivitiesAction showActivitiesAction;
77     private Action propertiesAction;
78     private SiteStateAction siteStateAction;
79     private Action installationHistoryAction;
80     private Action newExtensionLocationAction;
81     private FindUpdatesAction findUpdatesAction;
82     private SashForm splitter;
83     private ConfigurationPreview preview;
84     private Hashtable JavaDoc previewTasks;
85     
86     private IUpdateModelChangedListener modelListener;
87     private boolean refreshLock = false;
88     private Image eclipseImage;
89     private boolean initialized;
90     private ConfigurationManagerWindow configurationWindow;
91
92     class ConfigurationSorter extends ViewerSorter {
93         public int category(Object JavaDoc obj) {
94             // sites
95
if (obj instanceof IConfiguredSiteAdapter) {
96                 IConfiguredSite csite =
97                     ((IConfiguredSiteAdapter) obj).getConfiguredSite();
98                 if (csite.isProductSite())
99                     return 1;
100                 if (csite.isExtensionSite())
101                     return 2;
102                 return 3;
103             }
104             return super.category(obj);
105         }
106     }
107
108     class LocalSiteProvider
109         extends DefaultContentProvider
110         implements ITreeContentProvider {
111         public void inputChanged(
112             Viewer viewer,
113             Object JavaDoc oldInput,
114             Object JavaDoc newInput) {
115             if (newInput == null)
116                 return;
117         }
118
119         public Object JavaDoc[] getChildren(Object JavaDoc parent) {
120             if (parent instanceof UpdateModel) {
121                 LocalSiteWorkbenchAdapter localSite = getUIReadyLocalSite(getLocalSite());
122                 return (localSite != null) ? new Object JavaDoc[] { localSite }
123                 : new Object JavaDoc[0];
124             }
125
126             if (parent instanceof ILocalSite) {
127                 Object JavaDoc[] csites = openLocalSite();
128                 if (showSitesAction.isChecked())
129                     return csites;
130                 ArrayList JavaDoc result = new ArrayList JavaDoc();
131                 boolean showUnconf = showUnconfFeaturesAction.isChecked();
132                 for (int i = 0; i < csites.length; i++) {
133                     IConfiguredSiteAdapter adapter =
134                         (IConfiguredSiteAdapter) csites[i];
135                     Object JavaDoc[] roots = getFeatures(adapter, !showUnconf);
136                     for (int j = 0; j < roots.length; j++) {
137                         result.add(roots[j]);
138                     }
139                 }
140                 return result.toArray();
141             }
142
143             if (parent instanceof IConfiguredSiteAdapter) {
144                 return getFeatures(
145                     (IConfiguredSiteAdapter) parent,
146                     !showUnconfFeaturesAction.isChecked());
147             }
148             if (parent instanceof ConfiguredFeatureAdapter
149                 && showNestedFeaturesAction.isChecked()) {
150                 IFeatureAdapter[] nested =
151                     ((ConfiguredFeatureAdapter) parent).getIncludedFeatures(
152                         null);
153                 if (showUnconfFeaturesAction.isChecked())
154                     return nested;
155                 ArrayList JavaDoc result = new ArrayList JavaDoc();
156                 for (int i = 0; i < nested.length; i++) {
157                     if (((ConfiguredFeatureAdapter) nested[i]).isConfigured())
158                         result.add(nested[i]);
159                 }
160                 return (IFeatureAdapter[]) result.toArray(
161                     new IFeatureAdapter[result.size()]);
162             }
163             return new Object JavaDoc[0];
164         }
165
166         public Object JavaDoc getParent(Object JavaDoc child) {
167             return null;
168         }
169         public boolean hasChildren(Object JavaDoc parent) {
170             if (parent instanceof ConfiguredFeatureAdapter) {
171                 if (!showNestedFeaturesAction.isChecked())
172                     return false;
173                 IFeatureAdapter[] features =
174                     ((ConfiguredFeatureAdapter) parent).getIncludedFeatures(
175                         null);
176
177                 if (showUnconfFeaturesAction.isChecked())
178                     return features.length > 0;
179
180                 for (int i = 0; i < features.length; i++) {
181                     if (((ConfiguredFeatureAdapter) features[i])
182                         .isConfigured())
183                         return true;
184                 }
185                 return false;
186             }
187             if (parent instanceof ConfiguredSiteAdapter) {
188                 IConfiguredSite site =
189                     ((ConfiguredSiteAdapter) parent).getConfiguredSite();
190                 if (site.isEnabled()) {
191                     if (!showUnconfFeaturesAction.isChecked())
192                         return site.getConfiguredFeatures().length > 0;
193                     return site.getFeatureReferences().length > 0;
194                 }
195                 return (showUnconfFeaturesAction.isChecked());
196             }
197             return true;
198         }
199
200         public Object JavaDoc[] getElements(Object JavaDoc input) {
201             return getChildren(input);
202         }
203     }
204
205     class LocalSiteLabelProvider extends LabelProvider {
206         public String JavaDoc getText(Object JavaDoc obj) {
207             if (obj instanceof ILocalSite) {
208                 IProduct product = Platform.getProduct();
209                 if (product != null)
210                     return product.getName();
211                 return UpdateUIMessages.ConfigurationView_current;
212             }
213
214             if (obj instanceof IConfiguredSiteAdapter) {
215                 IConfiguredSite csite =
216                     ((IConfiguredSiteAdapter) obj).getConfiguredSite();
217                 ISite site = csite.getSite();
218                 return new File(site.getURL().getFile()).toString();
219             }
220             if (obj instanceof IFeatureAdapter) {
221                 try {
222                     IFeature feature = ((IFeatureAdapter) obj).getFeature(null);
223                     if (feature instanceof MissingFeature) {
224                         return NLS.bind(UpdateUIMessages.ConfigurationView_missingFeature, feature.getLabel());
225                     }
226                     String JavaDoc version = feature.getVersionedIdentifier().getVersion().toString();
227                     String JavaDoc pending = ""; //$NON-NLS-1$
228
if (OperationsManager.findPendingOperation(feature)
229                         != null)
230                         pending = UpdateUIMessages.ConfigurationView_pending;
231                     return feature.getLabel() + " " + version + pending; //$NON-NLS-1$
232
} catch (CoreException e) {
233                     return UpdateUIMessages.ConfigurationView_error;
234                 }
235             }
236             return super.getText(obj);
237         }
238
239         public Image getImage(Object JavaDoc obj) {
240             UpdateLabelProvider provider =
241                 UpdateUI.getDefault().getLabelProvider();
242             if (obj instanceof ILocalSite)
243                 return eclipseImage;
244
245             if (obj instanceof ConfiguredFeatureAdapter)
246                 return getFeatureImage(
247                     provider,
248                     (ConfiguredFeatureAdapter) obj);
249
250             if (obj instanceof IConfiguredSiteAdapter) {
251                 IConfiguredSite csite =
252                     ((IConfiguredSiteAdapter) obj).getConfiguredSite();
253                 int flags =
254                     csite.isUpdatable() ? 0 : UpdateLabelProvider.F_LINKED;
255                 if (!csite.isEnabled())
256                     flags |= UpdateLabelProvider.F_UNCONFIGURED;
257                 return provider.get(
258                     provider.getLocalSiteDescriptor(csite),
259                     flags);
260             }
261             return null;
262         }
263
264         private Image getFeatureImage(
265             UpdateLabelProvider provider,
266             ConfiguredFeatureAdapter adapter) {
267             try {
268                 IFeature feature = adapter.getFeature(null);
269                 if (feature instanceof MissingFeature) {
270                     if (((MissingFeature) feature).isOptional())
271                         return provider.get(
272                             UpdateUIImages.DESC_NOTINST_FEATURE_OBJ);
273                     return provider.get(
274                         UpdateUIImages.DESC_FEATURE_OBJ,
275                         UpdateLabelProvider.F_ERROR);
276                 }
277
278                 boolean efix = feature.isPatch();
279                 ImageDescriptor baseDesc =
280                     efix
281                         ? UpdateUIImages.DESC_EFIX_OBJ
282                         : (adapter.isConfigured()
283                             ? UpdateUIImages.DESC_FEATURE_OBJ
284                             : UpdateUIImages.DESC_UNCONF_FEATURE_OBJ);
285
286                 int flags = 0;
287                 if (efix && !adapter.isConfigured())
288                     flags |= UpdateLabelProvider.F_UNCONFIGURED;
289                 if (OperationsManager.findPendingOperation(feature) == null) {
290                     ILocalSite localSite = getLocalSite();
291                     if (localSite != null) {
292                         int code =
293                             getStatusCode(
294                                 feature,
295                                 localSite.getFeatureStatus(feature));
296                         switch (code) {
297                             case IFeature.STATUS_UNHAPPY :
298                                 flags |= UpdateLabelProvider.F_ERROR;
299                                 break;
300                             case IFeature.STATUS_AMBIGUOUS :
301                                 flags |= UpdateLabelProvider.F_WARNING;
302                                 break;
303                             default :
304                                 if (adapter.isConfigured()
305                                     && adapter.isUpdated())
306                                     flags |= UpdateLabelProvider.F_UPDATED;
307                                 break;
308                         }
309                     }
310                 }
311                 return provider.get(baseDesc, flags);
312             } catch (CoreException e) {
313                 return provider.get(
314                     UpdateUIImages.DESC_FEATURE_OBJ,
315                     UpdateLabelProvider.F_ERROR);
316             }
317         }
318     }
319
320     class PreviewTask implements IPreviewTask {
321         private String JavaDoc name;
322         private String JavaDoc desc;
323         private IAction action;
324         public PreviewTask(String JavaDoc name, String JavaDoc desc, IAction action) {
325             this.name = name;
326             this.desc = desc;
327             this.action = action;
328         }
329         public IAction getAction() {
330             return action;
331         }
332         public String JavaDoc getName() {
333             if (name != null)
334                 return name;
335             return action.getText();
336         }
337         public String JavaDoc getDescription() {
338             return desc;
339         }
340         public void setDescription(String JavaDoc desc) {
341             this.desc = desc;
342         }
343         public void run() {
344             action.run();
345         }
346         public boolean isEnabled() {
347             return action.isEnabled();
348         }
349     }
350
351     public ConfigurationView(ConfigurationManagerWindow window) {
352         UpdateUI.getDefault().getLabelProvider().connect(this);
353         configurationWindow=window;
354         initializeImages();
355     }
356
357     private void initializeImages() {
358         IProduct product = Platform.getProduct();
359         if (product != null) {
360             eclipseImage = getProductImage16(product);
361         }
362         if (eclipseImage==null) {
363             ImageDescriptor edesc = UpdateUIImages.DESC_APP_OBJ;
364             eclipseImage = UpdateUI.getDefault().getLabelProvider().get(edesc);
365         }
366     }
367     
368     private Image getProductImage16(IProduct product) {
369         // Loop through the product window images and
370
// pick the first whose size is 16x16 and does not
371
// alpha transparency type.
372
String JavaDoc windowImagesUrls = product.getProperty(IProductConstants.WINDOW_IMAGES);
373         Image png=null, gif=null, other = null;
374         if (windowImagesUrls != null ) {
375             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(windowImagesUrls, ","); //$NON-NLS-1$
376
while (st.hasMoreTokens()) {
377                 String JavaDoc windowImageURL = st.nextToken();
378                 ImageDescriptor edesc=null;
379                 try {
380                     edesc = ImageDescriptor.createFromURL(new URL(windowImageURL));
381                 } catch (MalformedURLException e) {
382                     // must be a path relative to the product bundle
383
Bundle productBundle = product.getDefiningBundle();
384                     if (productBundle != null) {
385                         URL url = FileLocator.find(productBundle, new Path(windowImageURL), null);
386                         if (url != null)
387                             edesc = ImageDescriptor.createFromURL(url);
388                     }
389                 }
390                 if (edesc!=null) {
391                     Image image = UpdateUI.getDefault().getLabelProvider().get(edesc);
392                     Rectangle bounds = image.getBounds();
393                     if (bounds.width==16 && bounds.height==16) {
394                         // avoid images with TRANSPARENCY_ALPHA
395
//if (image.getImageData().getTransparencyType()!=SWT.TRANSPARENCY_ALPHA)
396
// return image;
397
//Instead of returning, just store the image based on the
398
// extension.
399
if (windowImageURL.toLowerCase().endsWith(".gif")) //$NON-NLS-1$
400
gif = image;
401                         else if (windowImageURL.toLowerCase().endsWith(".png")) //$NON-NLS-1$
402
png = image;
403                         else
404                             other = image;
405                     }
406                 }
407             }
408         }
409         Image choice = null;
410         // Pick png first because of transparency
411
if (png!=null) {
412             choice = png;
413         }
414         // Pick other format
415
else if (other!=null)
416             choice = other;
417         // Pick gif
418
else if (gif!=null)
419             choice = gif;
420         return choice;
421     }
422
423     public void initProviders() {
424         treeViewer.setContentProvider(new LocalSiteProvider());
425         treeViewer.setLabelProvider(new LocalSiteLabelProvider());
426         treeViewer.setInput(UpdateUI.getDefault().getUpdateModel());
427         treeViewer.setSorter(new ConfigurationSorter());
428         ILocalSite localSite = getLocalSite();
429         if (localSite != null)
430             localSite.addLocalSiteChangedListener(this);
431
432         modelListener = new IUpdateModelChangedListener() {
433             public void objectsAdded(Object JavaDoc parent, Object JavaDoc[] children) {
434             }
435             public void objectsRemoved(Object JavaDoc parent, Object JavaDoc[] children) {
436             }
437             public void objectChanged(final Object JavaDoc obj, String JavaDoc property) {
438                 if (refreshLock)
439                     return;
440                 Control control = getControl();
441                 if (!control.isDisposed()) {
442                     control.getDisplay().asyncExec(new Runnable JavaDoc() {
443                         public void run() {
444                             treeViewer.refresh();
445                             handleSelectionChanged(
446                                 (IStructuredSelection) treeViewer
447                                     .getSelection());
448                         }
449                     });
450                 }
451             }
452         };
453         OperationsManager.addUpdateModelChangedListener(modelListener);
454         PlatformUI.getWorkbench().getHelpSystem().setHelp(
455             getControl(),
456             "org.eclipse.update.ui.ConfigurationView"); //$NON-NLS-1$
457
}
458
459     private ILocalSite getLocalSite() {
460         try {
461             return SiteManager.getLocalSite();
462         } catch (CoreException e) {
463             UpdateUI.logException(e);
464             return null;
465         }
466     }
467
468     private Object JavaDoc[] openLocalSite() {
469         final Object JavaDoc[][] bag = new Object JavaDoc[1][];
470         BusyIndicator.showWhile(getControl().getDisplay(), new Runnable JavaDoc() {
471             public void run() {
472                 ILocalSite localSite = getLocalSite();
473                 if (localSite == null)
474                     return;
475                 IInstallConfiguration config =
476                     getLocalSite().getCurrentConfiguration();
477                 IConfiguredSite[] sites = config.getConfiguredSites();
478                 Object JavaDoc[] result = new Object JavaDoc[sites.length];
479                 for (int i = 0; i < sites.length; i++) {
480                     result[i] = new ConfiguredSiteAdapter(config, sites[i]);
481                 }
482                 if (!initialized) {
483                     config.addInstallConfigurationChangedListener(
484                         ConfigurationView.this);
485                     initialized = true;
486                 }
487                 bag[0] = result;
488             }
489         });
490         return bag[0];
491     }
492
493     public void dispose() {
494         UpdateUI.getDefault().getLabelProvider().disconnect(this);
495         if (initialized) {
496             ILocalSite localSite = getLocalSite();
497             if (localSite != null) {
498                 localSite.removeLocalSiteChangedListener(this);
499                 IInstallConfiguration config =
500                     localSite.getCurrentConfiguration();
501                 config.removeInstallConfigurationChangedListener(this);
502             }
503             initialized = false;
504         }
505         OperationsManager.removeUpdateModelChangedListener(modelListener);
506         if (preview != null)
507             preview.dispose();
508         //super.dispose();
509
}
510
511     protected void makeActions() {
512         collapseAllAction = new Action() {
513             public void run() {
514                 treeViewer.getControl().setRedraw(false);
515                 treeViewer.collapseToLevel(
516                     treeViewer.getInput(),
517                     TreeViewer.ALL_LEVELS);
518                 treeViewer.getControl().setRedraw(true);
519             }
520         };
521         collapseAllAction.setText(UpdateUIMessages.ConfigurationView_collapseLabel);
522         collapseAllAction.setToolTipText(UpdateUIMessages.ConfigurationView_collapseTooltip);
523         collapseAllAction.setImageDescriptor(UpdateUIImages.DESC_COLLAPSE_ALL);
524
525         drillDownAdapter = new DrillDownAdapter(treeViewer);
526
527         featureStateAction = new FeatureStateAction(this.getConfigurationWindow().getShell(), ""); //$NON-NLS-1$
528
featuresStateAction = new FeaturesStateAction(this.getConfigurationWindow().getShell(), ""); //$NON-NLS-1$
529

530         siteStateAction = new SiteStateAction(getConfigurationWindow().getShell());
531
532         revertAction = new RevertConfigurationAction(getConfigurationWindow().getShell(),UpdateUIMessages.ConfigurationView_revertLabel);
533         PlatformUI.getWorkbench().getHelpSystem().setHelp(
534             revertAction,
535             "org.eclipse.update.ui.CofigurationView_revertAction"); //$NON-NLS-1$
536

537         installationHistoryAction =
538             new InstallationHistoryAction(getConfigurationWindow().getShell(),
539                 UpdateUIMessages.ConfigurationView_installHistory,
540                 UpdateUIImages.DESC_HISTORY_OBJ);
541         installationHistoryAction.setToolTipText(installationHistoryAction.getText());
542         
543         newExtensionLocationAction =
544             new NewExtensionLocationAction(getConfigurationWindow().getShell(),
545                 UpdateUIMessages.ConfigurationView_extLocation,
546                 UpdateUIImages.DESC_ESITE_OBJ);
547         
548         propertiesAction =
549             new PropertyDialogAction(
550                 getConfigurationWindow(),
551                 treeViewer);
552         PlatformUI.getWorkbench().getHelpSystem().setHelp(
553             propertiesAction,
554             "org.eclipse.update.ui.CofigurationView_propertiesAction"); //$NON-NLS-1$
555

556         uninstallFeatureAction = new UninstallFeatureAction(getConfigurationWindow().getShell(), UpdateUIMessages.ConfigurationView_uninstall);
557         unconfigureAndUninstallFeatureAction = new UnconfigureAndUninstallFeatureAction(getConfigurationWindow().getShell(), UpdateUIMessages.ConfigurationView_uninstall);
558         
559         uninstallFeaturesAction = new UninstallFeaturesAction(getConfigurationWindow().getShell(), UpdateUIMessages.ConfigurationView_uninstall);
560         unconfigureAndUninstallFeaturesAction = new UnconfigureAndUninstallFeaturesAction(getConfigurationWindow().getShell(), UpdateUIMessages.ConfigurationView_unconfigureAndUninstall);
561
562         
563         installOptFeatureAction =
564             new InstallOptionalFeatureAction(
565                 getControl().getShell(),
566                 UpdateUIMessages.ConfigurationView_install);
567
568         swapVersionAction = new ReplaceVersionAction(getConfigurationWindow().getShell(), UpdateUIMessages.ConfigurationView_anotherVersion);
569
570         findUpdatesAction =
571             new FindUpdatesAction(configurationWindow, UpdateUIMessages.ConfigurationView_findUpdates);
572
573         showActivitiesAction = new ShowActivitiesAction(getControl().getShell(), UpdateUIMessages.ConfigurationView_showActivitiesLabel);
574         PlatformUI.getWorkbench().getHelpSystem().setHelp(
575             showActivitiesAction,
576             "org.eclipse.update.ui.ConfigurationView_showActivitiesAction"); //$NON-NLS-1$
577

578         makeShowUnconfiguredFeaturesAction();
579         makeShowSitesAction();
580         makeShowNestedFeaturesAction();
581         makePreviewTasks();
582         configurationWindow.setPropertiesActionHandler(propertiesAction);
583     }
584
585     private void makeShowNestedFeaturesAction() {
586         final Preferences pref = UpdateUI.getDefault().getPluginPreferences();
587         pref.setDefault(STATE_SHOW_NESTED_FEATURES, true);
588         showNestedFeaturesAction = new Action() {
589             public void run() {
590                 treeViewer.refresh();
591                 pref.setValue(
592                     STATE_SHOW_NESTED_FEATURES,
593                     showNestedFeaturesAction.isChecked());
594             }
595         };
596         showNestedFeaturesAction.setText(UpdateUIMessages.ConfigurationView_showNestedFeatures);
597         showNestedFeaturesAction.setImageDescriptor(
598             UpdateUIImages.DESC_SHOW_HIERARCHY);
599         showNestedFeaturesAction.setDisabledImageDescriptor(
600             UpdateUIImages.DESC_SHOW_HIERARCHY_D);
601
602         showNestedFeaturesAction.setChecked(
603             pref.getBoolean(STATE_SHOW_NESTED_FEATURES));
604         showNestedFeaturesAction.setToolTipText(UpdateUIMessages.ConfigurationView_showNestedTooltip);
605     }
606
607     private void makeShowSitesAction() {
608         final Preferences pref = UpdateUI.getDefault().getPluginPreferences();
609         pref.setDefault(STATE_SHOW_SITES, true);
610         showSitesAction = new Action() {
611             public void run() {
612                 treeViewer.refresh();
613                 pref.setValue(STATE_SHOW_SITES, showSitesAction.isChecked());
614                 UpdateUI.getDefault().savePluginPreferences();
615             }
616         };
617         showSitesAction.setText(UpdateUIMessages.ConfigurationView_showInstall);
618         showSitesAction.setImageDescriptor(UpdateUIImages.DESC_LSITE_OBJ);
619         showSitesAction.setChecked(pref.getBoolean(STATE_SHOW_SITES));
620         showSitesAction.setToolTipText(UpdateUIMessages.ConfigurationView_showInstallTooltip);
621     }
622
623     private void makeShowUnconfiguredFeaturesAction() {
624         final Preferences pref = UpdateUI.getDefault().getPluginPreferences();
625         pref.setDefault(STATE_SHOW_UNCONF, false);
626         showUnconfFeaturesAction = new Action() {
627             public void run() {
628                 pref.setValue(
629                     STATE_SHOW_UNCONF,
630                     showUnconfFeaturesAction.isChecked());
631                 UpdateUI.getDefault().savePluginPreferences();
632                 treeViewer.refresh();
633             }
634         };
635         PlatformUI.getWorkbench().getHelpSystem().setHelp(
636             showUnconfFeaturesAction,
637             "org.eclipse.update.ui.CofigurationView_showUnconfFeaturesAction"); //$NON-NLS-1$
638
showUnconfFeaturesAction.setText(UpdateUIMessages.ConfigurationView_showDisabled);
639         showUnconfFeaturesAction.setImageDescriptor(
640             UpdateUIImages.DESC_UNCONF_FEATURE_OBJ);
641         showUnconfFeaturesAction.setChecked(pref.getBoolean(STATE_SHOW_UNCONF));
642         showUnconfFeaturesAction.setToolTipText(UpdateUIMessages.ConfigurationView_showDisabledTooltip);
643     }
644
645     protected void fillActionBars(ToolBarManager tbm) {
646         tbm.add(showSitesAction);
647         tbm.add(showNestedFeaturesAction);
648         tbm.add(showUnconfFeaturesAction);
649         tbm.add(new Separator());
650         drillDownAdapter.addNavigationActions(tbm);
651         tbm.add(new Separator());
652         tbm.add(collapseAllAction);
653         tbm.add(new Separator());
654         tbm.add(installationHistoryAction);
655     }
656
657     protected Object JavaDoc getSelectedObject() {
658         ISelection selection = treeViewer.getSelection();
659         if (selection instanceof IStructuredSelection
660             && !selection.isEmpty()) {
661             IStructuredSelection ssel = (IStructuredSelection) selection;
662             
663             if (ssel.size() == 1)
664                 return ssel.getFirstElement();
665             else
666                 return ssel.toArray();
667         }
668         return null;
669     }
670
671     protected void fillContextMenu(IMenuManager manager) {
672         Object JavaDoc obj = getSelectedObject();
673         boolean areMultipleFeaturesSelected = true;
674         
675         if ( obj instanceof Object JavaDoc[]) {
676             Object JavaDoc[] array = (Object JavaDoc[])obj;
677             for( int i = 0; i < array.length; i++) {
678                 if (!(array[i] instanceof ConfiguredFeatureAdapter)) {
679                     areMultipleFeaturesSelected = false;
680                 }
681             }
682         } else {
683             areMultipleFeaturesSelected = false;
684         }
685
686         if (obj instanceof ILocalSite) {
687             manager.add(findUpdatesAction);
688             manager.add(revertAction);
689         } else if (obj instanceof IConfiguredSiteAdapter) {
690             manager.add(siteStateAction);
691         }
692
693         if (obj instanceof ILocalSite
694             || obj instanceof IConfiguredSiteAdapter) {
695             manager.add(new Separator());
696             MenuManager mgr = new MenuManager(UpdateUIMessages.ConfigurationView_new);
697             mgr.add(newExtensionLocationAction);
698             manager.add(mgr);
699             manager.add(new Separator());
700         } else if ( (obj instanceof ConfiguredFeatureAdapter) && !areMultipleFeaturesSelected){
701             try {
702                 
703                 MenuManager mgr = new MenuManager(UpdateUIMessages.ConfigurationView_replaceWith);
704                 
705                 manager.add(findUpdatesAction);
706                 manager.add(new Separator());
707                 
708                 mgr.add(swapVersionAction);
709                 manager.add(mgr);
710
711                 manager.add(featureStateAction);
712                 
713
714                 IFeature feature =
715                     ((ConfiguredFeatureAdapter) obj).getFeature(null);
716                 if (feature instanceof MissingFeature) {
717                     manager.add(installOptFeatureAction);
718                 } else {
719                     boolean configured = ((ConfiguredFeatureAdapter)obj).isConfigured();
720                     if (!configured)
721                         manager.add(uninstallFeatureAction);
722                     else
723                         manager.add(unconfigureAndUninstallFeatureAction);
724                 }
725                 manager.add(new Separator());
726
727             } catch (CoreException e) {
728             }
729         } else if (areMultipleFeaturesSelected) {
730
731                 manager.add(findUpdatesAction);
732                 manager.add(new Separator());
733
734                 manager.add(featuresStateAction);
735                 
736                 manager.add(uninstallFeaturesAction);
737                 manager.add(unconfigureAndUninstallFeaturesAction);
738                 
739                 manager.add(new Separator());
740
741         }
742
743         drillDownAdapter.addNavigationActions(manager);
744
745         if (obj instanceof ILocalSite) {
746             manager.add(new Separator());
747             manager.add(installationHistoryAction);
748         }
749
750         if (obj instanceof IFeatureAdapter
751             || obj instanceof ILocalSite
752             || obj instanceof IConfiguredSiteAdapter) {
753             manager.add(new Separator());
754             manager.add(propertiesAction);
755         }
756     }
757
758     public void installSiteAdded(IConfiguredSite csite) {
759         asyncRefresh();
760     }
761     public void installSiteRemoved(IConfiguredSite site) {
762         asyncRefresh();
763     }
764     public void featureInstalled(IFeature feature) {
765         asyncRefresh();
766     }
767     public void featureRemoved(IFeature feature) {
768         asyncRefresh();
769     }
770     public void featureConfigured(IFeature feature) {
771     }
772
773     public void featureUnconfigured(IFeature feature) {
774     }
775
776     public void currentInstallConfigurationChanged(IInstallConfiguration configuration) {
777         asyncRefresh();
778     }
779
780     public void installConfigurationRemoved(IInstallConfiguration configuration) {
781         asyncRefresh();
782     }
783
784     private void asyncRefresh() {
785         Display display = SWTUtil.getStandardDisplay();
786         if (display == null)
787             return;
788         if (getControl().isDisposed())
789             return;
790         display.asyncExec(new Runnable JavaDoc() {
791             public void run() {
792                 if (!getControl().isDisposed())
793                     treeViewer.refresh();
794             }
795         });
796     }
797
798     private Object JavaDoc[] getFeatures(
799         final IConfiguredSiteAdapter siteAdapter,
800         final boolean configuredOnly) {
801         final IConfiguredSite csite = siteAdapter.getConfiguredSite();
802         final Object JavaDoc[][] bag = new Object JavaDoc[1][];
803         refreshLock = true;
804
805         IRunnableWithProgress op = new IRunnableWithProgress() {
806             public void run(IProgressMonitor monitor) {
807                 ArrayList JavaDoc result = new ArrayList JavaDoc();
808                 IFeatureReference[] refs;
809
810                 if (configuredOnly)
811                     refs = csite.getConfiguredFeatures();
812                 else {
813                     ISite site = csite.getSite();
814                     refs = site.getFeatureReferences();
815                 }
816                 monitor.beginTask(
817                     UpdateUIMessages.ConfigurationView_loading,
818                     refs.length);
819
820                 for (int i = 0; i < refs.length; i++) {
821                     IFeatureReference ref = refs[i];
822                     IFeature feature;
823                     try {
824                         monitor.subTask(ref.getURL().toString());
825                         feature = ref.getFeature(null);
826                     } catch (CoreException e) {
827                         feature =
828                             new MissingFeature(ref.getSite(), ref.getURL());
829                     }
830                     monitor.worked(1);
831                     result.add(
832                         new ConfiguredFeatureAdapter(
833                             siteAdapter,
834                             feature,
835                             csite.isConfigured(feature),
836                             false,
837                             false));
838                 }
839                 monitor.done();
840                 bag[0] = getRootFeatures(result);
841             }
842         };
843
844         try {
845             if (configurationWindow.getShell().isVisible())
846                 configurationWindow.run(true, false, op);
847             else
848                 op.run(new NullProgressMonitor());
849         } catch (InterruptedException JavaDoc e) {
850         } catch (InvocationTargetException e) {
851         } finally {
852             refreshLock = false;
853         }
854         return bag[0];
855     }
856
857     private Object JavaDoc[] getRootFeatures(ArrayList JavaDoc list) {
858         ArrayList JavaDoc children = new ArrayList JavaDoc();
859         ArrayList JavaDoc result = new ArrayList JavaDoc();
860         try {
861             for (int i = 0; i < list.size(); i++) {
862                 ConfiguredFeatureAdapter cf =
863                     (ConfiguredFeatureAdapter) list.get(i);
864                 IFeature feature = cf.getFeature(null);
865                 if (feature != null)
866                     addChildFeatures(
867                         feature,
868                         children,
869                         cf.isConfigured());
870             }
871             for (int i = 0; i < list.size(); i++) {
872                 ConfiguredFeatureAdapter cf =
873                     (ConfiguredFeatureAdapter) list.get(i);
874                 IFeature feature = cf.getFeature(null);
875                 if (feature != null
876                     && isChildFeature(feature, children) == false)
877                     result.add(cf);
878             }
879         } catch (CoreException e) {
880             return list.toArray();
881         }
882         return result.toArray();
883     }
884
885     private void addChildFeatures(
886         IFeature feature,
887         ArrayList JavaDoc children,
888         boolean configured) {
889         try {
890             IIncludedFeatureReference[] included =
891                 feature.getIncludedFeatureReferences();
892             for (int i = 0; i < included.length; i++) {
893                 IFeature childFeature;
894                 try {
895                     childFeature =
896                         included[i].getFeature(null);
897                 } catch (CoreException e) {
898                     childFeature = new MissingFeature(included[i]);
899                 }
900                 children.add(childFeature);
901             }
902         } catch (CoreException e) {
903             UpdateUI.logException(e);
904         }
905     }
906
907     private boolean isChildFeature(IFeature feature, ArrayList JavaDoc children) {
908         for (int i = 0; i < children.size(); i++) {
909             IFeature child = (IFeature) children.get(i);
910             if (feature
911                 .getVersionedIdentifier()
912                 .equals(child.getVersionedIdentifier()))
913                 return true;
914         }
915         return false;
916     }
917
918     protected void handleDoubleClick(DoubleClickEvent e) {
919         if (e.getSelection() instanceof IStructuredSelection) {
920             IStructuredSelection ssel = (IStructuredSelection) e.getSelection();
921             
922             Object JavaDoc obj = ssel.getFirstElement();
923             if (obj!=null)
924                 propertiesAction.run();
925         }
926     }
927
928     public void createPartControl(Composite parent) {
929         splitter = new SashForm(parent, SWT.HORIZONTAL);
930         splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
931         Composite leftContainer = createLineContainer(splitter);
932         Composite rightContainer = createLineContainer(splitter);
933         createTreeViewer(leftContainer);
934         makeActions();
935         createVerticalLine(leftContainer);
936         createVerticalLine(rightContainer);
937         preview = new ConfigurationPreview(this);
938         preview.createControl(rightContainer);
939         preview.getControl().setLayoutData(
940             new GridData(GridData.FILL_BOTH));
941         splitter.setWeights(new int[] { 2, 3 });
942         fillActionBars(getConfigurationWindow().getToolBarManager());
943
944         treeViewer.expandToLevel(2);
945
946         if (treeViewer.getTree().getItemCount() > 0) {
947             TreeItem[] items = treeViewer.getTree().getItems();
948             treeViewer.getTree().setSelection(new TreeItem[] { items[0] });
949             handleSelectionChanged(new StructuredSelection(items[0].getData()));
950         }
951     }
952
953     private void createTreeViewer(Composite parent) {
954         treeViewer =
955             new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
956         treeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
957         treeViewer.setUseHashlookup(true);
958         initProviders();
959
960         MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
961
menuMgr.setRemoveAllWhenShown(true);
962         menuMgr.addMenuListener(new IMenuListener() {
963             public void menuAboutToShow(IMenuManager manager) {
964                 manager.add(new GroupMarker("additions")); //$NON-NLS-1$
965
fillContextMenu(manager);
966             }
967         });
968
969         treeViewer.getControl().setMenu(
970             menuMgr.createContextMenu(treeViewer.getControl()));
971
972         treeViewer
973             .addSelectionChangedListener(new ISelectionChangedListener() {
974             public void selectionChanged(SelectionChangedEvent event) {
975                 handleSelectionChanged(event);
976             }
977         });
978
979         treeViewer.addDoubleClickListener(new IDoubleClickListener() {
980             public void doubleClick(DoubleClickEvent event) {
981                 handleDoubleClick(event);
982             }
983         });
984
985     }
986
987     public TreeViewer getTreeViewer() {
988         return treeViewer;
989     }
990
991     private Composite createLineContainer(Composite parent) {
992         Composite container = new Composite(parent, SWT.NULL);
993         GridLayout layout = new GridLayout();
994         layout.numColumns = 2;
995         layout.marginWidth = layout.marginHeight = 0;
996         layout.horizontalSpacing = 0;
997         container.setLayout(layout);
998         return container;
999     }
1000
1001    private void createVerticalLine(Composite parent) {
1002        Label line = new Label(parent, SWT.SEPARATOR | SWT.VERTICAL);
1003        GridData gd = new GridData(GridData.VERTICAL_ALIGN_FILL);
1004        gd.widthHint = 1;
1005        line.setLayoutData(gd);
1006    }
1007
1008    public Control getControl() {
1009        return splitter;
1010    }
1011
1012    private int getStatusCode(IFeature feature, IStatus status) {
1013        int code = status.getCode();
1014        if (code == IFeature.STATUS_UNHAPPY) {
1015            if (status.isMultiStatus()) {
1016                IStatus[] children = status.getChildren();
1017                for (int i = 0; i < children.length; i++) {
1018                    IStatus child = children[i];
1019                    if (child.isMultiStatus()
1020                        || child.getCode() != IFeature.STATUS_DISABLED)
1021                        return code;
1022                }
1023                // If we are here, global status is unhappy
1024
// because one or more included features
1025
// is disabled.
1026
if (UpdateUtils.hasObsoletePatches(feature)) {
1027                    // The disabled included features
1028
// are old patches that are now
1029
// subsumed by better versions of
1030
// the features they were designed to
1031
// patch.
1032
return IFeature.STATUS_HAPPY;
1033                }
1034            }
1035        }
1036        return code;
1037    }
1038
1039    protected void handleSelectionChanged(IStructuredSelection ssel) {
1040        Object JavaDoc obj = ssel.getFirstElement();
1041        
1042        boolean areMultipleFeaturesSelected = true;
1043        
1044        if (ssel.size() > 1) {
1045            Object JavaDoc[] array = ssel.toArray();
1046            for( int i = 0; i < array.length; i++) {
1047                if (!(array[i] instanceof ConfiguredFeatureAdapter)) {
1048                    areMultipleFeaturesSelected = false;
1049                }
1050            }
1051        } else {
1052            areMultipleFeaturesSelected = false;
1053        }
1054        
1055        if (ssel.size()>1)
1056            obj = null;
1057        
1058        if (obj!=null) {
1059            ILabelProvider labelProvider = (ILabelProvider)treeViewer.getLabelProvider();
1060            String JavaDoc text = labelProvider.getText(obj);
1061            //Image img = labelProvider.getImage(obj);
1062
Image img = null;
1063            configurationWindow.updateStatusLine(text, img);
1064        }
1065        else
1066            configurationWindow.updateStatusLine(null, null);
1067        
1068        if (areMultipleFeaturesSelected && (ssel.size() > 1)) {
1069            
1070            uninstallFeaturesAction.setSelection(ssel);
1071            uninstallFeaturesAction.setEnabled(uninstallFeatureAction.canExecuteAction());
1072            unconfigureAndUninstallFeaturesAction.setSelection(ssel);
1073            unconfigureAndUninstallFeaturesAction.setEnabled(unconfigureAndUninstallFeatureAction.canExecuteAction());
1074            featuresStateAction.setSelection(ssel);
1075            featuresStateAction.setEnabled(featuresStateAction.canExecuteAction());
1076            propertiesAction.setEnabled(false);
1077            preview.setSelection(ssel);
1078            return;
1079        }
1080        
1081        if (obj instanceof IFeatureAdapter) {
1082            try {
1083                propertiesAction.setEnabled(true);
1084                ConfiguredFeatureAdapter adapter = (ConfiguredFeatureAdapter) obj;
1085                IFeature feature = adapter.getFeature(null);
1086
1087                boolean missing = feature instanceof MissingFeature;
1088                boolean enable = !missing
1089                        && ((adapter.isOptional() || !adapter.isIncluded()));
1090
1091                uninstallFeatureAction.setSelection(ssel);
1092                uninstallFeatureAction.setEnabled(enable
1093                        && uninstallFeatureAction.canExecuteAction());
1094                unconfigureAndUninstallFeatureAction.setSelection(ssel);
1095                unconfigureAndUninstallFeatureAction.setEnabled(enable && unconfigureAndUninstallFeatureAction.canExecuteAction());
1096                if (adapter.isConfigured())
1097                    setDescriptionOnTask(
1098                            uninstallFeatureAction,
1099                            adapter,
1100                            UpdateUIMessages.ConfigurationView_uninstallDesc2);
1101                else
1102                    setDescriptionOnTask(
1103                            uninstallFeatureAction,
1104                            adapter,
1105                            UpdateUIMessages.ConfigurationView_uninstallDesc);
1106
1107                featureStateAction.setSelection(ssel);
1108                featureStateAction.setEnabled(enable);
1109                swapVersionAction.setEnabled(false);
1110                if (enable) {
1111                    IFeature[] features = UpdateUtils.getInstalledFeatures(
1112                            feature, false);
1113                    if (features.length > 1) {
1114                        if (adapter.isConfigured()) {
1115                            // We only enable replace action if configured
1116
// and selected. bug 74019
1117
swapVersionAction.setEnabled(true);
1118                            swapVersionAction.setCurrentFeature(feature);
1119                            swapVersionAction.setFeatures(features);
1120                        } else {
1121                            // If we are not configured and another version is
1122
// we want to disable StateAction. bug 74019
1123
features = UpdateUtils.getInstalledFeatures(
1124                                    feature, true);
1125                            if (features.length > 0) {
1126                                featureStateAction.setEnabled(false);
1127                            }
1128                        }
1129                    }
1130                }
1131
1132                findUpdatesAction.setEnabled(false);
1133                if (enable && adapter.isConfigured()) {
1134                    if (feature.getUpdateSiteEntry() != null) {
1135                        findUpdatesAction.setFeature(feature);
1136                        findUpdatesAction.setEnabled(true);
1137                    }
1138                }
1139                
1140                if (missing) {
1141                    MissingFeature mf = (MissingFeature) feature;
1142                    installOptFeatureAction.setEnabled(mf.isOptional()
1143                            && mf.getOriginatingSiteURL() != null);
1144                    installOptFeatureAction.setFeature(mf);
1145                } else {
1146                    installOptFeatureAction.setEnabled(false);
1147                }
1148            } catch (CoreException ex) {
1149                UpdateUI.logException(ex);
1150            }
1151        }
1152        if (obj instanceof ILocalSite) {
1153            propertiesAction.setEnabled(true);
1154            findUpdatesAction.setEnabled(true);
1155            findUpdatesAction.setFeature(null);
1156            ILocalSite site = getLocalSite();
1157            revertAction.setEnabled(site != null
1158                    && site.getConfigurationHistory().length > 1);
1159        } else if (obj instanceof IConfiguredSiteAdapter) {
1160            siteStateAction.setSite(((IConfiguredSiteAdapter) obj)
1161                    .getConfiguredSite());
1162            siteStateAction.setEnabled(true);
1163        }
1164        
1165        if (areMultipleFeaturesSelected) {
1166            uninstallFeaturesAction.setSelection(ssel);
1167            uninstallFeaturesAction.setEnabled(uninstallFeatureAction.canExecuteAction());
1168            unconfigureAndUninstallFeaturesAction.setSelection(ssel);
1169            unconfigureAndUninstallFeaturesAction.setEnabled(unconfigureAndUninstallFeatureAction.canExecuteAction());
1170            featuresStateAction.setSelection(ssel);
1171            featuresStateAction.setEnabled(featuresStateAction.canExecuteAction());
1172        }
1173        
1174        preview.setSelection(ssel);
1175    }
1176
1177    protected void handleSelectionChanged(SelectionChangedEvent e) {
1178        handleSelectionChanged(((IStructuredSelection) e.getSelection()));
1179    }
1180
1181    private void setDescriptionOnTask(IAction action, ConfiguredFeatureAdapter adapter, String JavaDoc desc) {
1182        IPreviewTask[] tasks = getPreviewTasks(adapter);
1183        if (tasks == null)
1184            return;
1185        for (int i=0; i<tasks.length; i++)
1186            if (tasks[i].getAction() == action)
1187                tasks[i].setDescription(desc);
1188    }
1189    
1190    private void makePreviewTasks() {
1191        previewTasks = new Hashtable JavaDoc();
1192        Class JavaDoc key;
1193        ArrayList JavaDoc array = new ArrayList JavaDoc();
1194        // local site tasks
1195
key = ILocalSite.class;
1196        array.add(
1197            new PreviewTask(
1198                UpdateUIMessages.ConfigurationView_updateLabel,
1199                UpdateUIMessages.ConfigurationView_updateDesc,
1200                findUpdatesAction));
1201        array.add(
1202            new PreviewTask(
1203                UpdateUIMessages.ConfigurationView_installHistLabel,
1204                UpdateUIMessages.ConfigurationView_installHistDesc,
1205                installationHistoryAction));
1206        array.add(
1207            new PreviewTask(
1208                UpdateUIMessages.ConfigurationView_activitiesLabel,
1209                UpdateUIMessages.ConfigurationView_activitiesDesc,
1210                showActivitiesAction));
1211        array.add(
1212                new PreviewTask(
1213                    UpdateUIMessages.ConfigurationView_extLocLabel,
1214                    UpdateUIMessages.ConfigurationView_extLocDesc,
1215                    newExtensionLocationAction));
1216        array.add(
1217                new PreviewTask(
1218                    UpdateUIMessages.ConfigurationView_revertPreviousLabel,
1219                    UpdateUIMessages.ConfigurationView_revertPreviousDesc,
1220                    revertAction));
1221
1222        previewTasks.put(key, array.toArray(new IPreviewTask[array.size()]));
1223
1224        // configured site tasks
1225
array.clear();
1226        key = IConfiguredSiteAdapter.class;
1227        array.add(
1228            new PreviewTask(
1229                null,
1230                UpdateUIMessages.ConfigurationView_enableLocDesc,
1231                siteStateAction));
1232        array.add(
1233            new PreviewTask(
1234                UpdateUIMessages.ConfigurationView_extLocLabel,
1235                UpdateUIMessages.ConfigurationView_extLocDesc,
1236                newExtensionLocationAction));
1237        array.add(
1238            new PreviewTask(
1239                UpdateUIMessages.ConfigurationView_propertiesLabel,
1240                UpdateUIMessages.ConfigurationView_installPropDesc,
1241                propertiesAction));
1242        previewTasks.put(key, array.toArray(new IPreviewTask[array.size()]));
1243
1244        // feature adapter tasks
1245
array.clear();
1246        key = IFeatureAdapter.class;
1247        array.add(
1248                new PreviewTask(
1249                    UpdateUIMessages.ConfigurationView_scanLabel,
1250                    UpdateUIMessages.ConfigurationView_scanDesc,
1251                    findUpdatesAction));
1252        array.add(
1253            new PreviewTask(
1254                UpdateUIMessages.ConfigurationView_replaceVersionLabel,
1255                UpdateUIMessages.ConfigurationView_replaceVersionDesc,
1256                swapVersionAction));
1257        array.add(
1258            new PreviewTask(
1259                null,
1260                UpdateUIMessages.ConfigurationView_enableFeatureDesc,
1261                featureStateAction));
1262        array.add(
1263            new PreviewTask(
1264                UpdateUIMessages.ConfigurationView_installOptionalLabel,
1265                UpdateUIMessages.ConfigurationView_installOptionalDesc,
1266                installOptFeatureAction));
1267        array.add(
1268            new PreviewTask(
1269                UpdateUIMessages.ConfigurationView_uninstallLabel,
1270                UpdateUIMessages.ConfigurationView_uninstallDesc,
1271                uninstallFeatureAction));
1272        array.add(
1273            new PreviewTask(
1274                UpdateUIMessages.ConfigurationView_featurePropLabel,
1275                UpdateUIMessages.ConfigurationView_featurePropDesc,
1276                propertiesAction));
1277        previewTasks.put(key, array.toArray(new IPreviewTask[array.size()]));
1278    }
1279
1280    public IPreviewTask[] getPreviewTasks(Object JavaDoc object) {
1281        IPreviewTask[] tasks = null;
1282
1283        if (object instanceof IFeatureAdapter)
1284            tasks = (IPreviewTask[]) previewTasks.get(IFeatureAdapter.class);
1285        if (object instanceof ILocalSite)
1286            tasks = (IPreviewTask[]) previewTasks.get(ILocalSite.class);
1287        if (object instanceof IConfiguredSiteAdapter)
1288            tasks =
1289                (IPreviewTask[]) previewTasks.get(IConfiguredSiteAdapter.class);
1290        return (tasks != null) ? tasks : new IPreviewTask[0];
1291    }
1292
1293    ConfigurationManagerWindow getConfigurationWindow(){
1294        return configurationWindow;
1295    }
1296    
1297    private LocalSiteWorkbenchAdapter getUIReadyLocalSite(ILocalSite localSite) {
1298            
1299        return new LocalSiteWorkbenchAdapter(localSite);
1300            
1301    }
1302    
1303    
1304
1305}
1306
1307class LocalSiteWorkbenchAdapter extends LocalSite implements IWorkbenchAdapter {
1308    
1309    private ILocalSite localSite;
1310    
1311    public LocalSiteWorkbenchAdapter(ILocalSite localSite) {
1312        this.localSite = localSite;
1313    }
1314    
1315    public Object JavaDoc[] getChildren(Object JavaDoc o) {
1316        return null;
1317    }
1318
1319    public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
1320        return null;
1321    }
1322
1323    public String JavaDoc getLabel(Object JavaDoc o) {
1324        return Platform.getProduct().getName();
1325    }
1326
1327    public Object JavaDoc getParent(Object JavaDoc o) {
1328        return null;
1329    }
1330
1331    public void addConfiguration(IInstallConfiguration config) {
1332        localSite.addConfiguration(config);
1333    }
1334
1335    public void addLocalSiteChangedListener(ILocalSiteChangedListener listener) {
1336        localSite.addLocalSiteChangedListener(listener);
1337    }
1338
1339    public IInstallConfiguration addToPreservedConfigurations(IInstallConfiguration configuration) throws CoreException {
1340        return localSite.addToPreservedConfigurations(configuration);
1341    }
1342
1343    public IInstallConfiguration cloneCurrentConfiguration() throws CoreException {
1344        return localSite.cloneCurrentConfiguration();
1345    }
1346
1347    public IInstallConfiguration[] getConfigurationHistory() {
1348        return localSite.getConfigurationHistory();
1349    }
1350
1351    public IInstallConfiguration getCurrentConfiguration() {
1352        return localSite.getCurrentConfiguration();
1353    }
1354
1355    public IStatus getFeatureStatus(IFeature feature) throws CoreException {
1356        return localSite.getFeatureStatus(feature);
1357    }
1358
1359    public int getMaximumHistoryCount() {
1360        return localSite.getMaximumHistoryCount();
1361    }
1362
1363    public IInstallConfiguration[] getPreservedConfigurations() {
1364        return localSite.getPreservedConfigurations();
1365    }
1366
1367    public void removeFromPreservedConfigurations(IInstallConfiguration configuration) {
1368        localSite.removeFromPreservedConfigurations(configuration);
1369    }
1370
1371    public void removeLocalSiteChangedListener(ILocalSiteChangedListener listener) {
1372        localSite.removeLocalSiteChangedListener(listener);
1373    }
1374
1375    public void revertTo(IInstallConfiguration configuration, IProgressMonitor monitor, IProblemHandler handler) throws CoreException {
1376        localSite.revertTo(configuration, monitor, handler);
1377    }
1378
1379    public boolean save() throws CoreException {
1380        return localSite.save();
1381    }
1382
1383    public void setMaximumHistoryCount(int history) {
1384        localSite.setMaximumHistoryCount(history);
1385    }
1386    
1387}
1388
Popular Tags