|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 package com.symbian.smt.gui; |
|
17 |
|
18 import org.eclipse.core.resources.IResourceChangeEvent; |
|
19 import org.eclipse.core.resources.ResourcesPlugin; |
|
20 import org.eclipse.ui.IPageListener; |
|
21 import org.eclipse.ui.IWindowListener; |
|
22 import org.eclipse.ui.IWorkbench; |
|
23 import org.eclipse.ui.IWorkbenchPage; |
|
24 import org.eclipse.ui.IWorkbenchWindow; |
|
25 import org.eclipse.ui.PlatformUI; |
|
26 import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
27 import org.osgi.framework.BundleContext; |
|
28 |
|
29 /** |
|
30 * The activator class controls the plug-in life cycle |
|
31 */ |
|
32 public class Activator extends AbstractUIPlugin { |
|
33 |
|
34 // The plug-in ID |
|
35 public static final String PLUGIN_ID = "com.symbian.smt.gui"; |
|
36 |
|
37 // The shared instance |
|
38 private static Activator plugin; |
|
39 |
|
40 /** |
|
41 * Returns the shared instance |
|
42 * |
|
43 * @return the shared instance |
|
44 */ |
|
45 public static Activator getDefault() { |
|
46 return plugin; |
|
47 } |
|
48 private SmmResourceChangeListener resourceListener; |
|
49 |
|
50 private SmmPartListener partListener; |
|
51 private IWindowListener windowListener; |
|
52 |
|
53 private IPageListener pageListener; |
|
54 |
|
55 /* |
|
56 * (non-Javadoc) |
|
57 * |
|
58 * @see |
|
59 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext |
|
60 * ) |
|
61 */ |
|
62 public void start(BundleContext context) throws Exception { |
|
63 super.start(context); |
|
64 plugin = this; |
|
65 |
|
66 PlatformUI.getWorkbench().getDecoratorManager().setEnabled( |
|
67 "com.symbian.smt.gui.outofsyncdecorator", true); |
|
68 |
|
69 resourceListener = new SmmResourceChangeListener(); |
|
70 partListener = new SmmPartListener(); |
|
71 |
|
72 ResourcesPlugin.getWorkspace().addResourceChangeListener( |
|
73 resourceListener, |
|
74 IResourceChangeEvent.POST_CHANGE |
|
75 | IResourceChangeEvent.PRE_DELETE |
|
76 | IResourceChangeEvent.PRE_BUILD); |
|
77 |
|
78 pageListener = new IPageListener() { |
|
79 |
|
80 public void pageActivated(IWorkbenchPage page) { |
|
81 page.addPartListener(partListener); |
|
82 } |
|
83 |
|
84 public void pageClosed(IWorkbenchPage page) { |
|
85 page.removePartListener(partListener); |
|
86 } |
|
87 |
|
88 public void pageOpened(IWorkbenchPage page) { |
|
89 page.addPartListener(partListener); |
|
90 } |
|
91 }; |
|
92 |
|
93 windowListener = new IWindowListener() { |
|
94 public void windowActivated(IWorkbenchWindow window) { |
|
95 window.addPageListener(pageListener); |
|
96 if (window.getActivePage() != null) { |
|
97 window.getActivePage().addPartListener(partListener); |
|
98 } |
|
99 } |
|
100 |
|
101 public void windowClosed(IWorkbenchWindow window) { |
|
102 window.removePageListener(pageListener); |
|
103 if (window.getActivePage() != null) { |
|
104 window.getActivePage().removePartListener(partListener); |
|
105 } |
|
106 } |
|
107 |
|
108 public void windowDeactivated(IWorkbenchWindow window) { |
|
109 window.removePageListener(pageListener); |
|
110 if (window.getActivePage() != null) { |
|
111 window.getActivePage().removePartListener(partListener); |
|
112 } |
|
113 } |
|
114 |
|
115 public void windowOpened(IWorkbenchWindow window) { |
|
116 window.addPageListener(pageListener); |
|
117 if (window.getActivePage() != null) { |
|
118 window.getActivePage().addPartListener(partListener); |
|
119 } |
|
120 } |
|
121 }; |
|
122 |
|
123 |
|
124 final IWorkbench workbench = PlatformUI.getWorkbench(); |
|
125 |
|
126 workbench.addWindowListener(windowListener); |
|
127 |
|
128 workbench.getDisplay().asyncExec(new Runnable() { |
|
129 public void run() { |
|
130 IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench() |
|
131 .getActiveWorkbenchWindow(); |
|
132 workbenchWindow.addPageListener(pageListener); |
|
133 if (workbenchWindow.getActivePage() != null) { |
|
134 workbenchWindow.getActivePage().addPartListener( |
|
135 partListener); |
|
136 } |
|
137 } |
|
138 |
|
139 }); |
|
140 } |
|
141 |
|
142 /* |
|
143 * (non-Javadoc) |
|
144 * |
|
145 * @see |
|
146 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext |
|
147 * ) |
|
148 */ |
|
149 public void stop(BundleContext context) throws Exception { |
|
150 plugin = null; |
|
151 super.stop(context); |
|
152 } |
|
153 } |