blob: d2903beebb3393984ff07146755d41b783aa5243 [file] [log] [blame]
bchilds25637a62008-04-30 19:06:32 +00001/*******************************************************************************
2 * Copyright (c) 2007, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
bchilds7267f872007-09-12 18:43:28 +000011/**
12 *
13 */
14package org.eclipse.wst.jsdt.web.ui;
15
bchilds7267f872007-09-12 18:43:28 +000016import org.eclipse.core.resources.IProject;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.jface.action.IAction;
19import org.eclipse.jface.viewers.ISelection;
bchilds7267f872007-09-12 18:43:28 +000020import org.eclipse.jface.viewers.StructuredSelection;
bchilds7267f872007-09-12 18:43:28 +000021import org.eclipse.ui.IActionDelegate;
bchilds7267f872007-09-12 18:43:28 +000022import org.eclipse.ui.IObjectActionDelegate;
bchilds7267f872007-09-12 18:43:28 +000023import org.eclipse.ui.IWorkbenchPart;
pberkland82712a92008-04-30 17:09:15 +000024import org.eclipse.wst.jsdt.core.IIncludePathEntry;
25import org.eclipse.wst.jsdt.core.JavaScriptCore;
26import org.eclipse.wst.jsdt.core.JavaScriptModelException;
bchilds7267f872007-09-12 18:43:28 +000027import org.eclipse.wst.jsdt.internal.core.JavaProject;
bchilds7267f872007-09-12 18:43:28 +000028import org.eclipse.wst.jsdt.web.core.internal.project.JsWebNature;
29
30/**
bchilds25637a62008-04-30 19:06:32 +000031*
32
33* Provisional API: This class/interface is part of an interim API that is still under development and expected to
34* change significantly before reaching stability. It is being made available at this early stage to solicit feedback
35* from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
36* (repeatedly) as the API evolves.
37*
bchilds7267f872007-09-12 18:43:28 +000038 * @author childsb
39 *
40 */
41public class SetupProjectsWizzard implements IObjectActionDelegate, IActionDelegate {
42
43 Object[] fTarget;
44
45 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
bchilds33749c32007-10-17 21:08:42 +000046 //throw new UnimplementedException("setActivePart(IAction action, IWorkbenchPart targetPart)");
bchilds7267f872007-09-12 18:43:28 +000047 }
48
49 public void run(IAction action) {
50 if(fTarget==null) return;
51
52 for(int i=0;i<fTarget.length;i++) {
53 if(fTarget[i] instanceof IProject) {
54 IProject project = (IProject)fTarget[i];
55
56 if(!JsWebNature.hasNature(project)) {
57 JsWebNature nature = new JsWebNature(project,null);
58 try {
59 nature.configure();
60
61 } catch (CoreException ex) {
62 // TODO Auto-generated catch block
63 ex.printStackTrace();
64 }
65 }else {
pberkland82712a92008-04-30 17:09:15 +000066 JavaProject jp = (JavaProject)JavaScriptCore.create(project);
67 IIncludePathEntry[] rawClasspath = null;
bchilds7267f872007-09-12 18:43:28 +000068 try {
pberkland82712a92008-04-30 17:09:15 +000069 rawClasspath = jp.getRawIncludepath();
70 } catch (JavaScriptModelException ex1) {
bchilds7267f872007-09-12 18:43:28 +000071 // TODO Auto-generated catch block
72 ex1.printStackTrace();
73 }
74
75
76 /* see if project has web cp entry and if it does leave */
77 for(int k = 0;rawClasspath!=null && k<rawClasspath.length;k++) {
78 if(rawClasspath[k].getPath().equals(JsWebNature.VIRTUAL_BROWSER_CLASSPATH)) {
79 return;
80 }
81 }
82 JsWebNature nature = new JsWebNature(project,null);
83 try {
84 nature.configure();
85
86 } catch (CoreException ex) {
87 // TODO Auto-generated catch block
88 ex.printStackTrace();
89 }
90 }
91
92
93 }
94 }
95
96 }
97
98 public void selectionChanged(IAction action, ISelection selection) {
99
100 if(selection instanceof StructuredSelection) {
101 fTarget = ((StructuredSelection)selection).toArray();
102 }else {
103 fTarget = null;
104 }
105 }
106
107
108}