KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > snippeteditor > SnippetAction


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.snippeteditor;
12
13 import org.eclipse.jface.action.Action;
14
15 /**
16  * A base class for evaluation state dependent actions.
17  */

18 public abstract class SnippetAction extends Action implements ISnippetStateChangedListener {
19         
20     private JavaSnippetEditor fEditor;
21     
22     public SnippetAction(JavaSnippetEditor editor) {
23         setEditor(editor);
24     }
25         
26     public void setEditor(JavaSnippetEditor editor) {
27         if (fEditor != null) {
28             fEditor.removeSnippetStateChangedListener(this);
29         }
30         fEditor= editor;
31         
32         if (fEditor != null) {
33             if (fEditor.getFile() == null) { //external file
34
setEnabled(false);
35                 return;
36             }
37             fEditor.addSnippetStateChangedListener(this);
38         }
39         snippetStateChanged(fEditor);
40     }
41     
42     protected JavaSnippetEditor getEditor() {
43         return fEditor;
44     }
45 }
46
Popular Tags