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-2006 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: package org.netbeans.modules.vmd.api.model.utils;
042:
043: import java.io.IOException;
044:
045: import javax.swing.undo.UndoableEdit;
046:
047: import org.netbeans.modules.vmd.api.model.DesignDocument;
048: import org.netbeans.modules.vmd.api.model.DocumentInterface;
049: import org.openide.filesystems.FileObject;
050: import org.openide.filesystems.FileSystem;
051: import org.openide.filesystems.FileUtil;
052: import org.openide.filesystems.Repository;
053:
054: /**
055: *
056: * @author Karol Harezlak
057: */
058: public class ModelTestUtil {
059:
060: public final static String PRESENTER_1_ID = "PRESENTER1"; // NOI18N
061: public final static String PRESENTER_2_ID = "PRESENTER2"; // NOI18N
062: public final static String PRESENTER_3_ID = "PRESENTER3"; // NOI18N
063: public final static String PRESENTER_4_ID = "PRESENTER4"; // NOI18N
064:
065: public final static String PROJECT_TYPE = "vmd"; //NOI18N
066: public final static String FOLDER_PATH_COMPONENTS = "/components"; // NOI18N
067: public final static String FOLDER_PATH_PRODUCERS = "/producers"; // NOI18N
068:
069: public final static String FIRST_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-FirstCD.instance"; // NOI18N
070: public final static String SECOND_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-SecondCD.instance"; // NOI18N
071: public final static String SUPER_FIRST_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-SuperFirstCD.instance"; // NOI18N
072: public final static String ENUM_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-EnumCD.instance"; // NOI18N
073: public final static String CANT_INSTANTIATE_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-CantInstantiateCD.instance"; // NOI18N
074: public final static String CANT_DERIVE_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-CantDeriveCD.instance"; // NOI18N
075: public final static String SUPER_CANT_DERIVE_FILE_NAME_CD = "org-netbeans-modules-vmd-api-model-descriptors-SuperCantDeriveCD.instance"; // NOI18N
076:
077: public final static String PROJECT_ID = "TEST_PROJECT"; // NOI18N
078:
079: public static DesignDocument createTestDesignDocument(
080: String projectID) {
081: return new DesignDocument(
082: createTestDocumentInterface(projectID));
083: }
084:
085: /**
086: * Creates new project
087: * @return project
088: */
089: public static DocumentInterface createTestDocumentInterface(
090: String projectID) {
091: return new DocumentInterface() {
092:
093: public String getProjectID() {
094: return PROJECT_ID;
095: }
096:
097: public String getProjectType() {
098: return "vmd"; // NOI18N
099: }
100:
101: public void undoableEditHappened(UndoableEdit edit) {
102: //TODO empty method
103: }
104:
105: public void notifyModified() {
106: }
107:
108: public void discardAllEdits() {
109: }
110:
111: };
112: }
113:
114: /**
115: * Returns folders if exists or creates new ones
116: * @param folder path example ("vmd/components")
117: * @return folder
118: */
119: public static FileObject getTestFolder(String folderPath) {
120: FileObject folder = null;
121: FileSystem fs = Repository.getDefault().getDefaultFileSystem();
122:
123: try {
124: folder = FileUtil.createFolder(fs.getRoot(), folderPath);
125: } catch (IOException ex) {
126: ex.printStackTrace();
127: }
128:
129: return folder;
130: }
131:
132: public static FileObject getTestFileObject(FileObject folder,
133: String fileName) {
134: FileObject file = folder.getFileObject(fileName);
135:
136: if (file == null) {
137: try {
138: file = folder.createData(fileName);
139: } catch (IOException ex) {
140: ex.printStackTrace();
141: file = null;
142: }
143: }
144:
145: return file;
146: }
147:
148: /**
149: * Returns Desgign document and registering descriptor components.
150: * @return document
151: */
152: public static DesignDocument createTestDesignDocument() {
153: //have to create additional folder for producers
154: getTestFolder(ModelTestUtil.PROJECT_TYPE
155: + FOLDER_PATH_PRODUCERS);
156: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
157: + FOLDER_PATH_COMPONENTS), SUPER_FIRST_FILE_NAME_CD);
158: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
159: + FOLDER_PATH_COMPONENTS),
160: SUPER_CANT_DERIVE_FILE_NAME_CD);
161: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
162: + FOLDER_PATH_COMPONENTS), FIRST_FILE_NAME_CD);
163: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
164: + FOLDER_PATH_COMPONENTS), SECOND_FILE_NAME_CD);
165: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
166: + FOLDER_PATH_COMPONENTS),
167: CANT_INSTANTIATE_FILE_NAME_CD);
168: getTestFileObject(getTestFolder(ModelTestUtil.PROJECT_TYPE
169: + FOLDER_PATH_COMPONENTS), CANT_DERIVE_FILE_NAME_CD);
170:
171: return ModelTestUtil
172: .createTestDesignDocument(ModelTestUtil.SUPER_FIRST_FILE_NAME_CD);
173: }
174: }
|