1 package org.enhydra.kelp.eclipse.actions; 2 3 import java.io.File ; 4 5 import org.eclipse.core.resources.IProject; 6 import org.eclipse.core.resources.IResource; 7 import org.eclipse.core.runtime.CoreException; 8 import org.eclipse.jdt.core.IJavaElement; 9 import org.eclipse.jface.action.IAction; 10 import org.eclipse.jface.viewers.ISelection; 11 import org.eclipse.jface.viewers.IStructuredSelection; 12 import org.eclipse.swt.widgets.MessageBox; 13 import org.eclipse.ui.IWorkbenchPage; 14 import org.eclipse.ui.IWorkbenchWindow; 15 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 16 import org.enhydra.dods.generator.DODSGenerator; 17 import org.enhydra.kelp.ant.dods.KelpDODSGenerator; 18 import org.enhydra.kelp.ant.node.AntProject; 19 import org.enhydra.kelp.eclipse.KelpPlugin; 20 21 25 public class DODSAction implements IWorkbenchWindowActionDelegate { 26 29 public DODSAction() { 30 } 31 32 36 public void run(IAction action) { 37 IProject project = null; 38 String prjName = null; 39 String prjPath = null; 40 41 IWorkbenchPage page = KelpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); 42 if (page != null) { 43 ISelection selection = page.getSelection(); 44 if (selection instanceof IStructuredSelection) { 45 IStructuredSelection ss = (IStructuredSelection)selection; 46 if (!ss.isEmpty()) { 47 Object obj = ss.getFirstElement(); 48 if (obj instanceof IJavaElement) { 49 IResource res =((IJavaElement)obj).getResource(); 50 if (res == null) 51 project = ((IJavaElement)obj).getJavaProject().getProject(); 52 else 53 project = res.getProject(); 54 55 } 56 if (obj instanceof IResource) { 57 project = ((IResource)obj).getProject(); 58 } 59 } 60 } 61 } 62 if (project != null) { 63 prjName = project.getName(); 64 prjPath = project.getLocation().toString(); 65 66 try{ 68 if(prjPath!=null){ 69 AntProject antProject = new AntProject(prjPath); 70 String enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR); 71 File dodsDirFile = new File (enhydraDir,"dods"); 72 System.setProperty("DODS_HOME", dodsDirFile.getAbsolutePath()); 73 KelpDODSGenerator.main(new String []{prjPath}); 74 } 75 }catch(Exception e){ 76 e.printStackTrace(); 77 } 78 try { 80 project.refreshLocal(IResource.DEPTH_INFINITE, null); 81 } catch (CoreException e) { 82 System.err.println(prjName); 83 } 84 }else 85 System.err.println("Fail to start DODS Generator, no project is selected!"); 86 87 } 88 89 93 public void selectionChanged(IAction action, ISelection selection) { 94 } 95 96 100 public void dispose() { 101 } 102 103 107 public void init(IWorkbenchWindow window) { 108 } 109 } 110 | Popular Tags |