]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/org.argeo.cms.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
.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
;
11 * A base class that all pages that should be added to FormEditor must subclass.
12 * Form page has an instance of PageForm that extends managed form. Subclasses
13 * should override method 'createFormContent(ManagedForm)' to fill the form with
14 * content. Note that page itself can be loaded lazily (on first open).
15 * Consequently, the call to create the form content can come after the editor
16 * has been opened for a while (in fact, it is possible to open and close the
17 * editor and never create the form because no attempt has been made to show the
22 public class FormPage
implements IFormPage
{
23 private FormEditor editor
;
24 private PageForm mform
;
28 private String partName
;
32 public void setPartName(String partName
) {
33 this.partName
= partName
;
35 private static class PageForm
extends ManagedForm
{
36 public PageForm(FormPage page
, ScrolledComposite form
) {
37 super(page
.getEditor().getToolkit(), form
);
41 public FormPage
getPage() {
42 return (FormPage
)getContainer();
44 public void dirtyStateChanged() {
45 getPage().getEditor().editorDirtyStateChanged();
47 public void staleStateChanged() {
48 if (getPage().isActive())
53 * A constructor that creates the page and initializes it with the editor.
58 * the unique identifier
62 public FormPage(FormEditor editor
, String id
, String title
) {
67 * The constructor. The parent editor need to be passed in the
68 * <code>initialize</code> method if this constructor is used.
71 * a unique page identifier
73 * a user-friendly page title
75 public FormPage(String id
, String title
) {
80 * Initializes the form page.
82 * @see IEditorPart#init
84 // public void init(IEditorSite site, IEditorInput input) {
89 * Primes the form page with the parent editor instance.
94 public void initialize(FormEditor editor
) {
98 * Returns the parent editor.
100 * @return parent editor instance
102 public FormEditor
getEditor() {
106 * Returns the managed form owned by this page.
108 * @return the managed form
110 public IManagedForm
getManagedForm() {
114 * Implements the required method by refreshing the form when set active.
115 * Subclasses must call super when overriding this method.
117 public void setActive(boolean active
) {
119 // We are switching to this page - refresh it
126 * Tests if the page is active by asking the parent editor if this page is
127 * the currently active page.
129 * @return <code>true</code> if the page is currently active,
130 * <code>false</code> otherwise.
132 public boolean isActive() {
133 return this.equals(editor
.getActivePageInstance());
136 * Creates the part control by creating the managed form using the parent
137 * editor's toolkit. Subclasses should override
138 * <code>createFormContent(IManagedForm)</code> to populate the form with
142 * the page parent composite
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() {
149 createFormContent(mform
);
154 * Subclasses should override this method to create content in the form
155 * hosted in this page.
158 * the form hosted in this page.
160 protected void createFormContent(IManagedForm managedForm
) {
163 * Returns the form page control.
165 * @return managed form's control
167 public Control
getPartControl() {
168 return mform
!= null ? mform
.getForm() : null;
171 * Disposes the managed form.
173 public void dispose() {
178 * Returns the unique identifier that can be used to reference this page.
180 * @return the unique page identifier
182 public String
getId() {
186 * Returns <code>null</code>- form page has no title image. Subclasses
189 * @return <code>null</code>
191 public Image
getTitleImage() {
195 * Sets the focus by delegating to the managed form.
197 public void setFocus() {
202 * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
204 public void doSave(IProgressMonitor monitor
) {
209 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
211 public void doSaveAs() {
214 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
216 public boolean isSaveAsAllowed() {
220 * Implemented by testing if the managed form is dirty.
222 * @return <code>true</code> if the managed form is dirty,
223 * <code>false</code> otherwise.
225 * @see org.eclipse.ui.ISaveablePart#isDirty()
227 public boolean isDirty() {
228 return mform
!= null ? mform
.isDirty() : false;
231 * Preserves the page index.
234 * the assigned page index
236 public void setIndex(int index
) {
240 * Returns the saved page index.
242 * @return the page index
244 public int getIndex() {
248 * Form pages are not editors.
250 * @return <code>false</code>
252 public boolean isEditor() {
256 * Attempts to select and reveal the given object by passing the request to
260 * the object to select and reveal in the page if possible.
261 * @return <code>true</code> if the page has been successfully selected
262 * and revealed by one of the managed form parts, <code>false</code>
265 public boolean selectReveal(Object object
) {
267 return mform
.setInput(object
);
271 * By default, editor will be allowed to flip the page.
272 * @return <code>true</code>
274 public boolean canLeaveThePage() {