1 11 package org.eclipse.ui.forms.editor; 12 import org.eclipse.core.runtime.IProgressMonitor; 13 import org.eclipse.swt.custom.BusyIndicator; 14 import org.eclipse.swt.graphics.Image; 15 import org.eclipse.swt.widgets.*; 16 import org.eclipse.ui.*; 17 import org.eclipse.ui.forms.*; 18 import org.eclipse.ui.forms.widgets.ScrolledForm; 19 import org.eclipse.ui.part.EditorPart; 20 32 public class FormPage extends EditorPart implements IFormPage { 33 private FormEditor editor; 34 private PageForm mform; 35 private int index; 36 private String id; 37 38 private static class PageForm extends ManagedForm { 39 public PageForm(FormPage page, ScrolledForm form) { 40 super(page.getEditor().getToolkit(), form); 41 setContainer(page); 42 } 43 44 public FormPage getPage() { 45 return (FormPage)getContainer(); 46 } 47 public void dirtyStateChanged() { 48 getPage().getEditor().editorDirtyStateChanged(); 49 } 50 public void staleStateChanged() { 51 if (getPage().isActive()) 52 refresh(); 53 } 54 } 55 65 public FormPage(FormEditor editor, String id, String title) { 66 this(id, title); 67 initialize(editor); 68 } 69 78 public FormPage(String id, String title) { 79 this.id = id; 80 setPartName(title); 81 } 82 87 public void init(IEditorSite site, IEditorInput input) { 88 setSite(site); 89 setInput(input); 90 } 91 97 public void initialize(FormEditor editor) { 98 this.editor = editor; 99 } 100 105 public FormEditor getEditor() { 106 return editor; 107 } 108 113 public IManagedForm getManagedForm() { 114 return mform; 115 } 116 120 public void setActive(boolean active) { 121 if (active) { 122 mform.refresh(); 125 } 126 } 127 134 public boolean isActive() { 135 return this.equals(editor.getActivePageInstance()); 136 } 137 146 public void createPartControl(Composite parent) { 147 ScrolledForm form = editor.getToolkit().createScrolledForm(parent); 148 mform = new PageForm(this, form); 149 BusyIndicator.showWhile(parent.getDisplay(), new Runnable () { 150 public void run() { 151 createFormContent(mform); 152 } 153 }); 154 } 155 162 protected void createFormContent(IManagedForm managedForm) { 163 } 164 169 public Control getPartControl() { 170 return mform != null ? mform.getForm() : null; 171 } 172 175 public void dispose() { 176 if (mform != null) 177 mform.dispose(); 178 } 179 184 public String getId() { 185 return id; 186 } 187 193 public Image getTitleImage() { 194 return null; 195 } 196 199 public void setFocus() { 200 if (mform != null) 201 mform.setFocus(); 202 } 203 206 public void doSave(IProgressMonitor monitor) { 207 if (mform != null) 208 mform.commit(true); 209 } 210 213 public void doSaveAs() { 214 } 215 218 public boolean isSaveAsAllowed() { 219 return false; 220 } 221 229 public boolean isDirty() { 230 return mform != null ? mform.isDirty() : false; 231 } 232 238 public void setIndex(int index) { 239 this.index = index; 240 } 241 246 public int getIndex() { 247 return index; 248 } 249 254 public boolean isEditor() { 255 return false; 256 } 257 267 public boolean selectReveal(Object object) { 268 if (mform != null) 269 return mform.setInput(object); 270 return false; 271 } 272 276 public boolean canLeaveThePage() { 277 return true; 278 } 279 } 280 | Popular Tags |