1 19 package org.netbeans.modules.xml.core.lib; 20 21 import java.awt.event.ActionEvent ; 22 import javax.swing.Action ; 23 import javax.swing.SwingUtilities ; 24 25 import org.openide.ErrorManager; 26 import org.openide.NotifyDescriptor; 27 import org.openide.DialogDisplayer; 28 import org.openide.awt.StatusDisplayer; 29 import org.openide.filesystems.FileObject; 30 import org.openide.nodes.Node; 31 import org.openide.loaders.DataObject; 32 import org.openide.loaders.DataObjectNotFoundException; 33 import org.openide.util.Mutex; 34 35 38 public final class GuiUtil { 39 40 private GuiUtil() {} 41 42 45 public static void performDefaultAction (FileObject fo) { 46 if (fo == null) { 47 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("FileObject can not be null.", new IllegalArgumentException ()); return; 49 } 50 final DataObject obj; 51 try { 52 obj = DataObject.find(fo); 53 } catch (DataObjectNotFoundException e) { 54 if (Util.THIS.isLoggable()) { 55 Util.THIS.debug("DataObject not found", e); } 57 return; 58 } 59 Mutex.EVENT.readAccess(new Runnable () { 61 public void run() { 62 Node node = obj.getNodeDelegate(); 63 Action a = node.getPreferredAction(); 64 if (a != null) { 65 a.actionPerformed(new ActionEvent (node, ActionEvent.ACTION_PERFORMED, "")); } 67 } 68 }); 69 } 70 71 public static boolean confirmAction (String message) { 72 NotifyDescriptor nd = new NotifyDescriptor.Confirmation (message, NotifyDescriptor.YES_NO_OPTION); 73 Object option = DialogDisplayer.getDefault().notify (nd); 74 return ( option == NotifyDescriptor.YES_OPTION ); 75 } 76 77 78 public static void setStatusText (String text) { 79 StatusDisplayer.getDefault().setStatusText (text); 80 } 81 82 83 84 87 public static void notifyException (Throwable exc) { 88 notifyException (null, exc); 89 } 90 91 92 95 public static void notifyException (String desc, Throwable ex) { 96 ErrorManager err = ErrorManager.getDefault(); 97 if (desc != null) { 98 err.annotate (ex, desc); 99 } 100 err.notify (err.EXCEPTION, ex); } 102 103 106 public static void notifyWarning (final String message) { 107 SwingUtilities.invokeLater (new Runnable () { 109 public void run () { 110 NotifyDescriptor nd = new NotifyDescriptor.Message 111 (message, NotifyDescriptor.WARNING_MESSAGE); 112 DialogDisplayer.getDefault ().notify (nd); 113 } 114 }); 115 } 116 117 public static void notifyError (final String message) { 118 SwingUtilities.invokeLater (new Runnable () { 119 public void run () { 120 DialogDisplayer.getDefault().notify 121 (new NotifyDescriptor.Message (message, NotifyDescriptor.ERROR_MESSAGE) 122 ); 123 } 124 }); 125 } 126 127 } 128 | Popular Tags |