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.uml.codegen.action;
043:
044: import java.util.HashMap;
045: import java.util.Properties;
046:
047: import org.openide.util.Lookup;
048: import org.openide.util.NbBundle;
049:
050: import org.netbeans.api.progress.aggregate.ProgressContributor;
051: import org.netbeans.api.progress.aggregate.AggregateProgressFactory;
052:
053: import org.netbeans.modules.uml.core.coreapplication.ICodeGenerator;
054: import org.netbeans.modules.uml.core.coreapplication.ICodeGeneratorFactory;
055: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
056: import org.netbeans.modules.uml.core.support.umlutils.ETList;
057: import org.netbeans.modules.uml.util.AbstractNBTask;
058:
059: public class GenerateCodeTask extends AbstractNBTask {
060: private ETList<IElement> elements;
061: private String projectName;
062: private String sourceFolderName;
063: private final static int SUBTASK_TOT = 1;
064: private boolean backup = true;
065: private boolean generateMarkers = true;
066: private boolean addMarkers = false;
067: private boolean showGCDialog = true;
068:
069: //Kris Richards - this is no longer an option. Set to default value.
070: public final static String ATTR_PREFIX = "m"; // NOI18N
071:
072: public GenerateCodeTask(HashMap settings,
073: ETList<IElement> selElements, String umlProjectName,
074: String destFolderName, boolean backupFiles,
075: boolean generateMarkers, boolean addMarkers,
076: boolean showGCDialog) {
077: super (settings);
078: elements = selElements;
079: projectName = umlProjectName;
080: sourceFolderName = destFolderName;
081: backup = backupFiles;
082: this .generateMarkers = generateMarkers;
083: this .addMarkers = addMarkers;
084: this .showGCDialog = showGCDialog;
085: }
086:
087: protected void initTask() {
088: setLogLevel(TERSE);
089: setTaskName(getBundleMessage("LBL_GenerateCodeDialogTitle")); // NOI18N
090:
091: //Kris Richards - preference now hidden - always yes.
092:
093: setDisplayOutput(true);
094:
095: progressContribs = new ProgressContributor[SUBTASK_TOT];
096: int i = 0;
097:
098: progressContribs[i] = AggregateProgressFactory
099: .createProgressContributor(getBundleMessage("MSG_Processing")); // NOI18N
100: }
101:
102: protected void begin() {
103: exportCode();
104: }
105:
106: protected void finish() {
107: }
108:
109: /**
110: * @param elements The collection of elements to generate for
111: *
112: */
113: private void exportCode() {
114: if (elements == null || elements.size() == 0) {
115: return;
116: }
117: ICodeGeneratorFactory factory = (ICodeGeneratorFactory) Lookup
118: .getDefault().lookup(ICodeGeneratorFactory.class);
119:
120: ICodeGenerator cg = factory.getCodeGenerator("Java"); // NOI18N
121: Properties genProps = new Properties();
122: genProps.setProperty("generateMarkers", new Boolean(
123: generateMarkers).toString()); // NOI18N
124: genProps.setProperty("addMarkers", new Boolean(addMarkers)
125: .toString()); // NOI18N
126: genProps.setProperty("backup", new Boolean(backup).toString()); // NOI18N
127: cg.generate(this , elements, sourceFolderName, genProps);
128: }
129:
130: private static String getBundleMessage(String key) {
131: return NbBundle.getMessage(GenerateCodeTask.class, key);
132: }
133:
134: }
|