Add Office Scripting in Java NetBeans module

This commit is contained in:
Tomas O'Connor
2002-11-12 13:31:11 +00:00
parent ebb5dbaabb
commit e75a5b278c
73 changed files with 5148 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package org.openoffice.netbeans.modules.office.actions;
import java.util.Vector;
import java.util.Enumeration;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.RequestProcessor;
import org.openide.actions.BuildAllAction;
import org.openide.compiler.Compiler;
import org.openide.compiler.CompilerJob;
import org.openide.compiler.CompilerTask;
import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker;
public class BuildParcelAction extends BuildAllAction {
public String getName() {
return "Build";
}
protected void performAction(Node[] activatedNodes) {
FrameworkJarChecker.mountDependencies();
for (int i = 0; i < activatedNodes.length; i++) {
Vector v = new Vector(1);
v.addElement(activatedNodes[i]);
CompilerJob job = createJob(v.elements(), Compiler.DEPTH_INFINITE);
CompilerTask task = job.start();
task.waitFinished();
if (task.isSuccessful()) {
ParcelFolderCookie cookie = (ParcelFolderCookie)
activatedNodes[i].getCookie(ParcelFolderCookie.class);
if (cookie != null)
cookie.generate();
}
}
// FrameworkJarChecker.unmountDependencies();
}
}

View File

@@ -0,0 +1,18 @@
package org.openoffice.netbeans.modules.office.actions;
import org.openide.nodes.Node;
import org.openide.actions.CompileAllAction;
import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker;
public class CompileParcelAction extends CompileAllAction {
public String getName() {
return "Compile";
}
protected void performAction(Node[] activatedNodes) {
FrameworkJarChecker.mountDependencies();
super.performAction(activatedNodes);
// FrameworkJarChecker.unmountDependencies();
}
}

View File

@@ -0,0 +1,43 @@
package org.openoffice.netbeans.modules.office.actions;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.RequestProcessor;
import org.openide.util.actions.CookieAction;
import org.openoffice.netbeans.modules.office.utils.FrameworkJarChecker;
public class ConfigureParcelAction extends CookieAction {
public java.lang.String getName() {
return "Configure";
}
protected java.lang.Class[] cookieClasses() {
return new Class[] {ParcelFolderCookie.class};
}
protected int mode() {
return CookieAction.MODE_EXACTLY_ONE;
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
protected void performAction(final Node[] activatedNodes)
{
RequestProcessor.getDefault().post(new Runnable() {
public void run() {
FrameworkJarChecker.mountDependencies();
for (int i = 0; i < activatedNodes.length; i++) {
ParcelFolderCookie pfc = (ParcelFolderCookie)
activatedNodes[i].getCookie(ParcelFolderCookie.class);
if (pfc != null)
pfc.configure();
}
// FrameworkJarChecker.unmountDependencies();
}
});
}
}

View File

@@ -0,0 +1,253 @@
package org.openoffice.netbeans.modules.office.actions;
import java.awt.event.ActionEvent;
import java.io.*;
import java.util.*;
import javax.swing.JMenuItem;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
import org.openide.awt.Actions;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.openide.util.actions.*;
import org.openoffice.idesupport.SVersionRCFile;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.idesupport.LocalOffice;
import org.openoffice.netbeans.modules.office.utils.NagDialog;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
public class DeployParcelAction extends CookieAction implements Presenter.Popup {
public String getName () {
return "Deploy To";
}
public HelpCtx getHelpCtx () {
return HelpCtx.DEFAULT_HELP;
}
public JMenuItem getPopupPresenter() {
return new LocationsMenu (this, new LocationsModel (this), true);
}
protected int mode () {
return MODE_ALL;
}
protected Class[] cookieClasses () {
return new Class[] { ParcelCookie.class };
}
protected void performAction (Node[] activatedNodes) {
// do nothing, should not happen
}
/** Special submenu which notifies model when it is added as a component.
*/
private static final class LocationsMenu extends Actions.SubMenu {
private final LocationsModel model;
LocationsMenu (SystemAction action, LocationsModel model, boolean popup) {
super (action, model, popup);
this.model = model;
}
public void addNotify () {
model.addNotify ();
super.addNotify ();
}
}
/** Model to use for the submenu.
*/
private static final class LocationsModel implements Actions.SubMenuModel {
private List labels = null;
private Hashtable versions = null;
private final NodeAction action;
private String BROWSE_LABEL = "Office Document...";
LocationsModel (NodeAction action) {
this.action = action;
}
public int getCount () {
if (labels == null)
return 0;
return labels.size();
}
public String getLabel (int index) {
return (String)labels.get(index);
}
public HelpCtx getHelpCtx (int index) {
return HelpCtx.DEFAULT_HELP; // NOI18N
}
public void performActionAt (final int index) {
final String label = getLabel(index);
final File source;
final File target;
if (label.equals(BROWSE_LABEL)) {
target = getTargetFile();
if (target == null)
return;
}
else {
target = new File((String)versions.get(label) +
File.separator + "user" + File.separator + "Scripts" +
File.separator + "java");
if (!target.exists()) {
boolean response = askIfCreateDirectory(target);
if (response == false) {
return;
}
}
}
Node[] nodes = action.getActivatedNodes();
final ParcelCookie parcelCookie =
(ParcelCookie)nodes[0].getCookie(ParcelCookie.class);
RequestProcessor.getDefault().post(new Runnable() {
public void run() {
boolean result = parcelCookie.deploy(target);
if (result == true && target.isDirectory()) {
showNagDialog();
// refreshOffice((String)versions.get(label));
}
}
});
}
void addNotify () {
SVersionRCFile rcfile = new SVersionRCFile();
try {
versions = rcfile.getVersions();
}
catch (IOException ioe) {
return;
}
Enumeration enum = versions.keys();
labels = new ArrayList();
while (enum.hasMoreElements()) {
String s = (String)enum.nextElement();
// System.out.println("Adding: " + s);
labels.add(s);
}
labels.add(null);
labels.add(BROWSE_LABEL);
// IDE will not show the submenu if there is only one item
// so add a blank item which will not be shown
if (labels.size() == 1)
labels.add(null);
}
private boolean askIfCreateDirectory(File directory) {
String message = "Your Office installation does not have a " +
"directory for scripts written in java. Do you want to " +
"create one now?";
NotifyDescriptor d = new NotifyDescriptor.Confirmation(
message, NotifyDescriptor.OK_CANCEL_OPTION);
TopManager.getDefault().notify(d);
if (d.getValue() == NotifyDescriptor.CANCEL_OPTION)
return false;
boolean result;
try {
result = directory.mkdirs();
}
catch (SecurityException se) {
result = false;
}
if (result == false) {
String tmp = "Error creating: " + directory.getAbsolutePath();
NotifyDescriptor d2 = new NotifyDescriptor.Message(
tmp, NotifyDescriptor.ERROR_MESSAGE);
TopManager.getDefault().notify(d2);
}
return result;
}
private void refreshOffice(String path) {
ClassLoader syscl = TopManager.getDefault().currentClassLoader();
LocalOffice office = LocalOffice.create(syscl, path, 8100);
office.refreshStorage("file://" + path + "/program/../user");
office.disconnect();
}
private void showNagDialog() {
String message = "If you currently have Office running you will " +
"need to click on the Tools/Refresh Scripts(java) menu item " +
"in Office so that the scripts in this parcel can be " +
"detected.";
OfficeSettings settings = OfficeSettings.getDefault();
if (settings.getWarnAfterDirDeploy() == true) {
NagDialog warning = NagDialog.createInformationDialog(
message, "Show this message in future", true);
warning.show();
if (warning.getState() == false)
settings.setWarnAfterDirDeploy(false);
}
}
private File getTargetFile() {
File target = null;
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Deploy Parcel To Office Document");
chooser.setApproveButtonText("Deploy");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileFilter() {
public boolean accept(File file) {
if (file.isDirectory() ||
file.getName().endsWith(".sxw") ||
file.getName().endsWith(".sxc") ||
file.getName().endsWith(".sxi"))
return true;
return false;
}
public String getDescription() {
return "Office Documents";
}
});
int result = chooser.showDialog(null, null);
if (result == JFileChooser.APPROVE_OPTION) {
target = chooser.getSelectedFile();
}
return target;
}
public synchronized void addChangeListener (ChangeListener l) {
}
public synchronized void removeChangeListener (ChangeListener l) {
}
}
}

View File

@@ -0,0 +1,58 @@
package org.openoffice.netbeans.modules.office.actions;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.RequestProcessor;
import org.openide.util.actions.CookieAction;
/**
*
* @author adams
* @version 1.0
*/
public class MountDocumentAction extends CookieAction
{
public MountDocumentAction()
{
}
public java.lang.String getName()
{
return "Mount Document"; //NOI18N
}
public HelpCtx getHelpCtx()
{
return HelpCtx.DEFAULT_HELP;
}
protected int mode()
{
// enable duplication for as many qualifying nodes as are selected:
return CookieAction.MODE_ALL;
}
protected java.lang.Class[] cookieClasses()
{
// just the DuplicateCookie:
return new Class[] {OfficeDocumentCookie.class};
}
protected void performAction(final Node[] activatedNodes)
{
RequestProcessor.getDefault().post(new Runnable()
{
public void run()
{
for (int i=0; i<activatedNodes.length; i++)
{
OfficeDocumentCookie cookie = (OfficeDocumentCookie)activatedNodes[i].getCookie(OfficeDocumentCookie.class);
if (cookie != null)
{
cookie.mount();
}
}
}
});
}
}

View File

@@ -0,0 +1,57 @@
package org.openoffice.netbeans.modules.office.actions;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import org.openide.util.RequestProcessor;
import org.openide.util.actions.CookieAction;
/**
*
* @author adams
* @version 1.0
*/
public class MountParcelAction extends CookieAction
{
public MountParcelAction()
{
}
public java.lang.String getName()
{
return "Mount Parcel"; //NOI18N
}
public HelpCtx getHelpCtx()
{
return HelpCtx.DEFAULT_HELP;
}
protected int mode()
{
// enable duplication for as many qualifying nodes as are selected:
return CookieAction.MODE_ALL;
}
protected java.lang.Class[] cookieClasses()
{
return new Class[] {ParcelCookie.class};
}
protected void performAction(final Node[] activatedNodes)
{
RequestProcessor.getDefault().post(new Runnable()
{
public void run()
{
for (int i=0; i<activatedNodes.length; i++)
{
ParcelCookie mpc = (ParcelCookie)activatedNodes[i].getCookie(ParcelCookie.class);
if (mpc != null)
{
mpc.mount();
}
}
}
});
}
}

View File

@@ -0,0 +1,15 @@
package org.openoffice.netbeans.modules.office.actions;
import java.util.Enumeration;
import javax.swing.event.ChangeListener;
import org.openide.nodes.Node;
public interface OfficeDocumentCookie extends Node.Cookie
{
public void mount();
public Enumeration getParcels();
public void removeParcel(String name);
public void addChangeListener(ChangeListener cl);
public void removeChangeListener(ChangeListener cl);
}

View File

@@ -0,0 +1,122 @@
package org.openoffice.netbeans.modules.office.actions;
import java.io.IOException;
import java.io.File;
import java.beans.PropertyVetoException;
import java.util.Enumeration;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.FileChangeListener;
import org.openide.filesystems.FileEvent;
import org.openide.filesystems.FileAttributeEvent;
import org.openide.filesystems.FileRenameEvent;
import org.openide.cookies.OpenCookie;
import org.openoffice.idesupport.OfficeDocument;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.netbeans.modules.office.loader.OfficeDocumentDataObject;
import org.openoffice.netbeans.modules.office.utils.ZipMounter;
import org.openoffice.netbeans.modules.office.utils.ManifestParser;
public class OfficeDocumentSupport implements OfficeDocumentCookie, OpenCookie, FileChangeListener
{
protected OfficeDocumentDataObject dataObj;
private boolean isMounted = false;
private OfficeDocument document;
private Set listeners;
public OfficeDocumentSupport(OfficeDocumentDataObject dataObj) {
this.dataObj = dataObj;
FileObject fo = dataObj.getPrimaryFile();
try {
this.document = new OfficeDocument(FileUtil.toFile(fo));
}
catch (Exception e) {
e.printStackTrace();
}
fo.addFileChangeListener(this);
}
// ensure that ParcelZipper's XMLParser is set
static {
ParcelZipper.setXMLParser(ManifestParser.getManifestParser());
}
public void mount() {
File file = FileUtil.toFile(dataObj.getPrimaryFile());
try {
ZipMounter.getZipMounter().mountZipFile(file);
isMounted = true;
}
catch (IOException ioe) {
ErrorManager.getDefault().notify(ioe);
}
catch (PropertyVetoException pve) {
ErrorManager.getDefault().notify(pve);
}
}
public void open () {
File file = FileUtil.toFile(dataObj.getPrimaryFile());
OfficeSettings settings = OfficeSettings.getDefault();
File soffice = new File(settings.getOfficeDirectory() +
File.separator + "soffice");
try {
Process p = Runtime.getRuntime ().exec (new String[] {
soffice.getAbsolutePath(), file.getAbsolutePath ()
});
} catch (IOException ioe) {
ErrorManager.getDefault().notify(ioe);
}
}
public Enumeration getParcels() {
return document.getParcels();
}
public void removeParcel(String name) {
document.removeParcel(name);
dataObj.getPrimaryFile().refresh(true);
}
public void addChangeListener(ChangeListener cl) {
if (listeners == null)
listeners = new HashSet();
listeners.add(cl);
}
public void removeChangeListener(ChangeListener cl) {
if (listeners == null)
return;
listeners.remove(cl);
}
public void fileChanged(FileEvent fe) {
if (listeners != null) {
Iterator iter = listeners.iterator();
while (iter.hasNext())
((ChangeListener)iter.next()).stateChanged(new ChangeEvent(this));
}
}
public void fileAttributeChanged(FileAttributeEvent fe) {}
public void fileDataCreated(FileEvent fe) {}
public void fileDeleted(FileEvent fe) {}
public void fileFolderCreated(FileEvent fe) {}
public void fileRenamed(FileRenameEvent fe) {}
}

View File

@@ -0,0 +1,13 @@
package org.openoffice.netbeans.modules.office.actions;
import java.io.File;
import org.openide.nodes.Node;
public interface ParcelCookie extends Node.Cookie
{
public File getFile();
public void mount();
public boolean deploy(File target);
}

View File

@@ -0,0 +1,114 @@
package org.openoffice.netbeans.modules.office.actions;
import java.io.IOException;
import org.openide.cookies.*;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.text.DataEditorSupport;
import org.openide.windows.CloneableOpenSupport;
import org.openoffice.netbeans.modules.office.loader.ParcelDescriptorDataObject;
/** Support for editing a data object as text.
*
* @author tomaso
*/
// Replace OpenCookie with EditCookie or maybe ViewCookie as desired:
public class ParcelDescriptorEditorSupport extends DataEditorSupport implements EditorCookie, OpenCookie, CloseCookie, PrintCookie {
/** Create a new editor support.
* @param obj the data object whose primary file will be edited as text
*/
public ParcelDescriptorEditorSupport(ParcelDescriptorDataObject obj) {
super(obj, new ParcelDescriptorEnv(obj));
// Set a MIME type as needed, e.g.:
setMIMEType("text/xml");
}
/** Called when the document is modified.
* Here, adding a save cookie to the object and marking it modified.
* @return true if the modification is acceptable
*/
protected boolean notifyModified() {
if (!super.notifyModified()) {
return false;
}
ParcelDescriptorDataObject obj = (ParcelDescriptorDataObject)getDataObject();
if (obj.getCookie(SaveCookie.class) == null) {
obj.setModified(true);
// You must implement this method on the object:
obj.addSaveCookie(new Save());
}
return true;
}
/** Called when the document becomes unmodified.
* Here, removing the save cookie from the object and marking it unmodified.
*/
protected void notifyUnmodified() {
ParcelDescriptorDataObject obj = (ParcelDescriptorDataObject)getDataObject();
SaveCookie save = (SaveCookie)obj.getCookie(SaveCookie.class);
if (save != null) {
// You must implement this method on the object:
obj.removeSaveCookie(save);
obj.setModified(false);
}
super.notifyUnmodified();
}
/** A save cookie to use for the editor support.
* When saved, saves the document to disk and marks the object unmodified.
*/
private class Save implements SaveCookie {
public void save() throws IOException {
saveDocument();
getDataObject().setModified(false);
}
}
/** A description of the binding between the editor support and the object.
* Note this may be serialized as part of the window system and so
* should be static, and use the transient modifier where needed.
*/
private static class ParcelDescriptorEnv extends DataEditorSupport.Env {
//private static final long serialVersionUID = ...L;
/** Create a new environment based on the data object.
* @param obj the data object to edit
*/
public ParcelDescriptorEnv(ParcelDescriptorDataObject obj) {
super(obj);
}
/** Get the file to edit.
* @return the primary file normally
*/
protected FileObject getFile() {
return getDataObject().getPrimaryFile();
}
/** Lock the file to edit.
* Should be taken from the file entry if possible, helpful during
* e.g. deletion of the file.
* @return a lock on the primary file normally
* @throws IOException if the lock could not be taken
*/
protected FileLock takeLock() throws IOException {
return ((ParcelDescriptorDataObject)getDataObject()).getPrimaryEntry().takeLock();
}
/** Find the editor support this environment represents.
* Note that we have to look it up, as keeping a direct
* reference would not permit this environment to be serialized.
* @return the editor support
*/
public CloneableOpenSupport findCloneableOpenSupport() {
return (ParcelDescriptorEditorSupport)getDataObject().getCookie(ParcelDescriptorEditorSupport.class);
}
}
}

View File

@@ -0,0 +1,15 @@
package org.openoffice.netbeans.modules.office.actions;
import org.w3c.dom.NodeList;
import javax.swing.event.ChangeListener;
import org.openide.nodes.Node;
public interface ParcelDescriptorParserCookie extends Node.Cookie
{
// should return a NodeList of org.w3c.dom.Element
public NodeList getScriptElements();
public void addChangeListener(ChangeListener cl);
public void removeChangeListener(ChangeListener cl);
}

View File

@@ -0,0 +1,94 @@
package org.openoffice.netbeans.modules.office.actions;
import java.io.*;
import java.util.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.openide.filesystems.*;
import org.openide.xml.XMLUtil;
public class ParcelDescriptorParserSupport
implements ParcelDescriptorParserCookie, FileChangeListener
{
private FileObject fo;
private Document document;
private Set listeners;
public ParcelDescriptorParserSupport(FileObject fo)
{
this.fo = fo;
fo.addFileChangeListener(this);
}
private synchronized void parseFile()
{
File file = FileUtil.toFile(fo);
InputSource is;
try {
is = new InputSource(new FileInputStream(file));
}
catch (FileNotFoundException fnfe) {
System.out.println("Couldn't find file: " + file.getName());
return;
}
document = null;
try {
document = XMLUtil.parse(is, false, false, null, null);
}
catch (IOException ioe) {
System.out.println("IO Error parsing file: " + file.getName());
}
catch (SAXException se) {
System.out.println("Sax Error parsing file: " + file.getName());
}
}
public synchronized NodeList getScriptElements()
{
if (document == null)
parseFile();
if (document != null)
return document.getElementsByTagName("script");
return null;
}
public void addChangeListener(ChangeListener cl) {
if (listeners == null)
listeners = new HashSet();
listeners.add(cl);
}
public void removeChangeListener(ChangeListener cl) {
if (listeners == null)
return;
listeners.remove(cl);
}
public void fileChanged(FileEvent fe) {
parseFile();
if (listeners != null) {
Iterator iter = listeners.iterator();
while (iter.hasNext())
((ChangeListener)iter.next()).stateChanged(new ChangeEvent(this));
}
}
public void fileAttributeChanged(FileAttributeEvent fe) {}
public void fileDataCreated(FileEvent fe) {}
public void fileDeleted(FileEvent fe) {}
public void fileFolderCreated(FileEvent fe) {}
public void fileRenamed(FileRenameEvent fe) {}
}

View File

@@ -0,0 +1,10 @@
package org.openoffice.netbeans.modules.office.actions;
import org.openide.nodes.Node;
public interface ParcelFolderCookie extends Node.Cookie
{
public void generate();
public void configure();
}

View File

@@ -0,0 +1,154 @@
package org.openoffice.netbeans.modules.office.actions;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.*;
import java.beans.PropertyVetoException;
import java.awt.Dialog;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.openide.TopManager;
import org.openide.DialogDescriptor;
import org.openide.ErrorManager;
import org.openide.xml.XMLUtil;
import org.openide.execution.NbClassPath;
import org.openide.cookies.OpenCookie;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataNode;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.JarFileSystem;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.Repository;
import org.openide.nodes.*;
import org.openide.windows.OutputWriter;
import org.openoffice.netbeans.modules.office.loader.ParcelFolder;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.netbeans.modules.office.utils.ManifestParser;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.idesupport.filter.FileFilter;
import org.openoffice.idesupport.ui.ConfigurePanel;
public class ParcelFolderSupport implements ParcelFolderCookie
{
protected ParcelFolder pf;
public ParcelFolderSupport(ParcelFolder pf) {
this.pf = pf;
}
// ensure that ParcelZipper's XMLParser is set
static {
ParcelZipper.setXMLParser(ManifestParser.getManifestParser());
}
public void generate() {
ParcelFolder.ParcelFolderNode node =
(ParcelFolder.ParcelFolderNode)pf.getNodeDelegate();
FileObject parcelBase = pf.getPrimaryFile();
FileObject contentsBase =
parcelBase.getFileObject(ParcelZipper.CONTENTS_DIRNAME);
File parcelDir = FileUtil.toFile(parcelBase);
File contentsDir = FileUtil.toFile(contentsBase);
File targetfile = new File(node.getTargetDir() + File.separator +
parcelBase.getName() + "." + ParcelZipper.PARCEL_EXTENSION);
configure();
final OutputWriter out =
ParcelSupport.getOutputWindowWriter(parcelDir.getName() + " (generating)");
try {
out.println("Generating: " + parcelDir.getName(), null);
ParcelZipper.getParcelZipper().zipParcel(contentsDir, targetfile, node.getFileFilter());
out.println("\nGENERATION SUCCESSFUL.");
out.println("\nRight click on the generated parcel to deploy it");
if (node.getTargetDir().equals(parcelDir))
parcelBase.refresh(true);
}
catch (IOException ioe) {
out.println("GENERATION FAILED: reason: " + ioe.getClass().getName() + ": "+ ioe.getMessage());
}
finally
{
if( out != null)
{
out.close();
}
}
}
public void configure() {
FileObject primary = pf.getPrimaryFile();
File contents = FileUtil.toFile(primary.getFileObject(ParcelZipper.CONTENTS_DIRNAME));
File parcelDescriptor = new File(contents, ParcelZipper.PARCEL_DESCRIPTOR_XML);
InputSource is;
Document previous = null;
try {
is = new InputSource(new FileInputStream(parcelDescriptor));
previous = XMLUtil.parse(is, false, false, null, null);
}
catch (FileNotFoundException fnfe) {
System.out.println("Couldn't find file: " + parcelDescriptor.getName());
}
catch (IOException ioe) {
System.out.println("IO Error parsing file: " + parcelDescriptor.getName());
}
catch (SAXException se) {
System.out.println("Sax Error parsing file: " + parcelDescriptor.getName());
}
Vector classpath = getClasspath();
classpath.addElement(contents.getAbsolutePath());
ConfigurePanel configuror = new ConfigurePanel(contents.getAbsolutePath(), classpath, previous);
DialogDescriptor descriptor = new DialogDescriptor(configuror, "Choose Methods to Export as Scripts");
Dialog dialog = TopManager.getDefault().createDialog(descriptor);
dialog.show();
if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
try {
Document doc = configuror.getConfiguration();
FileOutputStream fos = new FileOutputStream(parcelDescriptor);
XMLUtil.write(doc, fos, "");
}
catch (Exception e) {
ErrorManager.getDefault().notify(e);
}
}
}
private Vector getClasspath() {
Vector result = new Vector();
String classpath = NbClassPath.createRepositoryPath().getClassPath();
StringTokenizer tokens = new StringTokenizer(classpath, File.pathSeparator);
while(tokens.hasMoreTokens())
result.addElement(tokens.nextToken());
OfficeSettings settings = OfficeSettings.getDefault();
File classesDir = new File(settings.getOfficeDirectory() +
File.separator + "program" + File.separator + "classes");
File[] jarfiles = classesDir.listFiles();
for (int i = 0; i < jarfiles.length; i++)
result.addElement(jarfiles[i].getAbsolutePath());
return result;
}
}

View File

@@ -0,0 +1,149 @@
package org.openoffice.netbeans.modules.office.actions;
import java.io.File;
import java.io.IOException;
import java.beans.PropertyVetoException;
import java.util.Enumeration;
import java.util.Calendar;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
import org.openide.windows.OutputWriter;
import org.openide.windows.InputOutput;
import org.openide.ErrorManager;
import org.openide.nodes.Node;
import org.openide.filesystems.Repository;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.FileEvent;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.netbeans.modules.office.utils.NagDialog;
import org.openoffice.netbeans.modules.office.utils.ZipMounter;
import org.openoffice.netbeans.modules.office.utils.ManifestParser;
public class ParcelSupport implements ParcelCookie
{
private FileObject fo;
private ParcelZipper zipper = ParcelZipper.getParcelZipper();
public ParcelSupport(FileObject fo) {
this.fo = fo;
}
// ensure that ParcelZipper's XMLParser is set
static {
ParcelZipper.setXMLParser(ManifestParser.getManifestParser());
}
public File getFile() {
return FileUtil.toFile(fo);
}
public void mount()
{
File parcel = FileUtil.toFile(fo);
if (parcel != null) {
try {
ZipMounter.getZipMounter().mountZipFile(parcel);
}
catch (IOException ioe) {
ErrorManager.getDefault().notify(ioe);
}
catch (PropertyVetoException pve) {
ErrorManager.getDefault().notify(pve);
}
}
}
public boolean deploy(File target) {
File source = FileUtil.toFile(fo);
if (!target.isDirectory()) {
OfficeSettings settings = OfficeSettings.getDefault();
String message = "If you already have this document open in " +
"Office, please close it before continuing. Click OK to " +
"continue deployment.";
if (settings.getWarnBeforeDocDeploy() == true) {
NagDialog warning = NagDialog.createConfirmationDialog(
message, "Show this message in future", true);
boolean result = warning.show();
if (warning.getState() == false)
settings.setWarnBeforeDocDeploy(false);
if (result == false)
return false;
}
}
if (zipper.isOverwriteNeeded(source, target) == true)
if (promptForOverwrite(source, target) == false)
return false;
OutputWriter out =
getOutputWindowWriter(fo.getName() + " (deploying)");
try {
out.println("Deploying: " + fo.getName() +
"\nTo: " + target.getAbsolutePath(), null);
zipper.deployParcel(source, target);
out.println("\nDEPLOYMENT SUCCESSFUL.");
FileObject[] fileobjs = FileUtil.fromFile(target);
if (fileobjs != null) {
for (int i = 0; i < fileobjs.length; i++)
fileobjs[i].refresh(true);
}
}
catch (IOException ioe) {
out.println("DEPLOYMENT FAILED: reason: " +
ioe.getClass().getName() + ": "+ ioe.getMessage());
return false;
}
finally {
if( out != null)
out.close();
}
return true;
}
public static OutputWriter getOutputWindowWriter(String title) {
InputOutput io = TopManager.getDefault().getIO(title, false);
io.setFocusTaken(true);
io.setOutputVisible(true);
OutputWriter out = io.getOut();
try {
out.reset();
}
catch( IOException e) {
e.printStackTrace(System.err);
}
out.println(Calendar.getInstance().getTime() + ":\n");
return out;
}
private boolean promptForOverwrite(File source, File target) {
String message = source.getName() + " has already been deployed " +
"to this target. Do you wish to overwrite it?";
NotifyDescriptor d = new NotifyDescriptor.Confirmation(
message, NotifyDescriptor.OK_CANCEL_OPTION);
TopManager.getDefault().notify(d);
if (d.getValue() == NotifyDescriptor.CANCEL_OPTION)
return false;
else
return true;
}
}

View File

@@ -0,0 +1,43 @@
# Filesystems API
# {0} - root path
LAB_invalid_file_system=invalid OpenOffice document {0}
# {0} - root path
LAB_valid_file_system={0}
# {0} - root path
EXC_root_dir_does_not_exist=Root directory {0} does not exist.
# {0} - original name before annotation
LBL_modified_files={0} <somehow annotated>
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_file_could_not_be_locked={2} could not be locked; it did not exist or was not writable.
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_create_empty_name=Cannot create a file with an empty name.
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_folder_already_exists=Folder {2} already exists.
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_folder_could_not_be_created=Folder {2} could not be created.
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_file_could_not_be_created=File {2} could not be created.
# {0} - old file name and extension
# {1} - new file name and extension
# {2} - display name of filesystem
# {3} - full path to old file
# {4} - full path to new file
EXC_file_could_not_be_renamed=File {3} could not be renamed to {4}.
# {0} - file name and extension
# {1} - display name of filesystem
# {2} - full path to file
EXC_file_could_not_be_deleted=File {2} could not be deleted.
PROP_readOnly=Read Only
HINT_readOnly=Whether this filesystem should be writable, or read-only.
PROP_document=OpenOffice Document
HINT_document=OpenOffice Document (mount point) of this filesystem.

View File

@@ -0,0 +1,99 @@
package org.openoffice.netbeans.modules.office.filesystem;
import java.awt.Image;
import java.io.File;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.filesystems.FileSystem;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/**
* Description of the OpenOffice Document filesystem.
*
* @author misha <misha@openoffice.org>
*/
public class OpenOfficeDocFileSystemBeanInfo
extends SimpleBeanInfo
{
private static String ICONLOCATION =
"org/openoffice/netbeans/modules/office/resources";
private static String COLORICON16NAME =
ICONLOCATION + File.separator + "OpenOfficeDocFileSystemIcon.png";
private static String COLORICON32NAME =
ICONLOCATION + File.separator + "OpenOfficeDocFileSystemIcon32.png";
/**
* Retrives an additional bean information.
*/
public BeanInfo[] getAdditionalBeanInfo()
{
try {
return new BeanInfo[] {
Introspector.getBeanInfo(FileSystem.class)
};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
/*
// If you have a visual dialog to customize configuration of the
// filesystem:
public BeanDescriptor getBeanDescriptor()
{
return new BeanDescriptor(OpenOfficeDocFileSystem.class,
OpenOfficeDocFileSystemCustomizer.class);
}
*/
/**
* Retrives bean property descriptors.
*/
public PropertyDescriptor[] getPropertyDescriptors()
{
try {
// Included only to make it a writable property (it is read-only
// in FileSystem):
PropertyDescriptor readOnly = new PropertyDescriptor(
"readOnly", OpenOfficeDocFileSystem.class);
readOnly.setDisplayName(NbBundle.getMessage(
OpenOfficeDocFileSystemBeanInfo.class, "PROP_readOnly"));
readOnly.setShortDescription(NbBundle.getMessage(
OpenOfficeDocFileSystemBeanInfo.class, "HINT_readOnly"));
// This could be whatever properties you use to configure the
// filesystem:
PropertyDescriptor document = new PropertyDescriptor(
"Document", OpenOfficeDocFileSystem.class);
document.setDisplayName(NbBundle.getMessage(
OpenOfficeDocFileSystemBeanInfo.class, "PROP_document"));
document.setShortDescription(NbBundle.getMessage(
OpenOfficeDocFileSystemBeanInfo.class, "HINT_document"));
// Request to the property editor that it be permitted only to
// choose directories:
document.setValue("directories", Boolean.FALSE); // NOI18N
document.setValue("files", Boolean.TRUE); // NOI18N
return new PropertyDescriptor[] {readOnly, document};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
/**
* Retrives an icon by the icon type.
*/
public Image getIcon(int type)
{
if((type == BeanInfo.ICON_COLOR_16x16) ||
(type == BeanInfo.ICON_MONO_16x16)) {
return Utilities.loadImage(COLORICON16NAME);
} else {
return Utilities.loadImage(COLORICON32NAME);
}
}
}

View File

@@ -0,0 +1,12 @@
# Datasystems API
#PROP_myProp=<name of my property>
#HINT_myProp=<description of my property>
#LBL_DataNode_exec_sheet=Execution
#HINT_DataNode_exec_sheet=Properties pertaining to compiling, running, and debugging.
LBL_loaderName=<display name of the data loader>
# Datasystems API
#PROP_myProp=<name of my property>
#HINT_myProp=<description of my property>
#LBL_DataNode_exec_sheet=Execution
#HINT_DataNode_exec_sheet=Properties pertaining to compiling, running, and debugging.
LBL_loaderName=<display name of the data loader>

View File

@@ -0,0 +1,85 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.IOException;
import java.io.File;
import org.openide.actions.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.openoffice.netbeans.modules.office.actions.MountDocumentAction;
/** Recognizes single files in the Repository as being of a certain type.
*
* @author tomaso
*/
public class OfficeDocumentDataLoader extends UniFileLoader {
public OfficeDocumentDataLoader() {
this("org.openoffice.netbeans.modules.office.loader.OfficeDocumentDataObject");
}
// Can be useful for subclasses:
protected OfficeDocumentDataLoader(String recognizedObjectClass) {
super(recognizedObjectClass);
}
protected String defaultDisplayName() {
return "Office Document";
}
protected void initialize() {
super.initialize();
ExtensionList extensions = new ExtensionList();
extensions.addExtension("sxw");
extensions.addExtension("sxc");
extensions.addExtension("sxd");
extensions.addExtension("sxi");
setExtensions(extensions);
}
protected FileObject findPrimaryFile(FileObject fo) {
ExtensionList extensions = getExtensions();
if (extensions.isRegistered(fo) == false)
return null;
File document = FileUtil.toFile(fo);
JarFileSystem jarFs = new JarFileSystem();
try {
jarFs.setJarFile(document);
}
catch (IOException e) {
// TopManager.getDefault().notify(new NotifyDescriptor.Exception(e, "asdf"));
return null;
}
catch (Exception e) {
return null;
}
return fo;
}
protected SystemAction[] defaultActions() {
return new SystemAction[] {
SystemAction.get(OpenAction.class),
// SystemAction.get(MountDocumentAction.class),
null,
SystemAction.get(CutAction.class),
SystemAction.get(CopyAction.class),
SystemAction.get(PasteAction.class),
null,
SystemAction.get(DeleteAction.class),
SystemAction.get(RenameAction.class),
null,
// SystemAction.get(ToolsAction.class),
SystemAction.get(PropertiesAction.class),
};
}
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
return new OfficeDocumentDataObject(primaryFile, this);
}
}

View File

@@ -0,0 +1,45 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
public class OfficeDocumentDataLoaderBeanInfo extends SimpleBeanInfo {
// If you have additional properties:
/*
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor myProp = new PropertyDescriptor("myProp", StarOfficeDocumentDataLoader.class);
myProp.setDisplayName(NbBundle.getMessage(StarOfficeDocumentDataLoaderBeanInfo.class, "PROP_myProp"));
myProp.setShortDescription(NbBundle.getMessage(StarOfficeDocumentDataLoaderBeanInfo.class, "HINT_myProp"));
return new PropertyDescriptor[] {myProp};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
*/
public BeanInfo[] getAdditionalBeanInfo() {
try {
// I.e. MultiFileLoader.class or UniFileLoader.class.
return new BeanInfo[] {Introspector.getBeanInfo(OfficeDocumentDataLoader.class.getSuperclass())};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/resources/OfficeIcon.gif");
} else {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/resources/OfficeIcon32.gif");
}
}
}

View File

@@ -0,0 +1,93 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.datatransfer.Transferable;
import java.util.List;
import java.io.*;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.NbBundle;
import org.openide.filesystems.*;
import org.openoffice.netbeans.modules.office.actions.OfficeDocumentCookie;
import org.openoffice.netbeans.modules.office.nodes.OfficeDocumentChildren;
/** A node to represent this object.
*
* @author tomaso
*/
public class OfficeDocumentDataNode extends DataNode {
public OfficeDocumentDataNode(OfficeDocumentDataObject obj) {
// this(obj, Children.LEAF);
this(obj, new OfficeDocumentChildren((OfficeDocumentCookie)
obj.getCookie(OfficeDocumentCookie.class)));
}
public OfficeDocumentDataNode(OfficeDocumentDataObject obj, Children ch) {
super(obj, ch);
setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon");
}
protected OfficeDocumentDataObject getOfficeDocumentDataObject() {
return (OfficeDocumentDataObject)getDataObject();
}
// Allow for pasting of Script Parcels to Office Documents
protected void createPasteTypes(Transferable t, List ls) {
Node[] copies = NodeTransfer.nodes(t, NodeTransfer.COPY);
if (copies != null) {
for (int i = 0; i < copies.length; i++) {
if (copies[i] instanceof ParcelDataNode) {
File source = FileUtil.toFile(((ParcelDataNode)copies[i]).getDataObject().getPrimaryFile());
File target = FileUtil.toFile(getDataObject().getPrimaryFile());
if (source.exists() && source.canRead() &&
target.exists() && target.canWrite()) {
ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)copies[i], target, false));
}
}
}
}
Node[] moves = NodeTransfer.nodes(t, NodeTransfer.MOVE);
if (moves != null) {
for (int i = 0; i < moves.length; i++) {
if (moves[i] instanceof ParcelDataNode) {
File source = FileUtil.toFile(((ParcelDataNode)moves[i]).getDataObject().getPrimaryFile());
File target = FileUtil.toFile(getDataObject().getPrimaryFile());
if (source.exists() && source.canRead() &&
target.exists() && target.canWrite()) {
ls.add(new ParcelDataNode.ParcelPasteType((ParcelDataNode)moves[i], target, true));
}
}
}
}
// Also try superclass, but give it lower priority:
super.createPasteTypes(t, ls);
}
/* Example of adding Executor / Debugger / Arguments to node:
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set set = sheet.get(ExecSupport.PROP_EXECUTION);
if (set == null) {
set = new Sheet.Set();
set.setName(ExecSupport.PROP_EXECUTION);
set.setDisplayName(NbBundle.getMessage(StarOfficeDocumentDataNode.class, "LBL_DataNode_exec_sheet"));
set.setShortDescription(NbBundle.getMessage(StarOfficeDocumentDataNode.class, "HINT_DataNode_exec_sheet"));
}
((ExecSupport)getCookie(ExecSupport.class)).addProperties(set);
// Maybe:
((CompilerSupport)getCookie(CompilerSupport.class)).addProperties(set);
sheet.put(set);
return sheet;
}
*/
// Don't use getDefaultAction(); just make that first in the data loader's getActions list
}

View File

@@ -0,0 +1,31 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.actions.*;
import org.openide.cookies.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openoffice.netbeans.modules.office.actions.*;
public class OfficeDocumentDataObject extends MultiDataObject {
public OfficeDocumentDataObject(FileObject pf, OfficeDocumentDataLoader loader) throws DataObjectExistsException {
super(pf, loader);
init();
}
private void init() {
CookieSet cookies = getCookieSet();
cookies.add(new OfficeDocumentSupport(this));
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
protected Node createNodeDelegate() {
return new OfficeDocumentDataNode(this);
}
}

View File

@@ -0,0 +1,13 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObjectExistsException;
import org.openide.filesystems.FileObject;
public class ParcelContentsFolder extends DataFolder {
public ParcelContentsFolder(FileObject pf, ParcelContentsFolderDataLoader loader)
throws DataObjectExistsException {
super(pf, loader);
}
}

View File

@@ -0,0 +1,54 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.loaders.*;
import org.openide.filesystems.FileObject;
import org.openide.actions.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.openoffice.idesupport.zip.ParcelZipper;
public class ParcelContentsFolderDataLoader extends UniFileLoader {
public ParcelContentsFolderDataLoader() {
this("org.openide.loaders.DataFolder");
}
protected ParcelContentsFolderDataLoader(String recognizedObjectClass) {
super(recognizedObjectClass);
}
protected String defaultDisplayName() {
return "Office Script Parcel Contents";
}
protected void initialize() {
super.initialize();
}
protected FileObject findPrimaryFile(FileObject fo) {
if (fo.isFolder() == false ||
fo.getName().equals(ParcelZipper.CONTENTS_DIRNAME) == false ||
fo.getFileObject(ParcelZipper.PARCEL_DESCRIPTOR_XML) == null)
return null;
return fo;
}
protected SystemAction[] defaultActions() {
return new SystemAction[] {
SystemAction.get(PasteAction.class),
// null,
// SystemAction.get(PropertiesAction.class),
};
}
protected MultiDataObject createMultiObject(FileObject primaryFile)
throws DataObjectExistsException {
return new ParcelContentsFolder(primaryFile, this);
}
protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) {
return new FileEntry.Folder(obj, primaryFile);
}
}

View File

@@ -0,0 +1,49 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/** Description of {@link ParcelFolderDataLoader}.
*
* @author tomaso
*/
public class ParcelContentsFolderDataLoaderBeanInfo extends SimpleBeanInfo {
// If you have additional properties:
/*
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor myProp = new PropertyDescriptor("myProp", ParcelFolderDataLoader.class);
myProp.setDisplayName(NbBundle.getMessage(ParcelFolderDataLoaderBeanInfo.class, "PROP_myProp"));
myProp.setShortDescription(NbBundle.getMessage(ParcelFolderDataLoaderBeanInfo.class, "HINT_myProp"));
return new PropertyDescriptor[] {myProp};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
*/
public BeanInfo[] getAdditionalBeanInfo() {
try {
// I.e. MultiFileLoader.class or UniFileLoader.class.
return new BeanInfo[] {Introspector.getBeanInfo(ParcelContentsFolderDataLoader.class.getSuperclass())};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelFolderDataIcon.gif");
} else {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelFolderDataIcon32.gif");
}
}
}

View File

@@ -0,0 +1,62 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.IOException;
import java.io.File;
import org.openide.actions.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.openoffice.netbeans.modules.office.actions.*;
import org.openoffice.idesupport.zip.ParcelZipper;
/** Recognizes single files in the Repository as being of a certain type.
*
* @author tomaso
*/
public class ParcelDataLoader extends UniFileLoader {
public ParcelDataLoader() {
this("org.openoffice.netbeans.modules.office.loader.ParcelDataObject");
}
// Can be useful for subclasses:
protected ParcelDataLoader(String recognizedObjectClass) {
super(recognizedObjectClass);
}
protected String defaultDisplayName() {
return "Office Script Parcel";
}
protected void initialize() {
super.initialize();
ExtensionList extensions = new ExtensionList();
extensions.addExtension(ParcelZipper.PARCEL_EXTENSION);
setExtensions(extensions);
}
protected SystemAction[] defaultActions() {
return new SystemAction[] {
// SystemAction.get(MountParcelAction.class),
SystemAction.get(DeployParcelAction.class),
null,
SystemAction.get(CutAction.class),
SystemAction.get(CopyAction.class),
// SystemAction.get(PasteAction.class),
null,
SystemAction.get(DeleteAction.class),
SystemAction.get(RenameAction.class),
null,
// SystemAction.get(ToolsAction.class),
SystemAction.get(PropertiesAction.class),
};
}
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
return new ParcelDataObject(primaryFile, this);
}
}

View File

@@ -0,0 +1,49 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/** Description of {@link ParcelDataLoader}.
*
* @author tomaso
*/
public class ParcelDataLoaderBeanInfo extends SimpleBeanInfo {
// If you have additional properties:
/*
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor myProp = new PropertyDescriptor("myProp", ParcelDataLoader.class);
myProp.setDisplayName(NbBundle.getMessage(ParcelDataLoaderBeanInfo.class, "PROP_myProp"));
myProp.setShortDescription(NbBundle.getMessage(ParcelDataLoaderBeanInfo.class, "HINT_myProp"));
return new PropertyDescriptor[] {myProp};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
*/
public BeanInfo[] getAdditionalBeanInfo() {
try {
// I.e. MultiFileLoader.class or UniFileLoader.class.
return new BeanInfo[] {Introspector.getBeanInfo(ParcelDataLoader.class.getSuperclass())};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelDataIcon.gif");
} else {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelDataIcon32.gif");
}
}
}

View File

@@ -0,0 +1,87 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.*;
import java.awt.datatransfer.Transferable;
import java.util.zip.*;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
import org.openide.util.datatransfer.*;
import org.openide.ErrorManager;
import org.openide.windows.OutputWriter;
import org.openoffice.netbeans.modules.office.actions.ParcelCookie;
/** A node to represent this object.
*
* @author tomaso
*/
public class ParcelDataNode extends DataNode {
public ParcelDataNode(ParcelDataObject obj) {
this(obj, Children.LEAF);
}
public ParcelDataNode(ParcelDataObject obj, Children ch) {
super(obj, ch);
setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon");
}
protected ParcelDataObject getParcelDataObject() {
return (ParcelDataObject)getDataObject();
}
public static class ParcelPasteType extends PasteType {
ParcelDataNode sourceParcel = null;
File targetDocument = null;
boolean isCut = false;
public ParcelPasteType(ParcelDataNode sourceParcel,
File targetDocument, boolean isCut) {
this.sourceParcel = sourceParcel;
this.targetDocument = targetDocument;
this.isCut = isCut;
}
public Transferable paste() {
ParcelCookie parcelCookie =
(ParcelCookie)sourceParcel.getCookie(ParcelCookie.class);
parcelCookie.deploy(targetDocument);
if (isCut == true) {
FileObject fo = sourceParcel.getDataObject().getPrimaryFile();
try {
fo.delete();
}
catch (IOException ioe) {}
return ExTransferable.EMPTY;
}
else {
return null;
}
}
}
/* Example of adding Executor / Debugger / Arguments to node:
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set set = sheet.get(ExecSupport.PROP_EXECUTION);
if (set == null) {
set = new Sheet.Set();
set.setName(ExecSupport.PROP_EXECUTION);
set.setDisplayName(NbBundle.getMessage(ParcelDataNode.class, "LBL_DataNode_exec_sheet"));
set.setShortDescription(NbBundle.getMessage(ParcelDataNode.class, "HINT_DataNode_exec_sheet"));
}
((ExecSupport)getCookie(ExecSupport.class)).addProperties(set);
// Maybe:
((CompilerSupport)getCookie(CompilerSupport.class)).addProperties(set);
sheet.put(set);
return sheet;
}
*/
// Don't use getDefaultAction(); just make that first in the data loader's getActions list
}

View File

@@ -0,0 +1,50 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.actions.*;
import org.openide.cookies.*;
import org.openide.filesystems.FileObject;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openoffice.netbeans.modules.office.actions.*;
/** Represents a Parcel object in the Repository.
*
* @author tomaso
*/
public class ParcelDataObject extends MultiDataObject {
public ParcelDataObject(FileObject pf, ParcelDataLoader loader) throws DataObjectExistsException {
super(pf, loader);
init();
}
private void init() {
CookieSet cookies = getCookieSet();
cookies.add(new ParcelSupport(getPrimaryFile()));
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
// If you add context help, change to:
// return new HelpCtx(ParcelDataObject.class);
}
protected Node createNodeDelegate() {
return new ParcelDataNode(this);
}
/* If you made an Editor Support you will want to add these methods:
final void addSaveCookie(SaveCookie save) {
getCookieSet().add(save);
}
final void removeSaveCookie(SaveCookie save) {
getCookieSet().remove(save);
}
*/
}

View File

@@ -0,0 +1,62 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.IOException;
import org.openide.actions.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
/** Recognizes single files in the Repository as being of a certain type.
*
* @author tomaso
*/
public class ParcelDescriptorDataLoader extends UniFileLoader {
public ParcelDescriptorDataLoader() {
this("org.openoffice.netbeans.modules.office.loader.ParcelDescriptorDataObject");
}
// Can be useful for subclasses:
protected ParcelDescriptorDataLoader(String recognizedObjectClass) {
super(recognizedObjectClass);
}
protected String defaultDisplayName() {
return "StarOffice Script Parcel Descriptor";
}
protected void initialize() {
super.initialize();
// ExtensionList extensions = new ExtensionList();
// extensions.addMimeType("text/x-parcel+xml");
// extensions.addExtension("pml");
getExtensions().addMimeType("text/x-parcel+xml");
// setExtensions(extensions);
}
protected SystemAction[] defaultActions() {
return new SystemAction[] {
SystemAction.get(OpenAction.class),
// SystemAction.get(GenerateParcelAction.class),
null,
SystemAction.get(CutAction.class),
SystemAction.get(CopyAction.class),
SystemAction.get(PasteAction.class),
null,
SystemAction.get(DeleteAction.class),
SystemAction.get(RenameAction.class),
null,
// SystemAction.get(SaveAsTemplateAction.class),
// null,
// SystemAction.get(ToolsAction.class),
SystemAction.get(PropertiesAction.class),
};
}
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
return new ParcelDescriptorDataObject(primaryFile, this);
}
}

View File

@@ -0,0 +1,49 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/** Description of {@link ParcelDescriptorDataLoader}.
*
* @author tomaso
*/
public class ParcelDescriptorDataLoaderBeanInfo extends SimpleBeanInfo {
// If you have additional properties:
/*
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor myProp = new PropertyDescriptor("myProp", ParcelDescriptorDataLoader.class);
myProp.setDisplayName(NbBundle.getMessage(ParcelDescriptorDataLoaderBeanInfo.class, "PROP_myProp"));
myProp.setShortDescription(NbBundle.getMessage(ParcelDescriptorDataLoaderBeanInfo.class, "HINT_myProp"));
return new PropertyDescriptor[] {myProp};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
*/
public BeanInfo[] getAdditionalBeanInfo() {
try {
// I.e. MultiFileLoader.class or UniFileLoader.class.
return new BeanInfo[] {Introspector.getBeanInfo(ParcelDescriptorDataLoader.class.getSuperclass())};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelDescriptorDataIcon.gif");
} else {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelDescriptorDataIcon32.gif");
}
}
}

View File

@@ -0,0 +1,54 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.NbBundle;
import org.openoffice.netbeans.modules.office.nodes.*;
import org.openoffice.netbeans.modules.office.actions.*;
/** A node to represent this object.
*
* @author tomaso
*/
public class ParcelDescriptorDataNode extends DataNode {
public ParcelDescriptorDataNode(ParcelDescriptorDataObject obj) {
this(obj, Children.LEAF);
}
public ParcelDescriptorDataNode(ParcelDescriptorDataObject obj, Children ch) {
super(obj, ch);
setHidden(true);
setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon");
}
protected ParcelDescriptorDataObject getParcelDescriptorDataObject() {
return (ParcelDescriptorDataObject)getDataObject();
}
public boolean canRename() {
return false;
}
/* Example of adding Executor / Debugger / Arguments to node:
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set set = sheet.get(ExecSupport.PROP_EXECUTION);
if (set == null) {
set = new Sheet.Set();
set.setName(ExecSupport.PROP_EXECUTION);
set.setDisplayName(NbBundle.getMessage(ParcelDescriptorDataNode.class, "LBL_DataNode_exec_sheet"));
set.setShortDescription(NbBundle.getMessage(ParcelDescriptorDataNode.class, "HINT_DataNode_exec_sheet"));
}
((ExecSupport)getCookie(ExecSupport.class)).addProperties(set);
// Maybe:
((CompilerSupport)getCookie(CompilerSupport.class)).addProperties(set);
sheet.put(set);
return sheet;
}
*/
// Don't use getDefaultAction(); just make that first in the data loader's getActions list
}

View File

@@ -0,0 +1,56 @@
package org.openoffice.netbeans.modules.office.loader;
import org.openide.actions.*;
import org.openide.cookies.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorEditorSupport;
import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserSupport;
/** Represents a ParcelDescriptor object in the Repository.
*
* @author tomaso
*/
public class ParcelDescriptorDataObject extends MultiDataObject {
private boolean canParse = false;
public ParcelDescriptorDataObject(FileObject pf, ParcelDescriptorDataLoader loader) throws DataObjectExistsException {
super(pf, loader);
init();
}
private void init() {
FileObject fo = getPrimaryFile();
if (FileUtil.toFile(fo) != null)
canParse = true;
CookieSet cookies = getCookieSet();
cookies.add(new ParcelDescriptorEditorSupport(this));
if (canParse == true)
cookies.add(new ParcelDescriptorParserSupport(getPrimaryFile()));
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
protected Node createNodeDelegate() {
if (canParse == true)
return new ParcelDescriptorDataNode(this);
else
return new ParcelDescriptorDataNode(this, Children.LEAF);
}
// If you made an Editor Support you will want to add these methods:
public final void addSaveCookie(SaveCookie save) {
getCookieSet().add(save);
}
public final void removeSaveCookie(SaveCookie save) {
getCookieSet().remove(save);
}
}

View File

@@ -0,0 +1,177 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.File;
import java.io.IOException;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataFilter;
import org.openide.loaders.DataObjectExistsException;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.nodes.CookieSet;
import org.openide.nodes.Node;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.HelpCtx;
import org.openoffice.idesupport.filter.*;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.netbeans.modules.office.actions.ParcelFolderSupport;
public class ParcelFolder extends DataFolder {
public ParcelFolder(FileObject pf, ParcelFolderDataLoader loader)
throws DataObjectExistsException {
super(pf, loader);
CookieSet cookies = getCookieSet();
cookies.add(new ParcelFolderSupport(this));
}
public Node createNodeDelegate() {
return new ParcelFolderNode(this, new ParcelFolderFilter());
}
public class ParcelFolderNode extends DataFolder.FolderNode {
private static final String LOCATION = "location";
private static final String FILTER = "filter";
private File location;
private FileFilter filter;
private final FileFilter DEFAULT_FILTER = BinaryOnlyFilter.getInstance();
public ParcelFolderNode(ParcelFolder pf, DataFilter dataFilter) {
super(pf.createNodeChildren(dataFilter));
location = (File)pf.getPrimaryFile().getAttribute(LOCATION);
if (location == null)
location = FileUtil.toFile(pf.getPrimaryFile());
String name = (String)pf.getPrimaryFile().getAttribute(FILTER);
if (name == null)
filter = DEFAULT_FILTER;
else {
for (int i = 0; i < availableFilters.length; i++)
if (name.equals(availableFilters[i].toString()))
filter = availableFilters[i];
}
}
public File getTargetDir() {
return location;
}
public FileFilter getFileFilter() {
return filter;
}
public Sheet createSheet() {
Sheet sheet;
Sheet.Set props;
Node.Property prop;
sheet = super.createSheet();
props = sheet.get(Sheet.PROPERTIES);
if (props == null) {
props = Sheet.createPropertiesSet();
sheet.put(props);
}
// prop = createLocationProperty();
// props.put(prop);
prop = createFilterProperty();
props.put(prop);
return sheet;
}
private Node.Property createLocationProperty() {
Node.Property prop =
new PropertySupport.ReadWrite(LOCATION, File.class,
"Location", "Output location of Parcel Zip File") {
public void setValue(Object obj) {
if (obj instanceof File) {
location = (File)obj;
try {
getPrimaryFile().setAttribute(LOCATION, location);
}
catch (IOException ioe) {
System.out.println("Error setting location attribute");
}
}
}
public Object getValue() {
return location;
}
};
prop.setValue("files", Boolean.FALSE);
return prop;
}
private FileFilter[] availableFilters =
new FileFilter[] {BinaryOnlyFilter.getInstance(), AllFilesFilter.getInstance()};
private Node.Property createFilterProperty() {
Node.Property prop =
new PropertySupport.ReadWrite(FILTER, String.class,
"File Filter", "Files to be included in Parcel") {
public void setValue(Object obj) {
if (obj instanceof FileFilter) {
filter = (FileFilter)obj;
try {
getPrimaryFile().setAttribute(FILTER, filter.toString());
}
catch (IOException ioe) {
System.out.println("Error setting filter attribute");
}
}
}
public Object getValue() {
return filter;
}
public PropertyEditor getPropertyEditor() {
return new PropertyEditorSupport() {
public String[] getTags() {
String[] tags = new String[availableFilters.length];
for (int i = 0; i < availableFilters.length; i++)
tags[i] = availableFilters[i].toString();
return tags;
}
public void setAsText(String text) {
for (int i = 0; i < availableFilters.length; i++)
if (text.equals(availableFilters[i].toString()))
this.setValue(availableFilters[i]);
}
public String getAsText() {
return this.getValue().toString();
}
};
}
};
return prop;
}
}
private class ParcelFolderFilter implements DataFilter {
public boolean acceptDataObject(DataObject dobj) {
String name = dobj.getPrimaryFile().getNameExt();
if (name.equals(ParcelZipper.PARCEL_DESCRIPTOR_XML))
return false;
return true;
}
}
}

View File

@@ -0,0 +1,85 @@
package org.openoffice.netbeans.modules.office.loader;
import java.io.IOException;
import java.io.File;
import org.openide.actions.*;
import org.openide.filesystems.*;
import org.openide.loaders.*;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.netbeans.modules.office.actions.*;
/** Recognizes single files in the Repository as being of a certain type.
*
* @author tomaso
*/
public class ParcelFolderDataLoader extends UniFileLoader {
public ParcelFolderDataLoader() {
this("org.openoffice.netbeans.modules.office.loader.ParcelFolder");
}
protected ParcelFolderDataLoader(String recognizedObjectClass) {
super(recognizedObjectClass);
}
protected String defaultDisplayName() {
return "Office Script Parcel Folder";
}
protected void initialize() {
super.initialize();
}
protected FileObject findPrimaryFile(FileObject fo) {
if (fo.isFolder() == false)
return null;
FileObject contents = fo.getFileObject(ParcelZipper.CONTENTS_DIRNAME);
if (contents == null)
return null;
FileObject descriptor = contents.getFileObject(ParcelZipper.PARCEL_DESCRIPTOR_XML);
if (descriptor == null)
return null;
return fo;
}
protected SystemAction[] defaultActions() {
return new SystemAction[] {
// SystemAction.get(OpenLocalExplorerAction.class),
// SystemAction.get(FindAction.class),
// null,
// SystemAction.get(FileSystemAction.class),
// null,
SystemAction.get(CompileParcelAction.class),
SystemAction.get(BuildParcelAction.class),
SystemAction.get(ConfigureParcelAction.class),
null,
SystemAction.get(CutAction.class),
SystemAction.get(CopyAction.class),
// SystemAction.get(PasteAction.class),
null,
SystemAction.get(DeleteAction.class),
SystemAction.get(RenameAction.class),
null,
// SystemAction.get(SaveAsTemplateAction.class),
// null,
// SystemAction.get(ToolsAction.class),
SystemAction.get(PropertiesAction.class),
};
}
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
return new ParcelFolder(primaryFile, this);
}
protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) {
return new FileEntry.Folder(obj, primaryFile);
}
}

View File

@@ -0,0 +1,49 @@
package org.openoffice.netbeans.modules.office.loader;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/** Description of {@link ParcelFolderDataLoader}.
*
* @author tomaso
*/
public class ParcelFolderDataLoaderBeanInfo extends SimpleBeanInfo {
// If you have additional properties:
/*
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor myProp = new PropertyDescriptor("myProp", ParcelFolderDataLoader.class);
myProp.setDisplayName(NbBundle.getMessage(ParcelFolderDataLoaderBeanInfo.class, "PROP_myProp"));
myProp.setShortDescription(NbBundle.getMessage(ParcelFolderDataLoaderBeanInfo.class, "HINT_myProp"));
return new PropertyDescriptor[] {myProp};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
*/
public BeanInfo[] getAdditionalBeanInfo() {
try {
// I.e. MultiFileLoader.class or UniFileLoader.class.
return new BeanInfo[] {Introspector.getBeanInfo(ParcelFolderDataLoader.class.getSuperclass())};
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelFolderDataIcon.gif");
} else {
return Utilities.loadImage("org/openoffice/netbeans/modules/office/loaders/ParcelFolderDataIcon32.gif");
}
}
}

View File

@@ -0,0 +1,100 @@
package org.openoffice.netbeans.modules.office.nodes;
import java.io.IOException;
import java.util.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.nodes.*;
import org.openide.actions.*;
import org.openide.util.actions.SystemAction;
import org.openide.util.HelpCtx;
import org.openoffice.netbeans.modules.office.actions.OfficeDocumentCookie;
public class OfficeDocumentChildren extends Children.Keys implements ChangeListener {
private OfficeDocumentCookie document = null;
public OfficeDocumentChildren(OfficeDocumentCookie cookie) {
document = cookie;
}
private void refreshKeys() {
if (document == null) {
setKeys(Collections.EMPTY_SET);
return;
}
Enumeration parcels = document.getParcels();
if (parcels.hasMoreElements() != true) {
setKeys(Collections.EMPTY_SET);
return;
}
ArrayList keys = new ArrayList();
while (parcels.hasMoreElements()) {
String parcel = (String)parcels.nextElement();
keys.add(parcel);
}
setKeys(keys);
}
protected void addNotify() {
super.addNotify();
document.addChangeListener(this);
refreshKeys();
}
protected void removeNotify() {
super.removeNotify();
document.removeChangeListener(this);
setKeys(Collections.EMPTY_SET);
}
protected Node[] createNodes(Object key) {
String name = (String)key;
return new Node[] {new ParcelNode(name)};
}
public void stateChanged(ChangeEvent e) {
refreshKeys();
}
private class ParcelNode extends AbstractNode {
private String name;
public ParcelNode(String name) {
super(Children.LEAF);
this.name = name;
init();
}
private void init() {
setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon");
setName(name);
setDisplayName(name.substring(name.lastIndexOf(".") + 1));
setShortDescription(name);
}
protected SystemAction[] createActions() {
return new SystemAction[] {
SystemAction.get(DeleteAction.class),
};
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
public boolean canDestroy() {
return true;
}
public void destroy() throws IOException {
super.destroy();
document.removeParcel(name);
}
}
}

View File

@@ -0,0 +1,64 @@
package org.openoffice.netbeans.modules.office.nodes;
import java.util.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import org.openide.nodes.*;
import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserCookie;
/** List of children of a containing node.
* Remember to document what your permitted keys are!
*
* @author tomaso
*/
public class ParcelDescriptorChildren extends Children.Keys implements ChangeListener {
private ParcelDescriptorParserCookie parserCookie = null;
public ParcelDescriptorChildren(ParcelDescriptorParserCookie cookie) {
parserCookie = cookie;
}
private void refreshKeys() {
NodeList nl;
int len;
if (parserCookie == null ||
(nl = parserCookie.getScriptElements()) == null ||
(len = nl.getLength()) == 0) {
setKeys(Collections.EMPTY_SET);
return;
}
ArrayList keys = new ArrayList(len);
for (int i = 0; i < len; i++)
keys.add(nl.item(i));
setKeys(keys);
}
protected void addNotify() {
super.addNotify();
parserCookie.addChangeListener(this);
refreshKeys();
}
protected void removeNotify() {
super.removeNotify();
parserCookie.removeChangeListener(this);
setKeys(Collections.EMPTY_SET);
}
protected Node[] createNodes(Object key) {
Element el = (Element)key;
System.out.println("element is: " + el);
return new Node[] {new ScriptNode(el)};
}
public void stateChanged(ChangeEvent e) {
refreshKeys();
}
}

View File

@@ -0,0 +1,182 @@
package org.openoffice.netbeans.modules.office.nodes;
import org.w3c.dom.*;
import org.openide.actions.*;
import org.openide.nodes.*;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.SystemAction;
/** A simple node with no children.
*
* @author tomaso
*/
public class ScriptNode extends AbstractNode {
private Element element;
private static final String LOGICAL_NAME = "logicalname";
private static final String LANGUAGE_NAME = "languagename";
public ScriptNode(Element element) {
super(Children.LEAF);
this.element = element;
init();
}
private void init() {
setIconBase("/org/openoffice/netbeans/modules/office/resources/OfficeIcon");
setDefaultAction(SystemAction.get(PropertiesAction.class));
NodeList nl = element.getElementsByTagName(LOGICAL_NAME);
Element nameElement = (Element)nl.item(0);
String name = nameElement.getAttribute("value");
setName(name);
setDisplayName(name.substring(name.lastIndexOf(".") + 1));
setShortDescription(name);
}
protected SystemAction[] createActions() {
return new SystemAction[] {
SystemAction.get(ToolsAction.class),
null,
SystemAction.get(PropertiesAction.class),
};
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
// RECOMMENDED - handle cloning specially (so as not to invoke the overhead of FilterNode):
/*
public Node cloneNode() {
// Try to pass in similar constructor params to what you originally got:
return new ScriptNode();
}
*/
protected Sheet createSheet() {
Sheet sheet = super.createSheet();
Sheet.Set props = sheet.get(Sheet.PROPERTIES);
if (props == null) {
props = Sheet.createPropertiesSet();
sheet.put(props);
}
org.openide.nodes.Node.Property prop = null;
if ((prop = getStringProperty(LOGICAL_NAME)) != null)
props.put(prop);
if ((prop = getStringProperty(LANGUAGE_NAME)) != null)
props.put(prop);
return sheet;
}
private org.openide.nodes.Node.Property getStringProperty(String name) {
NodeList nl = element.getElementsByTagName(name);
if(nl.getLength() != 1)
return null;
Element nameElement = (Element)nl.item(0);
String value = nameElement.getAttribute("value");
return new StringProperty(this, name, value);
}
private class StringProperty extends PropertySupport.ReadOnly {
private String name, value;
private ScriptNode sn;
public StringProperty(ScriptNode sn, String name, String value) {
super(value, String.class, name,
"The name of the java language method for this script");
this.sn = sn;
this.name = name;
this.value = value;
}
public Object getValue() {
return value;
}
/* public void setValue(Object obj) {
System.out.println("Setting value to: " + obj.toString());
if ((value instanceof String) != true)
throw new IllegalArgumentException(name +
" property must be of type String");
value = obj.toString();
if (name.equals(LOGICAL_NAME)) {
sn.setName(value);
sn.setDisplayName(value.substring(value.lastIndexOf(".") + 1));
sn.setShortDescription(value);
}
} */
}
/* public boolean canRename() {
return true;
}
public void setName(String nue) {
// Update visible name, fire property changes:
super.setName(nue);
} */
/*
public boolean canDestroy() {
return true;
}
public void destroy() throws IOException {
// Actually remove the node itself and fire property changes:
super.destroy();
// perform additional actions, i.e. delete underlying object
} */
// Handle copying and cutting specially:
/*
public boolean canCopy() {
return true;
}
public boolean canCut() {
return true;
}
public Transferable clipboardCopy() {
// Add to, do not replace, the default node copy flavor:
ExTransferable et = ExTransferable.create(super.clipboardCopy());
et.put(new ExTransferable.Single(DataFlavor.stringFlavor) {
protected Object getData() {
return ScriptNode.this.getDisplayName();
}
});
return et;
}
public Transferable clipboardCut() {
// Add to, do not replace, the default node cut flavor:
ExTransferable et = ExTransferable.create(super.clipboardCut());
// This is not so useful because this node will not be destroyed afterwards
// (it is up to the paste type to decide whether to remove the "original",
// and it is not safe to assume that getData will only be called once):
et.put(new ExTransferable.Single(DataFlavor.stringFlavor) {
protected Object getData() {
return ScriptNode.this.getDisplayName();
}
});
return et;
}
*/
// Permit user to customize whole node at once (instead of per-property):
/*
public boolean hasCustomizer() {
return true;
}
public Component getCustomizer() {
return new MyCustomizingPanel(this);
}
*/
}

View File

@@ -0,0 +1,13 @@
# Options API
LBL_settings=Office Settings
PROP_OfficeDirectory=Path to Office installation
HINT_OfficeDirectory=Path to the Office installation
HINT_WarnBeforeDocDeploy=Pop up a dialog before deploying to a document
PROP_WarnBeforeDocDeploy=Pop up a dialog before deploying to a document
HINT_WarnAfterDirDeploy=Pop up a dialog after deploying to a directory
PROP_WarnAfterDirDeploy=Pop up a dialog after deploying to a directory
HINT_WarnBeforeMount=Warn before mounting Office Scripting Framework support jar
PROP_WarnBeforeMount=Warn before mounting Office Scripting Framework support jar

View File

@@ -0,0 +1,102 @@
package org.openoffice.netbeans.modules.office.options;
import java.util.Hashtable;
import java.util.Enumeration;
import java.io.File;
import java.io.IOException;
import org.openide.options.SystemOption;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openoffice.idesupport.SVersionRCFile;
/** Options for something or other.
*
* @author tomaso
*/
public class OfficeSettings extends SystemOption {
// private static final long serialVersionUID = ...;
public static final String OFFICE_DIRECTORY = "OfficeDirectory";
public static final String WARN_BEFORE_DOC_DEPLOY = "WarnBeforeDocDeploy";
public static final String WARN_AFTER_DIR_DEPLOY = "WarnAfterDirDeploy";
public static final String WARN_BEFORE_MOUNT = "WarnBeforeMount";
protected void initialize() {
super.initialize();
setWarnBeforeDocDeploy(true);
setWarnAfterDirDeploy(true);
setWarnBeforeMount(true);
SVersionRCFile sversion = new SVersionRCFile();
try {
Hashtable versions = sversion.getVersions();
Enumeration enum = versions.elements();
String path;
while (enum.hasMoreElements()) {
path = (String)enum.nextElement();
File f = new File(path);
if (f.exists()) {
setOfficeDirectory(path);
return;
}
}
}
catch (IOException ioe) {
/* do nothing a default will be used */
}
// if no office version is found try a default value
setOfficeDirectory(System.getProperty("user.home") +
System.getProperty("file.separator") + "StarOffice6.0");
}
public String displayName() {
return "Office Settings";
}
public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}
public static OfficeSettings getDefault() {
return (OfficeSettings)findObject(OfficeSettings.class, true);
}
public String getOfficeDirectory() {
return (String)getProperty(OFFICE_DIRECTORY);
}
public void setOfficeDirectory(String path) {
putProperty(OFFICE_DIRECTORY, path, true);
}
public boolean getWarnBeforeDocDeploy() {
return ((Boolean)getProperty(WARN_BEFORE_DOC_DEPLOY)).booleanValue();
}
public void setWarnBeforeDocDeploy(boolean value) {
putProperty(WARN_BEFORE_DOC_DEPLOY, new Boolean(value), true);
}
public boolean getWarnAfterDirDeploy() {
return ((Boolean)getProperty(WARN_AFTER_DIR_DEPLOY)).booleanValue();
}
public void setWarnAfterDirDeploy(boolean value) {
putProperty(WARN_AFTER_DIR_DEPLOY, new Boolean(value), true);
}
public boolean getWarnBeforeMount() {
return ((Boolean)getProperty(WARN_BEFORE_MOUNT)).booleanValue();
}
public void setWarnBeforeMount(boolean value) {
putProperty(WARN_BEFORE_MOUNT, new Boolean(value), true);
}
}

View File

@@ -0,0 +1,75 @@
package org.openoffice.netbeans.modules.office.options;
import java.awt.Image;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
/** Description of {@link OfficeSettings}.
*
* @author tomaso
*/
public class OfficeSettingsBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor[] props = new PropertyDescriptor[] {
new PropertyDescriptor(OfficeSettings.OFFICE_DIRECTORY,
OfficeSettings.class,
"get" + OfficeSettings.OFFICE_DIRECTORY,
"set" + OfficeSettings.OFFICE_DIRECTORY),
new PropertyDescriptor(OfficeSettings.WARN_BEFORE_DOC_DEPLOY,
OfficeSettings.class,
"get" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY,
"set" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY),
new PropertyDescriptor(OfficeSettings.WARN_AFTER_DIR_DEPLOY,
OfficeSettings.class,
"get" + OfficeSettings.WARN_AFTER_DIR_DEPLOY,
"set" + OfficeSettings.WARN_AFTER_DIR_DEPLOY),
new PropertyDescriptor(OfficeSettings.WARN_BEFORE_MOUNT,
OfficeSettings.class,
"get" + OfficeSettings.WARN_BEFORE_MOUNT,
"set" + OfficeSettings.WARN_BEFORE_MOUNT)
};
props[0].setDisplayName(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "PROP_OfficeDirectory"));
props[0].setShortDescription(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "HINT_OfficeDirectory"));
props[1].setDisplayName(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "PROP_WarnBeforeDocDeploy"));
props[1].setShortDescription(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "HINT_WarnBeforeDocDeploy"));
props[1].setHidden(true);
props[2].setDisplayName(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "PROP_WarnAfterDirDeploy"));
props[2].setShortDescription(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "HINT_WarnAfterDirDeploy"));
props[2].setHidden(true);
props[3].setDisplayName(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "PROP_WarnBeforeMount"));
props[3].setShortDescription(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "HINT_WarnBeforeMount"));
props[3].setHidden(true);
return props;
}
catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
public Image getIcon(int type) {
if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
return Utilities.loadImage("/org/openoffice/netbeans/modules/office/options/OfficeSettingsIcon.gif");
} else {
return Utilities.loadImage("/org/openoffice/netbeans/modules/office/options/OfficeSettingsIcon32.gif");
}
}
}

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
This wizard will let you mount the Office Application scripts directory
</BODY>
</HTML>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
<module name="org.openoffice.netbeans.modules.office/1"/>
<instanceof class="org.openide.filesystems.FileSystem"/>
<instance class="org.netbeans.core.ExLocalFileSystem"/>
</settings>

View File

@@ -0,0 +1,20 @@
Templates/StarOfficeScripting=StarOffice Scripting
Templates/StarOfficeScripting/parcel.xml=Script Parcel Descriptor
Services/MIMEResolver/org-netbeans-modules-office-mime-resolver.xml=Script Parcel Descriptor File
Templates=Templates
Templates/StarOfficeScripting/HelloWorld=Hello World Example Script
Templates/Mount/org-openoffice-netbeans-modules-office-resources-AppStorage.settings=Office Application Scripts
Templates/Mount/org-openoffice-netbeans-modules-office-resources-OpenOfficeDocFileSystem.settings=OpenOffice document
UI/Services/IDEConfiguration/ServerAndExternalToolSettings/org-openoffice-netbeans-modules-office-options-OfficeSettings.instance=Office Settings
Services/org-openoffice-netbeans-modules-office-resources-OfficeSettings.settings=Office Settings
PROP_OfficeDirectory=Office Installation Directory
HINT_OfficeDirectory=Path to directory where Office is installed
Templates/StarOfficeScripting/Parcel=Parcel Recipe
Menu/Help/office-scripting.url=&Office Scripting Framework Site

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
This allows you to create an Empty StarOffice Script.
</BODY>
</HTML>

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

View File

@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
<module name="org.openoffice.netbeans.modules.office"/>
<instanceof class="org.openide.util.SharedClassObject"/>
<instanceof class="org.openide.util.SystemOption"/>
<instanceof class="org.openoffice.netbeans.modules.office.options.OfficeSettings"/>
<instance class="org.openoffice.netbeans.modules.office.options.OfficeSettings"/>
</settings>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
This allows you to mount OpenOffice document.
</BODY>
</HTML>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
<module name="org.openoffice.netbeans.modules.office/1"/>
<instanceof class="org.openide.filesystems.FileSystem"/>
<instance class="org.openoffice.netbeans.modules.office.filesystem.OpenOfficeDocFileSystem"/>
</settings>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
This allows you to create a Hello World example StarOffice Script.
</BODY>
</HTML>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
This allows you to create a StarOffice Script Parcel Descriptor File.
</BODY>
</HTML>

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<folder name="Templates">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<folder name="StarOfficeScripting">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<folder name="Parcel">
<attr boolvalue="true" name="template"/>
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/OfficeIcon.gif"/>
<attr name="templateWizardURL" urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/EmptyParcel.html"/>
<attr name="templateWizardIterator" newvalue="org.openoffice.netbeans.modules.office.wizard.ParcelContentsIterator"/>
<folder name="Contents">
<file name="parcel-descriptor.xml" url="templates/EmptyParcelDescriptor.xml_"/>
<file name="Empty.java" url="templates/Empty.java_"/>
</folder>
</folder>
</folder>
<attr boolvalue="true" name="Ant/StarOfficeScripting"/>
<attr boolvalue="true" name="StarOfficeScripting/Other"/>
<!-- OpenOfficeDoc FileSystem BEGIN: -->
<!-- Uncomment to enable writable mounting of Office Documents
<folder name="Mount">
<attr name="org-netbeans-core-ExLocalFileSystem.settings/org-openoffice-netbeans-modules-office-resources-OpenOfficeDocFileSystem.settings"
boolvalue="true"/>
<attr name="org-openoffice-netbeans-modules-office-resources-OpenOfficeDocFileSystem.settings/VCS"
boolvalue="true"/>
<file name="org-openoffice-netbeans-modules-office-resources-OpenOfficeDocFileSystem.settings"
url="OpenOfficeDocFileSystem.settings">
<attr name="template"
boolvalue="true"/>
<attr name="SystemFileSystem.localizingBundle"
stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<attr name="SystemFileSystem.icon"
urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/OpenOfficeDocFileSystemIcon.png"/>
<attr name="templateWizardIterator"
methodvalue="org.netbeans.core.ui.MountNode.iterator"/>
<attr name="templateWizardURL"
urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/OpenOfficeDocFileSystem.html"/>
</file>
</folder>
-->
<!-- OpenOfficeDoc FileSystem END: -->
</folder>
<folder name="Services">
<folder name="MIMEResolver">
<file name="org-netbeans-modules-office-mime-resolver.xml" url="mime-resolver.xml">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/OfficeIcon.gif"/>
</file>
</folder>
<file name="org-openoffice-netbeans-modules-office-resources-OfficeSettings.settings" url="OfficeSettings.settings">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/OfficeIcon.gif"/>
</file>
</folder>
<folder name="Menu">
<folder name="Help">
<attr name="submit-feedback-link.url/office-scripting.url" boolvalue="true"/>
<file name="office-scripting.url" url="office-scripting.url">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.openoffice.netbeans.modules.office.resources.Bundle"/>
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/openoffice/netbeans/modules/office/resources/webLink.gif"/>
</file>
</folder>
</folder>
<folder name="UI">
<folder name="Services">
<folder name="IDEConfiguration">
<folder name="ServerAndExternalToolSettings">
<file name="org-openoffice-netbeans-modules-office-resources-OfficeSettings.shadow">
<attr name="originalFile" stringvalue="Services/org-openoffice-netbeans-modules-office-resources-OfficeSettings.settings"/>
</file>
</folder>
</folder>
</folder>
</folder>
<attr boolvalue="true" name="Templates/Services"/>
</filesystem>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.0//EN" "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
<MIME-resolver>
<!-- Resolve according to root element: -->
<file>
<ext name="xml"/>
<resolver mime="text/x-parcel+xml">
<xml-rule>
<element name="parcel"/>
</xml-rule>
</resolver>
</file>
</MIME-resolver>

View File

@@ -0,0 +1 @@
http://udk.openoffice.org/common/man/drafts/scripting/index.html

View File

@@ -0,0 +1,28 @@
// If using XMultiServiceFactory need to uncomment import directive below:
//import com.sun.star.lang.XMultiServiceFactory;
// If using XDesktop need to uncomment import directive below:
//import com.sun.star.frame.XDesktop;
// If using XComponent need to uncomment import directive below:
//import com.sun.star.lang.XComponent;
import drafts.com.sun.star.script.framework.XScriptContext;
public class Empty {
public void doMethod(XScriptContext xSc) {
/* Methods available from XScriptContext:
xSc.getDocument() returns XModel
xSc.getDesktop() returns XDesktop
xSc.getMultiComponentFactory() returns XMultiComponentFactory
*/
// Uncomment to get the current document as a component
// XComponent xcomponent = xSc.getDocument();
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<parcel>
</parcel>

View File

@@ -0,0 +1,41 @@
// If using XMultiServiceFactory need to uncomment import directive below:
//import com.sun.star.lang.XMultiServiceFactory;
// If using XDesktop need to uncomment import directive below:
//import com.sun.star.frame.XDesktop;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.*;
import com.sun.star.text.*;
import drafts.com.sun.star.script.framework.XScriptContext;
public class HelloWorld {
public void printHello(XScriptContext xSc) {
/* Methods available from XScriptContext:
xSc.getDocument() returns XModel
xSc.getDesktop() returns XDesktop
xSc.getMultiComponentFactory() returns XMultiComponentFactory
*/
// Getting the current document as a component
XComponent xcomponent = xSc.getDocument();
// Getting the text document object
XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
XTextDocument.class, xcomponent);
//Getting the text object
XText oText = xtextdocument.getText();
//Create a cursor object
XTextCursor oCursor = oText.createTextCursor();
// Print out Hello World
oText.insertString( oCursor, "**** HELLO ****", false );
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<parcel>
<script language="Java" deploymentdir="java/HelloWorld">
<logicalname value="HelloWorld.printHello"/>
<languagename value="HelloWorld.printHello" location="HelloWorld.class"/>
</script>
</parcel>

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

View File

@@ -0,0 +1,113 @@
package org.openoffice.netbeans.modules.office.utils;
import java.io.File;
import java.io.IOException;
import java.beans.PropertyVetoException;
import org.openide.filesystems.Repository;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.JarFileSystem;
import org.openoffice.idesupport.SVersionRCFile;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
public class FrameworkJarChecker {
public static void mountDependencies() {
String unoilPath = SVersionRCFile.getPathForUnoil(
OfficeSettings.getDefault().getOfficeDirectory());
if (unoilPath == null)
return;
File unoilFile = new File(unoilPath + File.separator + "unoil.jar");
JarFileSystem jfs = new JarFileSystem();
try {
jfs.setJarFile(unoilFile);
}
catch (IOException ioe) {
return;
}
catch (PropertyVetoException pve) {
return;
}
FileSystem result;
try {
result =
Repository.getDefault().findFileSystem(jfs.getSystemName());
}
catch(Exception exp) {
result = null;
}
finally {
jfs.removeNotify();
}
if(result == null) {
// warnBeforeMount();
JarFileSystem newjfs = new JarFileSystem();
try {
newjfs.setJarFile(unoilFile);
}
catch (IOException ioe) {
return;
}
catch (PropertyVetoException pve) {
return;
}
Repository.getDefault().addFileSystem(newjfs);
newjfs.setHidden(true);
}
}
public static void unmountDependencies() {
String unoilPath = SVersionRCFile.getPathForUnoil(
OfficeSettings.getDefault().getOfficeDirectory());
if (unoilPath == null)
return;
File unoilFile = new File(unoilPath + File.separator + "unoil.jar");
JarFileSystem jfs = new JarFileSystem();
try {
jfs.setJarFile(unoilFile);
}
catch (IOException ioe) {
return;
}
catch (PropertyVetoException pve) {
return;
}
FileSystem result;
try {
result =
Repository.getDefault().findFileSystem(jfs.getSystemName());
if(result != null)
Repository.getDefault().removeFileSystem(result);
}
catch(Exception exp) {
}
}
private static void warnBeforeMount() {
OfficeSettings settings = OfficeSettings.getDefault();
if (settings.getWarnBeforeMount() == false)
return;
String message = "The Office Scripting Framework support jar file " +
"is not mounted, so Office scripts will not compile. NetBeans " +
"is going to mount this jar file automatically.";
String prompt = "Show this message in future.";
NagDialog warning = NagDialog.createInformationDialog(
message, prompt, true);
if (warning.getState() == false) {
settings.setWarnBeforeMount(false);
}
}
}

View File

@@ -0,0 +1,70 @@
package org.openoffice.netbeans.modules.office.utils;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.File;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.openide.xml.XMLUtil;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.idesupport.xml.XMLParser;
public class ManifestParser implements XMLParser {
private static ManifestParser parser = null;
private ManifestParser() {
}
public static ManifestParser getManifestParser() {
if (parser == null) {
synchronized(ManifestParser.class) {
if (parser == null)
parser = new ManifestParser();
}
}
return parser;
}
public Document parse(InputStream inputStream) {
InputSource is;
Document result = null;
try {
is = new InputSource(inputStream);
is.setSystemId("file://" +
OfficeSettings.getDefault().getOfficeDirectory() +
File.separator + "share" +
File.separator + "dtd" +
File.separator + "officedocument" +
File.separator + "1_0" + File.separator);
result = XMLUtil.parse(is, false, false, null, null);
}
catch (IOException ioe) {
System.out.println("IO Error parsing stream.");
return null;
}
catch (SAXParseException spe) {
System.out.println("Sax Error parsing stream: " + spe.getMessage());
System.out.println("\tPublicId: " + spe.getPublicId());
System.out.println("\tSystemId: " + spe.getSystemId());
return null;
}
catch (SAXException se) {
System.out.println("Sax Error parsing stream: " + se.getMessage());
return null;
}
return result;
}
public void write(Document doc, OutputStream out) throws IOException {
XMLUtil.write(doc, out, "");
}
}

View File

@@ -0,0 +1,100 @@
package org.openoffice.netbeans.modules.office.utils;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import javax.swing.border.EmptyBorder;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
public class NagDialog {
private NotifyDescriptor descriptor;
private JPanel panel;
private JCheckBox checkbox;
private NagDialog(String message, String prompt, boolean initialState,
int type) {
initUI(message, prompt, initialState, type);
}
public static NagDialog createInformationDialog(
String message, String prompt, boolean initialState) {
NagDialog result = new NagDialog(
message, prompt, initialState, JOptionPane.INFORMATION_MESSAGE);
result.setDescriptor(new NotifyDescriptor.Message(result.getPanel(),
NotifyDescriptor.PLAIN_MESSAGE));
return result;
}
public static NagDialog createConfirmationDialog(
String message, String prompt, boolean initialState) {
NagDialog result = new NagDialog(
message, prompt, initialState, JOptionPane.QUESTION_MESSAGE);
result.setDescriptor(new NotifyDescriptor.Confirmation(
result.getPanel(), NotifyDescriptor.OK_CANCEL_OPTION,
NotifyDescriptor.PLAIN_MESSAGE));
return result;
}
public boolean show() {
TopManager.getDefault().notify(descriptor);
if (descriptor.getValue() == NotifyDescriptor.OK_OPTION)
return true;
else
return false;
}
public boolean getState() {
return checkbox.isSelected();
}
private JPanel getPanel() {
return this.panel;
}
private void setDescriptor(NotifyDescriptor descriptor) {
this.descriptor = descriptor;
}
private void initUI(String message, String prompt, boolean initialState,
int type) {
this.panel = new JPanel();
JOptionPane optionPane = new JOptionPane(message, type, 0, null,
new Object[0], null)
{
public int getMaxCharactersPerLineCount() {
return 100;
}
};
optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI() {
public Dimension getMinimumOptionPaneSize() {
if (minimumSize == null) {
return new Dimension(MinimumWidth, 50);
}
return new Dimension(minimumSize.width, 50);
}
});
optionPane.setWantsInput(false);
JPanel checkPanel = new JPanel();
checkbox = new JCheckBox(prompt, initialState);
checkPanel.setLayout(new BorderLayout());
checkPanel.setBorder(new EmptyBorder(0, 20, 0, 0));
checkPanel.add(checkbox, BorderLayout.WEST);
this.panel.setLayout(new BorderLayout());
this.panel.add(optionPane, BorderLayout.CENTER);
this.panel.add(checkPanel, BorderLayout.SOUTH);
}
}

View File

@@ -0,0 +1,60 @@
package org.openoffice.netbeans.modules.office.utils;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import org.openoffice.idesupport.zip.ParcelZipper;
public class PackageRemover {
private PackageRemover() {
}
public static void removeDeclaration(File source) throws IOException {
File tmp = new File(source.getAbsolutePath() + ".tmp");
BufferedReader in = new BufferedReader(new FileReader(source));
BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith("package") && line.indexOf(ParcelZipper.CONTENTS_DIRNAME) != -1) {
// got package declaration, do not write it
continue;
}
else {
out.write(line, 0, line.length());
out.newLine();
}
}
while ((line = in.readLine()) != null) {
out.write(line, 0, line.length());
out.newLine();
}
in.close();
out.close();
if (source.delete() == false) {
tmp.delete();
throw new IOException("Could not overwrite " + source);
}
else
tmp.renameTo(source);
}
public static void main(String[] args) {
File source = new File(args[0]);
try {
removeDeclaration(source);
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

View File

@@ -0,0 +1,65 @@
package org.openoffice.netbeans.modules.office.utils;
import java.io.*;
import java.util.zip.*;
import java.beans.PropertyVetoException;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.Repository;
import org.openoffice.netbeans.modules.office.filesystem.OpenOfficeDocFileSystem;
public class ZipMounter
{
private static ZipMounter mounter = null;
private ZipMounter() {
}
public static ZipMounter getZipMounter() {
if (mounter == null) {
synchronized(ZipMounter.class) {
if (mounter == null)
mounter = new ZipMounter();
}
}
return mounter;
}
public void mountZipFile(File zipfile)
throws IOException, PropertyVetoException
{
if (zipfile != null) {
addDocumentToRepository(zipfile, true);
}
}
private FileSystem addDocumentToRepository(File rootFile, boolean writeable)
throws IOException, PropertyVetoException
{
Repository repo = Repository.getDefault();
OpenOfficeDocFileSystem oofs;
oofs = (OpenOfficeDocFileSystem)getMountedDocument(rootFile);
if(oofs != null)
repo.removeFileSystem(oofs);
oofs = new OpenOfficeDocFileSystem();
oofs.setDocument(rootFile);
repo.addFileSystem(oofs);
return oofs;
}
/** @return FileSystem which has given jar file as its root or
* null if no such file system could be found in repository */
private FileSystem getMountedDocument(File rootFile)
{
if (rootFile == null)
return null;
FileSystem oofs = null;
try {
oofs = Repository.getDefault().findFileSystem(
OpenOfficeDocFileSystem.computeSystemName(rootFile));
} catch(Exception exp) {
}
return oofs;
}
}

View File

@@ -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

View File

@@ -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);
}
*/
}