001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sun.manager.jbi.actions;
042:
043: import com.sun.esb.management.api.configuration.ConfigurationService;
044: import com.sun.esb.management.common.ManagementRemoteException;
045: import java.awt.event.ActionEvent;
046: import javax.swing.AbstractAction;
047: import javax.swing.SwingUtilities;
048: import org.netbeans.modules.sun.manager.jbi.management.AppserverJBIMgmtController;
049: import org.netbeans.modules.sun.manager.jbi.nodes.JBIComponentNode;
050: import org.netbeans.modules.sun.manager.jbi.nodes.Refreshable;
051: import org.netbeans.modules.sun.manager.jbi.util.ProgressUI;
052: import org.openide.DialogDisplayer;
053: import org.openide.NotifyDescriptor;
054: import org.openide.nodes.Node;
055: import org.openide.util.Exceptions;
056: import org.openide.util.Lookup;
057: import org.openide.util.NbBundle;
058: import org.openide.windows.TopComponent;
059:
060: /**
061: * An action for an MBean operation (w/o any parameters) that is
062: * not known until runtime.
063: *
064: * @author jqian
065: */
066: // Can not use NetBeans' SystemAction because of sharability issue.
067: public class MBeanOperationAction extends AbstractAction {
068:
069: private String mBeanKey;
070: private String operationName;
071: private String description;
072:
073: public MBeanOperationAction(String mBeanKey, String operationName,
074: String displayName, String description, boolean enabled) {
075: super (displayName);
076:
077: this .mBeanKey = mBeanKey;
078: this .operationName = operationName;
079: this .description = description;
080:
081: setEnabled(enabled);
082: }
083:
084: public void actionPerformed(ActionEvent ev) {
085:
086: final Node[] activatedNodes = TopComponent.getRegistry()
087: .getActivatedNodes();
088: JBIComponentNode componentNode = activatedNodes[0].getLookup()
089: .lookup(JBIComponentNode.class);
090:
091: final String componentName = componentNode.getName();
092:
093: final AppserverJBIMgmtController controller = componentNode
094: .getAppserverJBIMgmtController();
095:
096: String title = NbBundle.getMessage(MBeanOperationAction.class,
097: "LBL_Invoking_MBean_Operation", // NOI18N
098: new Object[] { operationName });
099: final ProgressUI progressUI = new ProgressUI(title, false);
100: progressUI.start();
101:
102: // Invoke the action out of EDT 'cause the operation could be expensive.
103: new Thread() {
104:
105: @Override
106: public void run() {
107: try {
108: ConfigurationService configService = controller
109: .getConfigurationService();
110: final String result = (String) configService
111: .invokeExtensionMBeanOperation(
112: componentName,
113: mBeanKey,
114: operationName,
115: new Object[] {},
116: new String[] {},
117: AppserverJBIMgmtController.SERVER_TARGET,
118: null);
119:
120: Lookup lookup = activatedNodes[0].getLookup();
121: final Refreshable refreshable = lookup
122: .lookup(Refreshable.class);
123: if (refreshable != null) {
124: SwingUtilities.invokeLater(new Runnable() {
125:
126: public void run() {
127: if (result != null) {
128: NotifyDescriptor d = new NotifyDescriptor.Message(
129: result,
130: NotifyDescriptor.INFORMATION_MESSAGE);
131: DialogDisplayer.getDefault()
132: .notify(d);
133: }
134: refreshable.refresh();
135: }
136: });
137: }
138: } catch (ManagementRemoteException e) {
139: NotifyDescriptor d = new NotifyDescriptor.Message(e
140: .getMessage(),
141: NotifyDescriptor.ERROR_MESSAGE);
142: DialogDisplayer.getDefault().notify(d);
143: } finally {
144: SwingUtilities.invokeLater(new Runnable() {
145:
146: public void run() {
147: progressUI.finish();
148: }
149: });
150: }
151: }
152: }.start();
153: }
154: }
|