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 45 public class RestartAction extends NodeAction { 46 47 public String getName() { 48 return NbBundle.getMessage(RestartAction.class, "LBL_Restart"); 49 } 50 51 protected void performAction(Node[] nodes) { 52 performActionImpl(nodes); 53 } 54 55 protected boolean enable(Node[] nodes) { 56 return enableImpl(nodes); 57 } 58 59 public HelpCtx getHelpCtx() { 60 return HelpCtx.DEFAULT_HELP; 61 } 62 63 protected boolean asynchronous() { 64 return false; 65 } 66 67 69 private static void performActionImpl(Node[] nodes) { 70 for (int i = 0; i < nodes.length; i++) { 71 final ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class); 72 if (si != null) { 73 RequestProcessor.getDefault().post(new Runnable () { 74 public void run() { 75 String title = NbBundle.getMessage(RestartAction.class, "LBL_Restarting", si.getDisplayName()); 76 ProgressUI progressUI = new ProgressUI(title, false); 77 try { 78 progressUI.start(); 79 si.restart(progressUI); 80 } catch (ServerException ex) { 81 String msg = ex.getLocalizedMessage(); 82 NotifyDescriptor desc = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE); 83 DialogDisplayer.getDefault().notify(desc); 84 } finally { 85 progressUI.finish(); 86 } 87 } 88 }); 89 } 90 } 91 } 92 93 private static boolean enableImpl(Node[] nodes) { 94 for (int i = 0; i < nodes.length; i++) { 95 ServerInstance si = (ServerInstance)nodes[i].getCookie(ServerInstance.class); 96 if (si == null || !si.canStartServer()) { 97 return false; 98 } 99 int state = si.getServerState(); 100 if (state != ServerInstance.STATE_RUNNING 101 && state != ServerInstance.STATE_DEBUGGING 102 && state != ServerInstance.STATE_PROFILING 103 && state != ServerInstance.STATE_PROFILER_BLOCKING) { 104 return false; 105 } 106 } 107 return true; 108 } 109 110 111 public static class OutputAction extends AbstractAction implements ServerInstance.StateListener { 112 113 private static final String ICON = 114 "org/netbeans/modules/j2ee/deployment/impl/ui/resources/restart.png"; private static final String PROP_ENABLED = "enabled"; private Node node; 117 118 public OutputAction(Node node) { 119 super(NbBundle.getMessage(RestartAction.class, "LBL_RestartOutput"), 120 new ImageIcon (Utilities.loadImage(ICON))); 121 putValue(SHORT_DESCRIPTION, NbBundle.getMessage(RestartAction.class, "LBL_RestartOutputDesc")); 122 this.node = node; 123 124 ServerInstance si = (ServerInstance)node.getCookie(ServerInstance.class); 126 si.addStateListener(this); 127 } 128 129 public void actionPerformed(ActionEvent e) { 130 performActionImpl(new Node[] {node}); 131 } 132 133 public boolean isEnabled() { 134 return enableImpl(new Node[] {node}); 135 } 136 137 139 public void stateChanged(final int oldState, final int newState) { 140 Utils.runInEventDispatchThread(new Runnable () { 141 public void run() { 142 firePropertyChange( 143 PROP_ENABLED, 144 null, 145 isEnabled() ? Boolean.TRUE : Boolean.FALSE); 146 } 147 }); 148 } 149 } 150 } 151 | Popular Tags |