KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > actions > AddWebServiceGroupAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.actions;
21
22 import java.awt.Dialog JavaDoc;
23 import javax.swing.event.DocumentListener JavaDoc;
24 import javax.swing.text.BadLocationException JavaDoc;
25 import javax.swing.text.Document JavaDoc;
26 import org.netbeans.modules.websvc.registry.model.WebServiceGroup;
27 import org.netbeans.modules.websvc.registry.model.WebServiceListModel;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31 import org.openide.util.actions.NodeAction;
32 import org.openide.util.*;
33
34 import org.netbeans.modules.websvc.registry.nodes.*;
35 import org.netbeans.modules.websvc.registry.nodes.WebServiceGroupNode;
36 import org.openide.nodes.Node;
37
38 /** Add a webservice group node to the root node
39  * @author Winston Prakash
40  */

41 public class AddWebServiceGroupAction extends NodeAction {
42     
43     protected boolean enable(org.openide.nodes.Node[] node) {
44         return true;
45     }
46     
47     public org.openide.util.HelpCtx getHelpCtx() {
48         return HelpCtx.DEFAULT_HELP;
49     }
50     
51     public String JavaDoc getName() {
52         return NbBundle.getMessage(AddWebServiceGroupAction.class, "ADD_GROUP");
53     }
54     
55     protected void performAction(Node[] nodes) {
56         WebServiceListModel wsNodeModel = WebServiceListModel.getInstance();
57         AddWSGroupPanel innerPanel = new AddWSGroupPanel();
58         DialogDescriptor dialogDesc = new DialogDescriptor(innerPanel,
59                 NbBundle.getMessage(AddWebServiceGroupAction.class, "TTL_AddWSGroup"));
60         MyDocListener dl = new MyDocListener(dialogDesc,wsNodeModel);
61         innerPanel.getTFDocument().addDocumentListener(dl);
62         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDesc);
63         dialogDesc.setValid(false);
64         dialog.setVisible(true);
65         if (NotifyDescriptor.OK_OPTION.equals(dialogDesc.getValue())) {
66             WebServiceGroup wsGroup = new WebServiceGroup();
67             String JavaDoc groupName = innerPanel.getGroupName();
68             wsGroup.setName(groupName);
69             wsNodeModel.addWebServiceGroup(wsGroup);
70         }
71         innerPanel.getTFDocument().removeDocumentListener(dl);
72         dialog.dispose();
73     }
74     
75     /** @return <code>false</code> to be performed in event dispatch thread */
76     protected boolean asynchronous() {
77         return false;
78     }
79     
80     /** Listener that checks if group name is not empty or duplicite
81      */

82     private class MyDocListener implements DocumentListener JavaDoc {
83         
84         private DialogDescriptor dd;
85         private WebServiceListModel wsNodeModel;
86         
87         MyDocListener(DialogDescriptor dd, WebServiceListModel wsNodeModel) {
88             this.dd=dd;
89             this.wsNodeModel=wsNodeModel;
90         }
91               
92         public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
93             update(e);
94         }
95
96         public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
97             update(e);
98         }
99
100         public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
101             update(e);
102         }
103         
104         public void update(javax.swing.event.DocumentEvent JavaDoc e) {
105             Document JavaDoc doc = e.getDocument();
106             try {
107                 String JavaDoc text = doc.getText(0,doc.getLength()).trim();
108                 if (text.length()==0 || wsNodeModel.findWebServiceGroup(text) !=null) {
109                     dd.setValid(false);
110                     return;
111                 }
112             } catch (BadLocationException JavaDoc ex){}
113             dd.setValid(true);
114         }
115         
116     }
117     
118 }
119
Popular Tags