1 package org.enhydra.kelp.eclipse.actions; 2 3 import java.util.Map ; 4 5 import org.eclipse.core.internal.resources.Workspace; 6 import org.eclipse.core.resources.IProject; 7 import org.eclipse.core.resources.IResource; 8 import org.eclipse.core.runtime.CoreException; 9 import org.eclipse.jdt.core.IJavaElement; 10 import org.eclipse.jface.action.IAction; 11 import org.eclipse.jface.viewers.ISelection; 12 import org.eclipse.jface.viewers.IStructuredSelection; 13 import org.eclipse.ui.IWorkbenchPage; 14 import org.eclipse.ui.IWorkbenchWindow; 15 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 16 import org.enhydra.kelp.ant.xmlc.AntXMLCTool; 17 import org.enhydra.kelp.eclipse.KelpPlugin; 18 19 23 public class XMLCAction implements IWorkbenchWindowActionDelegate { 24 27 public XMLCAction() { 28 } 29 30 34 public void run(IAction action) { 35 IProject project = null; 36 String prjName = null; 37 String prjPath = null; 38 39 IWorkbenchPage page = KelpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); 40 if (page != null) { 41 ISelection selection = page.getSelection(); 42 if (selection instanceof IStructuredSelection) { 43 IStructuredSelection ss = (IStructuredSelection)selection; 44 if (!ss.isEmpty()) { 45 Object obj = ss.getFirstElement(); 46 if (obj instanceof IJavaElement) { 47 IResource res =((IJavaElement)obj).getResource(); 48 if (res == null) 49 project = ((IJavaElement)obj).getJavaProject().getProject(); 50 else 51 project = res.getProject(); 52 53 } 54 if (obj instanceof IResource) { 55 project = ((IResource)obj).getProject(); 56 } 57 } 58 } 59 } 60 if (project != null) { 61 prjName = project.getName(); 62 prjPath = project.getLocation().toString(); 63 64 66 AntXMLCTool.main(new String []{prjPath}); 67 68 try { 70 project.refreshLocal(IResource.DEPTH_INFINITE, null); 71 } catch (CoreException e) { 72 System.err.println(prjName); 73 } 74 }else 75 System.err.println("Fail to start XML Compiler, no project is selected!"); 76 } 77 78 79 83 public void selectionChanged(IAction action, ISelection selection) { 84 } 85 86 90 public void dispose() { 91 } 92 93 97 public void init(IWorkbenchWindow window) { 98 } 99 } 100 | Popular Tags |