1 21 22 package org.apache.derby.ui.actions; 23 24 25 import org.apache.derby.ui.DerbyPlugin; 26 import org.apache.derby.ui.common.CommonNames; 27 import org.apache.derby.ui.common.Messages; 28 import org.apache.derby.ui.util.DerbyUtils; 29 import org.apache.derby.ui.util.Logger; 30 import org.eclipse.core.resources.IFile; 31 import org.eclipse.core.resources.IProject; 32 import org.eclipse.core.runtime.IStatus; 33 import org.eclipse.jdt.core.IJavaProject; 34 import org.eclipse.jface.action.IAction; 35 import org.eclipse.jface.dialogs.MessageDialog; 36 import org.eclipse.jface.viewers.ISelection; 37 import org.eclipse.jface.viewers.IStructuredSelection; 38 import org.eclipse.swt.widgets.Shell; 39 import org.eclipse.ui.IActionDelegate; 40 import org.eclipse.ui.IObjectActionDelegate; 41 import org.eclipse.ui.IWorkbenchPart; 42 43 44 public class IJAction implements IObjectActionDelegate { 45 46 private IFile currentScript; 47 private IJavaProject currentJavaProject; 48 private IProject currentProject; 49 52 public IJAction() { 53 super(); 54 } 55 56 59 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 60 } 61 62 65 public void run(IAction action) { 66 67 Shell shell = new Shell(); 68 DerbyPlugin plugin = DerbyPlugin.getDefault(); 69 if (plugin== null) { 70 MessageDialog.openInformation(shell, 71 CommonNames.PLUGIN_NAME, 72 Messages.NO_ACTION); 73 } 74 else { 75 try { 76 if(currentJavaProject!=null){ 77 currentProject=currentJavaProject.getProject(); 78 } 79 if(currentProject.isNatureEnabled(CommonNames.DERBY_NATURE)){ 80 DerbyUtils.runIJ(currentScript,currentProject); 81 }else{ 82 shell = new Shell(); 83 MessageDialog.openInformation( 84 shell, 85 CommonNames.PLUGIN_NAME, 86 Messages.NO_DERBY_NATURE+"\n"+ 87 Messages.ADD_N_TRY); 88 } 89 }catch(Exception e){ 90 Logger.log("IAction.run() error "+e,IStatus.ERROR); 91 } 92 } 93 } 94 95 98 public void selectionChanged(IAction action, ISelection selection) { 99 currentJavaProject = org.apache.derby.ui.util.SelectionUtil.findSelectedJavaProject(selection); 100 if(currentJavaProject==null){ 101 currentProject=org.apache.derby.ui.util.SelectionUtil.findSelectedProject(selection); 102 } 103 currentScript = null; 104 if (selection != null) { 105 if (selection instanceof IStructuredSelection) { 106 IStructuredSelection ss = (IStructuredSelection)selection; 107 Object obj = ss.getFirstElement(); 109 if (obj instanceof IFile) { 110 currentScript = (IFile)obj; 111 } 112 if(currentScript!=null){ 113 currentProject=currentScript.getProject(); 114 } 115 } 116 } 117 121 } 131 132 } 133 | Popular Tags |