diff options
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/loader')
19 files changed, 1848 insertions, 0 deletions
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/Bundle.properties b/scripting/java/org/openoffice/netbeans/modules/office/loader/Bundle.properties new file mode 100644 index 000000000000..eab2fa1f3fbc --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/Bundle.properties @@ -0,0 +1,13 @@ +# 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. +# x-no-translate +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> diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java new file mode 100644 index 000000000000..27aae5ccce4a --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoaderBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoaderBeanInfo.java new file mode 100644 index 000000000000..cea24a71b126 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoaderBeanInfo.java @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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", OfficeDocumentDataLoader.class); + myProp.setDisplayName(NbBundle.getMessage(OfficeDocumentDataLoaderBeanInfo.class, "PROP_myProp")); + myProp.setShortDescription(NbBundle.getMessage(OfficeDocumentDataLoaderBeanInfo.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"); + } + } + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java new file mode 100644 index 000000000000..095b04a9f90c --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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(OfficeDocumentDataNode.class, "LBL_DataNode_exec_sheet")); + set.setShortDescription(NbBundle.getMessage(OfficeDocumentDataNode.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 + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java new file mode 100644 index 000000000000..b93f59d21350 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java new file mode 100644 index 000000000000..5bca0a6b2d5a --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java @@ -0,0 +1,137 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package org.openoffice.netbeans.modules.office.loader; + +import java.io.IOException; + +import org.openide.TopManager; +import org.openide.NotifyDescriptor; +import org.openide.ErrorManager; + +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.Repository; + +import org.openide.loaders.DataObject; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObjectExistsException; + +import org.openide.nodes.Node; +import org.openide.util.datatransfer.NewType; + +import org.openoffice.netbeans.modules.office.actions.ParcelFolderCookie; +import org.openoffice.netbeans.modules.office.utils.PackageRemover; + +public class ParcelContentsFolder extends DataFolder { + public ParcelContentsFolder(FileObject pf, ParcelContentsFolderDataLoader loader) + throws DataObjectExistsException { + super(pf, loader); + } + + public Node createNodeDelegate() { + return new DataFolder.FolderNode() { + public NewType[] getNewTypes() { + NewType[] newtypes = new NewType[1]; + newtypes[0] = new NewType() { + public String getName() { + return "New Script"; + } + + public void create() { + DataFolder contents = (DataFolder)getDataObject(); + ParcelFolderCookie cookie = + (ParcelFolderCookie)contents.getFolder(). + getCookie(ParcelFolderCookie.class); + + String language = cookie.getLanguage(); + ParcelContentsFolder.createEmptyScript(contents, + language); + } + }; + return newtypes; + } + }; + } + + public static void createEmptyScript(DataFolder parent, String language) { + String sourceFile = "Templates/OfficeScripting/EmptyScript/Empty"; + + if (language.toLowerCase().equals("java")) { + sourceFile += ".java"; + } + else if (language.toLowerCase().equals("beanshell")) { + sourceFile += ".bsh"; + } + else { + NotifyDescriptor d = new NotifyDescriptor.Message( + "Language not defined for this Parcel Folder"); + TopManager.getDefault().notify(d); + return; + } + + FileSystem fs = Repository.getDefault().getDefaultFileSystem(); + DataObject result = null; + try { + DataObject dObj = DataObject.find(fs.findResource(sourceFile)); + result = dObj.createFromTemplate(parent); + } + catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + + FileObject fo = result.getPrimaryFile(); + if (fo.getExt().equals("java")) { + FileLock lock = null; + try { + PackageRemover.removeDeclaration(FileUtil.toFile(fo)); + + // IssueZilla 11986 - rename the FileObject + // so the JavaNode is resynchronized + lock = fo.lock(); + if (lock != null) { + fo.rename(lock, fo.getName(), fo.getExt()); + } + } + 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); + } + finally { + if (lock != null) { + lock.releaseLock(); + } + } + } + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java new file mode 100644 index 000000000000..4c0777cf1c25 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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), + SystemAction.get(NewAction.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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoaderBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoaderBeanInfo.java new file mode 100644 index 000000000000..6f1f44255945 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoaderBeanInfo.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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"); + } + } + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java new file mode 100644 index 000000000000..81a753bab7a0 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoaderBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoaderBeanInfo.java new file mode 100644 index 000000000000..3fdd32f497f4 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoaderBeanInfo.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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"); + } + } + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java new file mode 100644 index 000000000000..bc6cf5a64336 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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/ParcelIcon"); + } + + 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 + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java new file mode 100644 index 000000000000..7aeeda69176a --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } + + */ + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java new file mode 100644 index 000000000000..80fbcd99ee58 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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; + +import org.openoffice.idesupport.OfficeDocument; + +/** 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 OfficeDocument.OFFICE_PRODUCT_NAME + " 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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoaderBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoaderBeanInfo.java new file mode 100644 index 000000000000..42b89fdf86ed --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoaderBeanInfo.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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"); + } + } + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataNode.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataNode.java new file mode 100644 index 000000000000..440e91cbabf4 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataNode.java @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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 + +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java new file mode 100644 index 000000000000..9a80dcd5534b --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java @@ -0,0 +1,83 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java new file mode 100644 index 000000000000..44d04be0414a --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java @@ -0,0 +1,303 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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.ParcelFolderCookie; +import org.openoffice.netbeans.modules.office.actions.ParcelFolderSupport; + +public class ParcelFolder extends DataFolder { + + public static final String LANGUAGE_ATTRIBUTE = "language"; + + 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 static final String LANGUAGE = LANGUAGE_ATTRIBUTE; + private static final String CLASSPATH = "classpath"; + + private File location; + private FileFilter filter; + private String language; + private String classpath; + + 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]; + } + + language = (String)pf.getPrimaryFile().getAttribute(LANGUAGE); + + ParcelFolderCookie cookie = + (ParcelFolderCookie)pf.getCookie(ParcelFolderCookie.class); + String s = cookie.getClasspath(); + if (s != null) { + classpath = s; + } + else { + classpath = "."; + cookie.setClasspath(classpath); + } + } + + public File getTargetDir() { + return location; + } + + public FileFilter getFileFilter() { + return filter; + } + + public String getLanguage() { + if (language == null) + language = (String)getPrimaryFile().getAttribute(LANGUAGE); + return language; + } + + 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); + + prop = createFilterProperty(); + props.put(prop); + + // prop = createLanguageProperty(); + // props.put(prop); + + prop = createClasspathProperty(); + 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) { + } + } + } + + public Object getValue() { + return location; + } + }; + prop.setValue("files", Boolean.FALSE); + return prop; + } + + private String[] languages = {"Java", "BeanShell"}; + + private Node.Property createLanguageProperty() { + Node.Property prop = + new PropertySupport.ReadWrite(LANGUAGE, String.class, + "Parcel Language", "Language of scripts in this Parcel") { + public void setValue(Object obj) { + if (obj instanceof String) { + language = (String)obj; + + try { + getPrimaryFile().setAttribute(LANGUAGE, language); + } + catch (IOException ioe) { + } + } + } + + public Object getValue() { + if (language == null) + language = (String)getPrimaryFile().getAttribute(LANGUAGE); + return language; + } + + public PropertyEditor getPropertyEditor() { + return new PropertyEditorSupport() { + public String[] getTags() { + return languages; + } + + public void setAsText(String text) { + for (int i = 0; i < languages.length; i++) + if (text.equals(languages[i])) + this.setValue(languages[i]); + } + + public String getAsText() { + return (String)this.getValue(); + } + }; + } + }; + 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) { + } + } + } + + 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 Node.Property createClasspathProperty() { + Node.Property prop = + new PropertySupport.ReadWrite(CLASSPATH, String.class, + "Classpath", "Classpath property for scripts in this parcel") { + public void setValue(Object obj) { + if (obj instanceof String) { + classpath = (String)obj; + + ParcelFolderCookie cookie = (ParcelFolderCookie) + getDataObject().getCookie(ParcelFolderCookie.class); + cookie.setClasspath(classpath); + } + } + + public Object getValue() { + return classpath; + } + }; + 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; + } + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java new file mode 100644 index 000000000000..ee3957ccb2ef --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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); + } +} diff --git a/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoaderBeanInfo.java b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoaderBeanInfo.java new file mode 100644 index 000000000000..68888dde3c52 --- /dev/null +++ b/scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoaderBeanInfo.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +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"); + } + } + +} |