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 |
// SystemDefinitionFiles.java
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
package com.symbian.smt.gui.properties;
|
|
19 |
|
|
20 |
import org.eclipse.core.resources.IProject;
|
|
21 |
import org.eclipse.core.resources.ProjectScope;
|
|
22 |
import org.eclipse.core.runtime.preferences.IScopeContext;
|
|
23 |
import org.eclipse.swt.SWT;
|
|
24 |
import org.eclipse.swt.custom.BusyIndicator;
|
|
25 |
import org.eclipse.swt.layout.FillLayout;
|
|
26 |
import org.eclipse.swt.widgets.Composite;
|
|
27 |
import org.eclipse.swt.widgets.Control;
|
|
28 |
import org.eclipse.ui.IWorkbenchPropertyPage;
|
|
29 |
import org.eclipse.ui.dialogs.PropertyPage;
|
|
30 |
|
|
31 |
import com.symbian.smt.gui.Activator;
|
|
32 |
import com.symbian.smt.gui.ManageResources;
|
|
33 |
import com.symbian.smt.gui.NodeListener;
|
|
34 |
import com.symbian.smt.gui.PersistentDataStore;
|
|
35 |
import com.symbian.smt.gui.smtwidgets.SystemDefinitionFilesWidget;
|
|
36 |
import com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener;
|
|
37 |
import com.symbian.smt.gui.smtwidgets.ValidModelEvent;
|
|
38 |
import com.symbian.smt.gui.smtwidgets.ValidModelObservable;
|
|
39 |
|
|
40 |
public class SystemDefinitionFilesProperties extends PropertyPage implements
|
|
41 |
IWorkbenchPropertyPage, ValidModelDefinedListener {
|
|
42 |
private SystemDefinitionFilesWidget systemDefinitionFilesWidget;
|
|
43 |
private PersistentDataStore projectStore;
|
|
44 |
|
|
45 |
@Override
|
|
46 |
protected Control createContents(Composite parent) {
|
|
47 |
new NodeListener(getProject());
|
|
48 |
|
|
49 |
// Disable the restore defaults button
|
|
50 |
noDefaultAndApplyButton();
|
|
51 |
|
|
52 |
// Create the project scope data store
|
|
53 |
IScopeContext projectScope = new ProjectScope(this.getProject());
|
|
54 |
projectStore = new PersistentDataStore(projectScope
|
|
55 |
.getNode(Activator.PLUGIN_ID));
|
|
56 |
|
|
57 |
// Create the widget
|
|
58 |
Composite composite = new Composite(parent, SWT.NONE);
|
|
59 |
composite.setLayout(new FillLayout(SWT.VERTICAL));
|
|
60 |
systemDefinitionFilesWidget = new SystemDefinitionFilesWidget(
|
|
61 |
composite, SWT.NONE);
|
|
62 |
|
|
63 |
if (systemDefinitionFilesWidget instanceof ValidModelObservable) {
|
|
64 |
((ValidModelObservable) systemDefinitionFilesWidget)
|
|
65 |
.addModelListener(this);
|
|
66 |
}
|
|
67 |
|
|
68 |
// Set required values
|
|
69 |
populate(projectStore);
|
|
70 |
|
|
71 |
return composite;
|
|
72 |
}
|
|
73 |
|
|
74 |
@Override
|
|
75 |
public void dispose() {
|
|
76 |
if (systemDefinitionFilesWidget != null) {
|
|
77 |
((ValidModelObservable) systemDefinitionFilesWidget)
|
|
78 |
.removeModelListener(this);
|
|
79 |
}
|
|
80 |
|
|
81 |
super.dispose();
|
|
82 |
}
|
|
83 |
|
|
84 |
private IProject getProject() {
|
|
85 |
return (IProject) getElement();
|
|
86 |
}
|
|
87 |
|
|
88 |
@Override
|
|
89 |
public boolean isValid() {
|
|
90 |
// return requiredInformationPresent;
|
|
91 |
return super.isValid();
|
|
92 |
}
|
|
93 |
|
|
94 |
@Override
|
|
95 |
protected void performApply() {
|
|
96 |
saveChanges();
|
|
97 |
}
|
|
98 |
|
|
99 |
@Override
|
|
100 |
protected void performDefaults() {
|
|
101 |
}
|
|
102 |
|
|
103 |
@Override
|
|
104 |
public boolean performOk() {
|
|
105 |
saveChanges();
|
|
106 |
return super.performOk();
|
|
107 |
}
|
|
108 |
|
|
109 |
private void populate(PersistentDataStore dataStore) {
|
|
110 |
systemDefinitionFilesWidget.setSystemDefinitions(dataStore
|
|
111 |
.getSystemDefinitionFiles());
|
|
112 |
}
|
|
113 |
|
|
114 |
private void saveChanges() {
|
|
115 |
Runnable runnable = new Runnable() {
|
|
116 |
public void run() {
|
|
117 |
// Update the system definition files in the project
|
|
118 |
ManageResources.updateSystemDefinitionFiles(getProject(),
|
|
119 |
systemDefinitionFilesWidget.getSystemDefinitions(), false);
|
|
120 |
|
|
121 |
// Write to the persistent data store
|
|
122 |
projectStore.setSystemDefinitionFiles(systemDefinitionFilesWidget
|
|
123 |
.getSystemDefinitions());
|
|
124 |
}
|
|
125 |
};
|
|
126 |
|
|
127 |
BusyIndicator.showWhile(getShell().getDisplay(), runnable);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* This is called by the observed object when a change is used to ensure the
|
|
132 |
* information entered into the widget is acceptable, in this case at least
|
|
133 |
* 1 system definition xml file
|
|
134 |
*
|
|
135 |
* @return void
|
|
136 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener#validModelDefined(ValidModelEvent)
|
|
137 |
*/
|
|
138 |
public void validModelDefined(ValidModelEvent event) {
|
|
139 |
Boolean isValid = event.isValid();
|
|
140 |
|
|
141 |
setValid(isValid);
|
|
142 |
|
|
143 |
if (isValid) {
|
|
144 |
setErrorMessage(null);
|
|
145 |
} else {
|
|
146 |
setErrorMessage(event.getMessage());
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
}
|