1 package com.bull.eclipse.jonas.actions; 2 3 import org.eclipse.jdt.core.IPackageFragment; 4 import org.eclipse.jdt.internal.ui.JavaPlugin; 5 import org.eclipse.jface.action.IAction; 6 import org.eclipse.jface.dialogs.MessageDialog; 7 import org.eclipse.jface.viewers.ISelection; 8 import org.eclipse.jface.viewers.IStructuredSelection; 9 import org.eclipse.swt.widgets.Shell; 10 import org.eclipse.ui.IWorkbenchWindow; 11 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 12 13 import com.bull.eclipse.jonas.JonasLauncherPlugin; 14 15 abstract public class JonasPackageAbstractActionDelegate implements IWorkbenchWindowActionDelegate { 16 protected IWorkbenchWindow window; 17 private String msg; 18 19 22 public void dispose() { 23 } 24 25 28 public void init(IWorkbenchWindow window) { 29 this.window = window; 30 } 31 32 35 public void run(IAction action) { 36 Shell shell= JavaPlugin.getActiveWorkbenchShell(); 37 try { 38 IPackageFragment packFragment = this.getCurrentSelection(); 39 String actionId = action.getId(); 40 if((packFragment != null) ) { 41 if (this.doActionOn(packFragment)) { 42 setMsgToSuccess(); 43 MessageDialog.openInformation(shell,"Jonas", msg); 44 } 45 } 46 } catch (Exception ex) { 47 System.out.println("Exception : " + ex.getMessage()); 48 JonasLauncherPlugin.log(ex.getStackTrace().toString()); 49 setMsgToFail(ex.getMessage(), true); 50 MessageDialog.openInformation(shell,"Jonas", msg); 51 } 52 53 } 54 55 56 protected IPackageFragment getCurrentSelection() { 57 IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow(); 58 IPackageFragment resultFragment = null; 59 if (window != null) { 60 ISelection selection= window.getSelectionService().getSelection(); 61 if (selection instanceof IStructuredSelection) { 62 Object packageFragment = ((IStructuredSelection)selection).getFirstElement(); 63 if(packageFragment instanceof IPackageFragment) 64 resultFragment = (IPackageFragment) packageFragment; 65 } 66 } 67 return resultFragment; 68 } 69 70 abstract public boolean doActionOn(IPackageFragment packFrag) throws Exception ; 71 72 76 private void setMsgToFail(String detail, boolean seelog) { 77 this.msg = JonasLauncherPlugin.getResourceString("msg.action.failed"); 78 this.msg += "\n" + detail; 79 if(seelog) { 80 this.msg += JonasLauncherPlugin.getResourceString("msg.action.seelog"); 81 } 82 } 83 84 88 private void setMsgToSuccess() { 89 this.msg = JonasLauncherPlugin.getResourceString("msg.action.succeeded"); 90 } 91 92 95 public void selectionChanged(IAction action, ISelection selection) { 96 97 } 98 99 } 100 101 | Popular Tags |