KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > SchemaOverviewPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc PAGE_ID = "overview"; //$NON-NLS-1$
38

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     /* (non-Javadoc)
55      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
56      */

57     protected String JavaDoc getHelpResource() {
58         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/schema_editor/overview.htm"; //$NON-NLS-1$
59
}
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     /**
96      * @return
97      */

98     private ControlContribution createUIControlConPreviewRefDoc() {
99         return new ControlContribution("Preview") { //$NON-NLS-1$
100
protected Control createControl(Composite parent) {
101                 // Create UI
102
createUIImageHyperlinkPreviewRefDoc(parent);
103                 // Create Listener
104
createUIListenerImageHyperlinkPreviewRefDoc();
105                 return fImageHyperlinkPreviewRefDoc;
106             }
107         };
108     }
109
110     /**
111      * @param parent
112      */

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     /**
123      *
124      */

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     /**
140      * @param message
141      */

142     private void handleLinkEnteredPreviewRefDoc(String JavaDoc message) {
143         // Update colour
144
fImageHyperlinkPreviewRefDoc.setForeground(
145                 getManagedForm().getToolkit().getHyperlinkGroup().getActiveForeground());
146         // Update IDE status line
147
getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(message);
148     }
149     
150     /**
151      *
152      */

153     private void handleLinkExitedPreviewRefDoc() {
154         // Update colour
155
fImageHyperlinkPreviewRefDoc.setForeground(
156                 getManagedForm().getToolkit().getHyperlinkGroup().getForeground());
157         // Update IDE status line
158
getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(null);
159     }
160     
161     /**
162      *
163      */

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