KickJava   Java API By Example, From Geeks To Geeks.

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


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 BuildSite
39 implements IObjectActionDelegate, IJavaLaunchConfigurationConstants {
40
41     private IProject activeProject;
42     
43     /**
44      * Constructor for Action1.
45      */

46     public BuildSite() {
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         String JavaDoc cmdString = null;
61         IPath path = JavaCore.getClasspathVariable("ECLIPSE_HOME");
62
63         // TODO: move preferences code to utilities class
64
String JavaDoc fhome = ForrestPlugin.getDefault().getPluginPreferences()
65                 .getString(ForrestPreferences.FORREST_HOME);
66         
67         if (fhome.equals("")) {
68             Shell dialog = new Shell(new Shell());
69             dialog.setText("Configure Forrest");
70             dialog.setSize(400, 100);
71             Label statusMsg = new Label(dialog, SWT.NONE);
72             statusMsg
73                     .setText("Please configure Forrest by providing values for the required preferences");
74             statusMsg.setLocation(30, 25);
75             statusMsg.pack();
76             // TODO: Add an OK button
77
dialog.open();
78             // TODO: open the properties editor
79
return;
80         }
81
82         IPath workingDirectory = activeProject.getLocation();
83         
84         Job forrest = ForrestManager.getInstance().getForrestJob(workingDirectory.toOSString(), ForrestManager.COMMAND_BUILD);
85         forrest.setUser(true);
86         forrest.schedule();
87     }
88
89     /**
90      * @see IActionDelegate#selectionChanged(IAction, ISelection)
91      */

92     public void selectionChanged(IAction action, ISelection selection) {
93         if (selection instanceof IStructuredSelection) {
94             Object JavaDoc first = ((IStructuredSelection)selection).getFirstElement();
95             IResource resource = (IResource)first;
96             if (resource instanceof IProject) {
97                 activeProject = (IProject)resource;
98             }
99         }
100     }
101
102 }
Popular Tags