1 19 20 package org.netbeans.modules.j2ee.deployment.impl.ui.actions; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.ImageIcon ; 25 import org.netbeans.modules.j2ee.deployment.config.Utils; 26 import org.netbeans.modules.j2ee.deployment.impl.ServerException; 27 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 28 import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI; 29 import org.openide.DialogDisplayer; 30 import org.openide.NotifyDescriptor; 31 import org.openide.nodes.Node; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 import org.openide.util.RequestProcessor; 35 import org.openide.util.Utilities; 36 import org.openide.util.actions.NodeAction; 37 38 39 44 public class DebugAction extends NodeAction { 45 46 public String getName() { 47 return NbBundle.getMessage(DebugAction.class, "LBL_Debug"); 48 } 49 50 protected void performAction(Node[] nodes) { 51 performActionImpl(nodes); 52 } 53 54 protected boolean enable(Node[] nodes) { 55 return enableImpl(nodes); 56 } 57 58 public HelpCtx getHelpCtx() { 59 return HelpCtx.DEFAULT_HELP; 60 } 61 62 protected boolean asynchronous() { 63 return false; 64 } 65 66 68 private static void performActionImpl(Node[] nodes) { 69 for (int i = 0; i < nodes.length; i++) { 70 final ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class); 71 if (si != null) { 72 RequestProcessor.getDefault().post(new Runnable () { 73 public void run() { 74 String title = NbBundle.getMessage(DebugAction.class, "LBL_Debugging", si.getDisplayName()); 75 ProgressUI progressUI = new ProgressUI(title, false); 76 try { 77 progressUI.start(); 78 si.startDebug(progressUI); 79 } catch (ServerException ex) { 80 String msg = ex.getLocalizedMessage(); 81 NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE); 82 DialogDisplayer.getDefault().notify(desc); 83 } finally { 84 progressUI.finish(); 85 } 86 } 87 }); 88 } 89 } 90 } 91 92 private static boolean enableImpl(Node[] nodes) { 93 for (int i = 0; i < nodes.length; i++) { 94 ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class); 95 if (si == null || si.getServerState() != ServerInstance.STATE_STOPPED 96 || !si.isDebugSupported()) { 97 return false; 98 } 99 } 100 return true; 101 } 102 103 104 public static class OutputAction extends AbstractAction implements ServerInstance.StateListener { 105 106 private static final String ICON = 107 "org/netbeans/modules/j2ee/deployment/impl/ui/resources/debug.png"; private static final String PROP_ENABLED = "enabled"; private Node node; 110 111 public OutputAction(Node node) { 112 super(NbBundle.getMessage(DebugAction.class, "LBL_DebugOutput"), 113 new ImageIcon (Utilities.loadImage(ICON))); 114 putValue(SHORT_DESCRIPTION, NbBundle.getMessage(DebugAction.class, "LBL_DebugOutputDesc")); 115 this.node = node; 116 117 ServerInstance si = (ServerInstance)node.getCookie(ServerInstance.class); 119 si.addStateListener(this); 120 } 121 122 public void actionPerformed(ActionEvent e) { 123 performActionImpl(new Node[] {node}); 124 } 125 126 public boolean isEnabled() { 127 return enableImpl(new Node[] {node}); 128 } 129 130 132 public void stateChanged(final int oldState, final int newState) { 133 Utils.runInEventDispatchThread(new Runnable () { 134 public void run() { 135 firePropertyChange( 136 PROP_ENABLED, 137 null, 138 isEnabled() ? Boolean.TRUE : Boolean.FALSE); 139 } 140 }); 141 } 142 } 143 } 144 | Popular Tags |