| /******************************************************************************* |
| * Copyright (c) 2003, 2004, 2005 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jst.j2ee.application.internal.operations; |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.jst.j2ee.internal.servertarget.J2EEProjectServerTargetDataModel; |
| import org.eclipse.jst.j2ee.internal.servertarget.J2EEProjectServerTargetOperation; |
| import org.eclipse.wst.common.componentcore.StructureEdit; |
| import org.eclipse.wst.common.componentcore.internal.ProjectComponents; |
| import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; |
| import org.eclipse.wst.common.frameworks.internal.WTPProjectUtilities; |
| import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModel; |
| import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation; |
| |
| public class FlexibleProjectCreationOperation extends WTPOperation { |
| |
| public FlexibleProjectCreationOperation(FlexibleProjectCreationDataModel operationDataModel) { |
| super(operationDataModel); |
| // TODO Auto-generated constructor stub |
| } |
| |
| protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { |
| createProject(monitor); |
| addServerTarget(monitor); |
| WTPProjectUtilities.addNatureToProjectLast(getProject(), IModuleConstants.MODULE_NATURE_ID); |
| createInitialWTPModulesFile(); |
| } |
| |
| private void addServerTarget(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException{ |
| J2EEProjectServerTargetDataModel serverModel = ((FlexibleProjectCreationDataModel) operationDataModel).getServerTargetDataModel(); |
| J2EEProjectServerTargetOperation serverTargetOperation = (J2EEProjectServerTargetOperation)serverModel.getDefaultOperation(); |
| serverTargetOperation.doRun(monitor); |
| } |
| |
| private void createProject(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { |
| ProjectCreationDataModel projModel = ((FlexibleProjectCreationDataModel) operationDataModel).getProjectDataModel(); |
| WTPOperation op = projModel.getDefaultOperation(); |
| op.doRun(monitor); |
| } |
| |
| private void createInitialWTPModulesFile() { |
| StructureEdit moduleCore = null; |
| try { |
| IProject containingProject = getProject(); |
| moduleCore = StructureEdit.getStructureEditForWrite(containingProject); |
| moduleCore.prepareProjectComponentsIfNecessary(); |
| ProjectComponents projectModules = moduleCore.getComponentModelRoot(); |
| moduleCore.saveIfNecessary(null); |
| } finally { |
| if(moduleCore != null) |
| moduleCore.dispose(); |
| } |
| } |
| |
| protected IProject getProject() { |
| String name = (String) ((FlexibleProjectCreationDataModel) operationDataModel).getStringProperty(FlexibleProjectCreationDataModel.PROJECT_NAME); |
| if (name != null && name.length() > 0) |
| return ResourcesPlugin.getWorkspace().getRoot().getProject(name); |
| return null; |
| } |
| } |