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

(-)core/arch/arch-core.xml (-1 / +10 lines)
Lines 566-572 Link Here
566
-->
566
-->
567
 <answer id="exec-reflection">
567
 <answer id="exec-reflection">
568
  <p>
568
  <p>
569
   XXX no answer for exec-reflection
569
   <api name="uihandler-hooks" category="friend" group="java" type="export">
570
       This module exports an API that allows the UI Gestures Collector module
571
       to plug and enhance the behaviour of exception dialog by own buttons.
572
       The behaviour is like this: If any of <code>Handler</code>s of
573
       <code>Logger.getLogger("")</code> implements <code>Callable&lt;JButton&gt;</code>
574
       then such button is going to be inserted to the exception dialog and
575
       can react and change the behaviour of that dialog. Such a button is
576
       going to be a "closing" one - e.g. the dialog will close as soon as
577
       the button is pressed.
578
   </api>
570
  </p>
579
  </p>
571
 </answer>
580
 </answer>
572
581
(-)core/nbproject/project.properties (-1 / +1 lines)
Lines 17-23 Link Here
17
17
18
javac.compilerargs=-Xlint:unchecked
18
javac.compilerargs=-Xlint:unchecked
19
javac.source=1.5
19
javac.source=1.5
20
spec.version.base=3.5.0
20
spec.version.base=3.6.0
21
21
22
javadoc.arch=${basedir}/arch/arch-core.xml
22
javadoc.arch=${basedir}/arch/arch-core.xml
23
23
(-)core/src/org/netbeans/core/NotifyExcPanel.java (-5 / +44 lines)
Lines 30-38 Link Here
30
import java.awt.event.ActionListener;
30
import java.awt.event.ActionListener;
31
import java.io.PrintWriter;
31
import java.io.PrintWriter;
32
import java.io.StringWriter;
32
import java.io.StringWriter;
33
import java.lang.reflect.ParameterizedType;
34
import java.lang.reflect.Type;
33
import java.util.ArrayList;
35
import java.util.ArrayList;
34
import java.util.ResourceBundle;
36
import java.util.ResourceBundle;
37
import java.util.concurrent.Callable;
38
import java.util.logging.Handler;
35
import java.util.logging.Level;
39
import java.util.logging.Level;
40
import java.util.logging.Logger;
36
import javax.swing.Icon;
41
import javax.swing.Icon;
37
import javax.swing.ImageIcon;
42
import javax.swing.ImageIcon;
38
import javax.swing.JButton;
43
import javax.swing.JButton;
Lines 47-52 Link Here
47
import org.openide.DialogDisplayer;
52
import org.openide.DialogDisplayer;
48
import org.openide.NotifyDescriptor;
53
import org.openide.NotifyDescriptor;
49
import org.openide.awt.Mnemonics;
54
import org.openide.awt.Mnemonics;
55
import org.openide.util.Exceptions;
50
import org.openide.util.NbBundle;
56
import org.openide.util.NbBundle;
51
import org.openide.util.Utilities;
57
import org.openide.util.Utilities;
52
import org.openide.windows.WindowManager;
58
import org.openide.windows.WindowManager;
Lines 133-143 Link Here
133
        descriptor = new DialogDescriptor ("", ""); // NOI18N
139
        descriptor = new DialogDescriptor ("", ""); // NOI18N
134
140
135
        descriptor.setMessageType (DialogDescriptor.ERROR_MESSAGE);
141
        descriptor.setMessageType (DialogDescriptor.ERROR_MESSAGE);
136
        descriptor.setOptions (new Object[] {
142
        descriptor.setOptions (computeOptions(previous, next));
137
                                   previous,
138
                                   next,
139
                                   DialogDescriptor.OK_OPTION
140
                               });
141
        descriptor.setAdditionalOptions (new Object[] {
143
        descriptor.setAdditionalOptions (new Object[] {
142
                                             details
144
                                             details
143
                                         });
145
                                         });
Lines 160-165 Link Here
160
        dialog.getAccessibleContext().setAccessibleDescription(bundle.getString("ACD_NotifyExcPanel_Dialog")); // NOI18N
162
        dialog.getAccessibleContext().setAccessibleDescription(bundle.getString("ACD_NotifyExcPanel_Dialog")); // NOI18N
161
    }
163
    }
162
164
165
    static Object[] computeOptions(Object previous, Object next) {
166
        ArrayList<Object> arr = new ArrayList<java.lang.Object>();
167
        arr.add(previous);
168
        arr.add(next);
169
        
170
        for (Handler h : Logger.getLogger("").getHandlers()) {
171
            if (h instanceof Callable<?>) {
172
                boolean foundCallableForJButton = false;
173
                for (Type t : h.getClass().getGenericInterfaces()) {
174
                    if (t instanceof ParameterizedType) {
175
                        ParameterizedType p = (ParameterizedType)t;
176
                        Type[] params = p.getActualTypeArguments();
177
                        if (params.length == 1 && params[0] == JButton.class) {
178
                            foundCallableForJButton = true;
179
                            break;
180
                        }
181
                    }
182
                }
183
                if (!foundCallableForJButton) {
184
                    continue;
185
                }
186
                
187
                
188
                try {
189
                    Object o = ((Callable<?>)h).call();
190
                    assert o instanceof JButton;
191
                    arr.add(o);
192
                } catch (Exception ex) {
193
                    Exceptions.printStackTrace(ex);
194
                }
195
            }
196
        }
197
        
198
        arr.add(DialogDescriptor.OK_OPTION);
199
        return arr.toArray();
200
    }
201
    
163
    private static boolean isModalDialogPresent() {
202
    private static boolean isModalDialogPresent() {
164
        return hasModalDialog(WindowManager.getDefault().getMainWindow())
203
        return hasModalDialog(WindowManager.getDefault().getMainWindow())
165
            // XXX Trick to get the shared frame instance.
204
            // XXX Trick to get the shared frame instance.
(-)core/test/unit/src/org/netbeans/core/NotifyExcPanelTest.java (+104 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.core;
21
22
import java.util.Arrays;
23
import java.util.List;
24
import java.util.concurrent.Callable;
25
import java.util.logging.Handler;
26
import java.util.logging.LogRecord;
27
import java.util.logging.Logger;
28
import javax.swing.JButton;
29
import org.netbeans.junit.NbTestCase;
30
31
/**
32
 *
33
 * @author Jaroslav Tulach
34
 */
35
public class NotifyExcPanelTest extends NbTestCase {
36
    Logger main;
37
    
38
    public NotifyExcPanelTest(String testName) {
39
        super(testName);
40
    }
41
    
42
    protected void setUp() throws Exception {
43
        main = Logger.getLogger("");
44
        for (Handler h : main.getHandlers()) {
45
            main.removeHandler(h);
46
        }
47
    }
48
    
49
    public void testHandlesThatImplementCallableForJButtonAreIncluded() throws Exception {
50
        class H extends Handler 
51
        implements Callable<JButton> {
52
            public JButton button = new JButton("Extra");
53
        
54
            public void publish(LogRecord arg0) {
55
            }
56
57
            public void flush() {
58
            }
59
60
            public void close() throws SecurityException {
61
            }
62
63
            public JButton call() throws Exception {
64
                return button;
65
            }
66
        } // end of H
67
        
68
        H handler = new H();
69
        
70
        main.addHandler(handler);
71
        
72
        List<Object> options = Arrays.asList(NotifyExcPanel.computeOptions("prev", "next"));
73
        
74
        assertTrue("Contains our button: " + options, options.contains(handler.button));
75
    }
76
77
    public void testHandlesThatImplementCallableForOtherObjectsAreNotIncluded() throws Exception {
78
        class H extends Handler 
79
        implements Callable<Object> {
80
            public JButton button = new JButton("Extra");
81
        
82
            public void publish(LogRecord arg0) {
83
            }
84
85
            public void flush() {
86
            }
87
88
            public void close() throws SecurityException {
89
            }
90
91
            public JButton call() throws Exception {
92
                return button;
93
            }
94
        } // end of H
95
        
96
        H handler = new H();
97
        
98
        main.addHandler(handler);
99
        
100
        List<Object> options = Arrays.asList(NotifyExcPanel.computeOptions("prev", "next"));
101
        
102
        assertFalse("Does not contain our button: " + options, options.contains(handler.button));
103
    }
104
}
(-)logger/uihandler/arch.xml (+8 lines)
Lines 376-381 Link Here
376
            the analysis server.
376
            the analysis server.
377
            </api>
377
            </api>
378
        </li>            
378
        </li>            
379
        <li><api type='import' group='java' category='friend' name='uihandler-hooks' >
380
                This module makes on of its <code>Handler</code> implement
381
                <code>Callable&lt;JButton&gt;</code> which is a signal for
382
                core providing the exception dialog to include such a 
383
                <code>JButton</code> in its list of options. That way this 
384
                module can enhance the dialog with "Report..." button.
385
            </api>
386
        </li>            
379
    </ul>
387
    </ul>
380
  
388
  
381
 </answer>
389
 </answer>
(-)logger/uihandler/src/org/netbeans/modules/uihandler/Bundle.properties (+1 lines)
Lines 77-82 Link Here
77
# URL to display to as a welcome text in case of error
77
# URL to display to as a welcome text in case of error
78
ERROR_URL=http://logger.netbeans.org/nonav/welcome/error.html
78
ERROR_URL=http://logger.netbeans.org/nonav/welcome/error.html
79
MSG_ERROR_URL_EXIT=&Cancel
79
MSG_ERROR_URL_EXIT=&Cancel
80
MSG_SubmitButton=Report...
80
81
81
82
82
# view data
83
# view data
(-)logger/uihandler/src/org/netbeans/modules/uihandler/Installer.java (+4 lines)
Lines 115-125 Link Here
115
        log.addHandler(ui);
115
        log.addHandler(ui);
116
        Logger all = Logger.getLogger("");
116
        Logger all = Logger.getLogger("");
117
        all.addHandler(handler);
117
        all.addHandler(handler);
118
        
118
        
119
        for (Activated a : Lookup.getDefault().lookupAll(Activated.class)) {
119
        for (Activated a : Lookup.getDefault().lookupAll(Activated.class)) {
120
            a.activated(log);
120
            a.activated(log);
Lines 467-472 Link Here
467
                    url = getClass().getResource("UnknownHostException.html");
475
                    url = getClass().getResource("UnknownHostException.html");
468
                    continue;
476
                    continue;
469
                } catch (UnknownHostException ex) {
477
                } catch (UnknownHostException ex) {
478
                    LOG.log(Level.INFO, url.toExternalForm(), ex);
479
                    url = getClass().getResource("UnknownHostException.html");
480
                    continue;
481
                } catch (java.net.NoRouteToHostException ex) {
470
                    LOG.log(Level.INFO, url.toExternalForm(), ex);
482
                    LOG.log(Level.INFO, url.toExternalForm(), ex);
471
                    url = getClass().getResource("UnknownHostException.html");
483
                    url = getClass().getResource("UnknownHostException.html");
472
                    continue;
484
                    continue;
(-)logger/uihandler/src/org/netbeans/modules/uihandler/UIHandler.java (-11 / +20 lines)
Lines 19-36 Link Here
19
19
20
package org.netbeans.modules.uihandler;
20
package org.netbeans.modules.uihandler;
21
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
22
import java.beans.PropertyChangeListener;
24
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeSupport;
25
import java.beans.PropertyChangeSupport;
24
import java.util.Queue;
26
import java.util.Queue;
27
import java.util.concurrent.Callable;
25
import java.util.logging.Handler;
28
import java.util.logging.Handler;
26
import java.util.logging.Level;
29
import java.util.logging.Level;
27
import java.util.logging.LogRecord;
30
import java.util.logging.LogRecord;
31
import javax.swing.JButton;
32
import org.openide.util.NbBundle;
28
33
29
/**
34
/**
30
 *
35
 *
31
 * @author Jaroslav Tulach
36
 * @author Jaroslav Tulach
32
 */
37
 */
33
public class UIHandler extends Handler implements Runnable {
38
public class UIHandler extends Handler 
39
implements ActionListener, Runnable, Callable<JButton> {
34
    private final Queue<LogRecord> logs;
40
    private final Queue<LogRecord> logs;
35
    private final boolean exceptionOnly;
41
    private final boolean exceptionOnly;
36
    static final PropertyChangeSupport SUPPORT = new PropertyChangeSupport(UIHandler.class);
42
    static final PropertyChangeSupport SUPPORT = new PropertyChangeSupport(UIHandler.class);
Lines 64-79 Link Here
64
        }
70
        }
65
        
71
        
66
        SUPPORT.firePropertyChange(null, null, null);
72
        SUPPORT.firePropertyChange(null, null, null);
67
68
        /*
69
        if (
70
            exceptionOnly &&
71
            record.getLevel().intValue() >= Level.WARNING.intValue() &&
72
            record.getThrown() != null
73
        ) {
74
            Installer.RP.post(this);
75
        }
76
         */
77
    }
73
    }
78
74
79
    public void flush() {
75
    public void flush() {
Lines 84-88 Link Here
84
    
80
    
85
    public void run() {
81
    public void run() {
86
        Installer.displaySummary("ERROR_URL", false); // NOI18N
82
        Installer.displaySummary("ERROR_URL", false); // NOI18N
83
    }
84
85
    private JButton button;
86
    public JButton call() throws Exception {
87
        if (button == null) {
88
            button = new JButton(NbBundle.getMessage(UIHandler.class, "MSG_SubmitButton")); // NOI18N
89
            button.addActionListener(this);
90
        }
91
        return button;
92
    }
93
94
    public void actionPerformed(ActionEvent ev) {
95
        run();
87
    }
96
    }
88
}
97
}
(-)logger/uihandler/src/org/netbeans/modules/uihandler/api/doc-files/ui.html (-2 / +7 lines)
Lines 10-16 Link Here
10
<h1>UI of Gestures Collector</h1>
10
<h1>UI of Gestures Collector</h1>
11
<dl>
11
<dl>
12
 <dt><em>Ve rsion:</em></dt>
12
 <dt><em>Ve rsion:</em></dt>
13
 <dd>$Date: 2007/01/04 16:28:23 $</dd>
13
 <dd>$Date: 2007/01/11 19:34:44 $</dd>
14
 <dt><em>Author:</em></dt>
14
 <dt><em>Author:</em></dt>
15
 <dd>Jaroslav  Tulach</dd>
15
 <dd>Jaroslav  Tulach</dd>
16
 <dt><em>Abstract:</em></dt>
16
 <dt><em>Abstract:</em></dt>
Lines 232-238 Link Here
232
<h3>Error Dialog</h3>
232
<h3>Error Dialog</h3>
233
233
234
<p>
234
<p>
235
    This dialog appears when an exception occurs in the system:
235
    When an exception is rised, its behaviour remains the same as is usual
236
    - e.g. in develpment builds to common "Unexpected Exception Dialog" is shown,
237
    in releases a blinking icon at the lower right corner starts to blink and
238
    when clicked the dialog is shown. However in contrast to previous versions,
239
    there is a new button <q>Report...</q> in the dialog. When clicked it 
240
    opens following dialog:
236
</p>
241
</p>
237
242
238
<pre>
243
<pre>

Return to bug 92075