1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.eclipse.org/org/documents/epl-v10.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.ide.eclipse.adt.internal.editors.export;
18
19import com.android.ide.eclipse.adt.AdtPlugin;
20import com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper.ManifestSectionPart;
21
22import org.eclipse.jface.text.DocumentEvent;
23import org.eclipse.swt.SWT;
24import org.eclipse.swt.graphics.Image;
25import org.eclipse.swt.widgets.Composite;
26import org.eclipse.swt.widgets.MessageBox;
27import org.eclipse.ui.forms.events.HyperlinkEvent;
28import org.eclipse.ui.forms.events.IHyperlinkListener;
29import org.eclipse.ui.forms.widgets.FormText;
30import org.eclipse.ui.forms.widgets.FormToolkit;
31import org.eclipse.ui.forms.widgets.Section;
32
33/**
34 * Links section part for export properties page.
35 * Displays some help and some links/actions for the user to use.
36 */
37final class ExportLinksPart extends ManifestSectionPart {
38
39    private FormText mFormText;
40
41    public ExportLinksPart(Composite body, FormToolkit toolkit, ExportEditor editor) {
42        super(body, toolkit, Section.TWISTIE | Section.EXPANDED, true /* description */);
43        Section section = getSection();
44        section.setText("Links");
45        section.setDescription("TODO SOME TEXT HERE. You can also edit the XML directly.");
46
47        final Composite table = createTableLayout(toolkit, 2 /* numColumns */);
48
49        StringBuffer buf = new StringBuffer();
50        buf.append("<form>"); //$NON-NLS-1$
51
52        buf.append("<li style=\"image\" value=\"android_img\"><a href=\"action_dosomething\">");
53        buf.append("TODO Custom Action");
54        buf.append("</a>"); //$NON-NLS-1$
55        buf.append(": blah blah do something (like build/export).");
56        buf.append("</li>"); //$NON-NLS-1$
57
58        buf.append(String.format("<li style=\"image\" value=\"android_img\"><a href=\"page:%1$s\">", //$NON-NLS-1$
59                ExportEditor.TEXT_EDITOR_ID));
60        buf.append("XML Source");
61        buf.append("</a>"); //$NON-NLS-1$
62        buf.append(": Directly edit the AndroidManifest.xml file.");
63        buf.append("</li>"); //$NON-NLS-1$
64
65        buf.append("<li style=\"image\" value=\"android_img\">"); //$NON-NLS-1$
66        buf.append("<a href=\"http://code.google.com/android/devel/bblocks-manifest.html\">Documentation</a>: Documentation from the Android SDK for AndroidManifest.xml."); //$NON-NLS-1$
67        buf.append("</li>"); //$NON-NLS-1$
68        buf.append("</form>"); //$NON-NLS-1$
69
70        mFormText = createFormText(table, toolkit, true, buf.toString(),
71                false /* setupLayoutData */);
72
73        Image androidLogo = AdtPlugin.getAndroidLogo();
74        mFormText.setImage("android_img", androidLogo); //$NON-NLS-1$
75
76        // Listener for default actions (page change, URL web browser)
77        mFormText.addHyperlinkListener(editor.createHyperlinkListener());
78
79        mFormText.addHyperlinkListener(new IHyperlinkListener() {
80            @Override
81            public void linkExited(HyperlinkEvent e) {
82                // pass
83            }
84
85            @Override
86            public void linkEntered(HyperlinkEvent e) {
87                // pass
88            }
89
90            @Override
91            public void linkActivated(HyperlinkEvent e) {
92                String link = e.data.toString();
93                if ("action_dosomething".equals(link)) {
94                    MessageBox mb = new MessageBox(table.getShell(), SWT.OK);
95                    mb.setText("Custom Action Invoked");
96                    mb.open();
97                }
98            }
99        });
100    }
101
102    /**
103     * Called after all pages have been created, to let the parts initialize their
104     * content based on the document's model.
105     * <p/>
106     * The model should be acceded via the {@link ExportEditor}.
107     *
108     * @param editor The {@link ExportEditor} instance.
109     */
110    public void onModelInit(ExportEditor editor) {
111        // pass
112    }
113
114    /**
115     * Called after the document model has been changed. The model should be acceded via
116     * the {@link ExportEditor} (e.g. getDocument, wrapRewriteSession)
117     *
118     * @param editor The {@link ExportEditor} instance.
119     * @param event Specification of changes applied to document.
120     */
121    public void onModelChanged(ExportEditor editor, DocumentEvent event) {
122        // pass
123    }
124}
125