1 19 20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import java.util.Map ; 28 import javax.swing.table.AbstractTableModel ; 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 46 public class ServiceProvidersTablePanel extends DefaultTablePanel { 47 48 private static final String [] columnName = {NbBundle.getMessage(ServiceProvidersTablePanel.class, 49 "MSG_ServiceProviders") }; 51 52 private ServiceProvidersTableModel tablemodel; 53 private WSDLModel model; 54 private STSConfiguration stsConfig; 55 56 private Map <String , ServiceProviderElement> addedProviders; 57 private RemoveActionListener removeActionListener; 58 private AddActionListener addActionListener; 59 60 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); 71 addedProviders = new HashMap <String , ServiceProviderElement>(); 72 73 addActionListener = new AddActionListener(); 74 ActionListener addListener = (ActionListener )WeakListeners.create(ActionListener .class, 75 addActionListener, addButton); 76 addButton.addActionListener(addListener); 77 78 removeActionListener = new RemoveActionListener(); 79 ActionListener removeListener = (ActionListener )WeakListeners.create(ActionListener .class, 80 removeActionListener, removeButton); 81 removeButton.addActionListener(removeListener); 82 } 83 84 public Map <String , ServiceProviderElement> getAddedProviders(){ 85 return addedProviders; 86 } 87 88 public List getChildren(){ 89 return tablemodel.getChildren(); 90 } 91 92 class RemoveActionListener implements ActionListener { 93 public void actionPerformed(ActionEvent 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()), NotifyDescriptor.YES_NO_OPTION); 109 DialogDisplayer.getDefault().notify(notifyDesc); 110 return (notifyDesc.getValue() == NotifyDescriptor.YES_OPTION); 111 } 112 } 113 114 class AddActionListener implements ActionListener { 115 public void actionPerformed(ActionEvent 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"), 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 url = spPanel.getSpUrl(); 132 String alias = spPanel.getCertAlias(); 133 String ttype = spPanel.getTokenType(); 134 String 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 { 149 150 List <ServiceProviderElement> children; 151 152 public Object 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 <ServiceProviderElement>(); 180 List <ServiceProviderElement> list = new ArrayList <ServiceProviderElement>(); 181 182 List <ServiceProvider> spList = ProprietarySecurityPolicyModelHelper.getSTSServiceProviders(stsConfig); 183 184 if ((spList != null) && !(spList.isEmpty())) { 185 for (ServiceProvider sp : spList) { 186 String endpoint = sp.getEndpoint(); 187 String certAlias = ProprietarySecurityPolicyModelHelper.getSPCertAlias(sp); 188 String tokenType = ProprietarySecurityPolicyModelHelper.getSPTokenType(sp); 189 String keyType = ProprietarySecurityPolicyModelHelper.getSPKeyType(sp); 190 ServiceProviderElement spe = new ServiceProviderElement(endpoint, certAlias, tokenType, keyType); 191 children.add(spe); 192 } 193 this.fireTableDataChanged(); } 195 } 196 197 @Override 198 public String getColumnName(int column) { 199 return columnName[column]; 200 } 201 202 public List getChildren(){ 203 return children; 204 } 205 } 206 } 207 | Popular Tags |