KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > actions > JonasPackageRootAbstractActionDelegate


1 package com.bull.eclipse.jonas.actions;
2
3 import org.eclipse.core.resources.IFolder;
4 import org.eclipse.jdt.internal.core.PackageFragmentRoot;
5 import org.eclipse.jdt.internal.ui.JavaPlugin;
6 import org.eclipse.jface.action.IAction;
7 import org.eclipse.jface.dialogs.MessageDialog;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.swt.widgets.Shell;
11 import org.eclipse.ui.IWorkbenchWindow;
12 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
13
14 import com.bull.eclipse.jonas.JonasLauncherPlugin;
15
16 abstract public class JonasPackageRootAbstractActionDelegate implements IWorkbenchWindowActionDelegate {
17     protected IWorkbenchWindow window;
18     private String JavaDoc msg;
19
20     /*
21      * @see IWorkbenchWindowActionDelegate#dispose()
22      */

23     public void dispose() {
24     }
25
26     /*
27      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
28      */

29     public void init(IWorkbenchWindow window) {
30         this.window = window;
31     }
32
33     /*
34      * @see IActionDelegate#run(IAction)
35      */

36     public void run(IAction action) {
37         Shell shell= JavaPlugin.getActiveWorkbenchShell();
38         try {
39             PackageFragmentRoot packageRoot = this.getCurrentSelection();
40             String JavaDoc actionId = action.getId();
41             if((packageRoot != null) ) {
42                 if (this.doActionOn(packageRoot)) {
43                     setMsgToSuccess();
44                     MessageDialog.openInformation(shell,"Jonas", msg);
45                 }
46             } else {
47                 setMsgToFail("You have to click on a folder in the resourceAdapter directory", true);
48             }
49         } catch (Exception JavaDoc ex) {
50             System.out.println("Exception : " + ex.getMessage());
51             JonasLauncherPlugin.log(ex.getStackTrace().toString());
52             setMsgToFail(ex.getMessage(), true);
53             MessageDialog.openInformation(shell,"Jonas", msg);
54         }
55         
56     }
57
58
59     protected PackageFragmentRoot getCurrentSelection() {
60         IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow();
61         PackageFragmentRoot result = null;
62         if (window != null) {
63             ISelection selection= window.getSelectionService().getSelection();
64             if (selection instanceof IStructuredSelection) {
65                 Object JavaDoc packageRoot = ((IStructuredSelection)selection).getFirstElement();
66                 if(packageRoot instanceof PackageFragmentRoot)
67                     result = (PackageFragmentRoot) packageRoot;
68             }
69         }
70         return result;
71     }
72     
73     abstract public boolean doActionOn(PackageFragmentRoot packageRoot) throws Exception JavaDoc;
74
75     /**
76      * Sets the msg.
77      * @param msg The msg to set
78      */

79     private void setMsgToFail(String JavaDoc detail, boolean seelog) {
80         this.msg = JonasLauncherPlugin.getResourceString("msg.action.failed");
81         this.msg += "\n" + detail;
82         if(seelog) {
83             this.msg += JonasLauncherPlugin.getResourceString("msg.action.seelog");
84         }
85     }
86     
87     /**
88      * Sets the msg.
89      * @param msg The msg to set
90      */

91     private void setMsgToSuccess() {
92         this.msg = JonasLauncherPlugin.getResourceString("msg.action.succeeded");
93     }
94     
95     /*
96      * @see IActionDelegate#selectionChanged(IAction, ISelection)
97      */

98     public void selectionChanged(IAction action, ISelection selection) {
99
100     }
101     
102 }
103
104
Popular Tags