001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.ffj.wizards;
007:
008: import java.util.Set;
009: import java.util.Collections;
010: import java.util.Enumeration;
011:
012: import java.io.IOException;
013: import java.io.ObjectStreamException;
014: import java.io.File;
015:
016: import java.awt.Component;
017:
018: import javax.swing.event.ChangeListener;
019:
020: import org.openide.WizardDescriptor;
021: import org.openide.TopManager;
022: import org.openide.ErrorManager;
023: import org.openide.NotifyDescriptor;
024:
025: import org.openide.util.NbBundle;
026:
027: import org.openide.execution.NbClassPath;
028:
029: import org.openide.loaders.TemplateWizard;
030: import org.openide.loaders.DataObject;
031: import org.openide.loaders.DataFolder;
032:
033: import org.openide.filesystems.FileSystem;
034: import org.openide.filesystems.Repository;
035: import org.openide.filesystems.LocalFileSystem;
036: import org.openide.filesystems.FileObject;
037:
038: import com.sun.portal.ffj.filesystems.PSFileSystem;
039:
040: import com.sun.portal.ffj.util.PSConstants;
041: import com.sun.portal.ffj.util.PortletWebInf;
042:
043: /** Iterator implementation which can iterate through three
044: * panels which forms jar template wizard
045: */
046: public final class GroupIterator implements TemplateWizard.Iterator,
047: PSConstants {
048:
049: /** No need to be public, access is provided through singleton()
050: * method call */
051: private GroupIterator() {
052: super ();
053: }
054:
055: /** @return Returns singleton instance of this iterator */
056: public static GroupIterator singleton() {
057: if (m_Singleton == null) {
058: m_Singleton = new GroupIterator();
059: }
060: return m_Singleton;
061: }
062:
063: //
064: // WizardDescriptorInterface methods implemented here.
065: //
066:
067: public void initialize(TemplateWizard tw) {
068: if (m_ArrayIterator == null) {
069: initializePanelNames();
070: Component panel = tw.targetChooser().getComponent();
071: if (panel instanceof javax.swing.JComponent) {
072: ((javax.swing.JComponent) panel).putClientProperty(
073: "WizardPanel_contentData", m_PanelNames);//NOI18N
074: }
075:
076: // build the array of panels
077: WizardDescriptor.Panel[] panelArray = initializePanels(tw);
078: m_ArrayIterator = new WizardDescriptor.ArrayIterator(
079: panelArray);
080: }
081: }
082:
083: /** Initializes all panels of jar wizard. */
084: protected WizardDescriptor.Panel[] initializePanels(
085: TemplateWizard tw) {
086: m_TemplateWizard = tw;
087: WizardDescriptor.Panel[] panelArray = new WizardDescriptor.Panel[1];
088: panelArray[0] = tw.targetChooser();
089: return panelArray;
090: }
091:
092: public void initializePanelNames() {
093: if (m_PanelNames == null) {
094: m_PanelNames = new String[1];
095: m_PanelNames[0] = "";
096: }
097: }
098:
099: public void uninitialize(TemplateWizard tw) {
100: m_TemplateWizard = null;
101: m_ArrayIterator = null;
102: }
103:
104: public String name() {
105: return NbBundle.getMessage(GroupIterator.class,
106: "GroupWizard.Title");
107: }
108:
109: public Set instantiate(TemplateWizard wiz) throws IOException {
110:
111: // force creation of filesystem, if it has to happen, before we create.
112:
113: PSFileSystem.getPSFilesystem(true);
114:
115: // Just do default template creation, with a name check.
116:
117: String nm = wiz.getTargetName();
118: DataFolder fold = wiz.getTargetFolder();
119: DataObject tpl = wiz.getTemplate();
120:
121: if (!nameLegal(nm)) {
122: TopManager.getDefault().notify(
123: new NotifyDescriptor.Message(NbBundle.getMessage(
124: GroupIterator.class,
125: "GroupWizard.NotJavaID"),
126: NotifyDescriptor.INFORMATION_MESSAGE));
127: return Collections.singleton(null);
128: }
129:
130: DataObject obj = tpl.createFromTemplate(fold, nm);
131:
132: return java.util.Collections.singleton(obj);
133: }
134:
135: //
136: // WizardDescriptorInterface methods delegated to the ArrayIterator
137: //
138:
139: /* The current panel.
140: */
141: public WizardDescriptor.Panel current() {
142: return m_ArrayIterator.current();
143: }
144:
145: /* Is there a next panel?
146: * @return true if so
147: */
148: public boolean hasNext() {
149: return m_ArrayIterator.hasNext();
150: }
151:
152: /* Is there a previous panel?
153: * @return true if so
154: */
155: public boolean hasPrevious() {
156: return m_ArrayIterator.hasNext();
157: }
158:
159: /* Moves to the next panel.
160: * @exception NoSuchElementException if the panel does not exist
161: */
162: public synchronized void nextPanel() {
163: m_ArrayIterator.nextPanel();
164: }
165:
166: /* Moves to previous panel.
167: * @exception NoSuchElementException if the panel does not exist
168: */
169: public synchronized void previousPanel() {
170: m_ArrayIterator.previousPanel();
171: }
172:
173: /* Ignores the listener, there are no changes in order of panels.
174: */
175: public void addChangeListener(ChangeListener l) {
176: m_ArrayIterator.addChangeListener(l);
177: }
178:
179: /* Ignored.
180: */
181: public void removeChangeListener(ChangeListener l) {
182: m_ArrayIterator.removeChangeListener(l);
183: }
184:
185: private boolean nameLegal(String nm) {
186: if (nm == null) {
187: return false;
188: }
189: char c1 = nm.charAt(0);
190: if (!Character.isJavaIdentifierStart(c1)) {
191: return false;
192: }
193: for (int i = 1; i < nm.length(); ++i) {
194: char ci = nm.charAt(i);
195: if (!Character.isJavaIdentifierPart(ci)) {
196: return false;
197: }
198: }
199: return true;
200: }
201:
202: private transient TemplateWizard m_TemplateWizard = null;
203: private transient String[] m_PanelNames = null;
204:
205: //
206: // This gets created in the call to initialize(TemplateWizard)
207: //
208: private WizardDescriptor.ArrayIterator m_ArrayIterator = null;
209:
210: private static GroupIterator m_Singleton;
211: }
|