merge the formfield patch from ooo-build
[ooovba.git] / scripting / java / org / openoffice / netbeans / modules / office / loader / ParcelFolder.java
blob0a1190662508770d8e3fc834c83ebfdb55311f7f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ParcelFolder.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package org.openoffice.netbeans.modules.office.loader;
33 import java.io.File;
34 import java.io.IOException;
35 import java.beans.PropertyEditor;
36 import java.beans.PropertyEditorSupport;
38 import org.openide.loaders.DataFolder;
39 import org.openide.loaders.DataObject;
40 import org.openide.loaders.DataFilter;
41 import org.openide.loaders.DataObjectExistsException;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileUtil;
46 import org.openide.nodes.CookieSet;
47 import org.openide.nodes.Node;
48 import org.openide.nodes.PropertySupport;
49 import org.openide.nodes.Sheet;
50 import org.openide.util.HelpCtx;
52 import org.openoffice.idesupport.filter.*;
53 import org.openoffice.idesupport.zip.ParcelZipper;
54 import org.openoffice.netbeans.modules.office.actions.ParcelFolderCookie;
55 import org.openoffice.netbeans.modules.office.actions.ParcelFolderSupport;
57 public class ParcelFolder extends DataFolder {
59 public static final String LANGUAGE_ATTRIBUTE = "language";
61 public ParcelFolder(FileObject pf, ParcelFolderDataLoader loader)
62 throws DataObjectExistsException {
63 super(pf, loader);
64 CookieSet cookies = getCookieSet();
65 cookies.add(new ParcelFolderSupport(this));
68 public Node createNodeDelegate() {
69 return new ParcelFolderNode(this, new ParcelFolderFilter());
72 public class ParcelFolderNode extends DataFolder.FolderNode {
73 private static final String LOCATION = "location";
74 private static final String FILTER = "filter";
75 private static final String LANGUAGE = LANGUAGE_ATTRIBUTE;
76 private static final String CLASSPATH = "classpath";
78 private File location;
79 private FileFilter filter;
80 private String language;
81 private String classpath;
83 private final FileFilter DEFAULT_FILTER = BinaryOnlyFilter.getInstance();
85 public ParcelFolderNode(ParcelFolder pf, DataFilter dataFilter) {
86 super(pf.createNodeChildren(dataFilter));
88 location = (File)pf.getPrimaryFile().getAttribute(LOCATION);
89 if (location == null)
90 location = FileUtil.toFile(pf.getPrimaryFile());
92 String name = (String)pf.getPrimaryFile().getAttribute(FILTER);
93 if (name == null)
94 filter = DEFAULT_FILTER;
95 else {
96 for (int i = 0; i < availableFilters.length; i++)
97 if (name.equals(availableFilters[i].toString()))
98 filter = availableFilters[i];
101 language = (String)pf.getPrimaryFile().getAttribute(LANGUAGE);
103 ParcelFolderCookie cookie =
104 (ParcelFolderCookie)pf.getCookie(ParcelFolderCookie.class);
105 String s = cookie.getClasspath();
106 if (s != null) {
107 classpath = s;
109 else {
110 classpath = ".";
111 cookie.setClasspath(classpath);
115 public File getTargetDir() {
116 return location;
119 public FileFilter getFileFilter() {
120 return filter;
123 public String getLanguage() {
124 if (language == null)
125 language = (String)getPrimaryFile().getAttribute(LANGUAGE);
126 return language;
129 public Sheet createSheet() {
130 Sheet sheet;
131 Sheet.Set props;
132 Node.Property prop;
134 sheet = super.createSheet();
135 props = sheet.get(Sheet.PROPERTIES);
136 if (props == null) {
137 props = Sheet.createPropertiesSet();
138 sheet.put(props);
141 // prop = createLocationProperty();
142 // props.put(prop);
144 prop = createFilterProperty();
145 props.put(prop);
147 prop = createFilterProperty();
148 props.put(prop);
150 // prop = createLanguageProperty();
151 // props.put(prop);
153 prop = createClasspathProperty();
154 props.put(prop);
156 return sheet;
159 private Node.Property createLocationProperty() {
160 Node.Property prop =
161 new PropertySupport.ReadWrite(LOCATION, File.class,
162 "Location", "Output location of Parcel Zip File") {
163 public void setValue(Object obj) {
164 if (obj instanceof File) {
165 location = (File)obj;
166 try {
167 getPrimaryFile().setAttribute(LOCATION, location);
169 catch (IOException ioe) {
174 public Object getValue() {
175 return location;
178 prop.setValue("files", Boolean.FALSE);
179 return prop;
182 private String[] languages = {"Java", "BeanShell"};
184 private Node.Property createLanguageProperty() {
185 Node.Property prop =
186 new PropertySupport.ReadWrite(LANGUAGE, String.class,
187 "Parcel Language", "Language of scripts in this Parcel") {
188 public void setValue(Object obj) {
189 if (obj instanceof String) {
190 language = (String)obj;
192 try {
193 getPrimaryFile().setAttribute(LANGUAGE, language);
195 catch (IOException ioe) {
200 public Object getValue() {
201 if (language == null)
202 language = (String)getPrimaryFile().getAttribute(LANGUAGE);
203 return language;
206 public PropertyEditor getPropertyEditor() {
207 return new PropertyEditorSupport() {
208 public String[] getTags() {
209 return languages;
212 public void setAsText(String text) {
213 for (int i = 0; i < languages.length; i++)
214 if (text.equals(languages[i]))
215 this.setValue(languages[i]);
218 public String getAsText() {
219 return (String)this.getValue();
224 return prop;
227 private FileFilter[] availableFilters = new FileFilter[] {
228 BinaryOnlyFilter.getInstance(), AllFilesFilter.getInstance()};
230 private Node.Property createFilterProperty() {
231 Node.Property prop =
232 new PropertySupport.ReadWrite(FILTER, String.class,
233 "File Filter", "Files to be included in Parcel") {
234 public void setValue(Object obj) {
235 if (obj instanceof FileFilter) {
236 filter = (FileFilter)obj;
238 try {
239 getPrimaryFile().setAttribute(FILTER, filter.toString());
241 catch (IOException ioe) {
246 public Object getValue() {
247 return filter;
250 public PropertyEditor getPropertyEditor() {
251 return new PropertyEditorSupport() {
252 public String[] getTags() {
253 String[] tags = new String[availableFilters.length];
255 for (int i = 0; i < availableFilters.length; i++)
256 tags[i] = availableFilters[i].toString();
258 return tags;
261 public void setAsText(String text) {
262 for (int i = 0; i < availableFilters.length; i++)
263 if (text.equals(availableFilters[i].toString()))
264 this.setValue(availableFilters[i]);
267 public String getAsText() {
268 return this.getValue().toString();
273 return prop;
276 private Node.Property createClasspathProperty() {
277 Node.Property prop =
278 new PropertySupport.ReadWrite(CLASSPATH, String.class,
279 "Classpath", "Classpath property for scripts in this parcel") {
280 public void setValue(Object obj) {
281 if (obj instanceof String) {
282 classpath = (String)obj;
284 ParcelFolderCookie cookie = (ParcelFolderCookie)
285 getDataObject().getCookie(ParcelFolderCookie.class);
286 cookie.setClasspath(classpath);
290 public Object getValue() {
291 return classpath;
294 return prop;
298 private class ParcelFolderFilter implements DataFilter {
299 public boolean acceptDataObject(DataObject dobj) {
300 String name = dobj.getPrimaryFile().getNameExt();
301 if (name.equals(ParcelZipper.PARCEL_DESCRIPTOR_XML))
302 return false;
303 return true;