|
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.preferences; |
|
17 |
|
18 import org.eclipse.core.runtime.preferences.DefaultScope; |
|
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
20 import org.eclipse.core.runtime.preferences.IScopeContext; |
|
21 import org.eclipse.core.runtime.preferences.InstanceScope; |
|
22 import org.eclipse.jface.preference.PreferencePage; |
|
23 import org.eclipse.jface.resource.ImageDescriptor; |
|
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.IWorkbench; |
|
29 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
30 |
|
31 import com.symbian.smt.gui.AbstractPersistentDataStore; |
|
32 import com.symbian.smt.gui.Activator; |
|
33 import com.symbian.smt.gui.PersistentDataStore; |
|
34 import com.symbian.smt.gui.smtwidgets.BuildControlWidget; |
|
35 import com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener; |
|
36 import com.symbian.smt.gui.smtwidgets.ValidModelEvent; |
|
37 |
|
38 public class BuildPreferences extends PreferencePage implements |
|
39 IWorkbenchPreferencePage, ValidModelDefinedListener { |
|
40 |
|
41 private BuildControlWidget buildWidget; |
|
42 |
|
43 private AbstractPersistentDataStore instanceStore; |
|
44 private AbstractPersistentDataStore defaultStore; |
|
45 |
|
46 public BuildPreferences() { |
|
47 } |
|
48 |
|
49 public BuildPreferences(String title) { |
|
50 super(title); |
|
51 } |
|
52 |
|
53 public BuildPreferences(String title, ImageDescriptor image) { |
|
54 super(title, image); |
|
55 } |
|
56 |
|
57 @Override |
|
58 protected Control createContents(Composite parent) { |
|
59 Composite composite = new Composite(parent, SWT.NONE); |
|
60 composite.setLayout(new FillLayout(SWT.VERTICAL)); |
|
61 |
|
62 buildWidget = new BuildControlWidget(composite, SWT.NONE, true); |
|
63 |
|
64 IScopeContext defaultScope = new DefaultScope(); |
|
65 IEclipsePreferences defaultNode = defaultScope |
|
66 .getNode(Activator.PLUGIN_ID); |
|
67 defaultStore = new PersistentDataStore(defaultNode); |
|
68 |
|
69 IScopeContext instanceScope = new InstanceScope(); |
|
70 IEclipsePreferences instanceNode = instanceScope |
|
71 .getNode(Activator.PLUGIN_ID); |
|
72 instanceStore = new PersistentDataStore(instanceNode, defaultNode); |
|
73 |
|
74 buildWidget.setOutputFilename(instanceStore.getOutputFilename()); |
|
75 buildWidget.setWarningLevel(instanceStore.getWarningLevel()); |
|
76 |
|
77 buildWidget.addModelListener(this); |
|
78 |
|
79 composite.pack(); |
|
80 parent.pack(); |
|
81 |
|
82 return composite; |
|
83 } |
|
84 |
|
85 @Override |
|
86 public void dispose() { |
|
87 if (buildWidget != null) { |
|
88 buildWidget.removeModelListener(this); |
|
89 } |
|
90 |
|
91 super.dispose(); |
|
92 } |
|
93 |
|
94 /* |
|
95 * Comma-separated list of filters to turn on when building the model. All |
|
96 * filters on an item must be present in this list in order for that item to |
|
97 * appear. Order does not matter |
|
98 */ |
|
99 public void init(IWorkbench workbench) { |
|
100 setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
|
101 setDescription("System Model Manager build options."); |
|
102 } |
|
103 |
|
104 public void performDefaults() { |
|
105 restoreDefaults(); |
|
106 } |
|
107 |
|
108 public boolean performOk() { |
|
109 storeValues(); |
|
110 return super.performOk(); |
|
111 } |
|
112 |
|
113 private void restoreDefaults() { |
|
114 buildWidget.setOutputFilename(defaultStore.getOutputFilename()); |
|
115 buildWidget.setWarningLevel(defaultStore.getWarningLevel()); |
|
116 } |
|
117 |
|
118 private void storeValues() { |
|
119 instanceStore.setOutputFilename(buildWidget.getOutputFilename()); |
|
120 instanceStore.setWarningLevel(buildWidget.getWarningLevel()); |
|
121 } |
|
122 |
|
123 /* |
|
124 * This is called by the observed object when a change is used to ensure the |
|
125 * information entered into the widget is acceptable, in this case at least |
|
126 * 1 system definition xml file |
|
127 * |
|
128 * @return void |
|
129 */ |
|
130 public void validModelDefined(ValidModelEvent event) { |
|
131 Boolean isValid = event.isValid(); |
|
132 |
|
133 setValid(isValid); |
|
134 |
|
135 if (isValid) { |
|
136 setErrorMessage(null); |
|
137 } else { |
|
138 setErrorMessage(event.getMessage()); |
|
139 } |
|
140 } |
|
141 } |