KickJava   Java API By Example, From Geeks To Geeks.

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


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

25 public class DODSAction implements IWorkbenchWindowActionDelegate {
26     /**
27      * The constructor.
28      */

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

36     public void run(IAction action) {
37         IProject project = null;
38         String JavaDoc prjName = null;
39         String JavaDoc 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 JavaDoc 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 //---------------------Dacha---------------------------------
67
try{
68                 if(prjPath!=null){
69                     AntProject antProject = new AntProject(prjPath);
70                     String JavaDoc enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR);
71                     File JavaDoc dodsDirFile = new File JavaDoc(enhydraDir,"dods");
72                     System.setProperty("DODS_HOME", dodsDirFile.getAbsolutePath());
73                     KelpDODSGenerator.main(new String JavaDoc[]{prjPath});
74                 }
75             }catch(Exception JavaDoc e){
76                 e.printStackTrace();
77             }
78             // Refresh project, so the generated files could be visible
79
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     /**
90      * Insert the method's description here.
91      * @see IWorkbenchWindowActionDelegate#selectionChanged
92      */

93     public void selectionChanged(IAction action, ISelection selection) {
94     }
95
96     /**
97      * Insert the method's description here.
98      * @see IWorkbenchWindowActionDelegate#dispose
99      */

100     public void dispose() {
101     }
102
103     /**
104      * Insert the method's description here.
105      * @see IWorkbenchWindowActionDelegate#init
106      */

107     public void init(IWorkbenchWindow window) {
108     }
109 }
110
Popular Tags