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 |
// ModelLabelsProperties.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.DefaultScope;
|
|
23 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
|
24 |
import org.eclipse.core.runtime.preferences.IScopeContext;
|
|
25 |
import org.eclipse.core.runtime.preferences.InstanceScope;
|
|
26 |
import org.eclipse.swt.SWT;
|
|
27 |
import org.eclipse.swt.layout.FillLayout;
|
|
28 |
import org.eclipse.swt.widgets.Composite;
|
|
29 |
import org.eclipse.swt.widgets.Control;
|
|
30 |
import org.eclipse.ui.IWorkbenchPropertyPage;
|
|
31 |
import org.eclipse.ui.dialogs.PropertyPage;
|
|
32 |
|
|
33 |
import com.symbian.smt.gui.Activator;
|
|
34 |
import com.symbian.smt.gui.NodeListener;
|
|
35 |
import com.symbian.smt.gui.PersistentDataStore;
|
|
36 |
import com.symbian.smt.gui.smtwidgets.ModelLabelsWidget;
|
|
37 |
import com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener;
|
|
38 |
import com.symbian.smt.gui.smtwidgets.ValidModelEvent;
|
|
39 |
import com.symbian.smt.gui.smtwidgets.ValidModelEvent.Type;
|
|
40 |
|
|
41 |
public class ModelLabelProperties extends PropertyPage implements
|
|
42 |
IWorkbenchPropertyPage, ValidModelDefinedListener {
|
|
43 |
|
|
44 |
private ModelLabelsWidget modelLabelsWidget;
|
|
45 |
private PersistentDataStore projectStore;
|
|
46 |
private PersistentDataStore instanceStore;
|
|
47 |
|
|
48 |
@Override
|
|
49 |
protected Control createContents(Composite parent) {
|
|
50 |
new NodeListener(getProject());
|
|
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 default scope data store
|
|
58 |
IScopeContext defaultScope = new DefaultScope();
|
|
59 |
IEclipsePreferences defaultNode = defaultScope
|
|
60 |
.getNode(Activator.PLUGIN_ID);
|
|
61 |
|
|
62 |
IScopeContext instanceScope = new InstanceScope();
|
|
63 |
IEclipsePreferences instanceNode = instanceScope
|
|
64 |
.getNode(Activator.PLUGIN_ID);
|
|
65 |
|
|
66 |
instanceStore = new PersistentDataStore(instanceNode, defaultNode);
|
|
67 |
|
|
68 |
// Create the widget
|
|
69 |
Composite composite = new Composite(parent, SWT.NONE);
|
|
70 |
composite.setLayout(new FillLayout(SWT.VERTICAL));
|
|
71 |
modelLabelsWidget = new ModelLabelsWidget(composite, SWT.NONE);
|
|
72 |
|
|
73 |
modelLabelsWidget.initialiseModelVersionText(projectStore);
|
|
74 |
modelLabelsWidget.initialiseDistributionText(projectStore);
|
|
75 |
modelLabelsWidget.addModelListener(this);
|
|
76 |
|
|
77 |
// Set required values
|
|
78 |
populate(projectStore);
|
|
79 |
|
|
80 |
return composite;
|
|
81 |
}
|
|
82 |
|
|
83 |
@Override
|
|
84 |
public void dispose() {
|
|
85 |
if (modelLabelsWidget != null) {
|
|
86 |
modelLabelsWidget.removeModelListener(this);
|
|
87 |
}
|
|
88 |
|
|
89 |
super.dispose();
|
|
90 |
}
|
|
91 |
|
|
92 |
private IProject getProject() {
|
|
93 |
return (IProject) getElement();
|
|
94 |
}
|
|
95 |
|
|
96 |
@Override
|
|
97 |
protected void performApply() {
|
|
98 |
saveChanges();
|
|
99 |
}
|
|
100 |
|
|
101 |
@Override
|
|
102 |
protected void performDefaults() {
|
|
103 |
populate(instanceStore);
|
|
104 |
}
|
|
105 |
|
|
106 |
@Override
|
|
107 |
public boolean performOk() {
|
|
108 |
saveChanges();
|
|
109 |
return super.performOk();
|
|
110 |
}
|
|
111 |
|
|
112 |
private void populate(PersistentDataStore dataStore) {
|
|
113 |
// Model Version Text and Distribution Text fields have already been
|
|
114 |
// initialised via the calls
|
|
115 |
// to modelLabelsWidget.initialiseModelVersionText() and
|
|
116 |
// modelLabelsWidget.initialiseDistributionText() respectively
|
|
117 |
modelLabelsWidget.setCopyrightText(dataStore.getCopyrightText());
|
|
118 |
|
|
119 |
modelLabelsWidget.setModelName(dataStore.getModelName());
|
|
120 |
|
|
121 |
modelLabelsWidget.setModelVersion(dataStore.getModelVersion());
|
|
122 |
|
|
123 |
modelLabelsWidget.setSystemName(dataStore.getSystemName());
|
|
124 |
|
|
125 |
modelLabelsWidget.setSystemVersion(dataStore.getSystemVersion());
|
|
126 |
}
|
|
127 |
|
|
128 |
private void saveChanges() {
|
|
129 |
projectStore.setCopyrightText(modelLabelsWidget.getCopyrightText());
|
|
130 |
|
|
131 |
projectStore.setDistributionTexts(modelLabelsWidget
|
|
132 |
.getDistributionTexts());
|
|
133 |
projectStore.setSelectedDistributionText(modelLabelsWidget
|
|
134 |
.getSelectedDistributionText());
|
|
135 |
|
|
136 |
projectStore.setModelName(modelLabelsWidget.getModelName());
|
|
137 |
|
|
138 |
projectStore.setModelVersion(modelLabelsWidget.getModelVersion());
|
|
139 |
|
|
140 |
projectStore.setModelVersionTexts(modelLabelsWidget
|
|
141 |
.getModelVersionTexts());
|
|
142 |
projectStore.setSelectedModelVersionText(modelLabelsWidget
|
|
143 |
.getSelectedModelVersionText());
|
|
144 |
|
|
145 |
projectStore.setSystemName(modelLabelsWidget.getSystemName());
|
|
146 |
|
|
147 |
projectStore.setSystemVersion(modelLabelsWidget.getSystemVersion());
|
|
148 |
}
|
|
149 |
|
|
150 |
/**
|
|
151 |
* This method is called by the observed object when a change occurs to
|
|
152 |
* ensure the information entered into the widget is acceptable. In this
|
|
153 |
* case we set the page in error mode if validation of the model version
|
|
154 |
* text field or of the distribution text field fails.
|
|
155 |
*
|
|
156 |
* @return void
|
|
157 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener#validModelDefined(ValidModelEvent)
|
|
158 |
*/
|
|
159 |
public void validModelDefined(ValidModelEvent event) {
|
|
160 |
Boolean isValid = event.isValid();
|
|
161 |
Type eventType = event.getType();
|
|
162 |
|
|
163 |
setValid(isValid);
|
|
164 |
|
|
165 |
if (isValid) {
|
|
166 |
setErrorMessage(null);
|
|
167 |
|
|
168 |
if (eventType == Type.WARNING) {
|
|
169 |
setMessage(event.getMessage(), WARNING);
|
|
170 |
}
|
|
171 |
} else {
|
|
172 |
setErrorMessage(event.getMessage());
|
|
173 |
setMessage(null);
|
|
174 |
}
|
|
175 |
}
|
|
176 |
} |