Project

General

Profile

Download (2.62 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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.navigator.framelist;
12

    
13
import org.eclipse.osgi.util.NLS;
14
import org.eclipse.ui.ISharedImages;
15
import org.eclipse.ui.PlatformUI;
16

    
17
/**
18
 * Generic "Back" action which goes back one frame,
19
 * @since 3.4
20
 */
21
public class BackAction extends FrameAction {
22

    
23
	private static final String ID = "org.eclipse.ui.framelist.back"; //$NON-NLS-1$
24
	
25
    /**
26
     * Constructs a new action for the specified frame list.
27
     * 
28
     * @param frameList the frame list
29
     */
30
    public BackAction(FrameList frameList) {
31
        super(frameList);
32
        setId(ID);
33
        setText(FrameListMessages.Back_text);
34
        ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
35
        setImageDescriptor(images
36
                .getImageDescriptor(ISharedImages.IMG_TOOL_BACK));
37
        setDisabledImageDescriptor(images
38
                .getImageDescriptor(ISharedImages.IMG_TOOL_BACK_DISABLED));
39
        PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
40
				IFrameListHelpContextIds.BACK_ACTION);
41
        update();
42
    }
43

    
44
    private Frame getPreviousFrame() {
45
        FrameList list = getFrameList();
46
        return list.getFrame(list.getCurrentIndex() - 1);
47
    }
48

    
49
    private String getToolTipText(Frame previousFrame) {
50
        if (previousFrame != null) {
51
            String text = previousFrame.getToolTipText();
52
            if (text != null && text.length() > 0) {
53
                return NLS.bind(FrameListMessages.Back_toolTipOneArg, text);
54
            }
55
        }
56
        return FrameListMessages.Back_toolTip;
57
    }
58

    
59
    /**
60
     * Calls <code>back()</code> on the frame list.
61
     */
62
    public void run() {
63
        getFrameList().back();
64
    }
65

    
66
    /**
67
     * Updates this action's enabled state and tool tip text.
68
     * This action is enabled only when there is a previous frame in the frame list.
69
     * The tool tip text is "Back to " plus the tool tip text for the previous frame.
70
     */
71
    public void update() {
72
        super.update();
73
        Frame previousFrame = getPreviousFrame();
74
        setEnabled(previousFrame != null);
75
        setToolTipText(getToolTipText(previousFrame));
76
    }
77

    
78
}
(1-1/15)