1 package org.argeo.cms.ui.eclipse.forms; 2 /** 3 * AbstractFormPart implements IFormPart interface and can be used as a 4 * convenient base class for concrete form parts. If a method contains 5 * code that must be called, look for instructions to call 'super' 6 * when overriding. 7 * 8 * @see org.eclipse.ui.forms.widgets.Section 9 * @since 1.0 10 */ 11 public abstract class AbstractFormPart implements IFormPart { 12 private IManagedForm managedForm; 13 private boolean dirty = false; 14 private boolean stale = true; 15 /** 16 * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm) 17 */ 18 public void initialize(IManagedForm form) { 19 this.managedForm = form; 20 } 21 /** 22 * Returns the form that manages this part. 23 * 24 * @return the managed form 25 */ 26 public IManagedForm getManagedForm() { 27 return managedForm; 28 } 29 /** 30 * Disposes the part. Subclasses should override to release any system 31 * resources. 32 */ 33 public void dispose() { 34 } 35 /** 36 * Commits the part. Subclasses should call 'super' when overriding. 37 * 38 * @param onSave 39 * <code>true</code> if the request to commit has arrived as a 40 * result of the 'save' action. 41 */ 42 public void commit(boolean onSave) { 43 dirty = false; 44 } 45 /** 46 * Sets the overall form input. Subclases may elect to override the method 47 * and adjust according to the form input. 48 * 49 * @param input 50 * the form input object 51 * @return <code>false</code> 52 */ 53 public boolean setFormInput(Object input) { 54 return false; 55 } 56 /** 57 * Instructs the part to grab keyboard focus. 58 */ 59 public void setFocus() { 60 } 61 /** 62 * Refreshes the section after becoming stale (falling behind data in the 63 * model). Subclasses must call 'super' when overriding this method. 64 */ 65 public void refresh() { 66 stale = false; 67 // since we have refreshed, any changes we had in the 68 // part are gone and we are not dirty 69 dirty = false; 70 } 71 /** 72 * Marks the part dirty. Subclasses should call this method as a result of 73 * user interaction with the widgets in the section. 74 */ 75 public void markDirty() { 76 dirty = true; 77 managedForm.dirtyStateChanged(); 78 } 79 /** 80 * Tests whether the part is dirty i.e. its widgets have state that is 81 * newer than the data in the model. 82 * 83 * @return <code>true</code> if the part is dirty, <code>false</code> 84 * otherwise. 85 */ 86 public boolean isDirty() { 87 return dirty; 88 } 89 /** 90 * Tests whether the part is stale i.e. its widgets have state that is 91 * older than the data in the model. 92 * 93 * @return <code>true</code> if the part is stale, <code>false</code> 94 * otherwise. 95 */ 96 public boolean isStale() { 97 return stale; 98 } 99 /** 100 * Marks the part stale. Subclasses should call this method as a result of 101 * model notification that indicates that the content of the section is no 102 * longer in sync with the model. 103 */ 104 public void markStale() { 105 stale = true; 106 managedForm.staleStateChanged(); 107 } 108 }