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

(-)a/core.windows/src/org/netbeans/core/windows/WindowSystemImpl.java (+7 lines)
Lines 43-51 Link Here
43
package org.netbeans.core.windows;
43
package org.netbeans.core.windows;
44
44
45
45
46
import java.awt.EventQueue;
46
import org.netbeans.core.NbTopManager;
47
import org.netbeans.core.NbTopManager;
47
import org.netbeans.core.windows.persistence.PersistenceManager;
48
import org.netbeans.core.windows.persistence.PersistenceManager;
48
import org.netbeans.core.windows.services.DialogDisplayerImpl;
49
import org.netbeans.core.windows.services.DialogDisplayerImpl;
50
import org.netbeans.core.windows.view.ui.MainWindow;
49
51
50
52
51
/**
53
/**
Lines 59-64 Link Here
59
    public WindowSystemImpl() {
61
    public WindowSystemImpl() {
60
    }
62
    }
61
63
64
65
    public void init() {
66
        assert !EventQueue.isDispatchThread();
67
        MainWindow.init();
68
    }
62
69
63
    // Persistence
70
    // Persistence
64
    /** Implements <code>NbTopManager.WindowSystem</code> interface method.
71
    /** Implements <code>NbTopManager.WindowSystem</code> interface method.
(-)a/core.windows/src/org/netbeans/core/windows/view/ui/MainWindow.java (+4 lines)
Lines 129-134 Link Here
129
            ((JPanel)c).setOpaque(false);
129
            ((JPanel)c).setOpaque(false);
130
            root.setGlassPane(c);
130
            root.setGlassPane(c);
131
        }
131
        }
132
    }
133
134
    public static void init() {
135
        createMenuBar();
132
    }
136
    }
133
    
137
    
134
    /** Initializes main window. */
138
    /** Initializes main window. */
(-)a/o.n.core/src/org/netbeans/core/NbTopManager.java (+1 lines)
Lines 309-314 Link Here
309
    /** Interface describing basic control over window system. 
309
    /** Interface describing basic control over window system. 
310
     * @since 1.15 */
310
     * @since 1.15 */
311
    public interface WindowSystem {
311
    public interface WindowSystem {
312
        void init();
312
        void show();
313
        void show();
313
        void hide();
314
        void hide();
314
        void load();
315
        void load();
(-)a/o.n.core/src/org/netbeans/core/NonGui.java (-1 / +6 lines)
Lines 160-166 Link Here
160
        // Starts GUI components to be created and shown on screen.
160
        // Starts GUI components to be created and shown on screen.
161
        // I.e. main window + current workspace components.
161
        // I.e. main window + current workspace components.
162
162
163
164
163
        // Access winsys from AWT thread only. In this case main thread wouldn't harm, just to be kosher.
165
        // Access winsys from AWT thread only. In this case main thread wouldn't harm, just to be kosher.
166
        final NbTopManager.WindowSystem windowSystem = Lookup.getDefault().lookup(NbTopManager.WindowSystem.class);
167
        if (windowSystem != null) {
168
            windowSystem.init();
169
        }
164
        SwingUtilities.invokeLater(new Runnable() {
170
        SwingUtilities.invokeLater(new Runnable() {
165
            public void run() {
171
            public void run() {
166
                StartLog.logProgress("Window system initialization");
172
                StartLog.logProgress("Window system initialization");
Lines 173-179 Link Here
173
                        }
179
                        }
174
                    });
180
                    });
175
                }
181
                }
176
                NbTopManager.WindowSystem windowSystem = Lookup.getDefault().lookup(NbTopManager.WindowSystem.class);
177
                if (windowSystem != null) {
182
                if (windowSystem != null) {
178
                    windowSystem.load();
183
                    windowSystem.load();
179
                    StartLog.logProgress("Window system loaded");
184
                    StartLog.logProgress("Window system loaded");
(-)a/openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.2
3
OpenIDE-Module-Specification-Version: 7.3
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Recommends: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Recommends: org.netbeans.modules.templates.v1_0
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.loaders/src/org/openide/awt/AWTTask.java (-1 / +5 lines)
Lines 41-46 Link Here
41
41
42
package org.openide.awt;
42
package org.openide.awt;
43
43
44
import java.awt.EventQueue;
45
44
/** A special task designed to run in AWT thread.
46
/** A special task designed to run in AWT thread.
45
 * It will fire itself immediatelly.
47
 * It will fire itself immediatelly.
46
 */
48
 */
Lines 52-57 Link Here
52
        org.openide.util.Mutex.EVENT.readAccess (this);
54
        org.openide.util.Mutex.EVENT.readAccess (this);
53
    }
55
    }
54
56
57
    @Override
55
    public void run () {
58
    public void run () {
56
        if (!executed) {
59
        if (!executed) {
57
            super.run ();
60
            super.run ();
Lines 59-66 Link Here
59
        }
62
        }
60
    }
63
    }
61
64
65
    @Override
62
    public void waitFinished () {
66
    public void waitFinished () {
63
        if (javax.swing.SwingUtilities.isEventDispatchThread ()) {
67
        if (EventQueue.isDispatchThread()) {
64
            run ();
68
            run ();
65
        } else {
69
        } else {
66
            super.waitFinished ();
70
            super.waitFinished ();
(-)a/openide.loaders/src/org/openide/awt/DynaMenuModel.java (-1 lines)
Lines 58-64 Link Here
58
import javax.swing.JPopupMenu;
58
import javax.swing.JPopupMenu;
59
import javax.swing.JSeparator;
59
import javax.swing.JSeparator;
60
import org.openide.util.Utilities;
60
import org.openide.util.Utilities;
61
import org.openide.awt.DynamicMenuContent;
62
import org.openide.util.actions.Presenter;
61
import org.openide.util.actions.Presenter;
63
62
64
/**
63
/**
(-)a/openide.loaders/src/org/openide/awt/MenuBar.java (-2 / +8 lines)
Lines 298-304 Link Here
298
         * @param folder a <code>DataFolder</code> to work with
298
         * @param folder a <code>DataFolder</code> to work with
299
         */
299
         */
300
        public MenuBarFolder (final DataFolder folder) {
300
        public MenuBarFolder (final DataFolder folder) {
301
            super(folder);
301
            super(folder, true);
302
            // preinitialize outside of AWT
303
            new DynaMenuModel();
302
            recreate ();
304
            recreate ();
303
        }
305
        }
304
306
Lines 432-437 Link Here
432
434
433
    /** Menu based on the folder content whith lazy items creation. */
435
    /** Menu based on the folder content whith lazy items creation. */
434
    private static class LazyMenu extends JMenu implements NodeListener, Runnable, ChangeListener {
436
    private static class LazyMenu extends JMenu implements NodeListener, Runnable, ChangeListener {
437
        static {
438
            // preinitialize outside of AWT
439
            new DynaMenuModel();
440
        }
435
        DataFolder master;
441
        DataFolder master;
436
        boolean icon;
442
        boolean icon;
437
        MenuFolder slave;
443
        MenuFolder slave;
Lines 579-585 Link Here
579
             * It will cause initial update of the Menu
585
             * It will cause initial update of the Menu
580
             */
586
             */
581
    	    public MenuFolder () {
587
    	    public MenuFolder () {
582
                super(master);
588
                super(master, true);
583
    	    }
589
    	    }
584
590
585
591
(-)a/openide.loaders/src/org/openide/awt/Toolbar.java (-1 / +1 lines)
Lines 969-975 Link Here
969
         *
969
         *
970
         */
970
         */
971
        public Folder () {
971
        public Folder () {
972
            super (backingFolder);
972
            super (backingFolder, true);
973
            recreate ();
973
            recreate ();
974
        }
974
        }
975
975
(-)a/openide.loaders/src/org/openide/awt/ToolbarPool.java (-3 / +3 lines)
Lines 457-463 Link Here
457
                new WeakHashMap<DataFolder, InstanceCookie> (15);
457
                new WeakHashMap<DataFolder, InstanceCookie> (15);
458
458
459
        public Folder (DataFolder f) {
459
        public Folder (DataFolder f) {
460
            super (f);
460
            super (f, true);
461
        }
461
        }
462
462
463
        /**
463
        /**
Lines 569-579 Link Here
569
        }
569
        }
570
570
571
        /** Recreate the instance in AWT thread.
571
        /** Recreate the instance in AWT thread.
572
        */
572
         */
573
        @Override
573
        protected Task postCreationTask (Runnable run) {
574
        protected Task postCreationTask (Runnable run) {
574
            return new AWTTask (run);
575
            return new AWTTask (run);
575
        }
576
        }
576
577
    } // end of Folder
577
    } // end of Folder
578
578
579
579
(-)a/openide.loaders/src/org/openide/loaders/FolderInstance.java (-27 / +74 lines)
Lines 48-56 Link Here
48
import java.util.logging.Level;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
49
import java.util.logging.Logger;
50
50
51
import org.openide.*;
52
import org.openide.filesystems.*;
51
import org.openide.filesystems.*;
53
import org.openide.cookies.InstanceCookie;
52
import org.openide.cookies.InstanceCookie;
53
import org.openide.util.Exceptions;
54
import org.openide.util.Task;
54
import org.openide.util.Task;
55
import org.openide.util.TaskListener;
55
import org.openide.util.TaskListener;
56
import org.openide.util.RequestProcessor;
56
import org.openide.util.RequestProcessor;
Lines 158-163 Link Here
158
     *  Started immediately after the <code>recognizingTask</code> is finished.
158
     *  Started immediately after the <code>recognizingTask</code> is finished.
159
     */
159
     */
160
    private Task creationTask;
160
    private Task creationTask;
161
    /** shall instances be precreated? */
162
    private boolean precreateInstances;
161
    
163
    
162
    /* -------------------------------------------------------------------- */
164
    /* -------------------------------------------------------------------- */
163
    /* -- Constructor(s) -------------------------------------------------- */
165
    /* -- Constructor(s) -------------------------------------------------- */
Lines 168-173 Link Here
168
    */
170
    */
169
    public FolderInstance (DataFolder df) {
171
    public FolderInstance (DataFolder df) {
170
        this ((DataObject.Container)df);
172
        this ((DataObject.Container)df);
173
    }
174
175
    /** Create new folder instance.
176
     * @param df data folder to create instances from
177
     * @param precreateInstances if true, then instances for all cookies
178
     *    are created before {@link #postCreationTask} is called
179
     * @since 7.3
180
    */
181
    public FolderInstance (DataFolder df, boolean precreateInstances) {
182
        this ((DataObject.Container)df);
183
        this.precreateInstances = precreateInstances;
171
    }
184
    }
172
    
185
    
173
    /** A new object that listens on changes in a container.
186
    /** A new object that listens on changes in a container.
Lines 237-251 Link Here
237
    */
250
    */
238
    public Class<?> instanceClass ()
251
    public Class<?> instanceClass ()
239
    throws java.io.IOException, ClassNotFoundException {
252
    throws java.io.IOException, ClassNotFoundException {
240
        Object object = this.object;
253
        Object tmp = this.object;
241
        if (object != null) {
254
        if (tmp != null) {
242
            if (object instanceof java.io.IOException) {
255
            if (tmp instanceof java.io.IOException) {
243
                throw (java.io.IOException)object;
256
                throw (java.io.IOException)tmp;
244
            }
257
            }
245
            if (object instanceof ClassNotFoundException) {
258
            if (tmp instanceof ClassNotFoundException) {
246
                throw (ClassNotFoundException)object;
259
                throw (ClassNotFoundException)tmp;
247
            }
260
            }
248
            return object.getClass ();
261
            return tmp.getClass ();
249
        }
262
        }
250
263
251
        return Object.class;
264
        return Object.class;
Lines 258-289 Link Here
258
    */
271
    */
259
    public Object instanceCreate ()
272
    public Object instanceCreate ()
260
    throws java.io.IOException, ClassNotFoundException {
273
    throws java.io.IOException, ClassNotFoundException {
261
        Object object = CURRENT.get ();
274
        Object tmp = CURRENT.get ();
262
        
275
        
263
        if (object == null || LAST_CURRENT.get () != this) {
276
        if (tmp == null || LAST_CURRENT.get () != this) {
264
            err.fine("do into waitFinished"); // NOI18N
277
            err.fine("do into waitFinished"); // NOI18N
265
            waitFinished ();
278
            waitFinished ();
266
279
267
            object = FolderInstance.this.object;
280
            tmp = FolderInstance.this.object;
268
        }
281
        }
269
282
270
        if (err.isLoggable(Level.FINE)) {
283
        if (err.isLoggable(Level.FINE)) {
271
            err.fine("instanceCreate: " + object); // NOI18N
284
            err.fine("instanceCreate: " + tmp); // NOI18N
272
        }
285
        }
273
286
274
        if (object instanceof java.io.IOException) {
287
        if (tmp instanceof java.io.IOException) {
275
            throw (java.io.IOException)object;
288
            throw (java.io.IOException)tmp;
276
        }
289
        }
277
        if (object instanceof ClassNotFoundException) {
290
        if (tmp instanceof ClassNotFoundException) {
278
            throw (ClassNotFoundException)object;
291
            throw (ClassNotFoundException)tmp;
279
        }
292
        }
280
        
293
        
281
        if (object == CURRENT) {
294
        if (tmp == CURRENT) {
282
            // uninitialized
295
            // uninitialized
283
            throw new IOException ("Cyclic reference. Somebody is trying to get value from FolderInstance (" + getClass ().getName () + ") from the same thread that is processing the instance"); // NOI18N
296
            throw new IOException ("Cyclic reference. Somebody is trying to get value from FolderInstance (" + getClass ().getName () + ") from the same thread that is processing the instance"); // NOI18N
284
        }
297
        }
285
        
298
        
286
        return object;
299
        return tmp;
287
    }
300
    }
288
    
301
    
289
    /* -------------------------------------------------------------------- */
302
    /* -------------------------------------------------------------------- */
Lines 406-420 Link Here
406
        }
419
        }
407
        
420
        
408
        if (cookie == null) {
421
        if (cookie == null) {
409
            DataFolder folder = dob.getCookie(DataFolder.class);
422
            DataFolder fld = dob.getCookie(DataFolder.class);
410
            if (folder != null) {
423
            if (fld != null) {
411
                HoldInstance previous = map.get (folder.getPrimaryFile ());
424
                HoldInstance previous = map.get (fld.getPrimaryFile ());
412
                if (previous != null && previous.cookie != null) {
425
                if (previous != null && previous.cookie != null) {
413
                    // the old cookie will be returned if the folder is already registered
426
                    // the old cookie will be returned if the folder is already registered
414
                    cookie = previous;
427
                    cookie = previous;
415
                    acceptType = 2;
428
                    acceptType = 2;
416
                } else {
429
                } else {
417
                    cookie = acceptFolder (folder);
430
                    cookie = acceptFolder (fld);
418
                    acceptType = 3;
431
                    acceptType = 3;
419
                }
432
                }
420
            }
433
            }
Lines 650-666 Link Here
650
    * @param arr collection of DataObjects
663
    * @param arr collection of DataObjects
651
    */
664
    */
652
    final void processObjects (final Collection<DataObject> arr) {
665
    final void processObjects (final Collection<DataObject> arr) {
653
        creationTask = postCreationTask (new Runnable () {
666
        class R implements Runnable {
654
            public void run () {
667
            HoldInstance[] all;
655
                defaultProcessObjects (arr);
668
            Object[] instances;
669
670
            public void init() {
671
                all = defaultProcessObjects(arr);
656
            }
672
            }
657
        });
673
674
            public void instances() {
675
                instances = new Object[all.length];
676
                int indx = 0;
677
                for (HoldInstance h : all) {
678
                    try {
679
                        instances[indx++] = h.instanceClass();
680
                    } catch (IOException ex) {
681
                        Exceptions.printStackTrace(ex);
682
                    } catch (ClassNotFoundException ex) {
683
                        Exceptions.printStackTrace(ex);
684
                    }
685
                }
686
            }
687
688
            public void run() {
689
                if (all == null) {
690
                    init();
691
                }
692
                defaultProcessObjectsFinal(all);
693
            }
694
        }
695
        R process = new R();
696
        if (precreateInstances) {
697
            process.init();
698
            process.instances();
699
        }
700
        creationTask = postCreationTask (process);
658
    }
701
    }
659
702
660
    /** Default processing of objects.
703
    /** Default processing of objects.
661
    * @param arr array of objects to process
704
    * @param arr array of objects to process
662
    */
705
    */
663
    private final void defaultProcessObjects (Collection<DataObject> arr) {
706
    private final HoldInstance[] defaultProcessObjects (Collection<DataObject> arr) {
664
        err.fine("defaultProcessObjects");
707
        err.fine("defaultProcessObjects");
665
        HashSet<FileObject> toRemove;
708
        HashSet<FileObject> toRemove;
666
        ArrayList<HoldInstance> cookies = new ArrayList<HoldInstance> ();
709
        ArrayList<HoldInstance> cookies = new ArrayList<HoldInstance> ();
Lines 762-767 Link Here
762
        
805
        
763
        updateWaitFor (all);
806
        updateWaitFor (all);
764
807
808
        return all;
809
    }
810
    
811
    private void defaultProcessObjectsFinal(HoldInstance[] all) {
765
        Object result = null;
812
        Object result = null;
766
        try {
813
        try {
767
            result = createInstance (all);
814
            result = createInstance (all);
(-)a/openide.loaders/test/unit/src/org/openide/awt/MenuBarTest.java (+3 lines)
Lines 41-46 Link Here
41
41
42
package org.openide.awt;
42
package org.openide.awt;
43
43
44
import java.awt.EventQueue;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionEvent;
45
import java.awt.event.ContainerEvent;
46
import java.awt.event.ContainerEvent;
46
import java.awt.event.ContainerListener;
47
import java.awt.event.ContainerListener;
Lines 297-302 Link Here
297
        public static int counter;
298
        public static int counter;
298
        
299
        
299
        public MyAction() {
300
        public MyAction() {
301
            assertFalse("Not initialized in AWT thread", EventQueue.isDispatchThread());
300
            counter++;
302
            counter++;
301
        }
303
        }
302
304
Lines 328-333 Link Here
328
        public CreateOnlyOnceAction() {
330
        public CreateOnlyOnceAction() {
329
            new Exception("created for " + (++instancesCount) + " time").printStackTrace(pw);
331
            new Exception("created for " + (++instancesCount) + " time").printStackTrace(pw);
330
            putValue(NAME, "TestAction");
332
            putValue(NAME, "TestAction");
333
            assertFalse("Not initialized in AWT thread", EventQueue.isDispatchThread());
331
        }
334
        }
332
335
333
    }
336
    }
(-)a/openide.loaders/test/unit/src/org/openide/awt/ToolbarPoolTest.java (+37 lines)
Lines 45-53 Link Here
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.io.ObjectOutputStream;
46
import java.io.ObjectOutputStream;
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import javax.swing.JButton;
48
import javax.swing.JComponent;
49
import javax.swing.JComponent;
49
import javax.swing.JLabel;
50
import javax.swing.JLabel;
51
import javax.swing.JPanel;
50
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.junit.NbTestCase;
53
import org.openide.awt.MenuBarTest.MyAction;
51
import org.openide.cookies.InstanceCookie;
54
import org.openide.cookies.InstanceCookie;
52
import org.openide.filesystems.FileLock;
55
import org.openide.filesystems.FileLock;
53
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
Lines 75-84 Link Here
75
        return 30000;
78
        return 30000;
76
    }
79
    }
77
    
80
    
81
    @Override
78
    protected Level logLevel() {
82
    protected Level logLevel() {
79
        return Level.FINE;
83
        return Level.FINE;
80
    }
84
    }
81
    
85
    
86
    @Override
82
    protected void setUp() throws Exception {
87
    protected void setUp() throws Exception {
83
        FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
88
        FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
84
        toolbars = FileUtil.createFolder (root, "Toolbars");
89
        toolbars = FileUtil.createFolder (root, "Toolbars");
Lines 149-154 Link Here
149
        
154
        
150
        assertLabels ("Now there are two", 2, myTlbs[0]);
155
        assertLabels ("Now there are two", 2, myTlbs[0]);
151
    }
156
    }
157
158
    public void testWhoCreatesConstructor() throws Exception {
159
        FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
160
        FileObject fo = FileUtil.createFolder (root, "ToolbarsWhoCreates");
161
        final DataFolder df = DataFolder.findFolder(fo);
162
        ToolbarPool pool = new ToolbarPool(df);
163
164
        assertEquals("No children now", 0, pool.getToolbars().length);
165
166
        class Atom implements FileSystem.AtomicAction {
167
168
            FileObject m1, m2;
169
170
            public void run() throws IOException {
171
                m1 = FileUtil.createFolder(df.getPrimaryFile(), "m1");
172
                DataFolder f1 = DataFolder.findFolder(m1);
173
                InstanceDataObject.create(f1, "X", MyAction.class);
174
            }
175
        }
176
        Atom atom = new Atom();
177
        df.getPrimaryFile().getFileSystem().runAtomicAction(atom);
178
        pool.waitFinished();
179
180
        assertEquals("One toolbar is there", 1, pool.getToolbars().length);
181
        assertEquals("Pool name", "m1", pool.getToolbars()[0].getName());
182
183
        Object o1 = pool.getToolbars()[0].getComponent(1);
184
        if (!(o1 instanceof JButton)) {
185
            fail("Need JPanel " + o1);
186
        }
187
        assertEquals("And now the action is created", 1, MyAction.counter);
188
    }
152
    
189
    
153
    private static Object writeInstance (final FileObject folder, final String name, final Object inst) throws IOException {
190
    private static Object writeInstance (final FileObject folder, final String name, final Object inst) throws IOException {
154
        class W implements FileSystem.AtomicAction {
191
        class W implements FileSystem.AtomicAction {

Return to bug 144426