KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > IntroAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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 package org.eclipse.ui.internal;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.swt.widgets.Event;
17 import org.eclipse.ui.IPageListener;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.actions.ActionFactory;
21 import org.eclipse.ui.internal.intro.IntroDescriptor;
22 import org.eclipse.ui.internal.intro.IntroMessages;
23
24 /**
25  * Action that will launch the intro in the given window.
26  *
27  * @since 3.0
28  */

29 public class IntroAction extends Action implements
30         ActionFactory.IWorkbenchAction {
31
32     private IWorkbenchWindow workbenchWindow;
33
34     private IPageListener pageListener = new IPageListener() {
35
36         public void pageActivated(IWorkbenchPage page) {
37             //no-op
38
}
39
40         public void pageClosed(IWorkbenchPage page) {
41             setEnabled(workbenchWindow.getPages().length > 0);
42         }
43
44         public void pageOpened(IWorkbenchPage page) {
45             setEnabled(true);
46         }
47     };
48
49     /**
50      * @param window the window to bind the action to.
51      */

52     public IntroAction(IWorkbenchWindow window) {
53         super(IntroMessages.Intro_action_text);
54         if (window == null) {
55             throw new IllegalArgumentException JavaDoc();
56         }
57         this.workbenchWindow = window;
58         IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
59                 .getWorkbench()).getIntroDescriptor();
60         String JavaDoc labelOverride = introDescriptor.getLabelOverride();
61         if (labelOverride != null)
62             setText(labelOverride);
63         
64         setActionDefinitionId("org.eclipse.ui.help.quickStartAction"); //$NON-NLS-1$
65

66         window.addPageListener(pageListener);
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
71      */

72     public void dispose() {
73         workbenchWindow.removePageListener(pageListener);
74         workbenchWindow = null;
75     }
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
79      */

80     public void runWithEvent(Event event) {
81         IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
82                 .getWorkbench()).getIntroDescriptor();
83         if (introDescriptor == null) {
84             MessageDialog.openWarning(workbenchWindow.getShell(),
85                     IntroMessages.Intro_missing_product_title,
86                     IntroMessages.Intro_missing_product_message);
87         } else {
88             workbenchWindow.getWorkbench().getIntroManager().showIntro(
89                     workbenchWindow, false);
90         }
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.jface.action.IAction#getImageDescriptor()
95      */

96     public ImageDescriptor getImageDescriptor() {
97         IntroDescriptor introDescriptor = ((Workbench) workbenchWindow
98                 .getWorkbench()).getIntroDescriptor();
99         if (introDescriptor == null) {
100             return null;
101         }
102         return introDescriptor.getImageDescriptor();
103     }
104 }
105
Popular Tags