|
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.BuildControlWidget; |
|
35 import com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener; |
|
36 import com.symbian.smt.gui.smtwidgets.ValidModelEvent; |
|
37 |
|
38 public class BuildControlProperties extends PropertyPage implements |
|
39 IWorkbenchPropertyPage, ValidModelDefinedListener { |
|
40 |
|
41 private BuildControlWidget buildWidget; |
|
42 private PersistentDataStore projectStore; |
|
43 private PersistentDataStore instanceStore; |
|
44 |
|
45 @Override |
|
46 protected Control createContents(Composite parent) { |
|
47 new NodeListener(getProject()); |
|
48 |
|
49 // Create the project scope data store |
|
50 IScopeContext projectScope = new ProjectScope(getProject()); |
|
51 projectStore = new PersistentDataStore(projectScope |
|
52 .getNode(Activator.PLUGIN_ID)); |
|
53 |
|
54 // Create the default scope data store |
|
55 IScopeContext defaultScope = new DefaultScope(); |
|
56 IEclipsePreferences defaultNode = defaultScope |
|
57 .getNode(Activator.PLUGIN_ID); |
|
58 |
|
59 IScopeContext instanceScope = new InstanceScope(); |
|
60 IEclipsePreferences instanceNode = instanceScope |
|
61 .getNode(Activator.PLUGIN_ID); |
|
62 |
|
63 instanceStore = new PersistentDataStore(instanceNode, defaultNode); |
|
64 |
|
65 // Create the widget |
|
66 Composite composite = new Composite(parent, SWT.NONE); |
|
67 composite.setLayout(new FillLayout(SWT.VERTICAL)); |
|
68 buildWidget = new BuildControlWidget(composite, SWT.NONE, false); |
|
69 buildWidget.addModelListener(this); |
|
70 |
|
71 // Set required values |
|
72 populate(projectStore); |
|
73 |
|
74 return composite; |
|
75 } |
|
76 |
|
77 @Override |
|
78 public void dispose() { |
|
79 if (buildWidget != null) { |
|
80 buildWidget.removeModelListener(this); |
|
81 } |
|
82 |
|
83 super.dispose(); |
|
84 } |
|
85 |
|
86 private IProject getProject() { |
|
87 return (IProject) getElement(); |
|
88 } |
|
89 |
|
90 @Override |
|
91 public boolean isValid() { |
|
92 return super.isValid(); |
|
93 } |
|
94 |
|
95 @Override |
|
96 protected void performApply() { |
|
97 saveChanges(); |
|
98 } |
|
99 |
|
100 @Override |
|
101 protected void performDefaults() { |
|
102 populate(instanceStore); |
|
103 } |
|
104 |
|
105 @Override |
|
106 public boolean performOk() { |
|
107 saveChanges(); |
|
108 return super.performOk(); |
|
109 } |
|
110 |
|
111 private void populate(PersistentDataStore dataStore) { |
|
112 buildWidget.setOutputFilename(dataStore.getOutputFilename()); |
|
113 } |
|
114 |
|
115 private void saveChanges() { |
|
116 projectStore.setOutputFilename(buildWidget.getOutputFilename()); |
|
117 } |
|
118 |
|
119 /** |
|
120 * This is called by the observed object when a change is used to ensure the |
|
121 * information entered into the widget is acceptable, in this case a non |
|
122 * empty output file name with no illegal characters. |
|
123 * |
|
124 * @return void |
|
125 * @see com.symbian.smt.gui.smtwidgets.ValidModelDefinedListener#validModelDefined(ValidModelEvent) |
|
126 */ |
|
127 public void validModelDefined(ValidModelEvent event) { |
|
128 Boolean isValid = event.isValid(); |
|
129 |
|
130 setValid(isValid); |
|
131 |
|
132 if (isValid) { |
|
133 setErrorMessage(null); |
|
134 } else { |
|
135 setErrorMessage(event.getMessage()); |
|
136 } |
|
137 } |
|
138 } |