KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > framelist > ForwardAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.views.framelist;
12
13 import org.eclipse.osgi.util.NLS;
14 import org.eclipse.ui.ISharedImages;
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.internal.views.framelist.FrameListMessages;
17
18 /**
19  * Generic "Forward" action which goes forward one frame.
20  */

21 public class ForwardAction extends FrameAction {
22
23     /**
24      * Constructs a new action for the specified frame list.
25      *
26      * @param frameList the frame list
27      */

28     public ForwardAction(FrameList frameList) {
29         super(frameList);
30         setText(FrameListMessages.Forward_text);
31         ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
32         setImageDescriptor(images
33                 .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD));
34         setDisabledImageDescriptor(images
35                 .getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD_DISABLED));
36         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
37                 IFrameListHelpContextIds.FORWARD_ACTION);
38         update();
39     }
40
41     private Frame getNextFrame() {
42         FrameList list = getFrameList();
43         return list.getFrame(list.getCurrentIndex() + 1);
44     }
45
46     private String JavaDoc getToolTipText(Frame nextFrame) {
47         if (nextFrame != null) {
48             String JavaDoc text = nextFrame.getToolTipText();
49             if (text != null && text.length() > 0) {
50                 return NLS.bind(FrameListMessages.Forward_toolTipOneArg, text);
51             }
52         }
53         return FrameListMessages.Forward_toolTip;
54     }
55
56     /**
57      * Calls <code>forward()</code> on the frame list.
58      */

59     public void run() {
60         getFrameList().forward();
61     }
62
63     /**
64      * Updates this action's enabled state and tool tip text.
65      * This action is enabled only when there is a next frame in the frame list.
66      * The tool tip text is "Forward to " plus the tool tip text for the next
67      * frame.
68      */

69     public void update() {
70         super.update();
71         Frame nextFrame = getNextFrame();
72         setEnabled(nextFrame != null);
73         setToolTipText(getToolTipText(nextFrame));
74     }
75
76 }
77
Popular Tags