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

(-)core/windows/src/org/netbeans/core/windows/services/NbPresenter.java (-1 / +65 lines)
Lines 14-24 Link Here
14
package org.netbeans.core.windows.services;
14
package org.netbeans.core.windows.services;
15
15
16
16
17
import java.lang.reflect.InvocationTargetException;
18
import java.lang.reflect.Method;
17
import java.util.Arrays;
19
import java.util.Arrays;
18
import java.util.List;
20
import java.util.List;
19
import org.netbeans.core.windows.WindowManagerImpl;
21
import org.netbeans.core.windows.WindowManagerImpl;
20
import org.netbeans.core.windows.view.dnd.WindowDnDManager;
22
import org.netbeans.core.windows.view.dnd.WindowDnDManager;
21
import org.openide.DialogDescriptor;
23
import org.openide.DialogDescriptor;
24
import org.openide.ErrorManager;
22
import org.openide.NotifyDescriptor;
25
import org.openide.NotifyDescriptor;
23
import org.openide.WizardDescriptor;
26
import org.openide.WizardDescriptor;
24
import org.openide.awt.Mnemonics;
27
import org.openide.awt.Mnemonics;
Lines 27-32 Link Here
27
import org.openide.util.HelpCtx;
30
import org.openide.util.HelpCtx;
28
import org.openide.util.Mutex;
31
import org.openide.util.Mutex;
29
import org.openide.util.NbBundle;
32
import org.openide.util.NbBundle;
33
import org.openide.util.RequestProcessor;
30
import org.openide.util.Utilities;
34
import org.openide.util.Utilities;
31
35
32
import javax.swing.*;
36
import javax.swing.*;
Lines 35-40 Link Here
35
import java.awt.*;
39
import java.awt.*;
36
import java.awt.event.*;
40
import java.awt.event.*;
37
import java.beans.PropertyChangeListener;
41
import java.beans.PropertyChangeListener;
42
import java.lang.reflect.Field;
43
import java.util.Collection;
38
import java.util.Comparator;
44
import java.util.Comparator;
39
import java.util.HashSet;
45
import java.util.HashSet;
40
import java.util.Iterator;
46
import java.util.Iterator;
Lines 311-326 Link Here
311
        uninitializeClosingOptions ();
317
        uninitializeClosingOptions ();
312
    }
318
    }
313
    
319
    
320
    private final HackTypeAhead hack = new HackTypeAhead();
314
    public void addNotify() {
321
    public void addNotify() {
315
        super.addNotify();
322
        super.addNotify();
316
        initializePresenter();
323
        initializePresenter();
324
        
325
        hack.activate();
317
    }
326
    }
318
327
319
    public void removeNotify() {
328
    public void removeNotify() {
320
        super.removeNotify();
329
        super.removeNotify();
321
        uninitializePresenter();
330
        uninitializePresenter();
331
        
322
    }
332
    }
323
    
333
324
    /** Creates option pane message.
334
    /** Creates option pane message.
325
     */
335
     */
326
    private JOptionPane createOptionPane() {
336
    private JOptionPane createOptionPane() {
Lines 1156-1159 Link Here
1156
            }
1166
            }
1157
        }
1167
        }
1158
    }
1168
    }
1169
1170
    static Field markers;
1171
    static Method dequeue;
1172
    static {
1173
        try {
1174
            markers = DefaultKeyboardFocusManager.class.getDeclaredField("typeAheadMarkers"); // NOI18N
1175
            markers.setAccessible(true);
1176
            dequeue = DefaultKeyboardFocusManager.class.getDeclaredMethod("dequeueKeyEvents", new Class[] { Long.TYPE, java.awt.Component.class });
1177
            dequeue.setAccessible(true);
1178
        } catch (Throwable ex) {
1179
            ErrorManager.getDefault().log(ErrorManager.WARNING, "Not activating workaround for #50423"); // NOI18N
1180
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
1181
        }
1182
    }
1183
    
1184
    private final class HackTypeAhead implements Runnable {
1185
        private RequestProcessor.Task task = RequestProcessor.getDefault().create(this);
1186
        
1187
        
1188
        public HackTypeAhead() {
1189
        }
1190
        
1191
        public void activate() {
1192
            if (markers != null) {
1193
                task.schedule(1000);
1194
            }
1195
        }
1196
        
1197
        public void run() {
1198
            if (!SwingUtilities.isEventDispatchThread()) {
1199
                SwingUtilities.invokeLater(this);
1200
                return;
1201
            }
1202
1203
            KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
1204
            Collection result = null;
1205
            try {
1206
                result = (Collection) markers.get(fm);
1207
            } catch (Exception ex) {
1208
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
1209
            }
1210
1211
            if (result == null || result.isEmpty()) {
1212
                return;
1213
            }
1214
1215
            ErrorManager.getDefault().log(ErrorManager.WARNING, "Symptoms of #50423: There is something in type ahead: " + result + " requesting focus change"); // NOI18N
1216
            try {
1217
                dequeue.invoke(fm, new Object[] { new Long(-1), NbPresenter.this });
1218
            } catch (Exception ex) {
1219
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
1220
            }
1221
        }
1222
    } // end of HackTypeAhead
1159
}
1223
}

Return to bug 50423