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:
042: package org.netbeans.modules.j2me.cdc.platform.wizard;
043:
044: import java.io.IOException;
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import java.util.Collections;
048:
049: import javax.swing.event.ChangeListener;
050:
051: import org.netbeans.api.java.platform.JavaPlatform;
052: import org.netbeans.modules.j2me.cdc.platform.CDCPlatform;
053: import org.netbeans.modules.j2me.cdc.platform.platformdefinition.PlatformConvertor;
054: import org.netbeans.modules.j2me.cdc.platform.spi.CDCPlatformDetector;
055: import org.openide.ErrorManager;
056: import org.openide.WizardDescriptor;
057: import org.openide.filesystems.FileObject;
058: import org.openide.filesystems.Repository;
059: import org.openide.loaders.DataFolder;
060: import org.openide.loaders.DataObject;
061: import org.openide.util.NbBundle;
062:
063: /**
064: * Wizard Iterator for standard J2SE platforms. It assumes that there is a
065: * 'bin{/}java[.exe]' underneath the platform's directory, which can be run to
066: * produce the target platform's VM environment.
067: *
068: * @author Svata Dedic, Tomas Zezula
069: */
070: public class CDCWizardIterator implements
071: WizardDescriptor.InstantiatingIterator {
072:
073: static final String CDC_PLATFORM_PROP = "cdcplatfrom";
074:
075: DataFolder installFolder;
076: DetectPanel.WizardPanel detectPanel;
077: Collection<ChangeListener> listeners;
078: CDCPlatform platform;
079: WizardDescriptor wizard;
080: int currentIndex;
081: CDCPlatformDetector detector;
082:
083: /**
084: * @param type @see CDCPlatformImpl.java
085: */
086: public CDCWizardIterator(FileObject installFolder,
087: CDCPlatformDetector detector) {
088: this .detector = detector;
089: this .installFolder = DataFolder.findFolder(installFolder);
090: listeners = new ArrayList<ChangeListener>();
091: }
092:
093: FileObject getInstallFolder() {
094: return installFolder.getPrimaryFile();
095: }
096:
097: public void addChangeListener(ChangeListener l) {
098: listeners.add(l);
099: }
100:
101: public WizardDescriptor.Panel current() {
102: switch (this .currentIndex) {
103: case 0:
104: return this .detectPanel;
105: default:
106: throw new IllegalStateException();
107: }
108: }
109:
110: public boolean hasNext() {
111: return false;
112: }
113:
114: public boolean hasPrevious() {
115: return false;
116: }
117:
118: public void initialize(WizardDescriptor wiz) {
119: this .wizard = wiz;
120: this .detectPanel = new DetectPanel.WizardPanel(this , detector);
121: this .currentIndex = 0;
122: }
123:
124: /**
125: * This finally produces the java platform's XML that represents the basic
126: * platform's properties. The XML is returned in the resulting Set.
127: * @return singleton Set with java platform's instance DO inside.
128: */
129: public java.util.Set instantiate() throws IOException {
130: //Workaround #44444
131: this .detectPanel.storeSettings(this .wizard);
132: CDCPlatform newPlatform = getPlatform();
133: final String systemName = platform.getAntName();
134: FileObject platformsFolder = Repository
135: .getDefault()
136: .getDefaultFileSystem()
137: .findResource(
138: "Services/Platforms/org-netbeans-api-java-Platform"); //NOI18N
139: if (platformsFolder.getFileObject(systemName, "xml") != null) { //NOI18N
140: String msg = NbBundle.getMessage(CDCWizardIterator.class,
141: "ERROR_InvalidName");
142: throw (IllegalStateException) ErrorManager.getDefault()
143: .annotate(new IllegalStateException(msg),
144: ErrorManager.USER, null, msg, null, null);
145: }
146: DataObject dobj = PlatformConvertor.create(newPlatform,
147: DataFolder.findFolder(platformsFolder), systemName);
148: JavaPlatform platform = (JavaPlatform) dobj.getNodeDelegate()
149: .getLookup().lookup(JavaPlatform.class);
150: return Collections.singleton(platform);
151: }
152:
153: public String name() {
154: return NbBundle.getMessage(CDCWizardIterator.class,
155: "TITLE_PlatformName");
156: }
157:
158: public void nextPanel() {
159: this .currentIndex++;
160: }
161:
162: public void previousPanel() {
163: this .currentIndex--;
164: }
165:
166: public void removeChangeListener(ChangeListener l) {
167: listeners.add(l);
168: }
169:
170: public void uninitialize(WizardDescriptor wiz) {
171: this .wizard = null;
172: this .detectPanel = null;
173: }
174:
175: public CDCPlatform getPlatform() {
176: return platform;
177: }
178:
179: public void setPlatform(CDCPlatform platform) {
180: this.platform = platform;
181: }
182: }
|