KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > eclipse > actions > XMLCAction


1 package org.enhydra.kelp.eclipse.actions;
2
3 import java.util.Map JavaDoc;
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 /**
20  * Insert the type's description here.
21  * @see IWorkbenchWindowActionDelegate
22  */

23 public class XMLCAction implements IWorkbenchWindowActionDelegate {
24     /**
25      * The constructor.
26      */

27     public XMLCAction() {
28     }
29
30     /**
31      * Insert the method's description here.
32      * @see IWorkbenchWindowActionDelegate#run
33      */

34     public void run(IAction action) {
35         IProject project = null;
36         String JavaDoc prjName = null;
37         String JavaDoc 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 JavaDoc 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 //---------------------Dacha---------------------------------
65

66             AntXMLCTool.main(new String JavaDoc[]{prjPath});
67     
68             // Refresh project, so the generated files could be visible
69
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     /**
80      * Insert the method's description here.
81      * @see IWorkbenchWindowActionDelegate#selectionChanged
82      */

83     public void selectionChanged(IAction action, ISelection selection) {
84     }
85
86     /**
87      * Insert the method's description here.
88      * @see IWorkbenchWindowActionDelegate#dispose
89      */

90     public void dispose() {
91     }
92
93     /**
94      * Insert the method's description here.
95      * @see IWorkbenchWindowActionDelegate#init
96      */

97     public void init(IWorkbenchWindow window) {
98     }
99 }
100
Popular Tags