KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > eclipse > popup > actions > StartForrest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation or its licensors,
3  * as applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.forrest.eclipse.popup.actions;
18
19 import org.apache.forrest.eclipse.ForrestPlugin;
20 import org.apache.forrest.eclipse.job.ForrestManager;
21 import org.apache.forrest.eclipse.preference.ForrestPreferences;
22 import org.eclipse.core.resources.IProject;
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.core.runtime.IPath;
25 import org.eclipse.core.runtime.jobs.Job;
26 import org.eclipse.jdt.core.JavaCore;
27 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.IStructuredSelection;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.ui.IActionDelegate;
35 import org.eclipse.ui.IObjectActionDelegate;
36 import org.eclipse.ui.IWorkbenchPart;
37
38 public class StartForrest
39 implements IObjectActionDelegate, IJavaLaunchConfigurationConstants {
40
41     private IProject activeProject;
42     
43     /**
44      * Constructor for Action1.
45      */

46     public StartForrest() {
47         super();
48     }
49
50     /**
51      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
52      */

53     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
54     }
55
56     /**
57      * @see IActionDelegate#run(IAction)
58      */

59     public void run(IAction action) {
60         Shell messageDialog;
61         Label statusMsg;
62         if (activeProject == null) {
63             return;
64         }
65         
66         Shell shell = new Shell();
67         IPath path = JavaCore.getClasspathVariable("ECLIPSE_HOME");
68         // TODO: This should be a monitor messageDialog
69
messageDialog = new Shell(shell);
70
71         String JavaDoc fhome = ForrestPlugin.getDefault().getPluginPreferences()
72                 .getString(ForrestPreferences.FORREST_HOME);
73         
74         IPath workingDirectory = activeProject.getLocation();
75         
76         if (fhome.equals("")) {
77             messageDialog.setText("Configure Forrest");
78             messageDialog.setSize(400, 100);
79             statusMsg = new Label(messageDialog, SWT.NONE);
80             statusMsg
81                     .setText("Please configure Forrest by providing values for the required preferences");
82             statusMsg.setLocation(30, 25);
83             statusMsg.pack();
84             // TODO: Add an OK button
85
messageDialog.open();
86             // TODO: open the properties editor
87
return;
88         }
89         
90         Job forrest = ForrestManager.getInstance().getForrestJob(workingDirectory.toOSString(), ForrestManager.COMMAND_START);
91         forrest.setUser(true);
92         forrest.schedule();
93     }
94
95     /**
96      * @see IActionDelegate#selectionChanged(IAction, ISelection)
97      */

98     public void selectionChanged(IAction action, ISelection selection) {
99         if (selection instanceof IStructuredSelection) {
100             Object JavaDoc first = ((IStructuredSelection)selection).getFirstElement();
101             IResource resource = (IResource)first;
102             if (resource instanceof IProject) {
103                 activeProject = (IProject)resource;
104             }
105         }
106     }
107     
108 }
Popular Tags