001: /*******************************************************************************
002: * Copyright (c) 2003, 2006 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: * Sebastian Davids <sdavids@gmx.de> - Fix for bug 95292 - [Intro]
011: * Help > Welcome missing F1 context
012: *******************************************************************************/package org.eclipse.ui.internal;
013:
014: import org.eclipse.jface.action.Action;
015: import org.eclipse.jface.dialogs.MessageDialog;
016: import org.eclipse.jface.resource.ImageDescriptor;
017: import org.eclipse.swt.widgets.Event;
018: import org.eclipse.ui.IPageListener;
019: import org.eclipse.ui.IWorkbenchPage;
020: import org.eclipse.ui.IWorkbenchWindow;
021: import org.eclipse.ui.actions.ActionFactory;
022: import org.eclipse.ui.internal.intro.IntroDescriptor;
023: import org.eclipse.ui.internal.intro.IntroMessages;
024:
025: /**
026: * Action that will launch the intro in the given window.
027: *
028: * @since 3.0
029: */
030: public class IntroAction extends Action implements
031: ActionFactory.IWorkbenchAction {
032:
033: private IWorkbenchWindow workbenchWindow;
034:
035: private IPageListener pageListener = new IPageListener() {
036:
037: public void pageActivated(IWorkbenchPage page) {
038: //no-op
039: }
040:
041: public void pageClosed(IWorkbenchPage page) {
042: setEnabled(workbenchWindow.getPages().length > 0);
043: }
044:
045: public void pageOpened(IWorkbenchPage page) {
046: setEnabled(true);
047: }
048: };
049:
050: /**
051: * @param window the window to bind the action to.
052: */
053: public IntroAction(IWorkbenchWindow window) {
054: super (IntroMessages.Intro_action_text);
055: if (window == null) {
056: throw new IllegalArgumentException();
057: }
058: this .workbenchWindow = window;
059: window.getWorkbench().getHelpSystem().setHelp(this ,
060: IWorkbenchHelpContextIds.INTRO_ACTION);
061:
062: IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
063: .getWorkbench()).getIntroDescriptor();
064: String labelOverride = introDescriptor.getLabelOverride();
065: if (labelOverride != null)
066: setText(labelOverride);
067:
068: setActionDefinitionId("org.eclipse.ui.help.quickStartAction"); //$NON-NLS-1$
069:
070: window.addPageListener(pageListener);
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
075: */
076: public void dispose() {
077: workbenchWindow.removePageListener(pageListener);
078: workbenchWindow = null;
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
083: */
084: public void runWithEvent(Event event) {
085: IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
086: .getWorkbench()).getIntroDescriptor();
087: if (introDescriptor == null) {
088: MessageDialog.openWarning(workbenchWindow.getShell(),
089: IntroMessages.Intro_missing_product_title,
090: IntroMessages.Intro_missing_product_message);
091: } else {
092: workbenchWindow.getWorkbench().getIntroManager().showIntro(
093: workbenchWindow, false);
094: }
095: }
096:
097: /* (non-Javadoc)
098: * @see org.eclipse.jface.action.IAction#getImageDescriptor()
099: */
100: public ImageDescriptor getImageDescriptor() {
101: IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
102: .getWorkbench()).getIntroDescriptor();
103: if (introDescriptor == null) {
104: return null;
105: }
106: return introDescriptor.getImageDescriptor();
107: }
108: }
|