1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 import org.eclipse.jface.action.ControlContribution; 13 import org.eclipse.pde.core.IModelChangedEvent; 14 import org.eclipse.pde.core.IModelChangedListener; 15 import org.eclipse.pde.internal.core.ischema.ISchema; 16 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 17 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor; 18 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 19 import org.eclipse.pde.internal.core.ischema.ISchemaObject; 20 import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference; 21 import org.eclipse.pde.internal.core.ischema.ISchemaRootElement; 22 import org.eclipse.pde.internal.ui.IHelpContextIds; 23 import org.eclipse.pde.internal.ui.IPDEUIConstants; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 26 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 27 import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock; 28 import org.eclipse.pde.internal.ui.editor.PDESection; 29 import org.eclipse.pde.internal.ui.editor.text.ColorManager; 30 import org.eclipse.pde.internal.ui.editor.text.IColorManager; 31 import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; 32 import org.eclipse.swt.SWT; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Control; 35 import org.eclipse.ui.PlatformUI; 36 import org.eclipse.ui.forms.DetailsPart; 37 import org.eclipse.ui.forms.IDetailsPage; 38 import org.eclipse.ui.forms.IDetailsPageProvider; 39 import org.eclipse.ui.forms.IManagedForm; 40 import org.eclipse.ui.forms.events.HyperlinkEvent; 41 import org.eclipse.ui.forms.events.IHyperlinkListener; 42 import org.eclipse.ui.forms.widgets.ImageHyperlink; 43 import org.eclipse.ui.forms.widgets.ScrolledForm; 44 45 public class SchemaFormPage extends PDEFormPage implements IModelChangedListener { 46 public static final String PAGE_ID = "form"; private ElementSection fSection; 48 private SchemaBlock fBlock; 49 private IColorManager fColorManager; 50 private DetailsPart fDetailsPart; 51 private ImageHyperlink fImageHyperlinkPreviewRefDoc; 52 private ShowDescriptionAction fPreviewAction; 53 54 public class SchemaBlock extends PDEMasterDetailsBlock implements IDetailsPageProvider { 55 56 public SchemaBlock() { 57 super(SchemaFormPage.this); 58 } 59 protected PDESection createMasterSection(IManagedForm managedForm, Composite parent) { 60 fSection = new ElementSection(getPage(), parent); 61 return fSection; 62 } 63 protected void registerPages(DetailsPart detailsPart) { 64 fDetailsPart = detailsPart; 65 detailsPart.setPageLimit(5); 66 detailsPart.registerPage(ISchemaObjectReference.class, new SchemaElementReferenceDetails(fSection)); 67 detailsPart.registerPage(ISchemaRootElement.class, new SchemaRootElementDetails(fSection)); 68 detailsPart.registerPage(ISchemaElement.class, new SchemaElementDetails(fSection)); 69 detailsPart.registerPage(ISchemaCompositor.class, new SchemaCompositorDetails(fSection)); 70 detailsPart.registerPage(ISchemaAttribute.class, new SchemaAttributeDetails(fSection)); 71 detailsPart.setPageProvider(this); 72 } 73 public Object getPageKey(Object object) { 74 if (object instanceof ISchemaObjectReference) 75 return ISchemaObjectReference.class; 76 else if (object instanceof ISchemaRootElement) 77 return ISchemaRootElement.class; 78 else if (object instanceof ISchemaElement) 79 return ISchemaElement.class; 80 else if (object instanceof ISchemaCompositor) 81 return ISchemaCompositor.class; 82 else if (object instanceof ISchemaAttribute) 83 return ISchemaAttribute.class; 84 else 85 return null; 86 } 87 88 public IDetailsPage getPage(Object object) { 89 return null; 90 } 91 } 92 93 public SchemaFormPage(PDEFormEditor editor) { 94 super(editor, PAGE_ID, PDEUIMessages.SchemaEditor_FormPage_title); 95 fBlock = new SchemaBlock(); 96 fColorManager = ColorManager.getDefault(); 97 } 98 99 102 protected String getHelpResource() { 103 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/schema_editor/definition.htm"; } 105 106 protected void createFormContent(IManagedForm managedForm) { 107 ScrolledForm form = managedForm.getForm(); 108 ISchema schema = (ISchema)((SchemaEditor)getEditor()).getAggregateModel(); 109 110 if (schema.isEditable()) { 111 form.getToolBarManager().add(createUIControlConPreviewRefDoc()); 112 form.getToolBarManager().update(true); 113 } 114 115 super.createFormContent(managedForm); 116 fBlock.createContent(managedForm); 117 DescriptionSection descSection = new DescriptionSection(this, form.getBody(), fColorManager); 118 managedForm.addPart(descSection); 119 PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.SCHEMA_EDITOR_MAIN); 120 initialize(); 121 } 122 123 126 private ControlContribution createUIControlConPreviewRefDoc() { 127 return new ControlContribution("Preview") { protected Control createControl(Composite parent) { 129 createUIImageHyperlinkPreviewRefDoc(parent); 131 createUIListenerImageHyperlinkPreviewRefDoc(); 133 return fImageHyperlinkPreviewRefDoc; 134 } 135 }; 136 } 137 138 141 private void createUIImageHyperlinkPreviewRefDoc(Composite parent) { 142 fImageHyperlinkPreviewRefDoc = new ImageHyperlink(parent, SWT.NONE); 143 fImageHyperlinkPreviewRefDoc.setText( 144 PDEUIMessages.SchemaEditor_previewLink); 145 fImageHyperlinkPreviewRefDoc.setUnderlined(true); 146 fImageHyperlinkPreviewRefDoc.setForeground( 147 getManagedForm().getToolkit().getHyperlinkGroup().getForeground()); 148 } 149 150 153 private void createUIListenerImageHyperlinkPreviewRefDoc() { 154 fImageHyperlinkPreviewRefDoc.addHyperlinkListener(new IHyperlinkListener() { 155 public void linkActivated(HyperlinkEvent e) { 156 handleLinkActivatedPreviewRefDoc(); 157 } 158 public void linkEntered(HyperlinkEvent e) { 159 handleLinkEnteredPreviewRefDoc(e.getLabel()); 160 } 161 public void linkExited(HyperlinkEvent e) { 162 handleLinkExitedPreviewRefDoc(); 163 } 164 }); 165 } 166 167 170 private void handleLinkEnteredPreviewRefDoc(String message) { 171 fImageHyperlinkPreviewRefDoc.setForeground( 173 getManagedForm().getToolkit().getHyperlinkGroup().getActiveForeground()); 174 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(message); 176 } 177 178 181 private void handleLinkExitedPreviewRefDoc() { 182 fImageHyperlinkPreviewRefDoc.setForeground( 184 getManagedForm().getToolkit().getHyperlinkGroup().getForeground()); 185 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(null); 187 } 188 189 192 private void handleLinkActivatedPreviewRefDoc() { 193 ISchema schema = (ISchema)((SchemaEditor)getEditor()).getAggregateModel(); 194 if(fPreviewAction == null) 195 { fPreviewAction = new ShowDescriptionAction(schema); 196 } 197 else 198 { fPreviewAction.setSchema(schema); 199 } 200 201 fPreviewAction.run(); 202 } 203 204 public void initialize() { 205 ISchema schema = (ISchema)getModel(); 206 getManagedForm().getForm().setText(schema.getName()); 207 schema.addModelChangedListener(this); 208 } 209 public void dispose() { 210 ISchema schema = (ISchema) getModel(); 211 if (schema != null) schema.removeModelChangedListener(this); 212 fColorManager.dispose(); 213 super.dispose(); 214 } 215 216 public void modelChanged(IModelChangedEvent event) { 217 if (event.getChangeType() == IModelChangedEvent.CHANGE) { 218 String changeProperty = event.getChangedProperty(); 219 if (changeProperty != null && changeProperty.equals(ISchemaObject.P_NAME)) { 220 Object [] change = event.getChangedObjects(); 221 if (change.length > 0 && change[0] instanceof ISchema) 222 getManagedForm().getForm().setText(((ISchema)change[0]).getName()); 223 } 224 } else if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { 225 handleModelEventWorldChanged(event); 226 } 227 if (fSection != null) { 229 fSection.handleModelChanged(event); 230 } 231 IDetailsPage page = fDetailsPart.getCurrentPage(); 233 if (page instanceof IModelChangedListener) { 234 ((IModelChangedListener)page).modelChanged(event); 235 } 236 } 237 238 241 private void handleModelEventWorldChanged(IModelChangedEvent event) { 242 ISchema schema = (ISchema)getModel(); 245 getManagedForm().getForm().setText(schema.getName()); 246 } 247 } 248 | Popular Tags |