[hg] main-silver: #223542: Call the AttachType's customizer in A...

  • From:
  • To:
  • Subject: [hg] main-silver: #223542: Call the AttachType's customizer in A...
  • Date: Tue, 11 Dec 2012 06:43:27 -0800

changeset b6ca6833cbcf in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/b6ca6833cbcf
description:
        #223542: Call the AttachType's customizer in AWT, but load it in an 
RP. JPDA's AttachType needs to load the connectors in RP an thread.

diffstat:

 debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/ConnectPanel.java 
            |  92 ++++++++-
 
spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java
 |  40 +++-
 2 files changed, 113 insertions(+), 19 deletions(-)

diffs (297 lines):

diff --git 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/ConnectPanel.java
 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/ConnectPanel.java
--- 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/ConnectPanel.java
+++ 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/ConnectPanel.java
@@ -50,6 +50,7 @@
 import com.sun.jdi.connect.*;
 
 import java.awt.Component;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -61,6 +62,7 @@
 import java.awt.event.FocusEvent;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
+import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -69,6 +71,7 @@
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
@@ -96,6 +99,7 @@
 import org.openide.NotifyDescriptor;
 import org.openide.awt.Mnemonics;
 import org.openide.util.Cancellable;
+import org.openide.util.Exceptions;
 import org.openide.util.HelpCtx;
 import org.openide.util.NbBundle;
 import org.openide.util.RequestProcessor;
@@ -114,18 +118,38 @@
     private static final Logger USG_LOGGER = 
Logger.getLogger("org.netbeans.ui.metrics.debugger"); // NOI18N
 
     /** List of all AttachingConnectors.*/
-    private List                    connectors;
+    private final List              connectors;
     /** Combo with list of all AttachingConnector names.*/
     private JComboBox               cbConnectors;
     /** List of JTextFields containing all parameters of curentConnector. */
     private JTextField[]            tfParams;
     private ConnectController       controller;
     private final DocumentListener  validityDocumentListener = new 
ValidityDocumentListener();
+    private final Cursor            standardCursor;
+    private final AtomicBoolean     connectorsLoaded = new 
AtomicBoolean(false);
+    private static final RequestProcessor RP = new 
RequestProcessor(ConnectPanel.class.getName());
 
 
     public ConnectPanel () {
+        connectors = new ArrayList ();
+        standardCursor = getCursor();
+        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+        RP.post(new Runnable() {
+            @Override
+            public void run() {
+                initConnectors();
+            }
+        });
+        
+        controller = new ConnectController();
+    }
+
+    public Controller getController() {
+        return controller;
+    }
+    
+    private void initConnectors() {
         VirtualMachineManager vmm = Bootstrap.virtualMachineManager ();
-        connectors = new ArrayList ();
         connectors.addAll (vmm.attachingConnectors ());
         connectors.addAll (vmm.listeningConnectors ());
            
@@ -143,14 +167,56 @@
                 ci.remove();
         }
                 
-        if (connectors.size () == 0) {
+        int defaultIndex = 0;
+        String lacn = Properties.getDefault ().getProperties ("debugger").
+            getString ("last_attaching_connector", "");
+        int i, k = connectors.size ();
+        for (i = 0; i < k; i++) {
+            Connector connector = (Connector) connectors.get (i);
+            if ((lacn != null) && connector.name ().equals (lacn)) {
+                defaultIndex = i;
+            }
+        }
+        final int finalDefaultIndex = defaultIndex;
+        
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    addConnectors(finalDefaultIndex);
+                }
+            });
+        } catch (InterruptedException ex) {
+            Exceptions.printStackTrace(ex);
+        } catch (InvocationTargetException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        
+        synchronized (connectorsLoaded) {
+            connectorsLoaded.set(true);
+            connectorsLoaded.notifyAll();
+        }
+    }
+    
+    private void waitForConnectorsLoad() {
+        synchronized (connectorsLoaded) {
+            while (!connectorsLoaded.get()) {
+                try {
+                    connectorsLoaded.wait();
+                } catch (InterruptedException ex) {}
+            }
+        }
+    }
+    
+    private void addConnectors(int defaultIndex) {
+        //assert connectorsLoaded.get();
+        if (connectors.isEmpty()) {
             // no attaching connectors available => print message only
             add (new JLabel (
                 NbBundle.getMessage (ConnectPanel.class, "CTL_No_Connector")
             ));
             return;
         }
-        int defaultIndex = 0;
         if (connectors.size () > 1) {
             // more than one attaching connector available => 
             // init cbConnectors & selext default connector
@@ -159,13 +225,9 @@
             cbConnectors.getAccessibleContext ().setAccessibleDescription (
                 NbBundle.getMessage (ConnectPanel.class, 
"ACSD_CTL_Connector")
             );
-            String lacn = Properties.getDefault ().getProperties 
("debugger").
-                getString ("last_attaching_connector", "");
             int i, k = connectors.size ();
             for (i = 0; i < k; i++) {
                 Connector connector = (Connector) connectors.get (i);
-                if ((lacn != null) && connector.name ().equals (lacn))
-                    defaultIndex = i;
                 int jj = connector.name ().lastIndexOf ('.');
                               
                 String s = (jj < 0) ? 
@@ -178,19 +240,15 @@
             cbConnectors.setActionCommand ("SwitchMe!");
             cbConnectors.addActionListener (this);
         }
-        
-        controller = new ConnectController();
         cbConnectors.setSelectedIndex (defaultIndex);
-    }
-
-    public Controller getController() {
-        return controller;
+        setCursor(standardCursor);
     }
 
     /**
      * Adds options for a selected connector type to this panel.
      */
     private void refresh (int index, Properties properties) {
+        assert SwingUtilities.isEventDispatchThread();
         removeAll();
         
         Connector connector = (Connector) connectors.get (index);
@@ -525,6 +583,7 @@
     }
 
     private void checkValid() {
+        assert connectorsLoaded.get();
         int index = cbConnectors.getSelectedIndex ();
         final Connector connector = (Connector) connectors.get (index);
         int i, k = tfParams.length;
@@ -584,6 +643,7 @@
         }
 
         public boolean ok () {
+            assert connectorsLoaded.get();
             int index = cbConnectors.getSelectedIndex ();
             final Connector connector = (Connector) connectors.get (index);
             final Map args = getEditedArgs (tfParams, connector);
@@ -668,6 +728,8 @@
         }
 
         public boolean load(Properties props) {
+            assert !SwingUtilities.isEventDispatchThread();
+            waitForConnectorsLoad();
             String connectorName = props.getString ("attaching_connector", 
"");
             int index, k = connectors.size ();
             boolean found = false;
@@ -687,6 +749,7 @@
         }
 
         public void save(Properties props) {
+            assert connectorsLoaded.get();
             int index = cbConnectors.getSelectedIndex ();
             final Connector connector = (Connector) connectors.get (index);
             final Map args = getEditedArgs (tfParams, connector);
@@ -711,6 +774,7 @@
         }
 
         public String getDisplayName() {
+            assert connectorsLoaded.get();
             int index = cbConnectors.getSelectedIndex ();
             final Connector connector = (Connector) connectors.get (index);
             final Map args = getEditedArgs (tfParams, connector);
diff --git 
a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java
 
b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java
--- 
a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java
+++ 
b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java
@@ -60,6 +60,7 @@
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 import javax.swing.JSeparator;
+import javax.swing.SwingUtilities;
 import javax.swing.event.PopupMenuEvent;
 import javax.swing.event.PopupMenuListener;
 import org.netbeans.api.debugger.DebuggerManager;
@@ -76,6 +77,7 @@
 import org.openide.util.Exceptions;
 import org.openide.util.ImageUtilities;
 import org.openide.util.NbBundle;
+import org.openide.util.RequestProcessor;
 import org.openide.util.WeakSet;
 import org.openide.util.actions.Presenter;
 
@@ -203,6 +205,7 @@
         private JPopupMenu menu;
         private JMenuItem[] items = new JMenuItem[0];
         private JSeparator separator = new JPopupMenu.Separator();
+        private static final RequestProcessor RP = new 
RequestProcessor(AttachHistorySupport.class.getName());
 
         public void init(JPopupMenu menu) {
             this.menu = menu;
@@ -239,25 +242,52 @@
                 }
             }
             if (index == -1) { return; } // should not occure
+            final int findex = index;
+            RP.post(new Runnable() {
+                @Override
+                public void run() {
+                    perform(findex);
+                }
+            });
+        }
+        
+        private void perform(int index) {
             Properties props = 
Properties.getDefault().getProperties("debugger").getProperties("last_attaches");
             Integer[] usedSlots = (Integer[]) props.getArray("used_slots", 
new Integer[0]);
             String attachTypeName = props.getProperties("slot_" + 
usedSlots[index]).getString("attach_type", "???");
             List types = DebuggerManager.getDebuggerManager().lookup (null, 
AttachType.class);
-            AttachType attachType = null;
+            AttachType att = null;
             for (Object t : types) {
-                AttachType att = (AttachType)t;
-                if (attachTypeName.equals(att.getTypeDisplayName())) {
-                    attachType = att;
+                AttachType at = (AttachType)t;
+                if (attachTypeName.equals(at.getTypeDisplayName())) {
+                    att = at;
                     break;
                 }
             } // for
-            if (attachType != null) {
+            if (att != null) {
+                final AttachType attachType = att;
+                final Controller[] controllerPtr = new Controller[] { null };
+                try {
+                    SwingUtilities.invokeAndWait(new Runnable() {
+                        @Override
+                        public void run() {
                 JComponent customizer = attachType.getCustomizer ();
                 Controller controller = attachType.getController();
                 if (controller == null && (customizer instanceof 
Controller)) {
                     Exceptions.printStackTrace(new 
IllegalStateException("FIXME: JComponent "+customizer+" must not implement 
Controller interface!"));
                     controller = (Controller) customizer;
                 }
+                            controllerPtr[0] = controller;
+                        }
+                    });
+                } catch (InterruptedException ex) {
+                    Exceptions.printStackTrace(ex);
+                    return ;
+                } catch (InvocationTargetException ex) {
+                    Exceptions.printStackTrace(ex);
+                    return ;
+                }
+                Controller controller = controllerPtr[0];
                 Method loadMethod = null;
                 try {
                     loadMethod = controller.getClass().getMethod("load", 
Properties.class);

[hg] main-silver: #223542: Call the AttachType's customizer in A...

mentlicher 12/11/2012

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close