1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 13 import org.eclipse.jface.action.ControlContribution; 14 import org.eclipse.pde.internal.core.ischema.ISchema; 15 import org.eclipse.pde.internal.ui.IHelpContextIds; 16 import org.eclipse.pde.internal.ui.IPDEUIConstants; 17 import org.eclipse.pde.internal.ui.PDEUIMessages; 18 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 19 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 20 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 21 import org.eclipse.pde.internal.ui.editor.text.ColorManager; 22 import org.eclipse.pde.internal.ui.editor.text.IColorManager; 23 import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.ui.PlatformUI; 29 import org.eclipse.ui.forms.IManagedForm; 30 import org.eclipse.ui.forms.events.HyperlinkEvent; 31 import org.eclipse.ui.forms.events.IHyperlinkListener; 32 import org.eclipse.ui.forms.widgets.ImageHyperlink; 33 import org.eclipse.ui.forms.widgets.ScrolledForm; 34 35 public class SchemaOverviewPage extends PDEFormPage { 36 37 public static final String PAGE_ID = "overview"; 39 private IColorManager fColorManager = ColorManager.getDefault(); 40 41 private ImageHyperlink fImageHyperlinkPreviewRefDoc; 42 43 private DocSection fDocSection; 44 45 private SchemaSpecSection fGeneralInfoSection; 46 private SchemaIncludesSection fInclusionSection; 47 48 private ShowDescriptionAction fPreviewAction; 49 50 public SchemaOverviewPage(PDEFormEditor editor) { 51 super(editor, PAGE_ID, PDEUIMessages.SchemaEditor_DocPage_title); 52 } 53 54 57 protected String getHelpResource() { 58 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/schema_editor/overview.htm"; } 60 61 public void setActive(boolean active) { 62 if (!active) 63 getManagedForm().commit(false); 64 super.setActive(active); 65 } 66 67 protected void createFormContent(IManagedForm managedForm) { 68 ScrolledForm form = managedForm.getForm(); 69 ISchema schema = (ISchema)((SchemaEditor)getEditor()).getAggregateModel(); 70 71 if (schema.isEditable()) { 72 form.getToolBarManager().add(createUIControlConPreviewRefDoc()); 73 form.getToolBarManager().update(true); 74 } 75 76 super.createFormContent(managedForm); 77 78 form.getBody().setLayout(FormLayoutFactory.createFormGridLayout(false, 1)); 79 80 Composite top = managedForm.getToolkit().createComposite(form.getBody()); 81 top.setLayout(FormLayoutFactory.createFormPaneGridLayout(true, 2)); 82 top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 83 84 fGeneralInfoSection = new SchemaSpecSection(this, top); 85 fInclusionSection = new SchemaIncludesSection(this, top); 86 fDocSection = new DocSection(this, form.getBody(), fColorManager); 87 88 managedForm.addPart(fGeneralInfoSection); 89 managedForm.addPart(fInclusionSection); 90 managedForm.addPart(fDocSection); 91 92 PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.SCHEMA_EDITOR_DOC); 93 } 94 95 98 private ControlContribution createUIControlConPreviewRefDoc() { 99 return new ControlContribution("Preview") { protected Control createControl(Composite parent) { 101 createUIImageHyperlinkPreviewRefDoc(parent); 103 createUIListenerImageHyperlinkPreviewRefDoc(); 105 return fImageHyperlinkPreviewRefDoc; 106 } 107 }; 108 } 109 110 113 private void createUIImageHyperlinkPreviewRefDoc(Composite parent) { 114 fImageHyperlinkPreviewRefDoc = new ImageHyperlink(parent, SWT.NONE); 115 fImageHyperlinkPreviewRefDoc.setText( 116 PDEUIMessages.SchemaEditor_previewLink); 117 fImageHyperlinkPreviewRefDoc.setUnderlined(true); 118 fImageHyperlinkPreviewRefDoc.setForeground( 119 getManagedForm().getToolkit().getHyperlinkGroup().getForeground()); 120 } 121 122 125 private void createUIListenerImageHyperlinkPreviewRefDoc() { 126 fImageHyperlinkPreviewRefDoc.addHyperlinkListener(new IHyperlinkListener() { 127 public void linkActivated(HyperlinkEvent e) { 128 handleLinkActivatedPreviewRefDoc(); 129 } 130 public void linkEntered(HyperlinkEvent e) { 131 handleLinkEnteredPreviewRefDoc(e.getLabel()); 132 } 133 public void linkExited(HyperlinkEvent e) { 134 handleLinkExitedPreviewRefDoc(); 135 } 136 }); 137 } 138 139 142 private void handleLinkEnteredPreviewRefDoc(String message) { 143 fImageHyperlinkPreviewRefDoc.setForeground( 145 getManagedForm().getToolkit().getHyperlinkGroup().getActiveForeground()); 146 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(message); 148 } 149 150 153 private void handleLinkExitedPreviewRefDoc() { 154 fImageHyperlinkPreviewRefDoc.setForeground( 156 getManagedForm().getToolkit().getHyperlinkGroup().getForeground()); 157 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(null); 159 } 160 161 164 private void handleLinkActivatedPreviewRefDoc() { 165 ISchema schema = (ISchema)((SchemaEditor)getEditor()).getAggregateModel(); 166 if(fPreviewAction == null) 167 { fPreviewAction = new ShowDescriptionAction(schema); 168 } 169 else 170 { fPreviewAction.setSchema(schema); 171 } 172 173 fPreviewAction.run(); 174 } 175 176 public void dispose() { 177 fColorManager.dispose(); 178 super.dispose(); 179 } 180 181 } 182 | Popular Tags |