KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > Installer


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 package org.netbeans.modules.uihandler;
20
21 import java.awt.Dialog JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.BufferedInputStream JavaDoc;
26 import java.io.BufferedOutputStream JavaDoc;
27 import java.io.DataOutputStream JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.FileOutputStream JavaDoc;
31 import java.io.FileWriter JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.io.OutputStream JavaDoc;
35 import java.io.PrintStream JavaDoc;
36 import java.net.MalformedURLException JavaDoc;
37 import java.net.NoRouteToHostException JavaDoc;
38 import java.net.URL JavaDoc;
39 import java.net.URLConnection JavaDoc;
40 import java.net.UnknownHostException JavaDoc;
41 import java.text.MessageFormat JavaDoc;
42 import java.util.ArrayList JavaDoc;
43 import java.util.Collections JavaDoc;
44 import java.util.Date JavaDoc;
45 import java.util.LinkedList JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.ListIterator JavaDoc;
48 import java.util.Map JavaDoc;
49 import java.util.Queue JavaDoc;
50 import java.util.concurrent.atomic.AtomicReference JavaDoc;
51 import java.util.logging.Level JavaDoc;
52 import java.util.logging.LogRecord JavaDoc;
53 import java.util.logging.Logger JavaDoc;
54 import java.util.prefs.Preferences JavaDoc;
55 import java.util.regex.Matcher JavaDoc;
56 import java.util.regex.Pattern JavaDoc;
57 import java.util.zip.GZIPInputStream JavaDoc;
58 import java.util.zip.GZIPOutputStream JavaDoc;
59 import javax.swing.AbstractButton JavaDoc;
60 import javax.swing.JButton JavaDoc;
61 import javax.xml.parsers.DocumentBuilder JavaDoc;
62 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
63 import javax.xml.parsers.ParserConfigurationException JavaDoc;
64 import org.netbeans.lib.uihandler.LogRecords;
65 import org.netbeans.modules.exceptions.ReportPanel;
66 import org.netbeans.modules.exceptions.ExceptionsSettings;
67 import org.netbeans.modules.uihandler.api.Activated;
68 import org.netbeans.modules.uihandler.api.Deactivated;
69 import org.openide.DialogDescriptor;
70 import org.openide.DialogDisplayer;
71 import org.openide.awt.HtmlBrowser;
72 import org.openide.awt.Mnemonics;
73 import org.openide.filesystems.FileUtil;
74 import org.openide.modules.ModuleInstall;
75 import org.openide.nodes.AbstractNode;
76 import org.openide.nodes.Children;
77 import org.openide.nodes.Node;
78 import org.openide.util.Lookup;
79 import org.openide.util.Mutex;
80 import org.openide.util.NbBundle;
81 import org.openide.util.NbPreferences;
82 import org.openide.util.RequestProcessor;
83 import org.w3c.dom.Document JavaDoc;
84 import org.w3c.dom.NodeList JavaDoc;
85 import org.xml.sax.SAXException JavaDoc;
86
87 /**
88  * Registers and unregisters loggers.
89  */

90 public class Installer extends ModuleInstall {
91     /**
92      *
93      */

94     static final String JavaDoc USER_CONFIGURATION = "UI_USER_CONFIGURATION"; // NOI18N
95
private static Queue JavaDoc<LogRecord JavaDoc> logs = new LinkedList JavaDoc<LogRecord JavaDoc>();
96     private static UIHandler ui = new UIHandler(logs, false);
97     private static UIHandler handler = new UIHandler(logs, true);
98     static final Logger JavaDoc LOG = Logger.getLogger(Installer.class.getName());
99     static final RequestProcessor RP = new RequestProcessor("UI Gestures"); // NOI18N
100

101     @Override JavaDoc
102     public void restored() {
103         File JavaDoc logFile = logFile();
104         if (logFile != null && logFile.canRead()) {
105             InputStream JavaDoc is = null;
106             try {
107                 is = new GZIPInputStream JavaDoc(new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(logFile)));
108                 LogRecords.scan(is, ui);
109             } catch (IOException JavaDoc ex) {
110                 LOG.log(Level.INFO, "Cannot read " + logFile, ex);
111             } finally {
112                 if (is != null) {
113                     try {
114                         is.close();
115                     } catch (Exception JavaDoc ex) {
116                         LOG.log(Level.INFO, "Cannot read " + logFile, ex);
117                     }
118                 }
119             }
120         }
121         
122         Logger JavaDoc log = Logger.getLogger("org.netbeans.ui"); // NOI18N
123
log.setUseParentHandlers(false);
124         log.setLevel(Level.FINEST);
125         log.addHandler(ui);
126         Logger JavaDoc all = Logger.getLogger("");
127         all.addHandler(handler);
128         
129         for (Activated a : Lookup.getDefault().lookupAll(Activated.class)) {
130             a.activated(log);
131         }
132         /*
133         Enumeration<String> en = LogManager.getLogManager().getLoggerNames();
134         while (en.hasMoreElements()) {
135             String name = en.nextElement();
136             if (name.startsWith("org.netbeans.ui")) {
137                 Logger l = Logger.getLogger(name);
138                 l.setLevel(Level.FINEST);
139             }
140         }
141          */

142     }
143     
144     @Override JavaDoc
145     public void uninstalled() {
146         close();
147     }
148     
149     @Override JavaDoc
150     public void close() {
151         Logger JavaDoc log = Logger.getLogger("org.netbeans.ui"); // NOI18N
152
log.removeHandler(ui);
153         Logger JavaDoc all = Logger.getLogger(""); // NOI18N
154
all.removeHandler(handler);
155         
156         File JavaDoc logFile = logFile();
157         if (logFile != null) {
158             try {
159                 logFile.getParentFile().mkdirs();
160                 // flush all the unsend data to disk
161
OutputStream JavaDoc os = new GZIPOutputStream JavaDoc(new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(logFile)));
162                 for (LogRecord JavaDoc r : getLogs()) {
163                     LogRecords.write(os, r);
164                 }
165                 os.close();
166             } catch (IOException JavaDoc ex) {
167                 LOG.log(Level.INFO, "Cannot write " + logFile, ex);
168             }
169         }
170     }
171     
172     public static int getLogsSize() {
173         return logs.size();
174     }
175     
176     public static List JavaDoc<LogRecord JavaDoc> getLogs() {
177         synchronized (UIHandler.class) {
178             return new ArrayList JavaDoc<LogRecord JavaDoc>(logs);
179         }
180     }
181     
182     private static File JavaDoc logFile() {
183         String JavaDoc ud = System.getProperty("netbeans.user"); // NOI18N
184
if (ud == null || "memory".equals(ud)) { // NOI18N
185
return null;
186         }
187         
188         File JavaDoc userDir = new File JavaDoc(ud); // NOI18N
189
File JavaDoc logFile = new File JavaDoc(new File JavaDoc(new File JavaDoc(userDir, "var"), "log"), "uigestures.gz");
190         return logFile;
191     }
192     
193     static void clearLogs() {
194         synchronized (UIHandler.class) {
195             logs.clear();
196         }
197         UIHandler.SUPPORT.firePropertyChange(null, null, null);
198     }
199     
200     public boolean closing() {
201         if (getLogsSize() == 0) {
202             return true;
203         }
204         
205         return displaySummary("EXIT_URL", false); // NOI18N
206
}
207     
208     private static AtomicReference JavaDoc<String JavaDoc> DISPLAYING = new AtomicReference JavaDoc<String JavaDoc>();
209     static boolean displaySummary(String JavaDoc msg, boolean explicit) {
210         if (!DISPLAYING.compareAndSet(null, msg)) {
211             return true;
212         }
213         
214         boolean v = true;
215         try {
216             if (!explicit) {
217                 boolean dontAsk = NbPreferences.forModule(Installer.class).getBoolean("ask.never.again." + msg, false); // NOI18N
218
if (dontAsk) {
219                     LOG.log(Level.INFO, "UI Gesture Collector's ask.never.again.{0} is true, exiting", msg); // NOI18N
220
return true;
221                 }
222             }
223             
224             v = doDisplaySummary(msg);
225         } finally {
226             DISPLAYING.set(null);
227         }
228         return v;
229     }
230     
231     protected static Throwable JavaDoc getThrown(){
232         List JavaDoc<LogRecord JavaDoc> list = getLogs();
233         ListIterator JavaDoc<LogRecord JavaDoc> it = list.listIterator(list.size());
234         while (it.hasPrevious()){
235             Throwable JavaDoc t = it.previous().getThrown();
236             // find first exception from end
237
if (t != null) return t;
238         }
239         return null;// no throwable found
240
}
241     
242     private static boolean doDisplaySummary(String JavaDoc msg) {
243         Submit submit = new Submit(msg);
244         submit.doShow();
245         return submit.okToExit;
246     }
247     
248     
249     private static boolean isChild(org.w3c.dom.Node JavaDoc child, org.w3c.dom.Node JavaDoc parent) {
250         while (child != null) {
251             if (child == parent) {
252                 return true;
253             }
254             child = child.getParentNode();
255         }
256         return false;
257     }
258     
259     private static String JavaDoc attrValue(org.w3c.dom.Node JavaDoc in, String JavaDoc attrName) {
260         org.w3c.dom.Node JavaDoc n = in.getAttributes().getNamedItem(attrName);
261         return n == null ? null : n.getNodeValue();
262     }
263     
264     /** Tries to parse a list of buttons provided by given page.
265      * @param u the url to read the page from
266      * @param defaultButton the button to add always to the list
267      */

268     static void parseButtons(InputStream JavaDoc is, Object JavaDoc defaultButton, DialogDescriptor dd)
269     throws IOException JavaDoc, ParserConfigurationException JavaDoc, SAXException JavaDoc {
270         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
271         factory.setValidating(false);
272         factory.setIgnoringComments(true);
273         DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
274         Document JavaDoc doc = builder.parse(is);
275         
276         List JavaDoc<Object JavaDoc> buttons = new ArrayList JavaDoc<Object JavaDoc>();
277         List JavaDoc<Object JavaDoc> left = new ArrayList JavaDoc<Object JavaDoc>();
278         
279         NodeList JavaDoc forms = doc.getElementsByTagName("form");
280         for (int i = 0; i < forms.getLength(); i++) {
281             Form f = new Form(forms.item(i).getAttributes().getNamedItem("action").getNodeValue());
282             NodeList JavaDoc inputs = doc.getElementsByTagName("input");
283             for (int j = 0; j < inputs.getLength(); j++) {
284                 if (isChild(inputs.item(j), forms.item(i))) {
285                     org.w3c.dom.Node JavaDoc in = inputs.item(j);
286                     String JavaDoc type = attrValue(in, "type");
287                     String JavaDoc name = attrValue(in, "name");
288                     String JavaDoc value = attrValue(in, "value");
289                     String JavaDoc align = attrValue(in, "align");
290                     String JavaDoc alt = attrValue(in, "alt");
291                     
292                     List JavaDoc<Object JavaDoc> addTo = "left".equals(align) ? left : buttons;
293                     
294                     if ("hidden".equals(type) && "submit".equals(name)) { // NOI18N
295
f.submitValue = value;
296                         JButton JavaDoc b = new JButton JavaDoc();
297                         Mnemonics.setLocalizedText(b, f.submitValue);
298                         b.setActionCommand("submit"); // NOI18N
299
b.putClientProperty("url", f.url); // NOI18N
300
b.setDefaultCapable(addTo.isEmpty() && addTo == buttons);
301                         b.putClientProperty("alt", alt); // NOI18N
302
b.putClientProperty("now", f.submitValue); // NOI18N
303
addTo.add(b);
304                         continue;
305                     }
306                     
307                     
308                     if ("hidden".equals(type)) { // NOI18N
309
JButton JavaDoc b = new JButton JavaDoc();
310                         Mnemonics.setLocalizedText(b, value);
311                         b.setActionCommand(name);
312                         b.setDefaultCapable(addTo.isEmpty() && addTo == buttons);
313                         b.putClientProperty("alt", alt); // NOI18N
314
b.putClientProperty("now", value); // NOI18N
315
addTo.add(b);
316                         if ("exit".equals(name)) { // NOI18N
317
defaultButton = null;
318                         }
319                     }
320                 }
321             }
322         }
323         if (defaultButton != null) {
324             buttons.add(defaultButton);
325         }
326         dd.setOptions(buttons.toArray());
327         dd.setAdditionalOptions(left.toArray());
328     }
329     
330     static String JavaDoc decodeButtons(Object JavaDoc res, URL JavaDoc[] url) {
331         if (res instanceof JButton JavaDoc) {
332             JButton JavaDoc b = (JButton JavaDoc)res;
333             Object JavaDoc post = b.getClientProperty("url"); // NOI18N
334
if (post instanceof String JavaDoc) {
335                 String JavaDoc replace = System.getProperty("org.netbeans.modules.uihandler.Submit"); // NOI18N
336
if (replace != null) {
337                     post = replace;
338                 }
339                 try {
340                     url[0] = new URL JavaDoc((String JavaDoc) post);
341                 } catch (MalformedURLException JavaDoc ex) {
342                     url[0] = null;
343                 }
344             }
345             return b.getActionCommand();
346         }
347         return res instanceof String JavaDoc ? (String JavaDoc)res : null;
348     }
349     
350     static URL JavaDoc uploadLogs(URL JavaDoc postURL, String JavaDoc id, Map JavaDoc<String JavaDoc,String JavaDoc> attrs, List JavaDoc<LogRecord JavaDoc> recs) throws IOException JavaDoc {
351         URLConnection JavaDoc conn = postURL.openConnection();
352         
353         conn.setReadTimeout(20000);
354         conn.setDoOutput(true);
355         conn.setDoInput(true);
356         conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=--------konec<>bloku");
357         conn.setRequestProperty("Pragma", "no-cache");
358         conn.setRequestProperty("Cache-control", "no-cache");
359         
360         PrintStream JavaDoc os = new PrintStream JavaDoc(conn.getOutputStream());
361         /*
362         os.println("POST " + postURL.getPath() + " HTTP/1.1");
363         os.println("Pragma: no-cache");
364         os.println("Cache-control: no-cache");
365         os.println("Content-Type: multipart/form-data; boundary=--------konec<>bloku");
366         os.println();
367          */

368         for (Map.Entry JavaDoc<String JavaDoc, String JavaDoc> en : attrs.entrySet()) {
369             os.println("----------konec<>bloku");
370             os.println("Content-Disposition: form-data; name=\"" + en.getKey() + "\"");
371             os.println();
372             os.println(en.getValue().getBytes());
373         }
374         
375         os.println("----------konec<>bloku");
376         
377         if (id == null) {
378             id = "uigestures"; // NOI18N
379
}
380         
381         os.println("Content-Disposition: form-data; name=\"logs\"; filename=\"" + id + "\"");
382         os.println("Content-Type: x-application/gzip");
383         os.println();
384         GZIPOutputStream JavaDoc gzip = new GZIPOutputStream JavaDoc(os);
385         DataOutputStream JavaDoc data = new DataOutputStream JavaDoc(gzip);
386         data.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes("utf-8")); // NOI18N
387
data.write("<uigestures version='1.0'>\n".getBytes("utf-8")); // NOI18N
388
for (LogRecord JavaDoc r : recs) {
389             LogRecords.write(data, r);
390         }
391         data.write("</uigestures>\n".getBytes("utf-8")); // NOI18N
392
data.flush();
393         gzip.finish();
394         os.println("----------konec<>bloku--");
395         os.close();
396         
397         
398         InputStream JavaDoc is = conn.getInputStream();
399         StringBuffer JavaDoc redir = new StringBuffer JavaDoc();
400         for (;;) {
401             int ch = is.read();
402             if (ch == -1) {
403                 break;
404             }
405             redir.append((char)ch);
406         }
407         is.close();
408         
409         LOG.fine("Reply from uploadLogs:");
410         LOG.fine(redir.toString());
411         
412         Pattern JavaDoc p = Pattern.compile("<meta\\s*http-equiv=.Refresh.\\s*content.*url=['\"]?([^'\" ]*)\\s*['\"]", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
413         Matcher JavaDoc m = p.matcher(redir);
414         
415         if (m.find()) {
416             return new URL JavaDoc(m.group(1));
417         } else {
418             File JavaDoc f = File.createTempFile("uipage", "html");
419             FileWriter JavaDoc w = new FileWriter JavaDoc(f);
420             w.write(redir.toString());
421             w.close();
422             return f.toURI().toURL();
423         }
424     }
425     
426     private static String JavaDoc findIdentity() {
427         Preferences JavaDoc p = NbPreferences.root().node("org/netbeans/modules/autoupdate"); // NOI18N
428
String JavaDoc id = p.get("ideIdentity", null);
429         LOG.log(Level.INFO, "findIdentity: {0}", id);
430         return id;
431     }
432     
433     static final class Form extends Object JavaDoc {
434         final String JavaDoc url;
435         String JavaDoc submitValue;
436         
437         public Form(String JavaDoc u) {
438             url = u;
439         }
440     }
441     
442     private static final class Submit implements ActionListener JavaDoc, Mutex.Action<Void JavaDoc> {
443         private String JavaDoc msg;
444         boolean okToExit;
445         private DialogDescriptor dd;
446         private Dialog JavaDoc d;
447         private SubmitPanel panel;
448         private HtmlBrowser browser;
449         private URL JavaDoc url;
450         private String JavaDoc exitMsg;
451         private boolean report;//property tells me wheather I'm in report mode
452
private ReportPanel reportPanel;
453         
454         public Submit(String JavaDoc msg) {
455             this.msg = msg;
456             if ("ERROR_URL".equals(msg)) report = true; // NOI18N
457
else report = false;
458         }
459         
460         private LogRecord JavaDoc getUserData(){
461             LogRecord JavaDoc userData;
462             ExceptionsSettings settings = new ExceptionsSettings();
463             ArrayList JavaDoc<String JavaDoc> params = new ArrayList JavaDoc<String JavaDoc>(6);
464             params.add(getOS());
465             params.add(getVM());
466             params.add(getVersion());
467             if (reportPanel != null) reportPanel.saveUserName();
468             params.add(settings.getUserName());
469             if (reportPanel != null){
470                 params.add(reportPanel.getSummary());
471                 params.add(reportPanel.getComment());
472             }
473             userData = new LogRecord JavaDoc(Level.CONFIG, USER_CONFIGURATION);
474             userData.setResourceBundle(NbBundle.getBundle(Installer.class));
475             userData.setResourceBundleName(Installer.class.getPackage().getName()+".Bundle");
476             userData.setParameters(params.toArray());
477             return userData;
478         }
479         
480         private String JavaDoc getOS(){
481             String JavaDoc unknown = "unknown"; // NOI18N
482
String JavaDoc str = System.getProperty("os.name", unknown)+", "+ // NOI18N
483
System.getProperty("os.version", unknown)+", "+ // NOI18N
484
System.getProperty("os.arch", unknown); // NOI18N
485
return str;
486         }
487         
488         private String JavaDoc getVersion(){
489             String JavaDoc str = MessageFormat.format(
490                     NbBundle.getBundle("org.netbeans.core.startup.Bundle").getString("currentVersion"), // NOI18N
491
new Object JavaDoc[] {System.getProperty("netbeans.buildnumber")}); // NOI18N
492
return str;
493         }
494         
495         private String JavaDoc getVM(){
496             return System.getProperty("java.vm.name", "unknown") + ", " + System.getProperty("java.vm.version", ""); // NOI18N
497
}
498         
499         public void doShow() {
500             Logger JavaDoc log = Logger.getLogger("org.netbeans.ui"); // NOI18N
501
for (Deactivated a : Lookup.getDefault().lookupAll(Deactivated.class)) {
502                 a.deactivated(log);
503             }
504             if (report) {
505                 dd = new DialogDescriptor(null, NbBundle.getMessage(Installer.class, "ErrorDialogTitle"));
506             } else {
507                 dd = new DialogDescriptor(null, NbBundle.getMessage(Installer.class, "MSG_SubmitDialogTitle"));
508             }
509
510             exitMsg = NbBundle.getMessage(Installer.class, "MSG_" + msg + "_EXIT"); // NOI18N
511
for (;;) {
512                 try {
513                     if (url == null) {
514                         String JavaDoc uri = NbBundle.getMessage(Installer.class, msg);
515                         if (uri == null || uri.length() == 0) {
516                             okToExit = true;
517                             return;
518                         }
519                         url = new URL JavaDoc(uri); // NOI18N
520
}
521                     
522                     URLConnection JavaDoc conn = url.openConnection();
523                     File JavaDoc tmp = File.createTempFile("uigesture", ".html");
524                     tmp.deleteOnExit();
525                     FileOutputStream JavaDoc os = new FileOutputStream JavaDoc(tmp);
526                     FileUtil.copy(conn.getInputStream(), os);
527                     os.close();
528                     conn.getInputStream().close();
529                     InputStream JavaDoc is = new FileInputStream JavaDoc(tmp);
530                     parseButtons(is, exitMsg, dd);
531                     is.close();
532                     url = tmp.toURI().toURL();
533                 } catch (ParserConfigurationException JavaDoc ex) {
534                     LOG.log(Level.WARNING, null, ex);
535                 } catch (SAXException JavaDoc ex) {
536                     LOG.log(Level.WARNING, url.toExternalForm(), ex);
537                 } catch (java.net.SocketTimeoutException JavaDoc ex) {
538                     LOG.log(Level.INFO, url.toExternalForm(), ex);
539                     url = getClass().getResource("UnknownHostException.html");
540                     msg = null;
541                     continue;
542                 } catch (UnknownHostException JavaDoc ex) {
543                     LOG.log(Level.INFO, url.toExternalForm(), ex);
544                     url = getClass().getResource("UnknownHostException.html");
545                     msg = null;
546                     continue;
547                 } catch (NoRouteToHostException JavaDoc ex) {
548                     LOG.log(Level.INFO, url.toExternalForm(), ex);
549                     url = getClass().getResource("UnknownHostException.html");
550                     msg = null;
551                     continue;
552                 } catch (IOException JavaDoc ex) {
553                     LOG.log(Level.WARNING, url.toExternalForm(), ex);
554                 }
555                 break;
556             }
557             Mutex.EVENT.readAccess(this);
558         }
559         
560         public Void JavaDoc run() {
561             if ("ERROR_URL".equals(msg)){ // NOI18N
562
if (reportPanel==null) reportPanel = new ReportPanel();
563                 Throwable JavaDoc t = getThrown();
564                 assert t!= null : "NO THROWABLE FOUND"; // NOI18N
565
String JavaDoc summary = t.getClass().getName();
566                 String JavaDoc[] pieces = summary.split("\\.");
567                 if (pieces.length > 0) summary = pieces[pieces.length-1];//posledni piece
568
if (t.getMessage()!= null)summary = summary.concat(" : " + t.getMessage()); //NOI18N
569
reportPanel.setSummary(summary);
570                 dd.setMessage(reportPanel);
571             }else{
572                 browser = new HtmlBrowser();
573                 browser.setURL(url);
574                 browser.setEnableLocation(false);
575                 browser.setEnableHome(false);
576                 browser.setStatusLineVisible(false);
577                 browser.setToolbarVisible(false);
578                 browser.setPreferredSize(new Dimension JavaDoc(640, 480));
579                 dd.setMessage(browser);
580                 
581                 // AbstractNode root = new AbstractNode(new Children.Array());
582
// root.setName("root"); // NOI18N
583
// root.setDisplayName(NbBundle.getMessage(Installer.class, "MSG_RootDisplayName", recs.size(), new Date()));
584
// root.setIconBaseWithExtension("org/netbeans/modules/uihandler/logs.gif");
585
// for (LogRecord r : recs) {
586
// root.getChildren().add(new Node[] { UINode.create(r) });
587
// }
588
//
589
// panel.getExplorerManager().setRootContext(root);
590

591             }
592             dd.setClosingOptions(new Object JavaDoc[] { exitMsg });
593             dd.setButtonListener(this);
594             dd.setModal(true);
595             d = DialogDisplayer.getDefault().createDialog(dd);
596             d.setVisible(true);
597             
598             Object JavaDoc res = dd.getValue();
599             
600             if (res == exitMsg) {
601                 okToExit = true;
602             }
603             
604             return null;
605         }
606         
607         private void uploadAndPost(List JavaDoc<LogRecord JavaDoc> recs, URL JavaDoc u) {
608             URL JavaDoc nextURL = null;
609             try {
610                 nextURL = uploadLogs(u, findIdentity(), Collections.<String JavaDoc,String JavaDoc>emptyMap(), recs);
611             } catch (IOException JavaDoc ex) {
612                 LOG.log(Level.INFO, null, ex);
613             }
614             if (nextURL != null) {
615                 clearLogs();
616                 HtmlBrowser.URLDisplayer.getDefault().showURL(nextURL);
617             }
618         }
619         
620         public void actionPerformed(ActionEvent JavaDoc e) {
621             final URL JavaDoc[] url = new URL JavaDoc[1];
622             String JavaDoc actionURL = decodeButtons(e.getSource(), url);
623             
624             if ("submit".equals(e.getActionCommand())) { // NOI18N
625
final List JavaDoc<LogRecord JavaDoc> recs = getLogs();
626                 if (report) reportPanel.saveUserName();
627                 recs.add(getUserData());
628                 RP.post (new Runnable JavaDoc() {
629                     public void run() {
630                         uploadAndPost(recs, url[0]);
631                     }
632                 });
633                 okToExit = false;
634                 // this should close the descriptor
635
dd.setValue(DialogDescriptor.CLOSED_OPTION);
636                 d.setVisible(false);
637                 return;
638             }
639             
640             if ("view-data".equals(e.getActionCommand())) { // NOI18N
641
if (panel == null) {
642                     panel = new SubmitPanel();
643                     AbstractNode root = new AbstractNode(new Children.Array());
644                     root.setName("root"); // NOI18N
645
List JavaDoc<LogRecord JavaDoc> recs = getLogs();
646                     recs.add(getUserData());
647                     root.setDisplayName(NbBundle.getMessage(Installer.class, "MSG_RootDisplayName", recs.size(), new Date JavaDoc()));
648                     root.setIconBaseWithExtension("org/netbeans/modules/uihandler/logs.gif");
649                     LinkedList JavaDoc<Node> reverted = new LinkedList JavaDoc<Node>();
650                     for (LogRecord JavaDoc r : recs) {
651                         reverted.addFirst(UINode.create(r));
652                         panel.addRecord(r);
653                     }
654                     root.getChildren().add(reverted.toArray(new Node[0]));
655                     panel.getExplorerManager().setRootContext(root);
656                 }
657                 
658                 if (report) {
659                     if (dd.getMessage() == reportPanel) {
660                         dd.setMessage(panel);
661                     } else {
662                         dd.setMessage(reportPanel);
663                     }
664                 } else {
665                     if (dd.getMessage() == browser) {
666                         dd.setMessage(panel);
667                     } else {
668                         dd.setMessage(browser);
669                     }
670                 }
671                 if (e.getSource() instanceof AbstractButton JavaDoc) {
672                     AbstractButton JavaDoc abut = (AbstractButton JavaDoc)e.getSource();
673                     String JavaDoc alt = (String JavaDoc) abut.getClientProperty("alt"); // NOI18N
674
if (alt != null) {
675                         String JavaDoc now = (String JavaDoc)abut.getClientProperty("now"); // NOI18N
676
Mnemonics.setLocalizedText(abut, alt);
677                         abut.putClientProperty("alt", now); // NOI18N
678
abut.putClientProperty("now", alt); // NOI18N
679
}
680                 }
681                 return;
682             }
683             
684             if ("never-again".equals(e.getActionCommand())) { // NOI18N
685
LOG.log(Level.FINE, "Assigning ask.never.again.{0} to true", msg); // NOI18N
686
NbPreferences.forModule(Installer.class).putBoolean("ask.never.again." + msg, true); // NOI18N
687
okToExit = true;
688                 // this should close the descriptor
689
dd.setValue(DialogDescriptor.CLOSED_OPTION);
690                 d.setVisible(false);
691                 return;
692             }
693             
694             if ("exit".equals(e.getActionCommand())) {
695                 // this should close the descriptor
696
dd.setValue(DialogDescriptor.CLOSED_OPTION);
697                 d.setVisible(false);
698                 return;
699             }
700             
701         }
702     } // end Submit
703
}
704
Popular Tags