KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > base > login > actions > LSDEditorActionDelegate


1 /*
2  * Created on Nov 23, 2004
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.base.login.actions;
7
8 import javax.security.auth.login.LoginException JavaDoc;
9
10 import org.eclipse.jface.action.IAction;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.ui.IEditorActionDelegate;
13 import org.eclipse.ui.IEditorPart;
14
15 import com.nightlabs.ipanema.base.login.Login;
16 import com.nightlabs.ipanema.base.login.LoginStateListener;
17
18 /**
19  * Provides login-state-dependency for WorkbenchWindowActions wich are
20  * actions contributed into an editor-activated menu or tool bar.
21  *
22  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
23  */

24 public abstract class LSDEditorActionDelegate implements IEditorActionDelegate, LoginStateListener {
25
26     private IEditorPart activeEditor;
27     /**
28      * Returns the IEditorPart passed in {@link #setActiveEditor(IAction, IEditorPart)}
29      * @return
30      */

31     protected IEditorPart getActiveEditor() {
32         return activeEditor;
33     }
34     
35     /**
36      * Default implementation remembers the passed
37      * IEditorPart and makes it Accessible through {@link}
38      * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
39      */

40     public void setActiveEditor(IAction action, IEditorPart targetEditor) {
41         this.activeEditor = targetEditor;
42     }
43
44     /**
45      * Has to be implemented
46      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
47      */

48     public abstract void run(IAction action);
49     
50     /**
51      * Subclasses may override this but have to make sure
52      * super.selectionChanged(action,selection) is called to
53      * further provide login-state-dependency
54      *
55      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
56      */

57     public void selectionChanged(IAction action, ISelection selection) {
58         try {
59             Login.getLogin(false).addLoginStateListener(this,action);
60         } catch (LoginException JavaDoc e) {
61             throw new RuntimeException JavaDoc("Login.getLogin(false) should never throw this exception!", e);
62         }
63     }
64     
65     /**
66      * Default implementation of loginStateChanged does nothing.
67      * @see LoginStateListener#loginStateChanged(int, IAction)
68      */

69     public void loginStateChanged(int loginState, IAction action) {
70     }
71
72 }
73
Popular Tags