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 62707
Collapse All | Expand All

(-)openide/loaders/api/apichanges.xml (-1 / +9 lines)
Lines 85-91 Link Here
85
  <changes>
85
  <changes>
86
     <change id="fileobject-in-lookup">
86
     <change id="fileobject-in-lookup">
87
        <api name="loaders"/>
87
        <api name="loaders"/>
88
        <summary>DataNode.getLookup contains FileObject</summary>
88
        <summary>DataNode.getLookup contains FileObject, DataObject has getLookup()</summary>
89
        <version major="6" minor="0"/>
89
        <version major="6" minor="0"/>
90
        <date day="2" month="11" year="2006"/>
90
        <date day="2" month="11" year="2006"/>
91
        <author login="jtulach"/>
91
        <author login="jtulach"/>
Lines 96-104 Link Here
96
            shall have <code>FileObject</code>(s) associated with its
96
            shall have <code>FileObject</code>(s) associated with its
97
            <a href="@TOP@/org/openide/loaders/DataObject.html#files()">DataObject</a> 
97
            <a href="@TOP@/org/openide/loaders/DataObject.html#files()">DataObject</a> 
98
            available in its own lookup.
98
            available in its own lookup.
99
            Also a 
100
            <a href="@TOP@/org/openide/loaders/DataObject.html">DataObject</a> 
101
            has been retrofitted to implement a 
102
            <a href="@org-openide-util@/org/openide/util/Lookup.Provider.html">Lookup.Provider</a>
103
            interface and thus have its
104
            <a href="@TOP@/org/openide/loaders/DataObject.html#getLookup()">getLookup</a> 
105
            method that can be used instead of the old <code>getCookie</code> one.
99
        </p>
106
        </p>
100
        </description>
107
        </description>
101
        <class package="org.openide.loaders" name="DataNode" />
108
        <class package="org.openide.loaders" name="DataNode" />
109
        <class package="org.openide.loaders" name="DataObject" />
102
        <issue number="62707"/>
110
        <issue number="62707"/>
103
    </change>
111
    </change>
104
112
(-)openide/loaders/src/org/openide/loaders/DataObject.java (-2 / +18 lines)
Lines 30-40 Link Here
30
import org.openide.nodes.*;
30
import org.openide.nodes.*;
31
import org.openide.util.*;
31
import org.openide.util.*;
32
32
33
/** Object that represents one or more file objects, with added behavior.
33
/** Object that represents one or more file objects, with added behavior 
34
* accessible though {@link #getLookup} lookup pattern. Since version 6.0
35
* this class implements {@link Lookup.Provider}.
34
*
36
*
35
* @author Jaroslav Tulach, Petr Hamernik, Jan Jancura, Ian Formanek
37
* @author Jaroslav Tulach, Petr Hamernik, Jan Jancura, Ian Formanek
36
*/
38
*/
37
public abstract class DataObject extends Object implements Node.Cookie, Serializable, HelpCtx.Provider {
39
public abstract class DataObject extends Object
40
implements Node.Cookie, Serializable, HelpCtx.Provider, Lookup.Provider {
38
    /** generated Serialized Version UID */
41
    /** generated Serialized Version UID */
39
    private static final long serialVersionUID = 3328227388376142699L;
42
    private static final long serialVersionUID = 3328227388376142699L;
40
43
Lines 882-887 Link Here
882
            return c.cast(this);
885
            return c.cast(this);
883
        }
886
        }
884
        return null;
887
        return null;
888
    }
889
    
890
    /** Represents a context of the data object. This method is a more 
891
     * general replacement for {@link #getCookie} and should preferably
892
     * be used instead of the old method. The default implementation 
893
     * inside a data object 
894
     * returns the <code>getNodeDelegate().getLookup()</code>.
895
     * 
896
     * @return lookup representing this data object and its content
897
     * @since 6.0
898
     */
899
    public Lookup getLookup() {
900
        return getNodeDelegate().getLookup();
885
    }
901
    }
886
    
902
    
887
    /** When a request for a cookie is done on a DataShadow of this DataObject
903
    /** When a request for a cookie is done on a DataShadow of this DataObject
(-)openide/loaders/test/unit/src/org/openide/loaders/BasicDataObjectTest.java (+9 lines)
Lines 278-283 Link Here
278
        ));
278
        ));
279
    }
279
    }
280
    
280
    
281
    public void testDataObjectIsInItLookup() throws Exception {
282
        DataObject obj = DataObject.find (
283
            FileUtil.createData (subDir, "somedata.txt")
284
        );
285
        
286
        DataObject query = obj.getLookup().lookup(DataObject.class);
287
        assertSame("Object is in its own lookup", obj, query);
288
    }
289
    
281
    private void doSerTest (DataObject obj) throws Exception {
290
    private void doSerTest (DataObject obj) throws Exception {
282
        org.openide.util.io.NbMarshalledObject mar = new org.openide.util.io.NbMarshalledObject (obj);
291
        org.openide.util.io.NbMarshalledObject mar = new org.openide.util.io.NbMarshalledObject (obj);
283
        
292
        
(-)openide/loaders/test/unit/src/org/openide/loaders/DataNodeTest.java (+40 lines)
Lines 23-28 Link Here
23
import java.lang.ref.WeakReference;
23
import java.lang.ref.WeakReference;
24
import java.util.Set;
24
import java.util.Set;
25
import junit.textui.TestRunner;
25
import junit.textui.TestRunner;
26
import org.openide.cookies.OpenCookie;
26
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileStatusEvent;
28
import org.openide.filesystems.FileStatusEvent;
28
import org.openide.filesystems.FileSystem;
29
import org.openide.filesystems.FileSystem;
Lines 103-108 Link Here
103
        assertEquals ("Size is two", 2, fs.lastFiles.size ());
104
        assertEquals ("Size is two", 2, fs.lastFiles.size ());
104
        assertEquals ("Now the secondary entry had to be created", 1, TwoPartLoader.get ().secondary);
105
        assertEquals ("Now the secondary entry had to be created", 1, TwoPartLoader.get ().secondary);
105
    }
106
    }
107
108
    
109
    public void testWhatIsAddedToNodeLookupIsByDefaultVisibleInDataObjectLookup() throws Exception {
110
        org.openide.filesystems.FileSystem lfs = TestUtilHid.createLocalFileSystem(getWorkDir (), new String[] {
111
            "F.java", "F.form"
112
        });
113
        
114
        FSWithStatus fs = new FSWithStatus ();
115
        fs.setRootDirectory(org.openide.filesystems.FileUtil.toFile(lfs.getRoot()));
116
        
117
        DataObject obj = DataObject.find (fs.findResource("F.java"));
118
119
        OpenCookie fromNode = obj.getNodeDelegate().getLookup().lookup(OpenCookie.class);
120
        assertNotNull("There is some cookie in node", fromNode);
121
        
122
        OpenCookie fromObject = obj.getLookup().lookup(OpenCookie.class);
123
        assertNotNull("There is a cookie in data object too", fromObject);
124
        
125
    }
106
    
126
    
107
    public void testDataNodeGetDataFromLookup() throws Exception {
127
    public void testDataNodeGetDataFromLookup() throws Exception {
108
128
Lines 245-250 Link Here
245
    public static final class TwoPartObject extends MultiDataObject {
265
    public static final class TwoPartObject extends MultiDataObject {
246
        public TwoPartObject(TwoPartLoader l, FileObject folder) throws DataObjectExistsException {
266
        public TwoPartObject(TwoPartLoader l, FileObject folder) throws DataObjectExistsException {
247
            super(folder, l);
267
            super(folder, l);
268
        }
269
270
        protected Node createNodeDelegate() {
271
            return new DN(this);
272
        }
273
    }
274
    
275
    private static final class DN extends DataNode {
276
        public DN(TwoPartObject obj) {
277
            super(obj, Children.LEAF);
278
        }
279
        
280
        public <T extends Node.Cookie> T getCookie(Class<T> clazz) {
281
            if (clazz.isAssignableFrom(OpenCookie.class)) {
282
                return clazz.cast(new OpenCookie () {
283
                    public void open() {
284
                    }
285
                });
286
            }
287
            return super.getCookie(clazz);
248
        }
288
        }
249
    }
289
    }
250
    
290
    
(-)openide/loaders/test/unit/src/org/openide/loaders/MultiDataObjectTest.java (-1 / +19 lines)
Lines 21-26 Link Here
21
21
22
import java.beans.PropertyChangeEvent;
22
import java.beans.PropertyChangeEvent;
23
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeListener;
24
import org.openide.cookies.OpenCookie;
24
25
25
import org.openide.filesystems.*;
26
import org.openide.filesystems.*;
26
import org.netbeans.junit.*;
27
import org.netbeans.junit.*;
Lines 147-153 Link Here
147
            err.log(i + " end of cycle");
148
            err.log(i + " end of cycle");
148
        }
149
        }
149
    }
150
    }
150
151
    
151
    public void testConsistencyWithContinuousQueryingForDeletedFiles() throws Exception {
152
    public void testConsistencyWithContinuousQueryingForDeletedFiles() throws Exception {
152
        err.log(" getting children of to");
153
        err.log(" getting children of to");
153
        DataObject[] to1 = to.getChildren();
154
        DataObject[] to1 = to.getChildren();
Lines 238-243 Link Here
238
        
239
        
239
        assertEquals("Fourty deleted files:" + que.deleted, 40, que.deleted.size());
240
        assertEquals("Fourty deleted files:" + que.deleted, 40, que.deleted.size());
240
    }
241
    }
242
243
    public void testAdditionsToCookieSetAreVisibleInLookup() throws Exception {
244
        assertTrue(this.one instanceof SimpleObject);
245
        SimpleObject s = (SimpleObject)this.one;
246
        
247
        class Open implements OpenCookie {
248
            public void open() {
249
            }
250
        }
251
        Open openCookie = new Open();
252
        
253
        
254
        s.getCookieSet().add(openCookie);
255
        
256
        assertSame("Cookie is in the lookup", openCookie, one.getLookup().lookup(OpenCookie.class));
257
    }
258
241
    
259
    
242
    public static final class Pool extends DataLoaderPool {
260
    public static final class Pool extends DataLoaderPool {
243
        protected Enumeration loaders() {
261
        protected Enumeration loaders() {

Return to bug 62707