This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 123899
Collapse All | Expand All

(-)openide/fs/apichanges.xml (+18 lines)
Lines 46-51 Link Here
46
        <apidef name="filesystems">Filesystems API</apidef>
46
        <apidef name="filesystems">Filesystems API</apidef>
47
    </apidefs>
47
    </apidefs>
48
    <changes>
48
    <changes>
49
        <change id="FileUtil.runAtomicAction">
50
            <api name="filesystems"/>
51
            <summary>Simple way to run atomic action without having a fileobject</summary>
52
            <version major="7" minor="5"/>
53
            <date day="4" month="1" year="2008"/>
54
            <author login="rmatous"/>
55
            <compatibility addition="yes"/>
56
            <description>
57
                <p>
58
                    Simple way to run atomic action without having a fileobject is ensured by 
59
                    adding two methods: <code>FileUtil.runAtomicAction</code>.
60
                    All events about filesystem changes (related to events on all affected instances of <code>FileSystem</code>)
61
                    are postponed after the whole code runned in atomic block is executed.
62
                </p>
63
            </description>
64
            <class package="org.openide.filesystems" name="FileUtil"/>
65
            <issue number="123899"/>
66
        </change>            
49
        <change id="FileObject.isLocked">
67
        <change id="FileObject.isLocked">
50
            <api name="filesystems"/>
68
            <api name="filesystems"/>
51
            <summary>Added method to test if file is locked</summary>
69
            <summary>Added method to test if file is locked</summary>
(-)openide/fs/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Specification-Version: 7.4
3
OpenIDE-Module-Specification-Version: 7.5
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
5
5
(-)openide/fs/src/org/openide/filesystems/FileUtil.java (+38 lines)
Lines 74-79 Link Here
74
import javax.swing.JFileChooser;
74
import javax.swing.JFileChooser;
75
import javax.swing.SwingUtilities;
75
import javax.swing.SwingUtilities;
76
import javax.swing.filechooser.FileSystemView;
76
import javax.swing.filechooser.FileSystemView;
77
import org.openide.filesystems.FileSystem.AtomicAction;
77
import org.openide.util.Exceptions;
78
import org.openide.util.Exceptions;
78
import org.openide.util.Lookup;
79
import org.openide.util.Lookup;
79
import org.openide.util.NbBundle;
80
import org.openide.util.NbBundle;
Lines 125-130 Link Here
125
    }
126
    }
126
127
127
    /**
128
    /**
129
     * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. 
130
     * <p>
131
     * All events about filesystem changes (related to events on all affected instances of <code>FileSystem</code>)
132
     * are postponed after the whole <code>atomicCode</code> 
133
     * is executed.
134
     * </p>
135
     * @param atomicCode code that is supposed to be run as atomic action. See {@link FileSystem#runAtomicAction}
136
     * @throws java.io.IOException
137
     * @since 7.5
138
     */
139
    public static final void runAtomicAction(final AtomicAction atomicCode) throws IOException {
140
        Repository.getDefault().getDefaultFileSystem().runAtomicAction(atomicCode);
141
    }
142
143
    /**
144
     * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. 
145
     * <p>
146
     * All events about filesystem changes (related to events on all affected instances of <code>FileSystem</code>)
147
     * are postponed after the whole <code>atomicCode</code> 
148
     * is executed.
149
     * </p>
150
     * @param atomicCode code that is supposed to be run as atomic action. See {@link FileSystem#runAtomicAction}
151
     * @since 7.5
152
     */
153
    public static final void runAtomicAction(final Runnable atomicCode) {
154
        final AtomicAction action = new FileSystem.AtomicAction() {
155
            public void run() throws IOException {
156
                atomicCode.run();
157
            }
158
        };
159
        try {
160
            FileUtil.runAtomicAction(action);
161
        } catch (IOException ex) {
162
            Exceptions.printStackTrace(ex);
163
        }
164
    }        
165
    /**
128
     * Returns FileObject for a folder.
166
     * Returns FileObject for a folder.
129
     * If such a folder does not exist then it is created, including any necessary but nonexistent parent 
167
     * If such a folder does not exist then it is created, including any necessary but nonexistent parent 
130
     * folders. Note that if this operation fails it may have succeeded in creating some of the necessary
168
     * folders. Note that if this operation fails it may have succeeded in creating some of the necessary
(-)openide/fs/test/unit/src/org/openide/filesystems/FileUtilTestHidden.java (+36 lines)
Lines 43-51 Link Here
43
43
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.IOException;
46
import java.net.URL;
47
import java.net.URL;
47
import java.util.List;
48
import java.util.List;
48
import java.util.ArrayList;
49
import java.util.ArrayList;
50
import org.openide.util.Exceptions;
49
import org.openide.util.Utilities;
51
import org.openide.util.Utilities;
50
52
51
public class FileUtilTestHidden extends TestBaseHid {
53
public class FileUtilTestHidden extends TestBaseHid {
Lines 77-82 Link Here
77
        super(name);
79
        super(name);
78
    }
80
    }
79
81
82
    private static class TestListener extends FileChangeAdapter {
83
        boolean wasCalled = false;
84
        public void fileFolderCreated(FileEvent fe) {
85
            wasCalled = true;
86
        }
87
    }
88
    
89
    public void testRunAtomicAction() throws Exception {
90
        if (this.testedFS.isReadOnly()) return;
91
        
92
        final FileSystem defSystem = Repository.getDefault().getDefaultFileSystem();
93
        final TestListener l = new TestListener();
94
        try {
95
            defSystem.addFileChangeListener(l);
96
            testedFS.addFileChangeListener(l);            
97
            assertFalse(l.wasCalled);            
98
            FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
99
                public void run() throws IOException {
100
                    assertFalse(l.wasCalled);
101
                    assertNull(defSystem.getRoot().getFileObject(getName()));
102
                    assertNotNull(FileUtil.createFolder(defSystem.getRoot(), getName()));
103
                    assertNull(testedFS.getRoot().getFileObject(getName()));
104
                    assertNotNull(FileUtil.createFolder(testedFS.getRoot(), getName()));
105
                    assertFalse(l.wasCalled);
106
                }
107
            });            
108
            assertTrue(l.wasCalled);
109
        } finally {
110
            defSystem.removeFileChangeListener(l);
111
            testedFS.removeFileChangeListener(l);            
112
        }        
113
    }
114
    
115
80
    public void testCreateFolder () throws Exception {
116
    public void testCreateFolder () throws Exception {
81
        if (this.testedFS instanceof JarFileSystem) return;
117
        if (this.testedFS instanceof JarFileSystem) return;
82
        
118
        

Return to bug 123899