1 package com.bull.eclipse.jonas.actions; 2 3 7 8 9 import org.eclipse.core.resources.IProject; 10 import org.eclipse.jdt.core.IJavaProject; 11 import org.eclipse.jdt.internal.ui.JavaPlugin; 12 import org.eclipse.jface.action.IAction; 13 import org.eclipse.jface.dialogs.MessageDialog; 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.swt.widgets.Shell; 17 import org.eclipse.ui.IWorkbenchWindow; 18 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 19 20 import com.bull.eclipse.jonas.JonasLauncherPlugin; 21 import com.bull.eclipse.jonas.JonasProject; 22 23 abstract public class JonasProjectAbstractActionDelegate implements IWorkbenchWindowActionDelegate { 24 protected IWorkbenchWindow window; 25 private String msg; 26 27 30 public void dispose() { 31 } 32 33 36 public void init(IWorkbenchWindow window) { 37 this.window = window; 38 } 39 40 43 public void run(IAction action) { 44 Shell shell= JavaPlugin.getActiveWorkbenchShell(); 45 try { 46 JonasProject prj = this.getCurrentSelection(); 47 String actionId = action.getId(); 48 if((prj != null) ) { 49 if (this.doActionOn(prj)) { 50 setMsgToSuccess(); 51 MessageDialog.openInformation(shell,"Jonas", msg); 52 } 53 } 54 } catch (Exception ex) { 55 JonasLauncherPlugin.log(ex.getStackTrace().toString()); 56 setMsgToFail(ex.getMessage(), true); 57 MessageDialog.openInformation(shell,"Jonas", msg); 58 } 59 60 } 61 62 65 public void selectionChanged(IAction action, ISelection selection) { 66 67 } 68 69 protected JonasProject getCurrentSelection() { 70 IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow(); 71 JonasProject result = null; 72 if (window != null) { 73 ISelection selection= window.getSelectionService().getSelection(); 74 if (selection instanceof IStructuredSelection) { 75 Object project = ((IStructuredSelection)selection).getFirstElement(); 76 if(project instanceof IProject) 77 result = JonasProject.create((IProject)project); 78 if(project instanceof IJavaProject) 79 result = JonasProject.create((IJavaProject)project); 80 } 81 } 82 return result; 83 } 84 85 abstract public boolean doActionOn(JonasProject prj) throws Exception ; 86 87 91 private void setMsgToFail(String detail, boolean seelog) { 92 this.msg = JonasLauncherPlugin.getResourceString("msg.action.failed"); 93 this.msg += "\n" + detail; 94 if(seelog) { 95 this.msg += JonasLauncherPlugin.getResourceString("msg.action.seelog"); 96 } 97 } 98 99 103 private void setMsgToSuccess() { 104 this.msg = JonasLauncherPlugin.getResourceString("msg.action.succeeded"); 105 } 106 } 107 108 | Popular Tags |