1 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 39 public abstract class CSAbstractPage extends PDEFormPage { 40 41 private ImageHyperlink fImageHyperlinkRegisterCS; 42 43 private FormToolkit fToolkit; 44 45 private IModel fModel; 46 47 52 public CSAbstractPage(FormEditor editor, String id, String title) { 53 super(editor, id, title); 54 } 55 56 60 protected void createUIFormTitleRegisterCSLink(IManagedForm managedForm, 61 IModel model) { 62 fToolkit = managedForm.getToolkit(); 64 fModel = model; 65 ScrolledForm form = managedForm.getForm(); 67 if (fModel.isEditable()) { 68 form.getToolBarManager().add(createUIControlConRegisterCS()); 69 form.getToolBarManager().update(true); 70 } 71 } 72 73 76 private ControlContribution createUIControlConRegisterCS() { 77 return new ControlContribution("Register") { protected Control createControl(Composite parent) { 79 createUIImageHyperlinkRegisterCS(parent); 81 createUIListenerImageHyperlinkRegisterCS(); 83 return fImageHyperlinkRegisterCS; 84 } 85 }; 86 } 87 88 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 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 120 private void handleLinkEnteredRegisterCS(String message) { 121 fImageHyperlinkRegisterCS.setForeground( 123 fToolkit.getHyperlinkGroup().getActiveForeground()); 124 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(message); 126 } 127 128 131 private void handleLinkExitedRegisterCS() { 132 fImageHyperlinkRegisterCS.setForeground( 134 fToolkit.getHyperlinkGroup().getForeground()); 135 getEditor().getEditorSite().getActionBars().getStatusLineManager().setMessage(null); 137 } 138 139 142 private void handleLinkActivatedRegisterCS() { 143 RegisterCSWizard wizard = new RegisterCSWizard(fModel); 144 wizard.init(PlatformUI.getWorkbench(), null); 146 WizardDialog dialog = 148 new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard); 149 dialog.create(); 150 SWTUtil.setDialogSize(dialog, 400, 300); 152 if (dialog.open() == Window.OK) { 154 } 156 } 157 158 } 159 | Popular Tags |