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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.apache.jmeter.module.wizards;
029:
030: import java.awt.Component;
031: import java.io.IOException;
032: import java.util.Collections;
033: import java.util.NoSuchElementException;
034: import java.util.Set;
035: import javax.swing.JComponent;
036: import javax.swing.event.ChangeListener;
037: import org.netbeans.api.project.Project;
038: import org.netbeans.spi.project.ui.templates.support.Templates;
039: import org.openide.WizardDescriptor;
040: import org.openide.WizardDescriptor.Panel;
041: import org.openide.filesystems.FileObject;
042: import org.openide.loaders.DataFolder;
043: import org.openide.loaders.DataObject;
044: import org.openide.loaders.TemplateWizard;
045: import org.openide.util.NbBundle;
046:
047: /**
048: *
049: * @author Jaroslav Bachorik
050: */
051: public class NewScriptIterator implements TemplateWizard.Iterator {
052:
053: private transient int index;
054: private transient WizardDescriptor.Panel[] panels;
055: private transient TemplateWizard wiz;
056:
057: private WizardDescriptor.Panel folderPanel;
058:
059: public static NewScriptIterator createInstance() {
060: return new NewScriptIterator();
061: }
062:
063: public void initialize(TemplateWizard wiz) {
064: this .wiz = wiz;
065: index = 0;
066: Project project = Templates.getProject(wiz);
067: panels = createPanels(project);
068:
069: // Creating steps.
070: Object prop = wiz.getProperty("WizardPanel_contentData"); // NOI18N
071: String[] beforeSteps = null;
072: if (prop != null && prop instanceof String[]) {
073: beforeSteps = (String[]) prop;
074: }
075: String[] steps = Utilities.createSteps(beforeSteps, panels);
076:
077: for (int i = 0; i < panels.length; i++) {
078: Component c = panels[i].getComponent();
079: if (steps[i] == null) {
080: // Default step name to component name of panel.
081: // Mainly useful for getting the name of the target
082: // chooser to appear in the list of steps.
083: steps[i] = c.getName();
084: }
085: if (c instanceof JComponent) {
086: // assume Swing components
087: JComponent jc = (JComponent) c;
088: // Step #.
089: jc.putClientProperty(
090: "WizardPanel_contentSelectedIndex",
091: new Integer(i)); // NOI18N
092: // Step name (actually the whole list for reference).
093: jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
094: }
095: }
096: }
097:
098: public Set<DataObject> instantiate(TemplateWizard wiz)
099: throws IOException {
100: org.openide.filesystems.FileObject dir = Templates
101: .getTargetFolder(wiz);
102: DataFolder df = DataFolder.findFolder(dir);
103: FileObject template = Templates.getTemplate(wiz);
104: // FileObject templateParent = template.getParent();
105: // TargetChooserPanel panel = (TargetChooserPanel) folderPanel;
106: DataObject dTemplate = DataObject.find(template);
107: DataObject dobj = dTemplate.createFromTemplate(df, Templates
108: .getTargetName(wiz));
109:
110: return Collections.singleton(dobj);
111: }
112:
113: public void uninitialize(TemplateWizard wiz) {
114: this .wiz = null;
115: panels = null;
116: }
117:
118: public void addChangeListener(ChangeListener l) {
119: }
120:
121: public Panel<WizardDescriptor> current() {
122: return panels[index];
123: }
124:
125: public boolean hasNext() {
126: return index < panels.length - 1;
127: }
128:
129: public boolean hasPrevious() {
130: return index > 0;
131: }
132:
133: public String name() {
134: return NbBundle.getMessage(NewScriptIterator.class,
135: "TITLE_x_of_y", new Integer(index + 1), new Integer(
136: panels.length));
137: }
138:
139: public void nextPanel() {
140: if (!hasNext())
141: throw new NoSuchElementException();
142: index++;
143: }
144:
145: public void previousPanel() {
146: if (!hasPrevious())
147: throw new NoSuchElementException();
148: index--;
149: }
150:
151: public void removeChangeListener(ChangeListener l) {
152: }
153:
154: // You should define what panels you want to use here:
155: protected WizardDescriptor.Panel[] createPanels(Project project) {
156:
157: folderPanel = new TargetChooserPanel(project);
158: return new WizardDescriptor.Panel[] { folderPanel };
159: }
160: }
|