0
|
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 |
// SmmResourceChaneListener.java
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
package com.symbian.smt.gui;
|
|
19 |
|
|
20 |
import org.eclipse.core.resources.IFile;
|
|
21 |
import org.eclipse.core.resources.IProject;
|
|
22 |
import org.eclipse.core.resources.IResource;
|
|
23 |
import org.eclipse.core.resources.IResourceChangeEvent;
|
|
24 |
import org.eclipse.core.resources.IResourceChangeListener;
|
|
25 |
import org.eclipse.core.resources.IResourceDelta;
|
|
26 |
import org.eclipse.core.resources.IWorkspace;
|
|
27 |
import org.eclipse.core.resources.IWorkspaceDescription;
|
|
28 |
import org.eclipse.core.resources.IWorkspaceRoot;
|
|
29 |
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
|
30 |
import org.eclipse.core.resources.ProjectScope;
|
|
31 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
32 |
import org.eclipse.core.runtime.CoreException;
|
|
33 |
import org.eclipse.core.runtime.IPath;
|
|
34 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
35 |
import org.eclipse.core.runtime.IStatus;
|
|
36 |
import org.eclipse.core.runtime.Path;
|
|
37 |
import org.eclipse.core.runtime.Status;
|
|
38 |
import org.eclipse.core.runtime.jobs.Job;
|
|
39 |
import org.eclipse.core.runtime.preferences.IScopeContext;
|
|
40 |
import org.eclipse.swt.widgets.Display;
|
|
41 |
import org.eclipse.ui.IEditorPart;
|
|
42 |
import org.eclipse.ui.IWorkbenchPage;
|
|
43 |
import org.eclipse.ui.PlatformUI;
|
|
44 |
import org.eclipse.ui.part.FileEditorInput;
|
|
45 |
|
|
46 |
import com.symbian.smt.gui.nature.Nature;
|
|
47 |
|
|
48 |
public class SmmResourceChangeListener implements IResourceChangeListener {
|
|
49 |
|
|
50 |
public void resourceChanged(final IResourceChangeEvent event) {
|
|
51 |
if (event.getType() == IResourceChangeEvent.PRE_BUILD) {
|
|
52 |
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
|
53 |
IWorkspaceDescription description = workspace.getDescription();
|
|
54 |
|
|
55 |
IWorkspaceRoot workspaceRoot = workspace.getRoot();
|
|
56 |
IResourceDelta delta = event.getDelta();
|
|
57 |
|
|
58 |
if (delta.getFullPath().equals(Path.ROOT)) {
|
|
59 |
IResourceDelta[] children = delta
|
|
60 |
.getAffectedChildren(IResourceDelta.CHANGED);
|
|
61 |
|
|
62 |
if (children.length == 0) {
|
|
63 |
return;
|
|
64 |
}
|
|
65 |
|
|
66 |
for (IResourceDelta child : children) {
|
|
67 |
if (child.getKind() == IResourceDelta.CHANGED) {
|
|
68 |
for (IProject aProject : workspaceRoot.getProjects()) {
|
|
69 |
try {
|
|
70 |
if (aProject.isOpen()
|
|
71 |
&& aProject.hasNature(Nature.ID)
|
|
72 |
&& aProject.getFullPath().equals(
|
|
73 |
child.getFullPath())) {
|
|
74 |
|
|
75 |
if (child.getFlags() == IResourceDelta.OPEN) {
|
|
76 |
final IProject theProject = aProject;
|
|
77 |
|
|
78 |
try {
|
|
79 |
theProject.refreshLocal(
|
|
80 |
IResource.DEPTH_INFINITE,
|
|
81 |
null);
|
|
82 |
|
|
83 |
IScopeContext projectScope = new ProjectScope(
|
|
84 |
theProject);
|
|
85 |
PersistentDataStore store = new PersistentDataStore(
|
|
86 |
projectScope
|
|
87 |
.getNode(Activator.PLUGIN_ID));
|
|
88 |
|
|
89 |
Boolean needsShortcutsRefreshing = true;
|
|
90 |
|
|
91 |
for (IResource resource : theProject
|
|
92 |
.members()) {
|
|
93 |
if (resource.isLinked()) {
|
|
94 |
needsShortcutsRefreshing = false;
|
|
95 |
break;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
if (needsShortcutsRefreshing == true) {
|
|
100 |
// We also need to get the
|
|
101 |
// shortcut to appear, as it
|
|
102 |
// does not always happen
|
|
103 |
// automatically
|
|
104 |
ManageResources
|
|
105 |
.updateSystemDefinitionFiles(
|
|
106 |
theProject,
|
|
107 |
store
|
|
108 |
.getSystemDefinitionFiles(),
|
|
109 |
true);
|
|
110 |
}
|
|
111 |
} catch (CoreException e) {
|
|
112 |
Logger.log(e.getMessage(), e);
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
if (!description.isAutoBuilding()) {
|
|
117 |
final IProject theProject = aProject;
|
|
118 |
Job j = new Job("Building workspace") {
|
|
119 |
@Override
|
|
120 |
protected IStatus run(
|
|
121 |
IProgressMonitor monitor) {
|
|
122 |
try {
|
|
123 |
if (event.getBuildKind() == IncrementalProjectBuilder.AUTO_BUILD) { // 9
|
|
124 |
theProject
|
|
125 |
.build(
|
|
126 |
IncrementalProjectBuilder.INCREMENTAL_BUILD,
|
|
127 |
monitor);
|
|
128 |
}
|
|
129 |
} catch (CoreException e) {
|
|
130 |
Logger.log(e.getMessage(),
|
|
131 |
e);
|
|
132 |
}
|
|
133 |
return new Status(
|
|
134 |
IStatus.OK,
|
|
135 |
Activator.PLUGIN_ID,
|
|
136 |
IStatus.OK,
|
|
137 |
"updating properties succeeded",
|
|
138 |
null);
|
|
139 |
}
|
|
140 |
};
|
|
141 |
j.schedule();
|
|
142 |
}
|
|
143 |
}
|
|
144 |
} catch (CoreException e) {
|
|
145 |
Logger.log(e.getMessage(), e);
|
|
146 |
}
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
} else if (event.getType() == IResourceChangeEvent.PRE_DELETE) {
|
|
152 |
// If it is a delete event then the resource is an IProject
|
|
153 |
IProject project = (IProject) event.getResource();
|
|
154 |
|
|
155 |
IScopeContext projectScope = new ProjectScope(project);
|
|
156 |
PersistentDataStore store = new PersistentDataStore(projectScope
|
|
157 |
.getNode(Activator.PLUGIN_ID));
|
|
158 |
|
|
159 |
final IFile oldProjectFile = project.getFile(store
|
|
160 |
.getOutputFilename());
|
|
161 |
|
|
162 |
ChangeManager manager = new ChangeManager();
|
|
163 |
manager.remove(project);
|
|
164 |
|
|
165 |
Display.getDefault().asyncExec(new Runnable() {
|
|
166 |
public void run() {
|
|
167 |
IWorkbenchPage page = PlatformUI.getWorkbench()
|
|
168 |
.getActiveWorkbenchWindow().getActivePage();
|
|
169 |
IEditorPart oldEditor = page
|
|
170 |
.findEditor(new FileEditorInput(oldProjectFile));
|
|
171 |
page.closeEditor(oldEditor, false);
|
|
172 |
}
|
|
173 |
});
|
|
174 |
} else {
|
|
175 |
IResourceDelta delta = event.getDelta();
|
|
176 |
|
|
177 |
if (event.getType() == IResourceChangeEvent.POST_CHANGE
|
|
178 |
&& delta.getKind() == IResourceDelta.CHANGED) {
|
|
179 |
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
|
180 |
IWorkspaceRoot workspaceRoot = workspace.getRoot();
|
|
181 |
IProject project = null;
|
|
182 |
|
|
183 |
IPath fullPath = delta.getFullPath();
|
|
184 |
|
|
185 |
if (delta.getFullPath().equals(Path.ROOT)) {
|
|
186 |
IResourceDelta[] children = delta
|
|
187 |
.getAffectedChildren(IResourceDelta.CHANGED);
|
|
188 |
|
|
189 |
if (children.length == 0) {
|
|
190 |
return;
|
|
191 |
}
|
|
192 |
|
|
193 |
for (IResourceDelta child : children) {
|
|
194 |
if (child.getKind() == IResourceDelta.CHANGED) {
|
|
195 |
fullPath = child.getFullPath();
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
for (IProject aProject : workspaceRoot.getProjects()) {
|
|
200 |
try {
|
|
201 |
if (aProject.isOpen() && aProject.hasNature(Nature.ID)
|
|
202 |
&& aProject.getFullPath().equals(fullPath)) {
|
|
203 |
project = aProject;
|
|
204 |
break;
|
|
205 |
}
|
|
206 |
} catch (CoreException e) {
|
|
207 |
Logger.log(e.getMessage(), e);
|
|
208 |
}
|
|
209 |
}
|
|
210 |
|
|
211 |
if (project == null) {
|
|
212 |
return;
|
|
213 |
}
|
|
214 |
|
|
215 |
ChangeManager manager = new ChangeManager();
|
|
216 |
manager.handleDelta(delta, project);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
}
|