KickJava   Java API By Example, From Geeks To Geeks.

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


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 JonasFolderAbstractActionDelegate 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             IFolder folder= this.getCurrentSelection();
40             String JavaDoc actionId = action.getId();
41             if((folder != null) ) {
42                 if (this.doActionOn(folder)) {
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 IFolder getCurrentSelection() {
60         IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow();
61         IFolder folderSelect = null;
62         IFolder result = null;
63         if (window != null) {
64             ISelection selection= window.getSelectionService().getSelection();
65             if (selection instanceof IStructuredSelection) {
66                 Object JavaDoc folder = ((IStructuredSelection)selection).getFirstElement();
67                 if(folder instanceof IFolder)
68                     result = (IFolder) folder;
69             }
70         }
71         return result;
72     }
73     
74     abstract public boolean doActionOn(IFolder folder) throws Exception JavaDoc;
75
76     /**
77      * Sets the msg.
78      * @param msg The msg to set
79      */

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

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

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