]>
git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/eclipse/forms/editor/FormPage.java
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
.swt
.custom
.BusyIndicator
;
5 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
6 import org
.eclipse
.swt
.graphics
.Image
;
7 import org
.eclipse
.swt
.widgets
.Composite
;
8 import org
.eclipse
.swt
.widgets
.Control
;
10 * A base class that all pages that should be added to FormEditor must subclass.
11 * Form page has an instance of PageForm that extends managed form. Subclasses
12 * should override method 'createFormContent(ManagedForm)' to fill the form with
13 * content. Note that page itself can be loaded lazily (on first open).
14 * Consequently, the call to create the form content can come after the editor
15 * has been opened for a while (in fact, it is possible to open and close the
16 * editor and never create the form because no attempt has been made to show the
21 public class FormPage
implements IFormPage
{
22 private FormEditor editor
;
23 private PageForm mform
;
27 private String partName
;
31 public void setPartName(String partName
) {
32 this.partName
= partName
;
34 private static class PageForm
extends ManagedForm
{
35 public PageForm(FormPage page
, ScrolledComposite form
) {
36 super(page
.getEditor().getToolkit(), form
);
40 public FormPage
getPage() {
41 return (FormPage
)getContainer();
43 public void dirtyStateChanged() {
44 getPage().getEditor().editorDirtyStateChanged();
46 public void staleStateChanged() {
47 if (getPage().isActive())
52 * A constructor that creates the page and initializes it with the editor.
57 * the unique identifier
61 public FormPage(FormEditor editor
, String id
, String title
) {
66 * The constructor. The parent editor need to be passed in the
67 * <code>initialize</code> method if this constructor is used.
70 * a unique page identifier
72 * a user-friendly page title
74 public FormPage(String id
, String title
) {
79 * Initializes the form page.
81 * @see IEditorPart#init
83 // public void init(IEditorSite site, IEditorInput input) {
88 * Primes the form page with the parent editor instance.
93 public void initialize(FormEditor editor
) {
97 * Returns the parent editor.
99 * @return parent editor instance
101 public FormEditor
getEditor() {
105 * Returns the managed form owned by this page.
107 * @return the managed form
109 public IManagedForm
getManagedForm() {
113 * Implements the required method by refreshing the form when set active.
114 * Subclasses must call super when overriding this method.
116 public void setActive(boolean active
) {
118 // We are switching to this page - refresh it
125 * Tests if the page is active by asking the parent editor if this page is
126 * the currently active page.
128 * @return <code>true</code> if the page is currently active,
129 * <code>false</code> otherwise.
131 public boolean isActive() {
132 return this.equals(editor
.getActivePageInstance());
135 * Creates the part control by creating the managed form using the parent
136 * editor's toolkit. Subclasses should override
137 * <code>createFormContent(IManagedForm)</code> to populate the form with
141 * the page parent composite
143 public void createPartControl(Composite parent
) {
144 ScrolledComposite form
= editor
.getToolkit().createScrolledForm(parent
);
145 mform
= new PageForm(this, form
);
146 BusyIndicator
.showWhile(parent
.getDisplay(), new Runnable() {
148 createFormContent(mform
);
153 * Subclasses should override this method to create content in the form
154 * hosted in this page.
157 * the form hosted in this page.
159 protected void createFormContent(IManagedForm managedForm
) {
162 * Returns the form page control.
164 * @return managed form's control
166 public Control
getPartControl() {
167 return mform
!= null ? mform
.getForm() : null;
170 * Disposes the managed form.
172 public void dispose() {
177 * Returns the unique identifier that can be used to reference this page.
179 * @return the unique page identifier
181 public String
getId() {
185 * Returns <code>null</code>- form page has no title image. Subclasses
188 * @return <code>null</code>
190 public Image
getTitleImage() {
194 * Sets the focus by delegating to the managed form.
196 public void setFocus() {
201 * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
203 // public void doSave(IProgressMonitor monitor) {
204 // if (mform != null)
205 // mform.commit(true);
208 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
210 public void doSaveAs() {
213 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
215 public boolean isSaveAsAllowed() {
219 * Implemented by testing if the managed form is dirty.
221 * @return <code>true</code> if the managed form is dirty,
222 * <code>false</code> otherwise.
224 * @see org.eclipse.ui.ISaveablePart#isDirty()
226 public boolean isDirty() {
227 return mform
!= null ? mform
.isDirty() : false;
230 * Preserves the page index.
233 * the assigned page index
235 public void setIndex(int index
) {
239 * Returns the saved page index.
241 * @return the page index
243 public int getIndex() {
247 * Form pages are not editors.
249 * @return <code>false</code>
251 public boolean isEditor() {
255 * Attempts to select and reveal the given object by passing the request to
259 * the object to select and reveal in the page if possible.
260 * @return <code>true</code> if the page has been successfully selected
261 * and revealed by one of the managed form parts, <code>false</code>
264 public boolean selectReveal(Object object
) {
266 return mform
.setInput(object
);
270 * By default, editor will be allowed to flip the page.
271 * @return <code>true</code>
273 public boolean canLeaveThePage() {