KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > target > OverviewPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.target;
12
13 import org.eclipse.jface.action.IStatusLineManager;
14 import org.eclipse.pde.internal.ui.IHelpContextIds;
15 import org.eclipse.pde.internal.ui.PDEPlugin;
16 import org.eclipse.pde.internal.ui.PDEPluginImages;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.SWTException;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.forms.IManagedForm;
24 import org.eclipse.ui.forms.editor.FormEditor;
25 import org.eclipse.ui.forms.events.HyperlinkEvent;
26 import org.eclipse.ui.forms.events.IHyperlinkListener;
27 import org.eclipse.ui.forms.widgets.ExpandableComposite;
28 import org.eclipse.ui.forms.widgets.FormText;
29 import org.eclipse.ui.forms.widgets.FormToolkit;
30 import org.eclipse.ui.forms.widgets.ScrolledForm;
31 import org.eclipse.ui.forms.widgets.Section;
32 import org.eclipse.ui.forms.widgets.TableWrapData;
33
34
35 public class OverviewPage extends AbstractTargetPage implements IHyperlinkListener {
36     
37     public static final String JavaDoc PAGE_ID = "overview"; //$NON-NLS-1$
38

39     public OverviewPage(FormEditor editor) {
40         super(editor, PAGE_ID, PDEUIMessages.OverviewPage_title);
41     }
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
45      */

46     protected void createFormContent(IManagedForm managedForm) {
47         super.createFormContent(managedForm);
48         ScrolledForm form = managedForm.getForm();
49         FormToolkit toolkit = managedForm.getToolkit();
50         form.setText(PDEUIMessages.OverviewPage_title);
51         form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_TARGET_DEFINITION));
52         fillBody(managedForm, toolkit);
53         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE );
54     }
55
56     private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
57         Composite body = managedForm.getForm().getBody();
58         body.setLayout(FormLayoutFactory.createFormTableWrapLayout(true, 2));
59         
60         managedForm.addPart(new TargetDefinitionSection(this, body));
61         managedForm.addPart(new LocationsSection(this, body));
62         createContentsSection(body, toolkit);
63         createEnvironmentSection(body, toolkit);
64     }
65     
66     private void createContentsSection(Composite parent, FormToolkit toolkit) {
67         Section section = createSection(parent, toolkit, PDEUIMessages.OverviewPage_contentTitle);
68         createText(section, PDEUIMessages.OverviewPage_contentDescription, toolkit);
69     }
70     
71     private void createEnvironmentSection(Composite parent, FormToolkit toolkit) {
72         Section section = createSection(parent, toolkit, PDEUIMessages.OverviewPage_environmentTitle);
73         createText(section, PDEUIMessages.OverviewPage_environmentDescription, toolkit);
74     }
75     
76     private Section createSection(Composite parent, FormToolkit toolkit, String JavaDoc title) {
77         Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
78         section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
79         section.setText(title);
80         section.setLayout(FormLayoutFactory.createClearTableWrapLayout(false, 1));
81         section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
82         return section;
83     }
84     
85     private FormText createText(Section section, String JavaDoc content, FormToolkit toolkit) {
86         Composite container = toolkit.createComposite(section, SWT.NONE);
87         container.setLayout(FormLayoutFactory.createSectionClientTableWrapLayout(false, 1));
88         section.setClient(container);
89         FormText text = toolkit.createFormText(container, true);
90         try {
91             text.setText(content, true, false);
92         } catch (SWTException e) {
93             text.setText(e.getMessage(), false, false);
94         }
95         text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
96         text.addHyperlinkListener(this);
97         return text;
98     }
99
100     public void linkActivated(HyperlinkEvent e) {
101         String JavaDoc href = (String JavaDoc) e.getHref();
102         if (href.equals("content")) //$NON-NLS-1$
103
getEditor().setActivePage(ContentPage.PAGE_ID);
104         else if (href.equals("environment")) //$NON-NLS-1$
105
getEditor().setActivePage(EnvironmentPage.PAGE_ID);
106     }
107
108     public void linkEntered(HyperlinkEvent e) {
109         IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
110         mng.setMessage(e.getLabel());
111     }
112
113     public void linkExited(HyperlinkEvent e) {
114         IStatusLineManager mng = getEditor().getEditorSite().getActionBars().getStatusLineManager();
115         mng.setMessage(null);
116     }
117
118     protected String JavaDoc getHelpResource() {
119         return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/overview.htm"; //$NON-NLS-1$
120
}
121
122 }
123
Popular Tags