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.cheatsheet;
011:
012: import org.eclipse.jface.action.ControlContribution;
013: import org.eclipse.jface.action.IToolBarManager;
014: import org.eclipse.jface.window.Window;
015: import org.eclipse.jface.wizard.WizardDialog;
016: import org.eclipse.pde.core.IModel;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEUIMessages;
019: import org.eclipse.pde.internal.ui.editor.MultiSourceEditor;
020: import org.eclipse.pde.internal.ui.wizards.cheatsheet.RegisterCSWizard;
021: import org.eclipse.swt.SWT;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Control;
024: import org.eclipse.ui.PlatformUI;
025: import org.eclipse.ui.forms.events.HyperlinkEvent;
026: import org.eclipse.ui.forms.events.IHyperlinkListener;
027: import org.eclipse.ui.forms.widgets.ImageHyperlink;
028:
029: public abstract class CSAbstractEditor extends MultiSourceEditor {
030:
031: private ImageHyperlink fImageHyperlinkRegisterCS;
032:
033: public void contributeToToolbar(IToolBarManager manager) {
034: // Add the register cheat sheet link to the form title area
035: if (getAggregateModel().isEditable())
036: manager.add(createUIControlConRegisterCS());
037: }
038:
039: /**
040: * @return
041: */
042: private ControlContribution createUIControlConRegisterCS() {
043: return new ControlContribution("Register") { //$NON-NLS-1$
044: protected Control createControl(Composite parent) {
045: // Create UI
046: createUIImageHyperlinkRegisterCS(parent);
047: // Create Listener
048: createUIListenerImageHyperlinkRegisterCS();
049: return fImageHyperlinkRegisterCS;
050: }
051: };
052: }
053:
054: /**
055: * @param parent
056: */
057: private void createUIImageHyperlinkRegisterCS(Composite parent) {
058: fImageHyperlinkRegisterCS = new ImageHyperlink(parent, SWT.NONE);
059: fImageHyperlinkRegisterCS
060: .setText(PDEUIMessages.CSAbstractPage_msgRegisterThisCheatSheet);
061: fImageHyperlinkRegisterCS.setUnderlined(true);
062: fImageHyperlinkRegisterCS.setForeground(getToolkit()
063: .getHyperlinkGroup().getForeground());
064: }
065:
066: /**
067: *
068: */
069: private void createUIListenerImageHyperlinkRegisterCS() {
070: fImageHyperlinkRegisterCS
071: .addHyperlinkListener(new IHyperlinkListener() {
072: public void linkActivated(HyperlinkEvent e) {
073: handleLinkActivatedRegisterCS();
074: }
075:
076: public void linkEntered(HyperlinkEvent e) {
077: handleLinkEnteredRegisterCS(e.getLabel());
078: }
079:
080: public void linkExited(HyperlinkEvent e) {
081: handleLinkExitedRegisterCS();
082: }
083: });
084: }
085:
086: /**
087: * @param message
088: */
089: private void handleLinkEnteredRegisterCS(String message) {
090: // Update colour
091: fImageHyperlinkRegisterCS.setForeground(getToolkit()
092: .getHyperlinkGroup().getActiveForeground());
093: // Update IDE status line
094: getEditorSite().getActionBars().getStatusLineManager()
095: .setMessage(message);
096: }
097:
098: /**
099: *
100: */
101: private void handleLinkExitedRegisterCS() {
102: // Update colour
103: fImageHyperlinkRegisterCS.setForeground(getToolkit()
104: .getHyperlinkGroup().getForeground());
105: // Update IDE status line
106: getEditorSite().getActionBars().getStatusLineManager()
107: .setMessage(null);
108: }
109:
110: /**
111: *
112: */
113: private void handleLinkActivatedRegisterCS() {
114: RegisterCSWizard wizard = new RegisterCSWizard(
115: (IModel) getAggregateModel());
116: // Initialize the wizard
117: wizard.init(PlatformUI.getWorkbench(), null);
118: // Create the dialog for the wizard
119: WizardDialog dialog = new WizardDialog(PDEPlugin
120: .getActiveWorkbenchShell(), wizard);
121: dialog.create();
122: // Configure the dialogs size
123: dialog.getShell().setSize(400, 370);
124: // Check the result
125: if (dialog.open() == Window.OK) {
126: // TODO: MP: COMPCS: HIGH: Automatic save of editor after creating simple cheat sheet?
127: }
128: }
129:
130: }
|