bchilds | 25637a6 | 2008-04-30 19:06:32 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 11 | /** |
| 12 | * |
| 13 | */ |
| 14 | package org.eclipse.wst.jsdt.web.ui; |
| 15 | |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 16 | import org.eclipse.core.resources.IProject; |
| 17 | import org.eclipse.core.runtime.CoreException; |
| 18 | import org.eclipse.jface.action.IAction; |
| 19 | import org.eclipse.jface.viewers.ISelection; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 20 | import org.eclipse.jface.viewers.StructuredSelection; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 21 | import org.eclipse.ui.IActionDelegate; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 22 | import org.eclipse.ui.IObjectActionDelegate; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 23 | import org.eclipse.ui.IWorkbenchPart; |
pberkland | 82712a9 | 2008-04-30 17:09:15 +0000 | [diff] [blame] | 24 | import org.eclipse.wst.jsdt.core.IIncludePathEntry; |
| 25 | import org.eclipse.wst.jsdt.core.JavaScriptCore; |
| 26 | import org.eclipse.wst.jsdt.core.JavaScriptModelException; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 27 | import org.eclipse.wst.jsdt.internal.core.JavaProject; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 28 | import org.eclipse.wst.jsdt.web.core.internal.project.JsWebNature; |
| 29 | |
| 30 | /** |
bchilds | 25637a6 | 2008-04-30 19:06:32 +0000 | [diff] [blame] | 31 | * |
| 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 | * |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 38 | * @author childsb |
| 39 | * |
| 40 | */ |
| 41 | public class SetupProjectsWizzard implements IObjectActionDelegate, IActionDelegate { |
| 42 | |
| 43 | Object[] fTarget; |
| 44 | |
| 45 | public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
bchilds | 33749c3 | 2007-10-17 21:08:42 +0000 | [diff] [blame] | 46 | //throw new UnimplementedException("setActivePart(IAction action, IWorkbenchPart targetPart)"); |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 47 | } |
| 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 { |
pberkland | 82712a9 | 2008-04-30 17:09:15 +0000 | [diff] [blame] | 66 | JavaProject jp = (JavaProject)JavaScriptCore.create(project); |
| 67 | IIncludePathEntry[] rawClasspath = null; |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 68 | try { |
pberkland | 82712a9 | 2008-04-30 17:09:15 +0000 | [diff] [blame] | 69 | rawClasspath = jp.getRawIncludepath(); |
| 70 | } catch (JavaScriptModelException ex1) { |
bchilds | 7267f87 | 2007-09-12 18:43:28 +0000 | [diff] [blame] | 71 | // 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 | } |