KickJava   Java API By Example, From Geeks To Geeks.

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


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.IViewActionDelegate;
13 import org.eclipse.ui.IViewPart;
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 a view's local tool bar, pulldown menu, or popup menu.
21  *
22  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
23  */

24 public abstract class LSDViewActionDelegate implements IViewActionDelegate, LoginStateListener {
25
26     private IViewPart viewPart;
27     protected IViewPart getViewPart() {
28         return viewPart;
29     }
30     /**
31      * Default implementation of init remembers the
32      * passed IViewPart and makes it accessible
33      * through {@link #getViewPart()}
34      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
35      */

36     public void init(IViewPart view) {
37         this.viewPart = view;
38     }
39
40     /**
41      * Has to be implemented.
42      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
43      */

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

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

65     public void loginStateChanged(int loginState, IAction action) {
66     }
67
68 }
69
Popular Tags