KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > cluster > ClusterAddConnectionAction


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.cluster;
18
19 import org.mc4j.console.connection.wizard.ConnectionDescriptor;
20 import org.mc4j.ems.connection.settings.ConnectionSettings;
21 import org.openide.DialogDisplayer;
22 import org.openide.ErrorManager;
23 import org.openide.WizardDescriptor;
24 import org.openide.nodes.Node;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.actions.NodeAction;
27
28 import javax.swing.*;
29 import java.awt.*;
30
31 /**
32  * Action sensitive to the node selection that does something useful.
33  * Consider using a cookie action instead if you can define what the
34  * action is applicable to in terms of cookies.
35  *
36  * @author Greg Hinkle (ghinkle@users.sourceforge.net), January 2002
37  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
38  */

39 public class ClusterAddConnectionAction extends NodeAction {
40
41     protected void performAction(Node[] nodes) {
42         // do work based on the current node selection, e.g.:
43
Node node = nodes[0];
44
45
46         final ConnectionDescriptor desc = new ConnectionDescriptor();
47
48
49         final Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
50         // The following assumes the wizard descriptor is modal:
51
try {
52             SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
53                 public void run() {
54                     dlg.show();
55                 }
56             });
57         } catch (Exception JavaDoc e) { // InterruptedException, InvocationTargetException
58
ErrorManager.getDefault().notify(e);
59             return;
60         }
61         if (desc.getValue() == WizardDescriptor.FINISH_OPTION) {
62
63             // Prepare connection persistence mechanism
64
ConnectionSettings settings = desc.getSettings();
65             
66             // Persist the new connection
67
//ConnectionSetDatabase.addNode(settings);
68

69             /*
70             ConnectionNode connectionNode = ConnectionNode.buildConnection(settings);
71
72             try {
73                 connectionNode.connect();
74             } catch (Throwable e) {
75                 ErrorManager.getDefault().notify(e);
76             }
77
78             ((ClusterConnection) node).addConnection(connectionNode);
79             */

80         }
81     }
82
83     protected boolean enable(Node[] nodes) {
84         // e.g.:
85
return true; //nodes.length == 1 && nodes[0] instanceof MyKindOfNode;
86
}
87
88     public String JavaDoc getName() {
89         return java.util.ResourceBundle.getBundle("org/mc4j/console/Bundle").getString("LBL_ConnectAction");
90     }
91
92     protected String JavaDoc iconResource() {
93         return "org/mc4j/console/connection/ConnectActionIcon.gif";
94     }
95
96     public HelpCtx getHelpCtx() {
97         return HelpCtx.DEFAULT_HELP;
98         // If you will provide context help then use:
99
// return new HelpCtx(ConnectAction.class);
100
}
101
102 }
103
Popular Tags