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

(-)ant/src/org/apache/tools/ant/module/AntSettings.java (+7 lines)
Lines 58-63 Link Here
58
    
58
    
59
    protected void initialize () {
59
    protected void initialize () {
60
        super.initialize();
60
        super.initialize();
61
        reset ();
62
    }
63
    
64
    /** Called from initialize and also using reflection when this option
65
     * is about to be "reset". See issue #20962.
66
     */
67
    protected void reset () {
61
        setVerbosity(2 /*Project.MSG_INFO*/);
68
        setVerbosity(2 /*Project.MSG_INFO*/);
62
        Properties p = new Properties ();
69
        Properties p = new Properties ();
63
        // Enable hyperlinking for Jikes:
70
        // Enable hyperlinking for Jikes:
(-)openide/api/doc/changes/apichanges.xml (+19 lines)
Lines 114-119 Link Here
114
114
115
<!-- ACTUAL CHANGES BEGIN HERE: -->
115
<!-- ACTUAL CHANGES BEGIN HERE: -->
116
<changes>
116
<changes>
117
    <change id="SharedClassObject.reset">
118
        <api name="util"/>
119
        <summary>Added <code>SharedClassObject.reset</code> method to allow subclasses to implement reset correctly</summary>
120
        <version major="4" minor="46"/>
121
        <date day="2" month="9" year="2004"/>
122
        <author login="jtulach"/>
123
        <compatibility addition="yes" binary="compatible" source="incompatible" semantic="compatible" />
124
        <description>
125
            The new <code>SharedClassObject.reset</code> method is called
126
            by the infrastructure in moments when an original (at the time
127
            of start) state of an option or any other <code>SharedClassObject</code>
128
            is requested. Interested subclasses (like <code>SystemOption</code>s
129
            in Tools/Option dialog) are free to implement any kind of clean
130
            then need.
131
        </description>
132
        <class package="org.openide.util" name="SharedClassObject"/>
133
        <issue number="20962"/>
134
    </change>
135
    
117
    <change id="TreeView.dragActive">
136
    <change id="TreeView.dragActive">
118
        <api name="explorer"/>
137
        <api name="explorer"/>
119
        <summary>Fixed <code>TreeView.drag/dropActive</code> switcher</summary>
138
        <summary>Fixed <code>TreeView.drag/dropActive</code> switcher</summary>
(-)openide/src/org/openide/util/SharedClassObject.java (-2 / +10 lines)
Lines 547-554 Link Here
547
        }
547
        }
548
    }
548
    }
549
549
550
    /** Resets shared data to it default value. */
550
    /** Is called by the infrastructure in cases when a clean instance is requested.
551
    private void reset () {
551
     * As instances of <code>SharedClassObject</code> are singletons, there is 
552
     * no way how to create new instance that would not contain the same data
553
     * as previously existing one. This method allows all subclasses that care
554
     * about the ability to refresh the settings (like <code>SystemOption</code>s) 
555
     * to be notified about the cleaning request and clean their settings themselves.
556
     *
557
     * @since made protected in version 4.46
558
     */
559
    protected void reset () {
552
        if (!systemOption || !isProjectOption ()) {
560
        if (!systemOption || !isProjectOption ()) {
553
            return;
561
            return;
554
        }
562
        }
(-)openide/test/unit/src/org/openide/loaders/InstanceDataObjectTest.java (+54 lines)
Lines 564-569 Link Here
564
        assertNotNull ("Has cookie", ic);
564
        assertNotNull ("Has cookie", ic);
565
        assertEquals ("And its value is x", x, ic.instanceCreate ());
565
        assertEquals ("And its value is x", x, ic.instanceCreate ());
566
    }
566
    }
567
568
    
569
    public void testWeAreAbleToResetSharedClassObjectByCallingResetOnItIssue20962 () throws Exception {
570
        FileObject lookupFO;
571
        {
572
            Object x = Setting.findObject (Setting.class, true);
573
            lookupFO = lfs.findResource("/system/Services/lookupTest");
574
            DataFolder folderTest = DataFolder.findFolder(lookupFO);
575
            InstanceDataObject ido = InstanceDataObject.create (folderTest, "testLookupRefresh", x, null);
576
            lookupFO = ido.getPrimaryFile ();
577
            WeakReference ref = new WeakReference (ido);
578
            Setting.resetCalled = 0;
579
        }
580
581
        InstanceDataObject ido = (InstanceDataObject)DataObject.find (lookupFO);
582
        InstanceCookie ic = (InstanceCookie)ido.getCookie (InstanceCookie.class);
583
        assertNotNull ("Has cookie", ic);
584
        Object obj = ic.instanceCreate ();
585
        assertNotNull ("Not null", obj);
586
        assertEquals ("It is settings", Setting.class, obj.getClass ());
587
        
588
        
589
        FileLock lock = lookupFO.lock ();
590
        OutputStream os = lookupFO.getOutputStream (lock);
591
        
592
        PrintWriter pw = new PrintWriter (os);
593
        pw.println ("<?xml version=\"1.0\"?>");
594
        pw.println ("<!DOCTYPE settings PUBLIC \"-//NetBeans//DTD Session settings 1.0//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">");
595
        pw.println ("<settings version=\"1.0\">");
596
        pw.println ("  <module name=\"org.openide/1\" spec=\"1.13\"/>");
597
        pw.println ("  <instanceof class=\"org.openide.options.SystemOption\"/>");
598
        pw.println ("  <instance class=\"" + Setting.class.getName () + "\"/>");
599
        pw.println ("</settings>");
600
        pw.close ();
601
        lock.releaseLock ();
602
        
603
        ic = (InstanceCookie)ido.getCookie (InstanceCookie.class);
604
        assertNotNull ("Has cookie", ic);
605
        assertNotNull ("Not null", obj);
606
        assertEquals ("It is settings", Setting.class, obj.getClass ());
607
        Setting s = (Setting)Setting.findObject (Setting.class, true);
608
        assertEquals ("Refresh has been called", 1, s.resetCalled);
609
    }
567
    
610
    
568
    /** Checks whether the instance is not saved multiple times.
611
    /** Checks whether the instance is not saved multiple times.
569
     *
612
     *
Lines 920-923 Link Here
920
        }
963
        }
921
    }
964
    }
922
965
966
    public static final class Setting extends org.openide.options.SystemOption {
967
        private static int resetCalled;
968
        
969
        protected void reset () {
970
            resetCalled++;
971
        }
972
        
973
        public String displayName () {
974
            return "My Setting";
975
        }
976
    }
923
}
977
}

Return to bug 20962