|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2004, 2011 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 10-16
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.wst.jsdt.web.core.internal; |
11 |
package org.eclipse.wst.jsdt.web.core.internal; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.core.resources.IResourceChangeEvent; |
| 14 |
import org.eclipse.core.resources.IResourceChangeListener; |
| 15 |
import org.eclipse.core.resources.ISaveContext; |
| 16 |
import org.eclipse.core.resources.ISaveParticipant; |
| 17 |
import org.eclipse.core.resources.ISavedState; |
| 18 |
import org.eclipse.core.resources.IWorkspace; |
| 19 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
| 20 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 21 |
import org.eclipse.core.runtime.CoreException; |
| 22 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 23 |
import org.eclipse.core.runtime.IStatus; |
| 13 |
import org.eclipse.core.runtime.Plugin; |
24 |
import org.eclipse.core.runtime.Plugin; |
|
|
25 |
import org.eclipse.core.runtime.Status; |
| 26 |
import org.eclipse.core.runtime.jobs.Job; |
| 14 |
import org.eclipse.wst.jsdt.web.core.javascript.search.JsIndexManager; |
27 |
import org.eclipse.wst.jsdt.web.core.javascript.search.JsIndexManager; |
| 15 |
import org.osgi.framework.BundleContext; |
28 |
import org.osgi.framework.BundleContext; |
| 16 |
|
29 |
|
|
Lines 27-38
Link Here
|
| 27 |
public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$ |
40 |
public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.web.core"; //$NON-NLS-1$ |
| 28 |
|
41 |
|
| 29 |
/** |
42 |
/** |
|
|
43 |
* <p>Job used to finish tasks needed to start up the plugin but that did not have |
| 44 |
* to block the plugin start up process.</p> |
| 45 |
*/ |
| 46 |
private Job fPluginInitializerJob; |
| 47 |
|
| 48 |
/** |
| 30 |
* Returns the shared instance. |
49 |
* Returns the shared instance. |
| 31 |
* |
|
|
| 32 |
* @deprecated - will be removed. Currently used to get "model preferences", |
| 33 |
* but there are other, better ways. |
| 34 |
*/ |
50 |
*/ |
| 35 |
|
|
|
| 36 |
public static JsCorePlugin getDefault() { |
51 |
public static JsCorePlugin getDefault() { |
| 37 |
return JsCorePlugin.plugin; |
52 |
return JsCorePlugin.plugin; |
| 38 |
} |
53 |
} |
|
Lines 43-48
Link Here
|
| 43 |
public JsCorePlugin() { |
58 |
public JsCorePlugin() { |
| 44 |
super(); |
59 |
super(); |
| 45 |
JsCorePlugin.plugin = this; |
60 |
JsCorePlugin.plugin = this; |
|
|
61 |
this.fPluginInitializerJob = new PluginInitializerJob(); |
| 46 |
} |
62 |
} |
| 47 |
|
63 |
|
| 48 |
/* |
64 |
/* |
|
Lines 58-63
Link Here
|
| 58 |
// listen for classpath changes |
74 |
// listen for classpath changes |
| 59 |
JsIndexManager.getInstance().initialize(); |
75 |
JsIndexManager.getInstance().initialize(); |
| 60 |
// listen for resource changes to update content properties keys |
76 |
// listen for resource changes to update content properties keys |
|
|
77 |
|
| 78 |
//schedule delayed initialization |
| 79 |
this.fPluginInitializerJob.schedule(2000); |
| 80 |
|
| 61 |
} |
81 |
} |
| 62 |
|
82 |
|
| 63 |
/* |
83 |
/* |
|
Lines 71-76
Link Here
|
| 71 |
// keys |
91 |
// keys |
| 72 |
// stop any indexing |
92 |
// stop any indexing |
| 73 |
JsIndexManager.getInstance().shutdown(); |
93 |
JsIndexManager.getInstance().shutdown(); |
|
|
94 |
|
| 95 |
//Stop the resource event manager |
| 96 |
JSWebResourceEventManager.getDefault().stop(); |
| 97 |
|
| 74 |
super.stop(context); |
98 |
super.stop(context); |
| 75 |
} |
99 |
} |
|
|
100 |
|
| 101 |
/** |
| 102 |
* <p>A {@link Job} used to perform delayed initialization for the plugin</p> |
| 103 |
*/ |
| 104 |
private static class PluginInitializerJob extends Job { |
| 105 |
/** |
| 106 |
* <p>Default constructor to set up this {@link Job} as a |
| 107 |
* long running system {@link Job}</p> |
| 108 |
*/ |
| 109 |
protected PluginInitializerJob() { |
| 110 |
super(JsCoreMessages.JsCorePlugin_Initializing_JS_Web_Tools); |
| 111 |
|
| 112 |
this.setUser(false); |
| 113 |
this.setSystem(true); |
| 114 |
this.setPriority(Job.LONG); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* <p>Perform delayed initialization for the plugin</p> |
| 119 |
* |
| 120 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
| 121 |
*/ |
| 122 |
protected IStatus run(IProgressMonitor monitor) { |
| 123 |
IStatus status = Status.OK_STATUS; |
| 124 |
final IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 125 |
try { |
| 126 |
/* |
| 127 |
* Restore save state and process any events that happened before |
| 128 |
* plug-in loaded. Don't do it immediately since adding the save |
| 129 |
* participant requires a lock on the workspace to compute the |
| 130 |
* accumulated deltas, and if the tree is not already locked it |
| 131 |
* becomes a blocking call. |
| 132 |
*/ |
| 133 |
workspace.run(new IWorkspaceRunnable() { |
| 134 |
public void run(final IProgressMonitor worspaceMonitor) throws CoreException { |
| 135 |
ISavedState savedState = null; |
| 136 |
|
| 137 |
try { |
| 138 |
//add the save participant for this bundle |
| 139 |
savedState = ResourcesPlugin.getWorkspace().addSaveParticipant( |
| 140 |
JsCorePlugin.plugin.getBundle().getSymbolicName(), new SaveParticipant()); |
| 141 |
} catch (CoreException e) { |
| 142 |
Logger.logException("JSP Core Plugin failed at loading previously saved state." + //$NON-NLS-1$ |
| 143 |
" All componenets dependent on this state will start as if first workspace load.", e); //$NON-NLS-1$ |
| 144 |
} |
| 145 |
|
| 146 |
//if there is a saved state start up using that, else start up cold |
| 147 |
if(savedState != null) { |
| 148 |
try { |
| 149 |
Thread.currentThread().setPriority(Thread.MIN_PRIORITY); |
| 150 |
} finally { |
| 151 |
savedState.processResourceChangeEvents(new IResourceChangeListener() { |
| 152 |
/** |
| 153 |
* @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) |
| 154 |
*/ |
| 155 |
public void resourceChanged(IResourceChangeEvent event) { |
| 156 |
JSWebResourceEventManager.getDefault().start(event.getDelta(), worspaceMonitor); |
| 157 |
} |
| 158 |
}); |
| 159 |
} |
| 160 |
} else { |
| 161 |
JSWebResourceEventManager.getDefault().start(null, worspaceMonitor); |
| 162 |
} |
| 163 |
} |
| 164 |
}, monitor); |
| 165 |
} catch(CoreException e) { |
| 166 |
status = e.getStatus(); |
| 167 |
} |
| 168 |
|
| 169 |
return status; |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Used so that all of the IResourceChangeEvents that occurred before |
| 176 |
* this plugin loaded can be processed. |
| 177 |
*/ |
| 178 |
private static class SaveParticipant implements ISaveParticipant { |
| 179 |
/** |
| 180 |
* <p>Default constructor</p> |
| 181 |
*/ |
| 182 |
protected SaveParticipant() { |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* @see org.eclipse.core.resources.ISaveParticipant#doneSaving(org.eclipse.core.resources.ISaveContext) |
| 187 |
*/ |
| 188 |
public void doneSaving(ISaveContext context) { |
| 189 |
//ignore |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(org.eclipse.core.resources.ISaveContext) |
| 194 |
*/ |
| 195 |
public void prepareToSave(ISaveContext context) throws CoreException { |
| 196 |
//ignore |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* @see org.eclipse.core.resources.ISaveParticipant#rollback(org.eclipse.core.resources.ISaveContext) |
| 201 |
*/ |
| 202 |
public void rollback(ISaveContext context) { |
| 203 |
//ignore |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* @see org.eclipse.core.resources.ISaveParticipant#saving(org.eclipse.core.resources.ISaveContext) |
| 208 |
*/ |
| 209 |
public void saving(ISaveContext context) throws CoreException { |
| 210 |
context.needDelta(); |
| 211 |
} |
| 212 |
} |
| 76 |
} |
213 |
} |