]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/eclipse/forms/editor/FormEditor.java
Improve deployment.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / eclipse / forms / editor / FormEditor.java
1 package org.argeo.cms.ui.eclipse.forms.editor;
2
3 import org.argeo.cms.ui.eclipse.forms.FormToolkit;
4 import org.eclipse.core.runtime.ListenerList;
5 import org.eclipse.jface.dialogs.IPageChangeProvider;
6 import org.eclipse.jface.dialogs.IPageChangedListener;
7 import org.eclipse.jface.dialogs.PageChangedEvent;
8 import org.eclipse.jface.util.SafeRunnable;
9
10 /**
11 * This class forms a base of multi-page form editors that typically use one or
12 * more pages with forms and one page for raw source of the editor input.
13 * <p>
14 * Pages are added 'lazily' i.e. adding a page reserves a tab for it but does
15 * not cause the page control to be created. Page control is created when an
16 * attempt is made to select the page in question. This allows editors with
17 * several tabs and complex pages to open quickly.
18 * <p>
19 * Subclasses should extend this class and implement <code>addPages</code>
20 * method. One of the two <code>addPage</code> methods should be called to
21 * contribute pages to the editor. One adds complete (standalone) editors as
22 * nested tabs. These editors will be created right away and will be hooked so
23 * that key bindings, selection service etc. is compatible with the one for the
24 * standalone case. The other method adds classes that implement
25 * <code>IFormPage</code> interface. These pages will be created lazily and
26 * they will share the common key binding and selection service. Since 3.1,
27 * FormEditor is a page change provider. It allows listeners to attach to it and
28 * get notified when pages are changed. This new API in JFace allows dynamic
29 * help to update on page changes.
30 *
31 * @since 1.0
32 */
33 // RAP [if] As RAP is still using workbench 3.4, the implementation of
34 // IPageChangeProvider is missing from MultiPageEditorPart. Remove this code
35 // with the adoption of workbench > 3.5
36 //public abstract class FormEditor extends MultiPageEditorPart {
37 public abstract class FormEditor implements
38 IPageChangeProvider {
39 private FormToolkit formToolkit;
40
41
42 public FormToolkit getToolkit() {
43 return formToolkit;
44 }
45
46 public void editorDirtyStateChanged() {
47
48 }
49
50 public FormPage getActivePageInstance() {
51 return null;
52 }
53
54 // RAP [if] As RAP is still using workbench 3.4, the implementation of
55 // IPageChangeProvider is missing from MultiPageEditorPart. Remove this code
56 // with the adoption of workbench > 3.5
57 private ListenerList pageListeners = new ListenerList();
58
59 /*
60 * (non-Javadoc)
61 *
62 * @see org.eclipse.jface.dialogs.IPageChangeProvider#addPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)
63 */
64 public void addPageChangedListener(IPageChangedListener listener) {
65 pageListeners.add(listener);
66 }
67
68 /*
69 * (non-Javadoc)
70 *
71 * @see org.eclipse.jface.dialogs.IPageChangeProvider#removePageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)
72 */
73 public void removePageChangedListener(IPageChangedListener listener) {
74 pageListeners.remove(listener);
75 }
76
77 private void firePageChanged(final PageChangedEvent event) {
78 Object[] listeners = pageListeners.getListeners();
79 for (int i = 0; i < listeners.length; ++i) {
80 final IPageChangedListener l = (IPageChangedListener) listeners[i];
81 SafeRunnable.run(new SafeRunnable() {
82 public void run() {
83 l.pageChanged(event);
84 }
85 });
86 }
87 }
88 // RAPEND [if]
89 }