You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/09/25 13:32:01 UTC

[GitHub] JaroslavTulach closed pull request #907: Make invokeWhenUIReady work in headless mode

JaroslavTulach closed pull request #907: Make invokeWhenUIReady work in headless mode
URL: https://github.com/apache/incubator-netbeans/pull/907
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/platform/core.windows/src/org/netbeans/core/windows/WindowManagerImpl.java b/platform/core.windows/src/org/netbeans/core/windows/WindowManagerImpl.java
index 922b7939ef..8f6faf1172 100644
--- a/platform/core.windows/src/org/netbeans/core/windows/WindowManagerImpl.java
+++ b/platform/core.windows/src/org/netbeans/core/windows/WindowManagerImpl.java
@@ -28,6 +28,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.*;
+import org.netbeans.core.IDESettings;
 import org.netbeans.core.windows.actions.ActionUtils;
 import org.netbeans.core.windows.options.WinSysPrefs;
 import org.netbeans.core.windows.persistence.PersistenceManager;
@@ -1527,8 +1528,12 @@ public synchronized void register(Runnable r) {
 
         @Override
         public void run() {
-            if (!WindowManagerImpl.getInstance().isVisible()) {
-                return;
+            if (IDESettings.isGui()) {
+                // running in GUI mode, but
+                if (!WindowManagerImpl.getInstance().isVisible()) {
+                    // window manager isn't yet visible => exit for now
+                    return;
+                }
             }
             
             synchronized (this) {
diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/InvokeWhenUIReadInHeadlessModeTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/InvokeWhenUIReadInHeadlessModeTest.java
new file mode 100644
index 0000000000..2a10d5ee5d
--- /dev/null
+++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/InvokeWhenUIReadInHeadlessModeTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.netbeans.core.windows;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import org.netbeans.junit.NbModuleSuite;
+import org.netbeans.junit.NbTestCase;
+import org.openide.windows.WindowManager;
+
+public class InvokeWhenUIReadInHeadlessModeTest extends NbTestCase {
+
+    public InvokeWhenUIReadInHeadlessModeTest(String name) {
+        super(name);
+    }
+
+    public static junit.framework.Test suite() {
+        return NbModuleSuite.emptyConfiguration().
+            gui(false).
+            addTest(InvokeWhenUIReadInHeadlessModeTest.class).
+            suite();
+    }
+
+
+    public void testInvokeWhenReadInHeadlessMode() throws Exception {
+        final CountDownLatch cdl = new CountDownLatch(1);
+        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
+            @Override
+            public void run() {
+                cdl.countDown();
+            }
+        });
+        cdl.await(15, TimeUnit.SECONDS);
+        assertEquals("Eventually the runnable is invoked", 0, cdl.getCount());
+    }
+}
diff --git a/platform/o.n.core/src/org/netbeans/core/IDESettings.java b/platform/o.n.core/src/org/netbeans/core/IDESettings.java
index 886cac196a..ca285b6342 100644
--- a/platform/o.n.core/src/org/netbeans/core/IDESettings.java
+++ b/platform/o.n.core/src/org/netbeans/core/IDESettings.java
@@ -22,6 +22,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.prefs.Preferences;
+import org.netbeans.core.startup.CLIOptions;
 import org.openide.awt.HtmlBrowser;
 import org.openide.cookies.InstanceCookie;
 import org.openide.filesystems.FileObject;
@@ -94,6 +95,14 @@ public static void setExternalWWWBrowser (HtmlBrowser.Factory brow) {
         setBrowser( PROP_EXTERNAL_WWWBROWSER, brow );
     }
 
+    /** Are we running in GUI or headless mode?
+     * 
+     * @return true if the GUI mode is on
+     */
+    public static boolean isGui() {
+        return CLIOptions.isGui();
+    }
+
     private static void setBrowser (String prefId, HtmlBrowser.Factory brow) {
         try {
             if (brow == null) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists