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