]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/eclipse/forms/ManagedForm.java
19e8211e6220e4beab1666c7d38682dd10fb7d38
1 package org
.argeo
.cms
.ui
.eclipse
.forms
;
3 import java
.util
.Vector
;
4 import org
.eclipse
.jface
.viewers
.ISelection
;
5 import org
.eclipse
.swt
.custom
.ScrolledComposite
;
6 import org
.eclipse
.swt
.widgets
.Composite
;
7 //import org.eclipse.ui.forms.widgets.FormToolkit;
8 //import org.eclipse.ui.forms.widgets.ScrolledForm;
11 * Managed form wraps a form widget and adds life cycle methods for form parts.
12 * A form part is a portion of the form that participates in form life cycle
15 * There is requirement for 1/1 mapping between widgets and form parts. A widget
16 * like Section can be a part by itself, but a number of widgets can join around
19 * Note to developers: this class is left public to allow its use beyond the
20 * original intention (inside a multi-page editor's page). You should limit the
21 * use of this class to make new instances inside a form container (wizard page,
22 * dialog etc.). Clients that need access to the class should not do it
23 * directly. Instead, they should do it through IManagedForm interface as much
28 public class ManagedForm
implements IManagedForm
{
31 private ScrolledComposite form
;
33 private FormToolkit toolkit
;
35 private Object container
;
37 private boolean ownsToolkit
;
39 private boolean initialized
;
41 private Vector parts
= new Vector();
44 * Creates a managed form in the provided parent. Form toolkit and widget
45 * will be created and owned by this object.
50 public ManagedForm(Composite parent
) {
51 toolkit
= new FormToolkit(parent
.getDisplay());
53 form
= toolkit
.createScrolledForm(parent
);
57 * Creates a managed form that will use the provided toolkit and
62 public ManagedForm(FormToolkit toolkit
, ScrolledComposite form
) {
64 this.toolkit
= toolkit
;
70 * @see org.eclipse.ui.forms.IManagedForm#addPart(org.eclipse.ui.forms.IFormPart)
72 public void addPart(IFormPart part
) {
74 part
.initialize(this);
80 * @see org.eclipse.ui.forms.IManagedForm#removePart(org.eclipse.ui.forms.IFormPart)
82 public void removePart(IFormPart part
) {
89 * @see org.eclipse.ui.forms.IManagedForm#getParts()
91 public IFormPart
[] getParts() {
92 return (IFormPart
[]) parts
.toArray(new IFormPart
[parts
.size()]);
98 * @see org.eclipse.ui.forms.IManagedForm#getToolkit()
100 public FormToolkit
getToolkit() {
107 * @see org.eclipse.ui.forms.IManagedForm#getForm()
109 public ScrolledComposite
getForm() {
116 * @see org.eclipse.ui.forms.IManagedForm#reflow(boolean)
118 public void reflow(boolean changed
) {
119 // form.reflow(changed);
123 * A part can use this method to notify other parts that implement
124 * IPartSelectionListener about selection changes.
127 * the part that broadcasts the selection
129 * the selection in the part
130 * @see IPartSelectionListener
132 public void fireSelectionChanged(IFormPart part
, ISelection selection
) {
133 for (int i
= 0; i
< parts
.size(); i
++) {
134 IFormPart cpart
= (IFormPart
) parts
.get(i
);
135 if (part
.equals(cpart
))
137 // if (cpart instanceof IPartSelectionListener) {
138 // ((IPartSelectionListener) cpart).selectionChanged(part,
145 * Initializes the form by looping through the managed parts and
146 * initializing them. Has no effect if already called once.
148 public void initialize() {
151 for (int i
= 0; i
< parts
.size(); i
++) {
152 IFormPart part
= (IFormPart
) parts
.get(i
);
153 part
.initialize(this);
159 * Disposes all the parts in this form.
161 public void dispose() {
162 for (int i
= 0; i
< parts
.size(); i
++) {
163 IFormPart part
= (IFormPart
) parts
.get(i
);
172 * Refreshes the form by refreshes all the stale parts. Since 3.1, this
173 * method is performed on a UI thread when called from another thread so it
174 * is not needed to wrap the call in <code>Display.syncExec</code> or
175 * <code>asyncExec</code>.
177 public void refresh() {
178 Thread t
= Thread
.currentThread();
179 Thread dt
= toolkit
.getColors().getDisplay().getThread();
183 toolkit
.getColors().getDisplay().asyncExec(new Runnable() {
191 private void doRefresh() {
193 for (int i
= 0; i
< parts
.size(); i
++) {
194 IFormPart part
= (IFormPart
) parts
.get(i
);
195 if (part
.isStale()) {
200 // if (nrefreshed > 0)
201 // form.reflow(true);
207 * @see org.eclipse.ui.forms.IManagedForm#commit(boolean)
209 public void commit(boolean onSave
) {
210 for (int i
= 0; i
< parts
.size(); i
++) {
211 IFormPart part
= (IFormPart
) parts
.get(i
);
220 * @see org.eclipse.ui.forms.IManagedForm#setInput(java.lang.Object)
222 public boolean setInput(Object input
) {
223 boolean pageResult
= false;
226 for (int i
= 0; i
< parts
.size(); i
++) {
227 IFormPart part
= (IFormPart
) parts
.get(i
);
228 boolean result
= part
.setFormInput(input
);
238 * @see org.eclipse.ui.forms.IManagedForm#getInput()
240 public Object
getInput() {
245 * Transfers the focus to the first form part.
247 public void setFocus() {
248 if (parts
.size() > 0) {
249 IFormPart part
= (IFormPart
) parts
.get(0);
257 * @see org.eclipse.ui.forms.IManagedForm#isDirty()
259 public boolean isDirty() {
260 for (int i
= 0; i
< parts
.size(); i
++) {
261 IFormPart part
= (IFormPart
) parts
.get(i
);
271 * @see org.eclipse.ui.forms.IManagedForm#isStale()
273 public boolean isStale() {
274 for (int i
= 0; i
< parts
.size(); i
++) {
275 IFormPart part
= (IFormPart
) parts
.get(i
);
285 * @see org.eclipse.ui.forms.IManagedForm#dirtyStateChanged()
287 public void dirtyStateChanged() {
293 * @see org.eclipse.ui.forms.IManagedForm#staleStateChanged()
295 public void staleStateChanged() {
301 * @see org.eclipse.ui.forms.IManagedForm#getContainer()
303 public Object
getContainer() {
310 * @see org.eclipse.ui.forms.IManagedForm#setContainer(java.lang.Object)
312 public void setContainer(Object container
) {
313 this.container
= container
;
317 * @see org.eclipse.ui.forms.IManagedForm#getMessageManager()
319 // public IMessageManager getMessageManager() {
320 // return form.getMessageManager();