KickJava   Java API By Example, From Geeks To Geeks.

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


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.IWorkbenchWindow;
13 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
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 the workbench window menu or tool bar.
21  *
22  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
23  */

24 public abstract class LSDWorkbenchWindowActionDelegate implements
25         IWorkbenchWindowActionDelegate, LoginStateListener {
26
27     /**
28      * Default implementation of dispose removes this instance
29      * as LoginStateListener, so make sure to always call super.dispose().
30      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
31      */

32     public void dispose() {
33         try {
34             Login.getLogin(false).removeLoginStateListener(this);
35         } catch (LoginException JavaDoc e) {
36             throw new RuntimeException JavaDoc("Login.getLogin(false) should never throw this exception!", e);
37         }
38     }
39     
40     IWorkbenchWindow window;
41     /**
42      * Returns the IWorkbenchWindow passed in {@link #init(IWorkbenchWindow)}
43      * @return
44      */

45     protected IWorkbenchWindow getWindow() {
46         return window;
47     }
48     
49     /**
50      * Default implementation of init remembers the
51      * passed IWorkbenchWindow and makes it accessible
52      * through {@link #getWindow()}
53      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
54      */

55     public void init(IWorkbenchWindow window){
56         this.window = window;
57     }
58
59     /**
60      * Has to be implemented.
61      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
62      */

63     public abstract void run(IAction action);
64     
65     /**
66      * Subclasses may override this but have to make sure
67      * super.selectionChanged(action,selection) is called to
68      * further provide login-state-dependency
69      *
70      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
71      */

72     public void selectionChanged(IAction action, ISelection selection) {
73         Login.sharedInstance().addLoginStateListener(this,action);
74     }
75     
76     /**
77      * Default implementation of loginStateChanged does nothing.
78      * @see LoginStateListener#loginStateChanged(int, IAction)
79      */

80     public void loginStateChanged(int loginState, IAction action) {
81     }
82
83 }
84
Popular Tags