|
| 1 | +package net.servicestack.eclipse.startup; |
| 2 | + |
| 3 | +import org.eclipse.jface.viewers.ISelection; |
| 4 | +import org.eclipse.ui.ISelectionListener; |
| 5 | +import org.eclipse.ui.ISelectionService; |
| 6 | +import org.eclipse.ui.IStartup; |
| 7 | +import org.eclipse.ui.IWindowListener; |
| 8 | +import org.eclipse.ui.IWorkbench; |
| 9 | +import org.eclipse.ui.IWorkbenchPart; |
| 10 | +import org.eclipse.ui.IWorkbenchWindow; |
| 11 | +import org.eclipse.ui.PlatformUI; |
| 12 | + |
| 13 | +public class PluginStartup implements IStartup, ISelectionListener { |
| 14 | + |
| 15 | + @Override |
| 16 | + public void earlyStartup() { |
| 17 | + final IWorkbench workbench = PlatformUI.getWorkbench(); |
| 18 | + workbench.addWindowListener(new IWindowListener() { |
| 19 | + |
| 20 | + @Override |
| 21 | + public void windowOpened(IWorkbenchWindow window) { |
| 22 | + addSelectionListener(window); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public void windowClosed(IWorkbenchWindow window) { |
| 27 | + removeSelectionListener(window); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public void windowActivated(IWorkbenchWindow window) { |
| 32 | + // TODO Auto-generated method stub |
| 33 | + |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void windowDeactivated(IWorkbenchWindow window) { |
| 38 | + // TODO Auto-generated method stub |
| 39 | + |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + workbench.getDisplay().asyncExec(new Runnable() { |
| 44 | + public void run() { |
| 45 | + for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { |
| 46 | + addSelectionListener(window); |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + private void addSelectionListener(IWorkbenchWindow window) { |
| 53 | + if (window != null) { |
| 54 | + window.getSelectionService().addSelectionListener("org.eclipse.jdt.ui.PackageExplorer", this); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + private void removeSelectionListener(IWorkbenchWindow window) { |
| 59 | + if (window != null) { |
| 60 | + window.getSelectionService().removeSelectionListener("org.eclipse.jdt.ui.PackageExplorer", this); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
| 66 | + // TODO handle selection changes |
| 67 | + System.out.println("selection changed"); |
| 68 | + } |
| 69 | +} |
0 commit comments