~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.editor/src/org/eclipse/linuxtools/internal/systemtap/ui/editor/actions/EditorAction.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
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 - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.internal.systemtap.ui.editor.actions;
 
13
 
 
14
import org.eclipse.jface.action.Action;
 
15
import org.eclipse.jface.action.IAction;
 
16
import org.eclipse.jface.viewers.ISelection;
 
17
import org.eclipse.ui.IEditorPart;
 
18
import org.eclipse.ui.IWorkbenchPage;
 
19
import org.eclipse.ui.IWorkbenchWindow;
 
20
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
21
import org.eclipse.ui.PlatformUI;
 
22
 
 
23
public abstract class EditorAction extends Action implements IWorkbenchWindowActionDelegate {
 
24
        public EditorAction() {
 
25
                super();
 
26
                setEnabled(true);
 
27
        }
 
28
 
 
29
        public void init(IWorkbenchWindow window) {
 
30
                this.window = window;
 
31
        }
 
32
 
 
33
        protected void updateState() {
 
34
                IEditorPart editor = getActiveEditor();
 
35
                setEnabled(editor != null && editor.isDirty());
 
36
        }
 
37
 
 
38
        protected IWorkbenchWindow getWorkbenchWindow() {
 
39
                return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
40
        }
 
41
 
 
42
        protected IWorkbenchPage getActivePage() {
 
43
                return getWorkbenchWindow().getActivePage();
 
44
        }
 
45
 
 
46
        protected IEditorPart getActiveEditor() {
 
47
                return getActivePage().getActiveEditor();
 
48
        }
 
49
 
 
50
        public void selectionChanged(IAction act, ISelection select) {
 
51
                action = act;
 
52
                buildEnablementChecks();
 
53
        }
 
54
        
 
55
        protected void buildEnablementChecks() {
 
56
                setEnablement(true);
 
57
        }
 
58
        
 
59
        protected void setEnablement(boolean enabled) {
 
60
                action.setEnabled(enabled);
 
61
        }
 
62
 
 
63
        public void dispose() {
 
64
                window = null;
 
65
                action = null;
 
66
        }
 
67
        
 
68
        protected IWorkbenchWindow window;
 
69
        protected IAction action;
 
70
}