summaryrefslogtreecommitdiffstats
path: root/scripting/java/org/openoffice/netbeans/modules/office/wizard
diff options
context:
space:
mode:
authorTomas O'Connor <toconnor@openoffice.org>2002-11-12 13:31:11 +0000
committerTomas O'Connor <toconnor@openoffice.org>2002-11-12 13:31:11 +0000
commite75a5b278c89166503ec8a875655724adb2b05a3 (patch)
tree23f81328bc7edf89423d65e40351ffe64c35aecc /scripting/java/org/openoffice/netbeans/modules/office/wizard
parentInitial checkin of org.openoffice.idesupport java package for shared (diff)
downloadcore-e75a5b278c89166503ec8a875655724adb2b05a3.tar.gz
core-e75a5b278c89166503ec8a875655724adb2b05a3.zip
Add Office Scripting in Java NetBeans module
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/wizard')
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle.properties50
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle_en_US.properties0
-rw-r--r--scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java245
3 files changed, 295 insertions, 0 deletions
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle.properties b/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle.properties
new file mode 100644
index 000000000000..4c089b7d3219
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle.properties
@@ -0,0 +1,50 @@
+# Window System API
+
+# TopComponent
+LBL_component_name=<name of component>
+#LBL_mode_name=<name of mode>
+#LBL_workspace_name=<name of workspace>
+
+# WizardDescriptor
+# Dialog title:
+TITLE_wizard=My Wizard
+
+# WizardDescriptor.Iterator
+# Label the sequence #. Appears at top of pane:
+# e.g. "Panel Name (1 of 3)"
+TITLE_x_of_y={0} of {1}
+# Provide list of steps to show in left pane:
+#LBL_step_1=Select First Thing
+#LBL_step_2=Configure Details
+
+# WizardDescriptor.Panel
+# Will appear in dialog title; see above
+TITLE_WizardPanel=Panel Name
+
+# CallableSystemAction
+LBL_Action=Run Action
+# Window System API
+
+# TopComponent
+LBL_component_name=<name of component>
+#LBL_mode_name=<name of mode>
+#LBL_workspace_name=<name of workspace>
+
+# WizardDescriptor
+# Dialog title:
+TITLE_wizard=My Wizard
+
+# WizardDescriptor.Iterator
+# Label the sequence #. Appears at top of pane:
+# e.g. "Panel Name (1 of 3)"
+TITLE_x_of_y={0} of {1}
+# Provide list of steps to show in left pane:
+#LBL_step_1=Select First Thing
+#LBL_step_2=Configure Details
+
+# WizardDescriptor.Panel
+# Will appear in dialog title; see above
+TITLE_WizardPanel=Panel Name
+
+# CallableSystemAction
+LBL_Action=Run Action
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle_en_US.properties b/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle_en_US.properties
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/Bundle_en_US.properties
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java
new file mode 100644
index 000000000000..30be84d0fa3d
--- /dev/null
+++ b/scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java
@@ -0,0 +1,245 @@
+package org.openoffice.netbeans.modules.office.wizard;
+
+import java.awt.Component;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import javax.swing.JComponent;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.openide.ErrorManager;
+import org.openide.TopManager;
+import org.openide.NotifyDescriptor;
+import org.openide.WizardDescriptor;
+import org.openide.cookies.OpenCookie;
+import org.openide.cookies.SourceCookie;
+import org.openide.loaders.*;
+import org.openide.util.NbBundle;
+import org.openide.filesystems.*;
+
+import org.openoffice.idesupport.zip.ParcelZipper;
+import org.openoffice.netbeans.modules.office.filesystem.OpenOfficeDocFileSystem;
+import org.openoffice.netbeans.modules.office.utils.PackageRemover;
+
+/** A template wizard iterator (sequence of panels).
+ * Used to fill in the second and subsequent panels in the New wizard.
+ * Associate this to a template inside a layer using the
+ * Sequence of Panels extra property.
+ * Create one or more panels from template as needed too.
+ *
+ * @author tomaso
+ */
+public class ParcelContentsIterator implements TemplateWizard.Iterator {
+
+
+ // private static final long serialVersionUID = ...L;
+
+ // You should define what panels you want to use here:
+
+ protected WizardDescriptor.Panel[] createPanels() {
+ return new WizardDescriptor.Panel[] {
+ // keep the default 2nd panel:
+ wiz.targetChooser(),
+ // new ParcelDescriptorPanel(),
+ };
+ }
+
+ // And the list of step names:
+
+ protected String[] createSteps() {
+ return new String[] {
+ null,
+ // "Parcel Properties",
+ };
+ }
+
+ private DataFolder checkTarget(DataFolder folder) {
+ FileObject fo = folder.getPrimaryFile();
+
+ try {
+ FileSystem fs = fo.getFileSystem();
+
+ if (fs instanceof OpenOfficeDocFileSystem && fo.isRoot()) {
+ FileObject scripts =
+ fo.getFileObject(OpenOfficeDocFileSystem.SCRIPTS_ROOT);
+ if (scripts == null)
+ scripts =
+ fo.createFolder(OpenOfficeDocFileSystem.SCRIPTS_ROOT);
+
+ FileObject javafolder = scripts.getFileObject("java");
+ if (javafolder == null)
+ javafolder = scripts.createFolder("java");
+
+ DataFolder subfolder = new DataFolder(javafolder);
+ return subfolder;
+ }
+ }
+ catch (IOException ioe) {
+ /* do nothing, we will just return the folder we were passed in */
+ }
+ return folder;
+ }
+
+ public Set instantiate(TemplateWizard wiz) throws IOException/*, IllegalStateException*/ {
+ String name = wiz.getTargetName();
+ DataFolder targetFolder = wiz.getTargetFolder();
+ targetFolder = checkTarget(targetFolder);
+
+ DataObject template = wiz.getTemplate();
+ DataObject result;
+ if (name == null) {
+ // Default name.
+ result = template.createFromTemplate(targetFolder);
+ } else {
+ result = template.createFromTemplate(targetFolder, name);
+ }
+
+ FileObject contents = result.getPrimaryFile().getFileObject(ParcelZipper.CONTENTS_DIRNAME);
+ DataFolder parent = DataFolder.findFolder(contents);
+ DataObject[] objs = parent.getChildren();
+
+ for (int i = 0; i < objs.length; i++) {
+ FileObject fo = objs[i].getPrimaryFile();
+ if (fo.getExt().equals("java")) {
+ try {
+ PackageRemover.removeDeclaration(FileUtil.toFile(fo));
+ }
+ catch (IOException ioe) {
+ NotifyDescriptor d = new NotifyDescriptor.Message(
+ "Error removing package declaration from file: " +
+ fo.getNameExt() +
+ ". You should manually remove this declaration before " +
+ "building the Parcel Recipe");
+ TopManager.getDefault().notify(d);
+ }
+ }
+ }
+
+ /* Uncomment this code to open the Parcel Descriptor file in an editor
+ * window
+ DataFolder parent = DataFolder.findFolder(result.getPrimaryFile());
+ DataObject[] objs = parent.getChildren();
+
+ if (objs != null) {
+ DataObject descriptor = objs[0];
+
+ OpenCookie open = (OpenCookie)descriptor.getCookie(OpenCookie.class);
+ if (open != null) {
+ open.open();
+ }
+ } */
+
+ /* Uncomment to open the Parcel in a new Explorer window
+ Node node = parent.getNodeDelegate();
+ TopManager.getDefault().getNodeOperation().explore(node);
+ */
+
+ return Collections.singleton(result);
+ }
+
+ // --- The rest probably does not need to be touched. ---
+
+ private transient int index;
+ private transient WizardDescriptor.Panel[] panels;
+ private transient TemplateWizard wiz;
+
+ // You can keep a reference to the TemplateWizard which can
+ // provide various kinds of useful information such as
+ // the currently selected target name.
+ // Also the panels will receive wiz as their "settings" object.
+ public void initialize(TemplateWizard wiz) {
+ this.wiz = wiz;
+ index = 0;
+ panels = createPanels();
+ // Make sure list of steps is accurate.
+ String[] steps = createSteps();
+ for (int i = 0; i < panels.length; i++) {
+ Component c = panels[i].getComponent();
+ if (steps[i] == null) {
+ // Default step name to component name of panel.
+ // Mainly useful for getting the name of the target
+ // chooser to appear in the list of steps.
+ steps[i] = c.getName();
+ }
+ if (c instanceof JComponent) { // assume Swing components
+ JComponent jc = (JComponent)c;
+ // Step #.
+ jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // NOI18N
+ // Step name (actually the whole list for reference).
+ jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
+ }
+ }
+ }
+ public void uninitialize(TemplateWizard wiz) {
+ this.wiz = null;
+ panels = null;
+ }
+
+ // --- WizardDescriptor.Iterator METHODS: ---
+ // Note that this is very similar to WizardDescriptor.Iterator, but with a
+ // few more options for customization. If you e.g. want to make panels appear
+ // or disappear dynamically, go ahead.
+
+ public String name() {
+ return "";
+ }
+
+ public boolean hasNext() {
+ return index < panels.length - 1;
+ }
+ public boolean hasPrevious() {
+ return index > 0;
+ }
+ public void nextPanel() {
+ if (!hasNext()) throw new NoSuchElementException();
+ index++;
+ }
+ public void previousPanel() {
+ if (!hasPrevious()) throw new NoSuchElementException();
+ index--;
+ }
+ public WizardDescriptor.Panel current() {
+ return panels[index];
+ }
+
+ // If nothing unusual changes in the middle of the wizard, simply:
+ public final void addChangeListener(ChangeListener l) {}
+ public final void removeChangeListener(ChangeListener l) {}
+ // If something changes dynamically (besides moving between panels),
+ // e.g. the number of panels changes in response to user input, then
+ // uncomment the following and call when needed:
+ // fireChangeEvent();
+ /*
+ private transient Set listeners = new HashSet(1); // Set<ChangeListener>
+ public final void addChangeListener(ChangeListener l) {
+ synchronized(listeners) {
+ listeners.add(l);
+ }
+ }
+ public final void removeChangeListener(ChangeListener l) {
+ synchronized(listeners) {
+ listeners.remove(l);
+ }
+ }
+ protected final void fireChangeEvent() {
+ Iterator it;
+ synchronized (listeners) {
+ it = new HashSet(listeners).iterator();
+ }
+ ChangeEvent ev = new ChangeEvent(this);
+ while (it.hasNext()) {
+ ((ChangeListener)it.next()).stateChanged(ev);
+ }
+ }
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ listeners = new HashSet(1);
+ }
+ */
+
+}