001: /*******************************************************************************
002: * Copyright (c) 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;
011:
012: import org.eclipse.core.runtime.IConfigurationElement;
013: import org.eclipse.jface.action.IStatusLineManager;
014: import org.eclipse.osgi.util.NLS;
015: import org.eclipse.swt.SWTException;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.ui.forms.events.HyperlinkEvent;
018: import org.eclipse.ui.forms.events.IHyperlinkListener;
019: import org.eclipse.ui.forms.widgets.ExpandableComposite;
020: import org.eclipse.ui.forms.widgets.FormText;
021: import org.eclipse.ui.forms.widgets.FormToolkit;
022: import org.eclipse.ui.forms.widgets.Section;
023: import org.eclipse.ui.forms.widgets.TableWrapData;
024:
025: public abstract class LaunchShortcutOverviewPage extends PDEFormPage
026: implements IHyperlinkListener {
027:
028: public LaunchShortcutOverviewPage(PDELauncherFormEditor editor,
029: String id, String title) {
030: super (editor, id, title);
031: }
032:
033: protected final Section createStaticSection(FormToolkit toolkit,
034: Composite parent, String text) {
035: Section section = toolkit.createSection(parent,
036: ExpandableComposite.TITLE_BAR);
037: section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
038: section.setText(text);
039: section.setLayout(FormLayoutFactory.createClearTableWrapLayout(
040: false, 1));
041: TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
042: section.setLayoutData(data);
043: return section;
044: }
045:
046: protected final FormText createClient(Composite section,
047: String content, FormToolkit toolkit) {
048: FormText text = toolkit.createFormText(section, true);
049: try {
050: text.setText(content, true, false);
051: } catch (SWTException e) {
052: text.setText(e.getMessage(), false, false);
053: }
054: text.addHyperlinkListener(this );
055: return text;
056: }
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see org.eclipse.ui.forms.events.HyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent)
062: */
063: public void linkActivated(HyperlinkEvent e) {
064: String href = (String) e.getHref();
065: getPDELauncherEditor().launch(
066: href,
067: getPDELauncherEditor().getPreLaunchRunnable(),
068: getPDELauncherEditor().getLauncherHelper()
069: .getLaunchObject());
070: }
071:
072: // returns the indent for each launcher
073: protected abstract short getIndent();
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.eclipse.ui.forms.events.HyperlinkListener#linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent)
079: */
080: public void linkEntered(HyperlinkEvent e) {
081: IStatusLineManager mng = getEditor().getEditorSite()
082: .getActionBars().getStatusLineManager();
083: mng.setMessage(e.getLabel());
084: }
085:
086: /*
087: * (non-Javadoc)
088: *
089: * @see org.eclipse.ui.forms.events.HyperlinkListener#linkExited(org.eclipse.ui.forms.events.HyperlinkEvent)
090: */
091: public void linkExited(HyperlinkEvent e) {
092: IStatusLineManager mng = getEditor().getEditorSite()
093: .getActionBars().getStatusLineManager();
094: mng.setMessage(null);
095: }
096:
097: protected final String getLauncherText(boolean osgi, String message) {
098: IConfigurationElement[][] elements = getPDELauncherEditor()
099: .getLaunchers(osgi);
100:
101: StringBuffer buffer = new StringBuffer();
102: String indent = Short.toString(getIndent());
103:
104: for (int i = 0; i < elements.length; i++) {
105: for (int j = 0; j < elements[i].length; j++) {
106: String mode = elements[i][j].getAttribute("mode"); //$NON-NLS-1$
107: buffer.append("<li style=\"image\" value=\""); //$NON-NLS-1$
108: buffer.append(mode);
109: buffer
110: .append("\" bindent=\"" + indent + "\"><a href=\"launchShortcut."); //$NON-NLS-1$ //$NON-NLS-2$
111: buffer.append(mode);
112: buffer.append('.');
113: buffer.append(elements[i][j].getAttribute("id")); //$NON-NLS-1$
114: buffer.append("\">"); //$NON-NLS-1$
115: buffer.append(elements[i][j].getAttribute("label")); //$NON-NLS-1$
116: buffer.append("</a></li>"); //$NON-NLS-1$
117: }
118: }
119: return NLS.bind(message, buffer.toString());
120: }
121:
122: protected PDELauncherFormEditor getPDELauncherEditor() {
123: return (PDELauncherFormEditor) getPDEEditor();
124: }
125: }
|