001: /*******************************************************************************
002: * Copyright (c) 2005, 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.target;
011:
012: import org.eclipse.jface.action.IStatusLineManager;
013: import org.eclipse.pde.internal.ui.IHelpContextIds;
014: import org.eclipse.pde.internal.ui.PDEPlugin;
015: import org.eclipse.pde.internal.ui.PDEPluginImages;
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.PDEFormPage;
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.SWTException;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.ui.PlatformUI;
024: import org.eclipse.ui.forms.IManagedForm;
025: import org.eclipse.ui.forms.editor.FormEditor;
026: import org.eclipse.ui.forms.events.HyperlinkEvent;
027: import org.eclipse.ui.forms.events.IHyperlinkListener;
028: import org.eclipse.ui.forms.widgets.ExpandableComposite;
029: import org.eclipse.ui.forms.widgets.FormText;
030: import org.eclipse.ui.forms.widgets.FormToolkit;
031: import org.eclipse.ui.forms.widgets.ScrolledForm;
032: import org.eclipse.ui.forms.widgets.Section;
033: import org.eclipse.ui.forms.widgets.TableWrapData;
034:
035: public class OverviewPage extends PDEFormPage implements
036: IHyperlinkListener {
037:
038: public static final String PAGE_ID = "overview"; //$NON-NLS-1$
039:
040: public OverviewPage(FormEditor editor) {
041: super (editor, PAGE_ID, PDEUIMessages.OverviewPage_title);
042: }
043:
044: /* (non-Javadoc)
045: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
046: */
047: protected void createFormContent(IManagedForm managedForm) {
048: super .createFormContent(managedForm);
049: ScrolledForm form = managedForm.getForm();
050: FormToolkit toolkit = managedForm.getToolkit();
051: form.setText(PDEUIMessages.OverviewPage_title);
052: form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
053: PDEPluginImages.DESC_TARGET_DEFINITION));
054: fillBody(managedForm, toolkit);
055: PlatformUI.getWorkbench().getHelpSystem().setHelp(
056: form.getBody(), IHelpContextIds.TARGET_OVERVIEW_PAGE);
057: }
058:
059: private void fillBody(IManagedForm managedForm, FormToolkit toolkit) {
060: Composite body = managedForm.getForm().getBody();
061: body.setLayout(FormLayoutFactory.createFormGridLayout(true, 2));
062:
063: managedForm.addPart(new TargetDefinitionSection(this , body));
064: managedForm.addPart(new LocationsSection(this , body));
065: createContentsSection(body, toolkit);
066: createEnvironmentSection(body, toolkit);
067: }
068:
069: private void createContentsSection(Composite parent,
070: FormToolkit toolkit) {
071: Section section = createSection(parent, toolkit,
072: PDEUIMessages.OverviewPage_contentTitle);
073: createText(section,
074: PDEUIMessages.OverviewPage_contentDescription, toolkit);
075: }
076:
077: private void createEnvironmentSection(Composite parent,
078: FormToolkit toolkit) {
079: Section section = createSection(parent, toolkit,
080: PDEUIMessages.OverviewPage_environmentTitle);
081: createText(section,
082: PDEUIMessages.OverviewPage_environmentDescription,
083: toolkit);
084: }
085:
086: private Section createSection(Composite parent,
087: FormToolkit toolkit, String title) {
088: Section section = toolkit.createSection(parent,
089: ExpandableComposite.TITLE_BAR);
090: section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
091: section.setText(title);
092: section.setLayout(FormLayoutFactory.createClearTableWrapLayout(
093: false, 1));
094: section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
095: | GridData.VERTICAL_ALIGN_BEGINNING));
096: return section;
097: }
098:
099: private FormText createText(Section section, String content,
100: FormToolkit toolkit) {
101: Composite container = toolkit
102: .createComposite(section, SWT.NONE);
103: container.setLayout(FormLayoutFactory
104: .createSectionClientTableWrapLayout(false, 1));
105: section.setClient(container);
106: FormText text = toolkit.createFormText(container, true);
107: try {
108: text.setText(content, true, false);
109: } catch (SWTException e) {
110: text.setText(e.getMessage(), false, false);
111: }
112: TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
113: data.maxWidth = 250;
114: text.setLayoutData(data);
115: text.addHyperlinkListener(this );
116: return text;
117: }
118:
119: public void linkActivated(HyperlinkEvent e) {
120: String href = (String) e.getHref();
121: if (href.equals("content")) //$NON-NLS-1$
122: getEditor().setActivePage(ContentPage.PAGE_ID);
123: else if (href.equals("environment")) //$NON-NLS-1$
124: getEditor().setActivePage(EnvironmentPage.PAGE_ID);
125: }
126:
127: public void linkEntered(HyperlinkEvent e) {
128: IStatusLineManager mng = getEditor().getEditorSite()
129: .getActionBars().getStatusLineManager();
130: mng.setMessage(e.getLabel());
131: }
132:
133: public void linkExited(HyperlinkEvent e) {
134: IStatusLineManager mng = getEditor().getEditorSite()
135: .getActionBars().getStatusLineManager();
136: mng.setMessage(null);
137: }
138:
139: protected String getHelpResource() {
140: return "/org.eclipse.pde.doc.user/guide/tools/editors/target_definition_editor/overview.htm"; //$NON-NLS-1$
141: }
142:
143: }
|