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 |
//
|
|
15 |
|
|
16 |
package com.symbian.smt.gui;
|
|
17 |
|
|
18 |
import org.eclipse.core.resources.IFile;
|
|
19 |
import org.eclipse.core.resources.IMarker;
|
|
20 |
import org.eclipse.core.resources.IProject;
|
|
21 |
import org.eclipse.core.resources.IWorkspaceRunnable;
|
|
22 |
import org.eclipse.core.resources.ProjectScope;
|
|
23 |
import org.eclipse.core.runtime.CoreException;
|
|
24 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
25 |
import org.eclipse.core.runtime.preferences.IScopeContext;
|
|
26 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
|
|
27 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
|
|
28 |
|
|
29 |
public class NodeListener {
|
|
30 |
|
|
31 |
public NodeListener(final IProject project) {
|
|
32 |
IScopeContext projectScope = new ProjectScope(project);
|
|
33 |
|
|
34 |
// if name changed in properties
|
|
35 |
projectScope.getNode(Activator.PLUGIN_ID).addPreferenceChangeListener(
|
|
36 |
new IPreferenceChangeListener() {
|
|
37 |
|
|
38 |
public void preferenceChange(PreferenceChangeEvent event) {
|
|
39 |
String key = event.getKey();
|
|
40 |
try {
|
|
41 |
if (key.equals(PersistentSettingsEnums.OUTPUT_NAME
|
|
42 |
.toString())
|
|
43 |
&& event.getNewValue() != null) {
|
|
44 |
final IFile oldfile = project
|
|
45 |
.getFile((String) event.getOldValue());
|
|
46 |
final IFile newfile = project
|
|
47 |
.getFile((String) event.getNewValue());
|
|
48 |
|
|
49 |
project.getWorkspace().run(
|
|
50 |
new IWorkspaceRunnable() {
|
|
51 |
public void run(
|
|
52 |
IProgressMonitor monitor) {
|
|
53 |
if (oldfile.exists()) {
|
|
54 |
try {
|
|
55 |
newfile
|
|
56 |
.create(
|
|
57 |
oldfile
|
|
58 |
.getContents(true),
|
|
59 |
false,
|
|
60 |
null);
|
|
61 |
newfile
|
|
62 |
.setDerived(true);
|
|
63 |
oldfile.delete(true,
|
|
64 |
null);
|
|
65 |
} catch (CoreException e) {
|
|
66 |
Logger.log(e
|
|
67 |
.getMessage(),
|
|
68 |
e);
|
|
69 |
}
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}, null);
|
|
73 |
|
|
74 |
} else {
|
|
75 |
Boolean alreadyHasMarker = false;
|
|
76 |
IMarker[] mMarkers = project.findMarkers(
|
|
77 |
IMarker.MESSAGE, false, 0);
|
|
78 |
|
|
79 |
for (IMarker aMarker : mMarkers) {
|
|
80 |
if (aMarker.getAttribute(IMarker.MESSAGE) != null) {
|
|
81 |
if (aMarker.getAttribute(
|
|
82 |
IMarker.MESSAGE).equals(
|
|
83 |
"properties changed")) {
|
|
84 |
alreadyHasMarker = true;
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
if (!alreadyHasMarker) {
|
|
90 |
IMarker marker = project
|
|
91 |
.createMarker(IMarker.MESSAGE);
|
|
92 |
marker.setAttribute(IMarker.MESSAGE,
|
|
93 |
"properties changed");
|
|
94 |
}
|
|
95 |
}
|
|
96 |
} catch (CoreException e) {
|
|
97 |
Logger.log(e.getMessage(), e);
|
|
98 |
}
|
|
99 |
}
|
|
100 |
});
|
|
101 |
}
|
|
102 |
}
|