KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > service > subpanels > ServiceProvidersTablePanel


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 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import javax.swing.table.AbstractTableModel JavaDoc;
29 import org.netbeans.modules.websvc.wsitconf.ui.security.listmodels.ServiceProviderElement;
30 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
31 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.STSConfiguration;
32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ServiceProvider;
33 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
34 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
38 import org.openide.util.HelpCtx;
39 import org.openide.util.NbBundle;
40 import org.openide.util.WeakListeners;
41
42 /**
43  *
44  * @author Martin Grebac
45  */

46 public class ServiceProvidersTablePanel extends DefaultTablePanel {
47
48     private static final String JavaDoc[] columnName = {NbBundle.getMessage(ServiceProvidersTablePanel.class,
49             "MSG_ServiceProviders") // NOI18N
50
};
51     
52     private ServiceProvidersTableModel tablemodel;
53     private WSDLModel model;
54     private STSConfiguration stsConfig;
55     
56     private Map JavaDoc<String JavaDoc, ServiceProviderElement> addedProviders;
57     private RemoveActionListener removeActionListener;
58     private AddActionListener addActionListener;
59     
60     /**
61      * Creates a new instance of ServiceProvidersTablePanel
62      */

63     public ServiceProvidersTablePanel(ServiceProvidersTableModel tablemodel, WSDLModel model, STSConfiguration stsConfig) {
64         super(tablemodel);
65         this.model = model;
66         this.stsConfig = stsConfig;
67         this.tablemodel = tablemodel;
68         
69         this.editButton.setVisible(false); //TODO - can't edit an entry yet
70

71         addedProviders = new HashMap JavaDoc<String JavaDoc, ServiceProviderElement>();
72         
73         addActionListener = new AddActionListener();
74         ActionListener JavaDoc addListener = (ActionListener JavaDoc)WeakListeners.create(ActionListener JavaDoc.class,
75                 addActionListener, addButton);
76         addButton.addActionListener(addListener);
77         
78         removeActionListener = new RemoveActionListener();
79         ActionListener JavaDoc removeListener = (ActionListener JavaDoc)WeakListeners.create(ActionListener JavaDoc.class,
80                 removeActionListener, removeButton);
81         removeButton.addActionListener(removeListener);
82     }
83
84     public Map JavaDoc<String JavaDoc, ServiceProviderElement> getAddedProviders(){
85         return addedProviders;
86     }
87     
88     public List JavaDoc getChildren(){
89         return tablemodel.getChildren();
90     }
91     
92     class RemoveActionListener implements ActionListener JavaDoc{
93         public void actionPerformed(ActionEvent JavaDoc e){
94             int row = getTable().getSelectedRow();
95             if(row == -1) return;
96             ServiceProviderElement spe = (ServiceProviderElement)getTable().getValueAt(row, 0);
97             if (confirmDeletion(spe)) {
98                 addedProviders.remove(spe);
99                 ServiceProvidersTablePanel.this.tablemodel.removeRow(row);
100                 ProprietarySecurityPolicyModelHelper.removeSTSServiceProvider(stsConfig, spe);
101             }
102         }
103         
104         private boolean confirmDeletion(ServiceProviderElement spe) {
105             NotifyDescriptor.Confirmation notifyDesc =
106                     new NotifyDescriptor.Confirmation(NbBundle.getMessage
107                     (ServiceProvidersTablePanel.class, "MSG_ServiceProviderConfirmDelete", spe.getEndpoint()), //NOI18N
108
NotifyDescriptor.YES_NO_OPTION);
109             DialogDisplayer.getDefault().notify(notifyDesc);
110             return (notifyDesc.getValue() == NotifyDescriptor.YES_OPTION);
111         }
112     }
113     
114     class AddActionListener implements ActionListener JavaDoc{
115         public void actionPerformed(ActionEvent JavaDoc e) {
116
117             ServiceProviderSelectorPanel spPanel = new ServiceProviderSelectorPanel(null, null, null, null);
118
119             DialogDescriptor dd = new DialogDescriptor(
120                     spPanel,
121                     NbBundle.getMessage(ServiceProvidersTablePanel.class, "LBL_SelectSProvider_Title"), //NOI18N
122
true,
123                     DialogDescriptor.OK_CANCEL_OPTION,
124                     DialogDescriptor.CANCEL_OPTION,
125                     DialogDescriptor.DEFAULT_ALIGN,
126                     new HelpCtx(ServiceProviderSelectorPanel.class),
127                     null);
128
129             if (DialogDisplayer.getDefault().notify(dd).equals(DialogDescriptor.OK_OPTION)) {
130                 if (spPanel != null) {
131                     String JavaDoc url = spPanel.getSpUrl();
132                     String JavaDoc alias = spPanel.getCertAlias();
133                     String JavaDoc ttype = spPanel.getTokenType();
134                     String JavaDoc ktype = spPanel.getKeyType();
135                     ServiceProviderElement spe = new ServiceProviderElement(url, alias, ttype, ktype);
136                     addedProviders.put(url, spe);
137                     ServiceProvidersTablePanel.this.tablemodel.addRow(spe);
138                     ProprietarySecurityPolicyModelHelper.addSTSServiceProvider(stsConfig, spe);
139                 }
140             }
141         }
142     }
143     
144     public void populateModel(){
145         tablemodel.setData(stsConfig);
146     }
147     
148     public static class ServiceProvidersTableModel extends AbstractTableModel JavaDoc {
149         
150         List JavaDoc<ServiceProviderElement> children;
151         
152         public Object JavaDoc getValueAt(int row, int column) {
153             return children.get(row);
154         }
155         
156         public int getRowCount() {
157             if(children != null){
158                 return children.size();
159             }
160             return 0;
161         }
162         
163         public int getColumnCount() {
164             return columnName.length;
165         }
166         
167         public void removeRow(int row){
168             children.remove(row);
169             fireTableRowsDeleted(row, row);
170         }
171         
172         public void addRow(ServiceProviderElement value){
173             children.add(value);
174             fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
175         }
176         
177         public void setData(STSConfiguration stsConfig) {
178             
179             children = new ArrayList JavaDoc<ServiceProviderElement>();
180             List JavaDoc<ServiceProviderElement> list = new ArrayList JavaDoc<ServiceProviderElement>();
181             
182             List JavaDoc<ServiceProvider> spList = ProprietarySecurityPolicyModelHelper.getSTSServiceProviders(stsConfig);
183             
184             if ((spList != null) && !(spList.isEmpty())) {
185                 for (ServiceProvider sp : spList) {
186                     String JavaDoc endpoint = sp.getEndpoint();
187                     String JavaDoc certAlias = ProprietarySecurityPolicyModelHelper.getSPCertAlias(sp);
188                     String JavaDoc tokenType = ProprietarySecurityPolicyModelHelper.getSPTokenType(sp);
189                     String JavaDoc keyType = ProprietarySecurityPolicyModelHelper.getSPKeyType(sp);
190                     ServiceProviderElement spe = new ServiceProviderElement(endpoint, certAlias, tokenType, keyType);
191                     children.add(spe);
192                 }
193                 this.fireTableDataChanged(); //do we need to do this?
194
}
195         }
196         
197         @Override JavaDoc
198         public String JavaDoc getColumnName(int column) {
199             return columnName[column];
200         }
201         
202         public List JavaDoc getChildren(){
203             return children;
204         }
205     }
206 }
207
Popular Tags