KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > cheatsheet > CSAbstractPage


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.pde.internal.ui.editor.cheatsheet;
13
14 import org.eclipse.jface.action.ControlContribution;
15 import org.eclipse.jface.window.Window;
16 import org.eclipse.jface.wizard.WizardDialog;
17 import org.eclipse.pde.core.IModel;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
21 import org.eclipse.pde.internal.ui.util.SWTUtil;
22 import org.eclipse.pde.internal.ui.wizards.cheatsheet.RegisterCSWizard;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.forms.IManagedForm;
28 import org.eclipse.ui.forms.editor.FormEditor;
29 import org.eclipse.ui.forms.events.HyperlinkEvent;
30 import org.eclipse.ui.forms.events.IHyperlinkListener;
31 import org.eclipse.ui.forms.widgets.FormToolkit;
32 import org.eclipse.ui.forms.widgets.ImageHyperlink;
33 import org.eclipse.ui.forms.widgets.ScrolledForm;
34
35 /**
36  * CSAbstractPage
37  *
38  */

39 public abstract class CSAbstractPage extends PDEFormPage {
40
41     private ImageHyperlink fImageHyperlinkRegisterCS;
42     
43     private FormToolkit fToolkit;
44     
45     private IModel fModel;
46     
47     /**
48      * @param editor
49      * @param id
50      * @param title
51      */

52     public CSAbstractPage(FormEditor editor, String JavaDoc id, String JavaDoc title) {
53         super(editor, id, title);
54     }
55
56     /**
57      * @param managedForm
58      * @param model
59      */

60     protected void createUIFormTitleRegisterCSLink(IManagedForm managedForm,
61             IModel model) {
62         // Set globals
63
fToolkit = managedForm.getToolkit();
64         fModel = model;
65         // Add the register cheat sheet link to the form title area
66
ScrolledForm form = managedForm.getForm();
67         if (fModel.isEditable()) {
68             form.getToolBarManager().add(createUIControlConRegisterCS());
69             form.getToolBarManager().update(true);
70         }
71     }
72     
73     /**
74      * @return
75      */

76     private ControlContribution createUIControlConRegisterCS() {
77         return new ControlContribution("Register") { //$NON-NLS-1$
78
protected Control createControl(Composite parent) {
79                 // Create UI
80
createUIImageHyperlinkRegisterCS(parent);
81                 // Create Listener
82
createUIListenerImageHyperlinkRegisterCS();
83                 return fImageHyperlinkRegisterCS;
84             }
85         };
86     }
87
88     /**
89      * @param parent
90      */

91     private void createUIImageHyperlinkRegisterCS(Composite parent) {
92         fImageHyperlinkRegisterCS = new ImageHyperlink(parent, SWT.NONE);
93         fImageHyperlinkRegisterCS.setText(
94                 PDEUIMessages.CSAbstractPage_msgRegisterThisCheatSheet);
95         fImageHyperlinkRegisterCS.setUnderlined(true);
96         fImageHyperlinkRegisterCS.setForeground(
97                 fToolkit.getHyperlinkGroup().getForeground());
98     }
99
100     /**
101      *
102      */

103     private void createUIListenerImageHyperlinkRegisterCS() {
104         fImageHyperlinkRegisterCS.addHyperlinkListener(new IHyperlinkListener() {
105             public void linkActivated(HyperlinkEvent e) {
106                 handleLinkActivatedRegisterCS();
107             }
108             public void linkEntered(HyperlinkEvent e) {
109                 handleLinkEnteredRegisterCS(e.getLabel());
110             }
111             public void linkExited(HyperlinkEvent e) {
112                 handleLinkExitedRegisterCS();
113             }
114         });
115     }
116     
117     /**
118      * @param message
119      */

120     private void handleLinkEnteredRegisterCS(String JavaDoc message) {
121         // Update colour
122
fImageHyperlinkRegisterCS.setForeground(
123                 fToolkit.getHyperlinkGroup().getActiveForeground());
124         // Update IDE status line
125
getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(message);
126     }
127     
128     /**
129      *
130      */

131     private void handleLinkExitedRegisterCS() {
132         // Update colour
133
fImageHyperlinkRegisterCS.setForeground(
134                 fToolkit.getHyperlinkGroup().getForeground());
135         // Update IDE status line
136
getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(null);
137     }
138     
139     /**
140      *
141      */

142     private void handleLinkActivatedRegisterCS() {
143         RegisterCSWizard wizard = new RegisterCSWizard(fModel);
144         // Initialize the wizard
145
wizard.init(PlatformUI.getWorkbench(), null);
146         // Create the dialog for the wizard
147
WizardDialog dialog =
148             new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard);
149         dialog.create();
150         // Configure the dialogs size
151
SWTUtil.setDialogSize(dialog, 400, 300);
152         // Check the result
153
if (dialog.open() == Window.OK) {
154             // TODO: MP: COMPCS: HIGH: Automatic save of editor after creating simple cheat sheet?
155
}
156     }
157     
158 }
159
Popular Tags