001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.schema;
011:
012: import org.eclipse.jface.action.ControlContribution;
013: import org.eclipse.pde.internal.core.ischema.ISchema;
014: import org.eclipse.pde.internal.ui.IHelpContextIds;
015: import org.eclipse.pde.internal.ui.IPDEUIConstants;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
018: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
019: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
020: import org.eclipse.pde.internal.ui.editor.text.ColorManager;
021: import org.eclipse.pde.internal.ui.editor.text.IColorManager;
022: import org.eclipse.pde.internal.ui.search.ShowDescriptionAction;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Control;
027: import org.eclipse.ui.PlatformUI;
028: import org.eclipse.ui.forms.IManagedForm;
029: import org.eclipse.ui.forms.events.HyperlinkEvent;
030: import org.eclipse.ui.forms.events.IHyperlinkListener;
031: import org.eclipse.ui.forms.widgets.ImageHyperlink;
032: import org.eclipse.ui.forms.widgets.ScrolledForm;
033:
034: public class SchemaOverviewPage extends PDEFormPage {
035:
036: public static final String PAGE_ID = "overview"; //$NON-NLS-1$
037:
038: private IColorManager fColorManager = ColorManager.getDefault();
039:
040: private ImageHyperlink fImageHyperlinkPreviewRefDoc;
041:
042: private DocSection fDocSection;
043:
044: private SchemaSpecSection fGeneralInfoSection;
045: private SchemaIncludesSection fInclusionSection;
046:
047: private ShowDescriptionAction fPreviewAction;
048:
049: public SchemaOverviewPage(PDEFormEditor editor) {
050: super (editor, PAGE_ID, PDEUIMessages.SchemaEditor_DocPage_title);
051: }
052:
053: /* (non-Javadoc)
054: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
055: */
056: protected String getHelpResource() {
057: return IPDEUIConstants.PLUGIN_DOC_ROOT
058: + "guide/tools/editors/schema_editor/overview.htm"; //$NON-NLS-1$
059: }
060:
061: public void setActive(boolean active) {
062: if (!active)
063: getManagedForm().commit(false);
064: super .setActive(active);
065: }
066:
067: protected void createFormContent(IManagedForm managedForm) {
068: ScrolledForm form = managedForm.getForm();
069: ISchema schema = (ISchema) ((SchemaEditor) getEditor())
070: .getAggregateModel();
071:
072: if (schema.isEditable()) {
073: form.getToolBarManager().add(
074: createUIControlConPreviewRefDoc());
075: form.getToolBarManager().update(true);
076: }
077:
078: super .createFormContent(managedForm);
079:
080: form.getBody().setLayout(
081: FormLayoutFactory.createFormGridLayout(false, 1));
082:
083: Composite top = managedForm.getToolkit().createComposite(
084: form.getBody());
085: top.setLayout(FormLayoutFactory.createFormPaneGridLayout(true,
086: 2));
087: top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
088:
089: fGeneralInfoSection = new SchemaSpecSection(this , top);
090: fInclusionSection = new SchemaIncludesSection(this , top);
091: fDocSection = new DocSection(this , form.getBody(),
092: fColorManager);
093:
094: managedForm.addPart(fGeneralInfoSection);
095: managedForm.addPart(fInclusionSection);
096: managedForm.addPart(fDocSection);
097:
098: PlatformUI.getWorkbench().getHelpSystem().setHelp(
099: form.getBody(), IHelpContextIds.SCHEMA_EDITOR_DOC);
100: }
101:
102: /**
103: * @return
104: */
105: private ControlContribution createUIControlConPreviewRefDoc() {
106: return new ControlContribution("Preview") { //$NON-NLS-1$
107: protected Control createControl(Composite parent) {
108: // Create UI
109: createUIImageHyperlinkPreviewRefDoc(parent);
110: // Create Listener
111: createUIListenerImageHyperlinkPreviewRefDoc();
112: return fImageHyperlinkPreviewRefDoc;
113: }
114: };
115: }
116:
117: /**
118: * @param parent
119: */
120: private void createUIImageHyperlinkPreviewRefDoc(Composite parent) {
121: fImageHyperlinkPreviewRefDoc = new ImageHyperlink(parent,
122: SWT.NONE);
123: fImageHyperlinkPreviewRefDoc
124: .setText(PDEUIMessages.SchemaEditor_previewLink);
125: fImageHyperlinkPreviewRefDoc.setUnderlined(true);
126: fImageHyperlinkPreviewRefDoc.setForeground(getManagedForm()
127: .getToolkit().getHyperlinkGroup().getForeground());
128: }
129:
130: /**
131: *
132: */
133: private void createUIListenerImageHyperlinkPreviewRefDoc() {
134: fImageHyperlinkPreviewRefDoc
135: .addHyperlinkListener(new IHyperlinkListener() {
136: public void linkActivated(HyperlinkEvent e) {
137: handleLinkActivatedPreviewRefDoc();
138: }
139:
140: public void linkEntered(HyperlinkEvent e) {
141: handleLinkEnteredPreviewRefDoc(e.getLabel());
142: }
143:
144: public void linkExited(HyperlinkEvent e) {
145: handleLinkExitedPreviewRefDoc();
146: }
147: });
148: }
149:
150: /**
151: * @param message
152: */
153: private void handleLinkEnteredPreviewRefDoc(String message) {
154: // Update colour
155: fImageHyperlinkPreviewRefDoc
156: .setForeground(getManagedForm().getToolkit()
157: .getHyperlinkGroup().getActiveForeground());
158: // Update IDE status line
159: getEditor().getEditorSite().getActionBars()
160: .getStatusLineManager().setMessage(message);
161: }
162:
163: /**
164: *
165: */
166: private void handleLinkExitedPreviewRefDoc() {
167: // Update colour
168: fImageHyperlinkPreviewRefDoc.setForeground(getManagedForm()
169: .getToolkit().getHyperlinkGroup().getForeground());
170: // Update IDE status line
171: getEditor().getEditorSite().getActionBars()
172: .getStatusLineManager().setMessage(null);
173: }
174:
175: /**
176: *
177: */
178: private void handleLinkActivatedPreviewRefDoc() {
179: ISchema schema = (ISchema) ((SchemaEditor) getEditor())
180: .getAggregateModel();
181: if (fPreviewAction == null) {
182: fPreviewAction = new ShowDescriptionAction(schema);
183: } else {
184: fPreviewAction.setSchema(schema);
185: }
186:
187: fPreviewAction.run();
188: }
189:
190: public void dispose() {
191: fColorManager.dispose();
192: super.dispose();
193: }
194:
195: }
|