|
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.properties; |
|
17 |
|
18 import org.eclipse.core.resources.IProject; |
|
19 import org.eclipse.core.resources.ProjectScope; |
|
20 import org.eclipse.core.runtime.preferences.DefaultScope; |
|
21 import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
22 import org.eclipse.core.runtime.preferences.IScopeContext; |
|
23 import org.eclipse.core.runtime.preferences.InstanceScope; |
|
24 import org.eclipse.swt.SWT; |
|
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.NodeListener; |
|
33 import com.symbian.smt.gui.PersistentDataStore; |
|
34 import com.symbian.smt.gui.smtwidgets.ModelControlWidget; |
|
35 import com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener; |
|
36 import com.symbian.smt.gui.smtwidgets.ValidModelEvent; |
|
37 import com.symbian.smt.gui.smtwidgets.ValidModelEvent.Type; |
|
38 |
|
39 public class ModelControlProperties extends PropertyPage implements |
|
40 IWorkbenchPropertyPage, ValidModelDefinedListener { |
|
41 |
|
42 private ModelControlWidget modelControlWidget; |
|
43 private PersistentDataStore projectStore; |
|
44 private PersistentDataStore instanceStore; |
|
45 |
|
46 @Override |
|
47 protected Control createContents(Composite parent) { |
|
48 new NodeListener(getProject()); |
|
49 |
|
50 // Create the project scope data store |
|
51 IScopeContext projectScope = new ProjectScope(this.getProject()); |
|
52 projectStore = new PersistentDataStore(projectScope |
|
53 .getNode(Activator.PLUGIN_ID)); |
|
54 |
|
55 // Create the default scope data store |
|
56 IScopeContext defaultScope = new DefaultScope(); |
|
57 IEclipsePreferences defaultNode = defaultScope |
|
58 .getNode(Activator.PLUGIN_ID); |
|
59 |
|
60 IScopeContext instanceScope = new InstanceScope(); |
|
61 IEclipsePreferences instanceNode = instanceScope |
|
62 .getNode(Activator.PLUGIN_ID); |
|
63 |
|
64 instanceStore = new PersistentDataStore(instanceNode, defaultNode); |
|
65 |
|
66 // Create the widget |
|
67 Composite composite = new Composite(parent, SWT.NONE); |
|
68 composite.setLayout(new FillLayout(SWT.VERTICAL)); |
|
69 modelControlWidget = new ModelControlWidget(composite, SWT.NONE); |
|
70 modelControlWidget.initialisePrintedDpi(projectStore); |
|
71 |
|
72 modelControlWidget.addModelListener(this); |
|
73 |
|
74 // Set required values |
|
75 populate(projectStore); |
|
76 |
|
77 return composite; |
|
78 } |
|
79 |
|
80 @Override |
|
81 public void dispose() { |
|
82 if (modelControlWidget != null) { |
|
83 modelControlWidget.removeModelListener(this); |
|
84 } |
|
85 |
|
86 super.dispose(); |
|
87 } |
|
88 |
|
89 private IProject getProject() { |
|
90 return (IProject) getElement(); |
|
91 } |
|
92 |
|
93 @Override |
|
94 protected void performApply() { |
|
95 saveChanges(); |
|
96 } |
|
97 |
|
98 @Override |
|
99 protected void performDefaults() { |
|
100 populate(instanceStore); |
|
101 } |
|
102 |
|
103 @Override |
|
104 public boolean performOk() { |
|
105 saveChanges(); |
|
106 return super.performOk(); |
|
107 } |
|
108 |
|
109 private void populate(PersistentDataStore dataStore) { |
|
110 // printedDpi field has already been initialised via the call to |
|
111 // modelControlWidget.initialisePrintedDpi() |
|
112 modelControlWidget.setHighlightCoreOS(dataStore.getHighlightCoreOS()); |
|
113 modelControlWidget.setLevelOfDetail(dataStore.getLevelOfDetail()); |
|
114 modelControlWidget.setSuppressMouseOverEffect(dataStore |
|
115 .getSuppressMouseOverEffect()); |
|
116 modelControlWidget.setFixItemSize(dataStore.getFixItemSize()); |
|
117 } |
|
118 |
|
119 private void saveChanges() { |
|
120 projectStore.setLevelOfDetail(modelControlWidget.getLevelOfDetail()); |
|
121 projectStore |
|
122 .setHighlightCoreOS(modelControlWidget.getHighlightCoreOS()); |
|
123 projectStore.setSuppressMouseOverEffect(modelControlWidget |
|
124 .getSuppressMouseOverEffect()); |
|
125 projectStore.setFixItemSize(modelControlWidget.getFixItemSize()); |
|
126 projectStore.setPrintedDpis(modelControlWidget.getPrintedDpis()); |
|
127 projectStore.setSelectedPrintedDpi(modelControlWidget |
|
128 .getSelectedPrintedDpi()); |
|
129 } |
|
130 |
|
131 /** |
|
132 * This method is called by the observed object when a change occurs to |
|
133 * ensure the information entered into the widget is acceptable. In this |
|
134 * case we set the page in error mode if validation of the printed DPI field |
|
135 * fails. |
|
136 * |
|
137 * @return void |
|
138 * @see com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener#validModelDefined(ValidModelEvent) |
|
139 */ |
|
140 public void validModelDefined(ValidModelEvent event) { |
|
141 Boolean isValid = event.isValid(); |
|
142 Type eventType = event.getType(); |
|
143 |
|
144 setValid(isValid); |
|
145 |
|
146 if (isValid) { |
|
147 setErrorMessage(null); |
|
148 |
|
149 if (eventType == Type.WARNING) { |
|
150 setMessage(event.getMessage(), WARNING); |
|
151 } |
|
152 } else { |
|
153 setErrorMessage(event.getMessage()); |
|
154 setMessage(null); |
|
155 } |
|
156 } |
|
157 } |