1 6 7 package SOFA.SOFAnet.Browser; 8 9 import javax.swing.*; 10 import SOFA.SOFAnet.Admin.RMI.*; 11 import SOFA.SOFAnet.Repository.Contract; 12 import java.rmi.RemoteException ; 13 import java.util.Arrays ; 14 15 19 public class ContractsPanel extends javax.swing.JPanel 20 { 21 private RMIAdminInterface admin; 22 private DefaultListModel content; 23 24 25 26 public ContractsPanel(RMIAdminInterface admin) 27 { 28 this.admin = admin; 29 content = new DefaultListModel(); 30 initComponents(); 31 } 32 33 private void reload() 34 { 35 content.clear(); 36 37 ContractDesc[] contractDescs = null; 38 try 39 { 40 contractDescs = admin.contractDescsList(); 41 } 42 catch (RemoteException e) 43 { 44 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 45 return; 46 } 47 48 Arrays.sort(contractDescs); 49 50 content.ensureCapacity(contractDescs.length); 51 for (int i = 0; i < contractDescs.length; i++) content.addElement(contractDescs[i]); 52 } 53 54 private String getSelectedContractName() 55 { 56 String contractName = ""; 57 58 int index = contentList.getSelectedIndex(); 59 if (index != -1) contractName = ((ContractDesc)content.getElementAt(index)).name; 60 return contractName; 61 } 62 63 68 private void initComponents() { 70 jPanel2 = new javax.swing.JPanel (); 71 jPanel4 = new javax.swing.JPanel (); 72 editButton = new javax.swing.JButton (); 73 addButton = new javax.swing.JButton (); 74 deleteButton = new javax.swing.JButton (); 75 generateTriggersButton = new javax.swing.JButton (); 76 deleteTriggersButton = new javax.swing.JButton (); 77 jPanel1 = new javax.swing.JPanel (); 78 jPanel3 = new javax.swing.JPanel (); 79 refreshButton = new javax.swing.JButton (); 80 jScrollPane1 = new javax.swing.JScrollPane (); 81 contentList = new javax.swing.JList (); 82 83 setLayout(new java.awt.BorderLayout ()); 84 85 addComponentListener(new java.awt.event.ComponentAdapter () 86 { 87 public void componentShown(java.awt.event.ComponentEvent evt) 88 { 89 formComponentShown(evt); 90 } 91 }); 92 93 jPanel2.setLayout(new java.awt.BorderLayout ()); 94 95 jPanel2.setPreferredSize(new java.awt.Dimension (200, 204)); 96 jPanel4.setLayout(new java.awt.GridLayout (5, 0)); 97 98 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Contract Specific")); 99 editButton.setText("Edit Contract"); 100 editButton.addActionListener(new java.awt.event.ActionListener () 101 { 102 public void actionPerformed(java.awt.event.ActionEvent evt) 103 { 104 editButtonActionPerformed(evt); 105 } 106 }); 107 108 jPanel4.add(editButton); 109 110 addButton.setText("Add New Contract"); 111 addButton.addActionListener(new java.awt.event.ActionListener () 112 { 113 public void actionPerformed(java.awt.event.ActionEvent evt) 114 { 115 addButtonActionPerformed(evt); 116 } 117 }); 118 119 jPanel4.add(addButton); 120 121 deleteButton.setText("Delete Contract"); 122 deleteButton.addActionListener(new java.awt.event.ActionListener () 123 { 124 public void actionPerformed(java.awt.event.ActionEvent evt) 125 { 126 deleteButtonActionPerformed(evt); 127 } 128 }); 129 130 jPanel4.add(deleteButton); 131 132 generateTriggersButton.setText("Generate Triggers"); 133 generateTriggersButton.addActionListener(new java.awt.event.ActionListener () 134 { 135 public void actionPerformed(java.awt.event.ActionEvent evt) 136 { 137 generateTriggersButtonActionPerformed(evt); 138 } 139 }); 140 141 jPanel4.add(generateTriggersButton); 142 143 deleteTriggersButton.setText("Delete Triggers"); 144 deleteTriggersButton.addActionListener(new java.awt.event.ActionListener () 145 { 146 public void actionPerformed(java.awt.event.ActionEvent evt) 147 { 148 deleteTriggersButtonActionPerformed(evt); 149 } 150 }); 151 152 jPanel4.add(deleteTriggersButton); 153 154 jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH); 155 156 jPanel1.setLayout(new java.awt.BorderLayout ()); 157 158 jPanel1.setBorder(new javax.swing.border.TitledBorder ("General")); 159 jPanel3.setLayout(new java.awt.GridLayout (1, 0)); 160 161 refreshButton.setText("Refresh"); 162 refreshButton.addActionListener(new java.awt.event.ActionListener () 163 { 164 public void actionPerformed(java.awt.event.ActionEvent evt) 165 { 166 refreshButtonActionPerformed(evt); 167 } 168 }); 169 170 jPanel3.add(refreshButton); 171 172 jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH); 173 174 jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER); 175 176 add(jPanel2, java.awt.BorderLayout.EAST); 177 178 contentList.setModel(content); 179 contentList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 180 contentList.setVisibleRowCount(-1); 181 contentList.addMouseListener(new java.awt.event.MouseAdapter () 182 { 183 public void mouseClicked(java.awt.event.MouseEvent evt) 184 { 185 contentListMouseClicked(evt); 186 } 187 }); 188 189 jScrollPane1.setViewportView(contentList); 190 191 add(jScrollPane1, java.awt.BorderLayout.CENTER); 192 193 } 195 private void deleteTriggersButtonActionPerformed(java.awt.event.ActionEvent evt) { DeleteTriggersOfContractDialog.showDialog(this, admin, getSelectedContractName()); 198 } 200 private void generateTriggersButtonActionPerformed(java.awt.event.ActionEvent evt) { GenerateTriggersOfContractDialog.showDialog(this, admin, getSelectedContractName()); 203 } 205 private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) { reload(); 208 } 210 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { String contractName = getSelectedContractName(); 213 214 if (contractName.length() == 0) 215 { 216 JOptionPane.showMessageDialog(this, "No Contract selected", "Warning", JOptionPane.WARNING_MESSAGE); 217 return; 218 } 219 else 220 { 221 if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Contract '" + contractName + "'?") != JOptionPane.YES_OPTION) return; 222 } 223 224 try 225 { 226 admin.updateContract(contractName, null); 227 } 228 catch (RemoteException e) 229 { 230 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 231 return; 232 } 233 catch (RMIAdminException e) 234 { 235 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 236 return; 237 } 238 239 reload(); 240 } 242 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { String contractName = JOptionPane.showInputDialog(this, "ID of New Contract:", "New Contract", JOptionPane.INFORMATION_MESSAGE); 245 if (contractName != null) 246 { 247 Contract contract = new Contract(); 248 249 try 250 { 251 admin.updateContract(contractName, contract); 252 } 253 catch (RemoteException e) 254 { 255 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 256 return; 257 } 258 catch (RMIAdminException e) 259 { 260 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 261 return; 262 } 263 264 reload(); 265 } 266 } 268 private void editButtonActionPerformed(java.awt.event.ActionEvent evt) { String contractName = getSelectedContractName(); 271 272 if (contractName.length() == 0) 273 { 274 JOptionPane.showMessageDialog(this, "No Contract selected", "Warning", JOptionPane.WARNING_MESSAGE); 275 return; 276 } 277 278 Contract contract = null; 279 try 280 { 281 contract = admin.getContract(contractName); 282 } 283 catch (RemoteException e) 284 { 285 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 286 return; 287 } 288 289 if (contract == null) 290 { 291 JOptionPane.showMessageDialog(this, "Selected Contract doesn't exist on the node anymore", "Error", JOptionPane.ERROR_MESSAGE); 292 return; 293 } 294 295 if (ContractEditDialog.showDialog(this, contract, "Contract Editor")) 296 { 297 try 298 { 299 admin.updateContract(contractName, contract); 300 } 301 catch (RemoteException e) 302 { 303 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 304 return; 305 } 306 catch (RMIAdminException e) 307 { 308 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 309 return; 310 } 311 312 reload(); 313 } 314 } 316 private void contentListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) 319 { 320 editButton.doClick(); } 322 } 324 private void formComponentShown(java.awt.event.ComponentEvent evt) { reload(); 327 } 329 330 private javax.swing.JButton addButton; 332 private javax.swing.JList contentList; 333 private javax.swing.JButton deleteButton; 334 private javax.swing.JButton deleteTriggersButton; 335 private javax.swing.JButton editButton; 336 private javax.swing.JButton generateTriggersButton; 337 private javax.swing.JPanel jPanel1; 338 private javax.swing.JPanel jPanel2; 339 private javax.swing.JPanel jPanel3; 340 private javax.swing.JPanel jPanel4; 341 private javax.swing.JScrollPane jScrollPane1; 342 private javax.swing.JButton refreshButton; 343 345 } 346 | Popular Tags |