Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 11-16
Link Here
|
11 |
package org.eclipse.pde.internal.runtime.registry; |
11 |
package org.eclipse.pde.internal.runtime.registry; |
12 |
|
12 |
|
13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
|
|
14 |
import java.util.Iterator; |
15 |
import java.util.List; |
14 |
|
16 |
|
15 |
import org.eclipse.core.runtime.IExtension; |
17 |
import org.eclipse.core.runtime.IExtension; |
16 |
import org.eclipse.core.runtime.IExtensionDelta; |
18 |
import org.eclipse.core.runtime.IExtensionDelta; |
Lines 24-33
Link Here
|
24 |
import org.eclipse.jface.action.IToolBarManager; |
26 |
import org.eclipse.jface.action.IToolBarManager; |
25 |
import org.eclipse.jface.action.MenuManager; |
27 |
import org.eclipse.jface.action.MenuManager; |
26 |
import org.eclipse.jface.action.Separator; |
28 |
import org.eclipse.jface.action.Separator; |
|
|
29 |
import org.eclipse.jface.viewers.IStructuredSelection; |
27 |
import org.eclipse.jface.viewers.TreeViewer; |
30 |
import org.eclipse.jface.viewers.TreeViewer; |
28 |
import org.eclipse.jface.viewers.Viewer; |
31 |
import org.eclipse.jface.viewers.Viewer; |
29 |
import org.eclipse.jface.viewers.ViewerComparator; |
32 |
import org.eclipse.jface.viewers.ViewerComparator; |
30 |
import org.eclipse.jface.viewers.ViewerFilter; |
33 |
import org.eclipse.jface.viewers.ViewerFilter; |
|
|
34 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
35 |
import org.eclipse.osgi.service.resolver.DisabledInfo; |
36 |
import org.eclipse.osgi.service.resolver.PlatformAdmin; |
37 |
import org.eclipse.osgi.service.resolver.State; |
31 |
import org.eclipse.pde.internal.runtime.IHelpContextIds; |
38 |
import org.eclipse.pde.internal.runtime.IHelpContextIds; |
32 |
import org.eclipse.pde.internal.runtime.PDERuntimeMessages; |
39 |
import org.eclipse.pde.internal.runtime.PDERuntimeMessages; |
33 |
import org.eclipse.pde.internal.runtime.PDERuntimePlugin; |
40 |
import org.eclipse.pde.internal.runtime.PDERuntimePlugin; |
Lines 52-62
Link Here
|
52 |
import org.eclipse.ui.part.ViewPart; |
59 |
import org.eclipse.ui.part.ViewPart; |
53 |
import org.osgi.framework.Bundle; |
60 |
import org.osgi.framework.Bundle; |
54 |
import org.osgi.framework.BundleEvent; |
61 |
import org.osgi.framework.BundleEvent; |
|
|
62 |
import org.osgi.framework.BundleException; |
55 |
import org.osgi.framework.BundleListener; |
63 |
import org.osgi.framework.BundleListener; |
56 |
import org.osgi.framework.Constants; |
64 |
import org.osgi.framework.Constants; |
|
|
65 |
|
57 |
public class RegistryBrowser extends ViewPart implements BundleListener, IRegistryChangeListener { |
66 |
public class RegistryBrowser extends ViewPart implements BundleListener, IRegistryChangeListener { |
58 |
|
67 |
|
59 |
public static final String SHOW_RUNNING_PLUGINS = "RegistryView.showRunning.label"; //$NON-NLS-1$ |
68 |
public static final String SHOW_RUNNING_PLUGINS = "RegistryView.showRunning.label"; //$NON-NLS-1$ |
|
|
69 |
public static final String SHOW_ADVANCED_MODE = "RegistryView.showAdvancedMode.label"; //$NON-NLS-1$ |
60 |
|
70 |
|
61 |
private FilteredTree fFilteredTree; |
71 |
private FilteredTree fFilteredTree; |
62 |
private TreeViewer fTreeViewer; |
72 |
private TreeViewer fTreeViewer; |
Lines 66-74
Link Here
|
66 |
// menus and action items |
76 |
// menus and action items |
67 |
private Action fRefreshAction; |
77 |
private Action fRefreshAction; |
68 |
private Action fShowPluginsAction; |
78 |
private Action fShowPluginsAction; |
|
|
79 |
private Action fShowAdvancedOperationsAction; |
69 |
private Action fCollapseAllAction; |
80 |
private Action fCollapseAllAction; |
70 |
private Action fRemoveAction; |
81 |
|
71 |
private Action fAddAction; |
82 |
// advanced actions |
|
|
83 |
private Action fStartAction; |
84 |
private Action fStopAction; |
85 |
private Action fEnableAction; |
86 |
private Action fDisableAction; |
87 |
|
72 |
private DrillDownAdapter drillDownAdapter; |
88 |
private DrillDownAdapter drillDownAdapter; |
73 |
private ViewerFilter fActiveFilter = new ViewerFilter() { |
89 |
private ViewerFilter fActiveFilter = new ViewerFilter() { |
74 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
90 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
Lines 126-131
Link Here
|
126 |
// show all plug-ins by default (i.e. not just activated ones) |
142 |
// show all plug-ins by default (i.e. not just activated ones) |
127 |
if (fMemento.getString(SHOW_RUNNING_PLUGINS) == null) |
143 |
if (fMemento.getString(SHOW_RUNNING_PLUGINS) == null) |
128 |
fMemento.putString(SHOW_RUNNING_PLUGINS, "false"); //$NON-NLS-1$ |
144 |
fMemento.putString(SHOW_RUNNING_PLUGINS, "false"); //$NON-NLS-1$ |
|
|
145 |
|
146 |
// default to not showing advanced options to users |
147 |
if (fMemento.getString(SHOW_ADVANCED_MODE) == null) |
148 |
fMemento.putString(SHOW_ADVANCED_MODE, "false"); //$NON-NLS-1$ |
129 |
} |
149 |
} |
130 |
|
150 |
|
131 |
public void dispose() { |
151 |
public void dispose() { |
Lines 223-228
Link Here
|
223 |
IMenuManager mgr = bars.getMenuManager(); |
243 |
IMenuManager mgr = bars.getMenuManager(); |
224 |
mgr.add(new Separator()); |
244 |
mgr.add(new Separator()); |
225 |
mgr.add(fShowPluginsAction); |
245 |
mgr.add(fShowPluginsAction); |
|
|
246 |
mgr.add(fShowAdvancedOperationsAction); |
247 |
|
226 |
} |
248 |
} |
227 |
public void fillContextMenu(IMenuManager manager) { |
249 |
public void fillContextMenu(IMenuManager manager) { |
228 |
manager.add(fRefreshAction); |
250 |
manager.add(fRefreshAction); |
Lines 244-258
Link Here
|
244 |
break; |
266 |
break; |
245 |
} |
267 |
} |
246 |
} |
268 |
} |
247 |
if (allRemoveable) |
|
|
248 |
manager.add(fRemoveAction); |
249 |
if (canAdd && selection.length == 1) |
250 |
manager.add(fAddAction); |
251 |
} |
269 |
} |
252 |
manager.add(new Separator()); |
270 |
manager.add(new Separator()); |
253 |
drillDownAdapter.addNavigationActions(manager); |
271 |
drillDownAdapter.addNavigationActions(manager); |
254 |
manager.add(new Separator()); |
272 |
manager.add(new Separator()); |
|
|
273 |
|
274 |
// check if we should enable advanced actions |
275 |
if(fShowAdvancedOperationsAction.isChecked() && isBundleSelected()) { |
276 |
// control bundle state actions |
277 |
if(selectedBundlesStopped()) |
278 |
manager.add(fStartAction); |
279 |
if(selectedBundlesStarted()) |
280 |
manager.add(fStopAction); |
281 |
|
282 |
// security related actions |
283 |
if(selectedBundlesDisabled()) |
284 |
manager.add(fEnableAction); |
285 |
if(selectedBundlesEnabled()) |
286 |
manager.add(fDisableAction); |
287 |
} |
288 |
|
289 |
manager.add(new Separator()); |
255 |
manager.add(fShowPluginsAction); |
290 |
manager.add(fShowPluginsAction); |
|
|
291 |
manager.add(fShowAdvancedOperationsAction); |
256 |
} |
292 |
} |
257 |
public TreeViewer getTreeViewer() { |
293 |
public TreeViewer getTreeViewer() { |
258 |
return fTreeViewer; |
294 |
return fTreeViewer; |
Lines 261-272
Link Here
|
261 |
public void saveState(IMemento memento) { |
297 |
public void saveState(IMemento memento) { |
262 |
if (memento == null || this.fMemento == null || fTreeViewer == null) |
298 |
if (memento == null || this.fMemento == null || fTreeViewer == null) |
263 |
return; |
299 |
return; |
264 |
boolean showRunning = fShowPluginsAction.isChecked(); |
300 |
fMemento.putBoolean(SHOW_RUNNING_PLUGINS, fShowPluginsAction.isChecked()); |
265 |
if (showRunning) |
301 |
fMemento.putBoolean(SHOW_ADVANCED_MODE, fShowAdvancedOperationsAction.isChecked()); |
266 |
this.fMemento.putString(SHOW_RUNNING_PLUGINS, Boolean.toString(true)); |
302 |
memento.putMemento(fMemento); |
267 |
else |
|
|
268 |
this.fMemento.putString(SHOW_RUNNING_PLUGINS, Boolean.toString(false)); |
269 |
memento.putMemento(this.fMemento); |
270 |
} |
303 |
} |
271 |
|
304 |
|
272 |
public void setFocus() { |
305 |
public void setFocus() { |
Lines 490-537
Link Here
|
490 |
}; |
523 |
}; |
491 |
fShowPluginsAction.setChecked(fMemento.getString(SHOW_RUNNING_PLUGINS).equals("true")); //$NON-NLS-1$ |
524 |
fShowPluginsAction.setChecked(fMemento.getString(SHOW_RUNNING_PLUGINS).equals("true")); //$NON-NLS-1$ |
492 |
|
525 |
|
493 |
fRemoveAction = new Action("Remove") { //$NON-NLS-1$ |
526 |
fShowAdvancedOperationsAction = new Action(PDERuntimeMessages.RegistryView_showAdvanced_label) { |
|
|
527 |
public void run() { |
528 |
if (fShowAdvancedOperationsAction.isChecked()) |
529 |
createAdvancedActions(); |
530 |
else |
531 |
disabledAdvancedActions(); |
532 |
} |
533 |
}; |
534 |
fShowAdvancedOperationsAction.setChecked(fMemento.getString(SHOW_ADVANCED_MODE).equals("true")); //$NON-NLS-1$ |
535 |
|
536 |
fStartAction = new Action(PDERuntimeMessages.RegistryView_startAction_label) { |
494 |
public void run() { |
537 |
public void run() { |
495 |
// Tree tree = getUndisposedTree(); |
538 |
try { |
496 |
// if (tree == null) |
539 |
List bundles = getSelectedBundles(); |
497 |
// return; |
540 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
498 |
// IExtensionRegistry registry = Platform.getExtensionRegistry(); |
541 |
Bundle bundle = (Bundle) it.next(); |
499 |
// Object token = ((ExtensionRegistry)registry).getTemporaryUserToken(); |
542 |
bundle.start(); |
500 |
// TreeItem[] selection = tree.getSelection(); |
543 |
} |
501 |
// for (int i = 0; i < selection.length; i++) { |
544 |
} catch (BundleException e) { |
502 |
// Object obj = selection[i].getData(); |
545 |
PDERuntimePlugin.log(e); |
503 |
// if (obj instanceof ParentAdapter) |
546 |
} |
504 |
// obj = ((ParentAdapter)obj).getObject(); |
547 |
} |
505 |
// if (obj instanceof IExtensionPoint) |
548 |
}; |
506 |
// registry.removeExtensionPoint((IExtensionPoint)obj, token); |
549 |
|
507 |
// else if (obj instanceof IExtension) |
550 |
fStopAction = new Action(PDERuntimeMessages.RegistryView_stopAction_label) { |
508 |
// registry.removeExtension((IExtension)obj, token); |
551 |
public void run() { |
509 |
// } |
552 |
try { |
510 |
|
553 |
List bundles = getSelectedBundles(); |
|
|
554 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
555 |
Bundle bundle = (Bundle) it.next(); |
556 |
bundle.stop(); |
557 |
} |
558 |
} catch (BundleException e) { |
559 |
PDERuntimePlugin.log(e); |
560 |
} |
511 |
} |
561 |
} |
512 |
}; |
562 |
}; |
513 |
|
563 |
|
514 |
fAddAction = new Action("Add...") { //$NON-NLS-1$ |
564 |
fEnableAction = new Action(PDERuntimeMessages.RegistryView_enableAction_label) { |
515 |
public void run() { |
565 |
public void run() { |
516 |
// Tree tree = getUndisposedTree(); |
566 |
List bundles = getSelectedBundles(); |
517 |
// if (tree == null) |
567 |
State state = PDERuntimePlugin.getDefault().getState(); |
518 |
// return; |
568 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
519 |
// FileDialog dialog = new FileDialog(getSite().getShell(), SWT.OPEN); |
569 |
Bundle bundle = (Bundle) it.next(); |
520 |
// String input = dialog.open(); |
570 |
BundleDescription desc = state.getBundle(bundle.getBundleId()); |
521 |
// if (input == null) |
571 |
DisabledInfo[] infos = state.getDisabledInfos(desc); |
522 |
// return; |
572 |
for (int i = 0; i < infos.length; i++) { |
523 |
// Object selection = tree.getSelection()[0].getData(); |
573 |
PlatformAdmin platformAdmin = PDERuntimePlugin.getDefault().getPlatformAdmin(); |
524 |
// if (selection instanceof PluginObjectAdapter) |
574 |
platformAdmin.removeDisabledInfo(infos[i]); |
525 |
// selection = ((PluginObjectAdapter)selection).getObject(); |
575 |
} |
526 |
// if (!(selection instanceof Bundle)) |
576 |
} |
527 |
// return; |
577 |
} |
528 |
// IContributor contributor = ContributorFactoryOSGi.createContributor((Bundle)selection); |
578 |
}; |
529 |
// IExtensionRegistry registry = Platform.getExtensionRegistry(); |
579 |
|
530 |
// Object token = ((ExtensionRegistry)registry).getTemporaryUserToken(); |
580 |
fDisableAction = new Action(PDERuntimeMessages.RegistryView_disableAction_label) { |
531 |
// try { |
581 |
public void run() { |
532 |
// registry.addContribution(new FileInputStream(input), contributor, false, null, null, token); |
582 |
List bundles = getSelectedBundles(); |
533 |
// } catch (FileNotFoundException e) { |
583 |
State state = PDERuntimePlugin.getDefault().getState(); |
534 |
// } |
584 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
|
|
585 |
Bundle bundle = (Bundle) it.next(); |
586 |
BundleDescription desc = state.getBundle(bundle.getBundleId()); |
587 |
DisabledInfo info = new DisabledInfo("ui", "Bundle disabled via PDE", desc); //$NON-NLS-1$ //$NON-NLS-2$ |
588 |
PlatformAdmin platformAdmin = |
589 |
PDERuntimePlugin.getDefault().getPlatformAdmin(); |
590 |
platformAdmin.addDisabledInfo(info); |
591 |
} |
535 |
} |
592 |
} |
536 |
}; |
593 |
}; |
537 |
|
594 |
|
Lines 545-550
Link Here
|
545 |
fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip); |
602 |
fCollapseAllAction.setToolTipText(PDERuntimeMessages.RegistryView_collapseAll_tooltip); |
546 |
} |
603 |
} |
547 |
|
604 |
|
|
|
605 |
protected void createAdvancedActions() { |
606 |
// TODO Auto-generated method stub |
607 |
|
608 |
} |
609 |
|
610 |
protected void disabledAdvancedActions() { |
611 |
// TODO Auto-generated method stub |
612 |
|
613 |
} |
614 |
|
548 |
public void updateTitle(){ |
615 |
public void updateTitle(){ |
549 |
if (fTreeViewer == null || fTreeViewer.getContentProvider() == null) |
616 |
if (fTreeViewer == null || fTreeViewer.getContentProvider() == null) |
550 |
return; |
617 |
return; |
Lines 556-559
Link Here
|
556 |
return null; |
623 |
return null; |
557 |
return fTreeViewer.getTree(); |
624 |
return fTreeViewer.getTree(); |
558 |
} |
625 |
} |
|
|
626 |
|
627 |
// TODO hackish, should rewrite |
628 |
private boolean isBundleSelected() { |
629 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
630 |
if(selection != null) { |
631 |
Object[] elements = selection.toArray(); |
632 |
for(int i = 0; i < elements.length; i++) { |
633 |
if(elements[i] instanceof PluginObjectAdapter) { |
634 |
PluginObjectAdapter adapter = (PluginObjectAdapter) elements[i]; |
635 |
Object object = adapter.getObject(); |
636 |
if(!(object instanceof Bundle)) |
637 |
return false; |
638 |
} else { |
639 |
return false; |
640 |
} |
641 |
} |
642 |
} |
643 |
return true; |
644 |
} |
645 |
|
646 |
private List getSelectedBundles() { |
647 |
List bundles = new ArrayList(); |
648 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
649 |
if(selection != null) { |
650 |
Object[] elements = selection.toArray(); |
651 |
for(int i = 0; i < elements.length; i++) { |
652 |
if(elements[i] instanceof PluginObjectAdapter) { |
653 |
PluginObjectAdapter adapter = (PluginObjectAdapter) elements[i]; |
654 |
Object object = adapter.getObject(); |
655 |
if(object instanceof Bundle) |
656 |
bundles.add(object); |
657 |
} |
658 |
} |
659 |
} |
660 |
return bundles; |
661 |
} |
662 |
|
663 |
private boolean selectedBundlesStarted() { |
664 |
List bundles = getSelectedBundles(); |
665 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
666 |
Bundle bundle = (Bundle) it.next(); |
667 |
if(bundle.getState() != Bundle.ACTIVE) |
668 |
return false; |
669 |
} |
670 |
return true; |
671 |
} |
672 |
|
673 |
private boolean selectedBundlesStopped() { |
674 |
List bundles = getSelectedBundles(); |
675 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
676 |
Bundle bundle = (Bundle) it.next(); |
677 |
if(bundle.getState() == Bundle.ACTIVE) |
678 |
return false; |
679 |
} |
680 |
return true; |
681 |
} |
682 |
|
683 |
private boolean selectedBundlesDisabled() { |
684 |
List bundles = getSelectedBundles(); |
685 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
686 |
Bundle bundle = (Bundle) it.next(); |
687 |
State state = |
688 |
PDERuntimePlugin.getDefault().getState(); |
689 |
BundleDescription desc = |
690 |
state.getBundle(bundle.getBundleId()); |
691 |
DisabledInfo[] infos = state.getDisabledInfos(desc); |
692 |
if(infos.length == 0) |
693 |
return false; |
694 |
} |
695 |
return true; |
696 |
} |
697 |
|
698 |
private boolean selectedBundlesEnabled() { |
699 |
List bundles = getSelectedBundles(); |
700 |
for(Iterator it = bundles.iterator(); it.hasNext();) { |
701 |
Bundle bundle = (Bundle) it.next(); |
702 |
State state = |
703 |
PDERuntimePlugin.getDefault().getState(); |
704 |
BundleDescription desc = |
705 |
state.getBundle(bundle.getBundleId()); |
706 |
DisabledInfo[] infos = state.getDisabledInfos(desc); |
707 |
if(infos.length > 0) |
708 |
return false; |
709 |
} |
710 |
return true; |
711 |
} |
712 |
|
559 |
} |
713 |
} |