1 package org.argeo.cms.ui.eclipse.forms.editor;
2 import org.argeo.cms.ui.eclipse.forms.IManagedForm;
3 import org.argeo.cms.ui.eclipse.forms.ManagedForm;
4 import org.eclipse.core.runtime.IProgressMonitor;
5 import org.eclipse.swt.custom.BusyIndicator;
6 import org.eclipse.swt.custom.ScrolledComposite;
7 import org.eclipse.swt.graphics.Image;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Control;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class FormPage implements IFormPage {
23 private FormEditor editor;
24 private PageForm mform;
25 private int index;
26 private String id;
27
28 private String partName;
29
30
31
32 public void setPartName(String partName) {
33 this.partName = partName;
34 }
35 private static class PageForm extends ManagedForm {
36 public PageForm(FormPage page, ScrolledComposite form) {
37 super(page.getEditor().getToolkit(), form);
38 setContainer(page);
39 }
40
41 public FormPage getPage() {
42 return (FormPage)getContainer();
43 }
44 public void dirtyStateChanged() {
45 getPage().getEditor().editorDirtyStateChanged();
46 }
47 public void staleStateChanged() {
48 if (getPage().isActive())
49 refresh();
50 }
51 }
52
53
54
55
56
57
58
59
60
61
62 public FormPage(FormEditor editor, String id, String title) {
63 this(id, title);
64 initialize(editor);
65 }
66
67
68
69
70
71
72
73
74
75 public FormPage(String id, String title) {
76 this.id = id;
77 setPartName(title);
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public void initialize(FormEditor editor) {
95 this.editor = editor;
96 }
97
98
99
100
101
102 public FormEditor getEditor() {
103 return editor;
104 }
105
106
107
108
109
110 public IManagedForm getManagedForm() {
111 return mform;
112 }
113
114
115
116
117 public void setActive(boolean active) {
118 if (active) {
119
120
121 if (mform != null)
122 mform.refresh();
123 }
124 }
125
126
127
128
129
130
131
132 public boolean isActive() {
133 return this.equals(editor.getActivePageInstance());
134 }
135
136
137
138
139
140
141
142
143
144 public void createPartControl(Composite parent) {
145 ScrolledComposite form = editor.getToolkit().createScrolledForm(parent);
146 mform = new PageForm(this, form);
147 BusyIndicator.showWhile(parent.getDisplay(), new Runnable() {
148 public void run() {
149 createFormContent(mform);
150 }
151 });
152 }
153
154
155
156
157
158
159
160 protected void createFormContent(IManagedForm managedForm) {
161 }
162
163
164
165
166
167 public Control getPartControl() {
168 return mform != null ? mform.getForm() : null;
169 }
170
171
172
173 public void dispose() {
174 if (mform != null)
175 mform.dispose();
176 }
177
178
179
180
181
182 public String getId() {
183 return id;
184 }
185
186
187
188
189
190
191 public Image getTitleImage() {
192 return null;
193 }
194
195
196
197 public void setFocus() {
198 if (mform != null)
199 mform.setFocus();
200 }
201
202
203
204 public void doSave(IProgressMonitor monitor) {
205 if (mform != null)
206 mform.commit(true);
207 }
208
209
210
211 public void doSaveAs() {
212 }
213
214
215
216 public boolean isSaveAsAllowed() {
217 return false;
218 }
219
220
221
222
223
224
225
226
227 public boolean isDirty() {
228 return mform != null ? mform.isDirty() : false;
229 }
230
231
232
233
234
235
236 public void setIndex(int index) {
237 this.index = index;
238 }
239
240
241
242
243
244 public int getIndex() {
245 return index;
246 }
247
248
249
250
251
252 public boolean isEditor() {
253 return false;
254 }
255
256
257
258
259
260
261
262
263
264
265 public boolean selectReveal(Object object) {
266 if (mform != null)
267 return mform.setInput(object);
268 return false;
269 }
270
271
272
273
274 public boolean canLeaveThePage() {
275 return true;
276 }
277 }