1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ParcelFolder.java,v $
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
;
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
{
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
);
90 location
= FileUtil
.toFile(pf
.getPrimaryFile());
92 String name
= (String
)pf
.getPrimaryFile().getAttribute(FILTER
);
94 filter
= DEFAULT_FILTER
;
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();
111 cookie
.setClasspath(classpath
);
115 public File
getTargetDir() {
119 public FileFilter
getFileFilter() {
123 public String
getLanguage() {
124 if (language
== null)
125 language
= (String
)getPrimaryFile().getAttribute(LANGUAGE
);
129 public Sheet
createSheet() {
134 sheet
= super.createSheet();
135 props
= sheet
.get(Sheet
.PROPERTIES
);
137 props
= Sheet
.createPropertiesSet();
141 // prop = createLocationProperty();
144 prop
= createFilterProperty();
147 prop
= createFilterProperty();
150 // prop = createLanguageProperty();
153 prop
= createClasspathProperty();
159 private Node
.Property
createLocationProperty() {
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
;
167 getPrimaryFile().setAttribute(LOCATION
, location
);
169 catch (IOException ioe
) {
174 public Object
getValue() {
178 prop
.setValue("files", Boolean
.FALSE
);
182 private String
[] languages
= {"Java", "BeanShell"};
184 private Node
.Property
createLanguageProperty() {
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
;
193 getPrimaryFile().setAttribute(LANGUAGE
, language
);
195 catch (IOException ioe
) {
200 public Object
getValue() {
201 if (language
== null)
202 language
= (String
)getPrimaryFile().getAttribute(LANGUAGE
);
206 public PropertyEditor
getPropertyEditor() {
207 return new PropertyEditorSupport() {
208 public String
[] getTags() {
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();
227 private FileFilter
[] availableFilters
= new FileFilter
[] {
228 BinaryOnlyFilter
.getInstance(), AllFilesFilter
.getInstance()};
230 private Node
.Property
createFilterProperty() {
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
;
239 getPrimaryFile().setAttribute(FILTER
, filter
.toString());
241 catch (IOException ioe
) {
246 public Object
getValue() {
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();
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();
276 private Node
.Property
createClasspathProperty() {
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() {
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
))