001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.gravy.model.project;
043:
044: import org.netbeans.jemmy.operators.JButtonOperator;
045: import org.netbeans.jemmy.operators.JCheckBoxOperator;
046: import org.netbeans.jemmy.operators.JDialogOperator;
047: import org.netbeans.jemmy.operators.JTreeOperator;
048: import org.netbeans.jemmy.operators.JComboBoxOperator;
049: import org.netbeans.jemmy.operators.JTextFieldOperator;
050: import org.netbeans.jemmy.JemmyException;
051: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
052: import org.netbeans.modules.visualweb.gravy.TestUtils;
053: import org.netbeans.modules.visualweb.gravy.Bundle;
054:
055: import java.io.File;
056:
057: /**
058: * Default factory for creation of projects.
059: */
060:
061: public class DefaultProjectFactory extends ProjectFactory {
062:
063: private final static String bundle = "org.netbeans.modules.visualweb.gravy.model.project.Bundle";
064:
065: /**
066: * Type of project.
067: */
068: private final static String projectType = Bundle.getStringTrimmed(
069: Bundle.getStringTrimmed(bundle, "ProjectWizardBundle"),
070: Bundle.getStringTrimmed(bundle, "ProjectType"));
071:
072: /**
073: * Category of project.
074: */
075: private final static String projectCategory = Bundle
076: .getStringTrimmed(Bundle.getStringTrimmed(bundle,
077: "ProjectWizardBundle"), Bundle.getStringTrimmed(
078: bundle, "ProjectCategory"));
079:
080: private final static String blueprintsStructure = Bundle
081: .getStringTrimmed(Bundle.getStringTrimmed(bundle,
082: "ProjectWizardBundle"), Bundle.getStringTrimmed(
083: bundle, "JavaBluePrints"));
084:
085: private final static String jakartaStructure = Bundle
086: .getStringTrimmed(Bundle.getStringTrimmed(bundle,
087: "ProjectWizardBundle"), Bundle.getStringTrimmed(
088: bundle, "Jakarta"));
089:
090: /**
091: * Default project factory.
092: */
093: private static DefaultProjectFactory defaultPFactory;
094:
095: /**
096: * Create new DefaultProjectFactory.
097: */
098: public DefaultProjectFactory() {
099: }
100:
101: /**
102: * Create instance of DefaultProjectFactory or return it, if it is already exist.
103: * Singleton.
104: * @return DefaultProjectFactory.
105: */
106: public static DefaultProjectFactory getFactory() {
107: if (defaultPFactory != null)
108: return defaultPFactory;
109: else
110: return (defaultPFactory = new DefaultProjectFactory());
111: }
112:
113: /**
114: * Create new project.
115: * @param projectDescriptor Descriptor of project.
116: * @return created project.
117: */
118: protected Project createProject(ProjectDescriptor projectDescriptor) {
119: String _projectPath = projectDescriptor
120: .getProperty(projectDescriptor.LOCATION_KEY);
121: String _projectName = projectDescriptor
122: .getProperty(projectDescriptor.NAME_KEY);
123: String _J2EEVersion = projectDescriptor
124: .getProperty(projectDescriptor.J2EEVERSION_KEY);
125: String _targetServer = projectDescriptor
126: .getProperty(projectDescriptor.SERVER_KEY);
127: if (_projectPath.lastIndexOf(File.separator) != _projectPath
128: .length() - 1)
129: _projectPath = _projectPath + File.separator;
130: try {
131: TestUtils.createNewProject(_projectPath, _projectName,
132: true, projectType, projectCategory,
133: blueprintsStructure, _J2EEVersion, _targetServer);
134: } catch (Exception e) {
135: throw new JemmyException("Project can't be created!", e);
136: }
137: return new JSFWebProject(projectDescriptor);
138: }
139:
140: /**
141: * Open existing project.
142: * @param pathToProject Path to project's folder.
143: * @return opened project.
144: */
145: protected Project openProject(String pathToProject) {
146: try {
147: TestUtils.openProject(pathToProject);
148: } catch (Exception e) {
149: throw new JemmyException("Project can't be opened!", e);
150: }
151: String projectName = pathToProject.substring(pathToProject
152: .lastIndexOf(File.separator) + 1, pathToProject
153: .length());
154: String projectLocation = pathToProject.substring(0,
155: pathToProject.lastIndexOf(File.separator) + 1);
156: ProjectNavigatorOperator.pressPopupItemOnNode(projectName,
157: "Properties");
158: JDialogOperator propertiesDialog = new JDialogOperator(
159: "Project Properties - " + projectName);
160: TestUtils.wait(1000);
161: JTreeOperator tree = new JTreeOperator(propertiesDialog);
162: tree.selectPath(tree.findPath("Run"));
163: TestUtils.wait(1000);
164: String targetServer = new JComboBoxOperator(propertiesDialog)
165: .getSelectedItem().toString();
166: String J2EEVersion = new JTextFieldOperator(propertiesDialog, 0)
167: .getText();
168: new JButtonOperator(propertiesDialog, "OK").pushNoBlock();
169: TestUtils.wait(1000);
170: System.out.println("projectName=" + projectName
171: + "; projectLocation=" + projectLocation
172: + "; J2EEVersion=" + J2EEVersion + "; targetServer="
173: + targetServer);
174: ProjectDescriptor projectDescriptor = new ProjectDescriptor(
175: projectName, projectLocation, J2EEVersion, targetServer);
176: return new JSFWebProject(projectDescriptor);
177: }
178: }
|