blob: 5973b45a9812df611ade6d15cc8e1fc06914f054 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= DevFaqNodePropertyForFiles
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqNodePropertyForFiles
:description: Apache NetBeans wiki DevFaqNodePropertyForFiles
:toc: left
:toc-title:
:syntax: true
== I have a Node.Property for a file. How can I control the file chooser that is the custom editor?
A number of the built-in property editors in NetBeans can have their behavior controlled by passing "hints" to them. Hints are providing by calling link:http://java.sun.com/j2se/1.5.0/docs/api/java/beans/FeatureDescriptor.html?is-external=true#setValue(java.lang.String,%20java.lang.Object)[setValue("something", someValue)] on the Node.Property. For example, to suppress the custom editor button for a property, use
[source,java]
----
Node.Property<String> myProp = new MyStringProp();
myProp.setValue ("suppressCustomEditor", Boolean.TRUE);
----
The built-in property editors for files and arrays of files support a number of hints:
|===
|String Hint Name |Value Type |Effect
|`filter` |`java.io.FilenameFilter` or `javax.swing.filechooser.FileFilter` or `java.io.FileFilter` |Sets the file filter used by the file chooser
|`directories` |`java.lang.Boolean` |Set the file chooser to accept only directories. If combined with the "files" hint set to true (see below), will accept both directories and files.
|`files` |`java.lang.Boolean` |Set the file chooser to accept only files (unless combined with the "directories" hint set to true above - in which case simply not using either hint has the same effect
|`currentDir` |`java.io.File` |The directory the file chooser should default to when it is first opened
|`baseDir` |`java.io.File` |The _base directory_ for the file property. This is needed only if the file has a relative path. Java files are just wrappers for a path name, and need not exist on disk. So if the file property is `foo/MyFile.txt` that is a perfectly legal file name (presumably the Java Bean or Node the property belongs to knows how to find the parent directory of "foo"). The file chooser needs to know the full path to `foo/` - so you would pass a file here to provide the parent folder for `foo/`. For example, if the complete path to `MyFile.txt` is `/Users/tim/Documents/foo/MyFile.txt`, you would call `setValue("baseDir", new File("/Users/tim/Documents")`
|`file_hiding` |`java.lang.Boolean` |Value to call `JFileChooser.setFileHidingEnabled()` with (remember, if your filter filters out directories and you set file hiding enabled, the user will not be able to usefully change directories)
|===
The built-in bean property editors in NetBeans are found in the package `org.netbeans.beaninfo` editors in the module `o.n.core` in NetBeans' sources.
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqNodePropertyForFiles[http://wiki.netbeans.org/DevFaqNodePropertyForFiles] ,
that was last modified by NetBeans user Jtulach
on 2010-07-24T19:22:43Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.