KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > display > DisplayViewAction


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.jdt.internal.debug.ui.display;
12
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.text.ITextOperationTarget;
17 import org.eclipse.ui.texteditor.IUpdate;
18
19
20 public class DisplayViewAction extends Action implements IUpdate {
21     
22     /** The text operation code */
23     private int fOperationCode= -1;
24     /** The text operation target */
25     private ITextOperationTarget fOperationTarget;
26     /** The text operation target provider */
27     private IAdaptable fTargetProvider;
28     
29     
30     public DisplayViewAction(ITextOperationTarget target, int operationCode) {
31         super();
32         fOperationTarget= target;
33         fOperationCode= operationCode;
34         update();
35     }
36         
37     public DisplayViewAction(IAdaptable targetProvider, int operationCode) {
38         super();
39         fTargetProvider= targetProvider;
40         fOperationCode= operationCode;
41         update();
42     }
43     
44     /**
45      * The <code>TextOperationAction</code> implementation of this
46      * <code>IAction</code> method runs the operation with the current
47      * operation code.
48      */

49     public void run() {
50         if (fOperationCode != -1 && fOperationTarget != null)
51             fOperationTarget.doOperation(fOperationCode);
52     }
53     
54     /**
55      * The <code>TextOperationAction</code> implementation of this
56      * <code>IUpdate</code> method discovers the operation through the current
57      * editor's <code>ITextOperationTarget</code> adapter, and sets the
58      * enabled state accordingly.
59      */

60     public void update() {
61         if (fOperationTarget == null && fTargetProvider != null && fOperationCode != -1){
62             fOperationTarget= (ITextOperationTarget) fTargetProvider.getAdapter(ITextOperationTarget.class);
63         }
64     
65         boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
66         setEnabled(isEnabled);
67     }
68 }
69
Popular Tags