blob: 58f83c5ee7d97548f37e21e5bee9a86b79e375ff [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
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.
--><mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.3" xml:lang="en" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd">
<siteinfo>
<sitename>NetBeans Wiki</sitename>
<base>http://wiki.netbeans.org/Main_Page</base>
<generator>MediaWiki 1.15.1</generator>
<case>first-letter</case>
<namespaces>
<namespace key="-2">Media</namespace>
<namespace key="-1">Special</namespace>
<namespace key="0"/>
<namespace key="1">Talk</namespace>
<namespace key="2">User</namespace>
<namespace key="3">User talk</namespace>
<namespace key="4">NetBeans Wiki</namespace>
<namespace key="5">NetBeans Wiki talk</namespace>
<namespace key="6">File</namespace>
<namespace key="7">File talk</namespace>
<namespace key="8">MediaWiki</namespace>
<namespace key="9">MediaWiki talk</namespace>
<namespace key="10">Template</namespace>
<namespace key="11">Template talk</namespace>
<namespace key="12">Help</namespace>
<namespace key="13">Help talk</namespace>
<namespace key="14">Category</namespace>
<namespace key="15">Category talk</namespace>
</namespaces>
</siteinfo>
<page>
<title>DevFaqListeningForFileChanges</title>
<id>14367</id>
<revision>
<id>32775</id>
<timestamp>2010-01-23T20:41:36Z</timestamp>
<contributor>
<username>Tboudreau</username>
<id>108</id>
</contributor>
<minor/>
<text xml:space="preserve">__NOTOC__
===I am listening for changes in a folder/file but when there are changes I do not receive an event===
If you are adding/deleting/changes using the FileSystems API - i.e. adding using [http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/FileUtil.html#createData(org.openide.filesystems.FileObject,%20java.lang.String) FileUtil.createData()] then it should work.
If not, get the parent folder as a FileObject and call theFolder.getFileSystem().refresh().
NetBeans will automatically do the refresh if focus is shifted away from the main window and back. However if files are created by an external process, or by using java.io.File.mkdir() or java.io.File.createNewFile() (which you shouldn't be using inside a NetBeans module unless you really need to), changes will not be noticed until something forces a refresh.
The reasons for the way this is handled are twofold:
# There is not native support in Java for listening for changes in a file/folder (yet), though most OS's natively support it
# We used to use a system that polled on a timer, but this is a bad idea because the user can be using, say, email, and most of the in-memory copy of NetBeans can have been swapped out to disk by the OS - but to check for modified files, it has to be dragged back into memory out of the swap file to see if some files have changed, even though the user is using another application. That hurts performance of the user's other applications.
If you are creating files or folders programmatically, use [http://bits.netbeans.org/dev/javadoc/index.html FileObject], not java.io.File and any nodes your UI shows for those files will automatically update.</text>
</revision>
</page>
</mediawiki>