1 6 7 package SOFA.SOFAnet.Browser; 8 9 import javax.swing.*; 10 import SOFA.SOFAnet.Admin.RMI.*; 11 import SOFA.SOFAnet.Repository.OutputTrigger; 12 import java.rmi.RemoteException ; 13 import java.util.Arrays ; 14 15 19 public class OutputTriggersPanel extends javax.swing.JPanel 20 { 21 private RMIAdminInterface admin; 22 private DefaultListModel content; 23 24 25 26 public OutputTriggersPanel(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 OutputTriggerDesc[] outputTriggerDescs = null; 38 try 39 { 40 outputTriggerDescs = admin.outputTriggerDescsList(); 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(outputTriggerDescs); 49 50 content.ensureCapacity(outputTriggerDescs.length); 51 for (int i = 0; i < outputTriggerDescs.length; i++) content.addElement(outputTriggerDescs[i]); 52 } 53 54 private String getSelectedOutputTriggerName() 55 { 56 String outputTriggerName = ""; 57 58 int index = contentList.getSelectedIndex(); 59 if (index != -1) outputTriggerName = ((OutputTriggerDesc)content.getElementAt(index)).name; 60 return outputTriggerName; 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 jPanel1 = new javax.swing.JPanel (); 76 jPanel3 = new javax.swing.JPanel (); 77 refreshButton = new javax.swing.JButton (); 78 generateTriggersOfContractButton = new javax.swing.JButton (); 79 deleteTriggersOfContractButton = 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 (3, 0)); 97 98 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Output Trigger Specific")); 99 editButton.setText("Edit Output Tigger"); 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 OutputTrigger"); 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 Output Trigger"); 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 jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH); 133 134 jPanel1.setLayout(new java.awt.BorderLayout ()); 135 136 jPanel1.setBorder(new javax.swing.border.TitledBorder ("General")); 137 jPanel3.setLayout(new java.awt.GridLayout (3, 0)); 138 139 refreshButton.setText("Refresh"); 140 refreshButton.addActionListener(new java.awt.event.ActionListener () 141 { 142 public void actionPerformed(java.awt.event.ActionEvent evt) 143 { 144 refreshButtonActionPerformed(evt); 145 } 146 }); 147 148 jPanel3.add(refreshButton); 149 150 generateTriggersOfContractButton.setText("Generate Triggers of Contract"); 151 generateTriggersOfContractButton.addActionListener(new java.awt.event.ActionListener () 152 { 153 public void actionPerformed(java.awt.event.ActionEvent evt) 154 { 155 generateTriggersOfContractButtonActionPerformed(evt); 156 } 157 }); 158 159 jPanel3.add(generateTriggersOfContractButton); 160 161 deleteTriggersOfContractButton.setText("Delete Triggers of Contract"); 162 deleteTriggersOfContractButton.addActionListener(new java.awt.event.ActionListener () 163 { 164 public void actionPerformed(java.awt.event.ActionEvent evt) 165 { 166 deleteTriggersOfContractButtonActionPerformed(evt); 167 } 168 }); 169 170 jPanel3.add(deleteTriggersOfContractButton); 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 deleteTriggersOfContractButtonActionPerformed(java.awt.event.ActionEvent evt) { if (DeleteTriggersOfContractDialog.showDialog(this, admin, "")) reload(); 198 } 200 private void generateTriggersOfContractButtonActionPerformed(java.awt.event.ActionEvent evt) { if (GenerateTriggersOfContractDialog.showDialog(this, admin, "")) reload(); 203 } 205 private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) { reload(); 208 } 210 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { String outputTriggerName = getSelectedOutputTriggerName(); 213 214 if (outputTriggerName.length() == 0) 215 { 216 JOptionPane.showMessageDialog(this, "No Output Trigger selected", "Warning", JOptionPane.WARNING_MESSAGE); 217 return; 218 } 219 else 220 { 221 if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Output Trigger '" + outputTriggerName + "'?") != JOptionPane.YES_OPTION) return; 222 } 223 224 try 225 { 226 admin.updateOutputTrigger(outputTriggerName, 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 outputTriggerName = JOptionPane.showInputDialog(this, "Name of New Output Trigger:", "New Output Trigger", JOptionPane.INFORMATION_MESSAGE); 245 if (outputTriggerName != null) 246 { 247 OutputTrigger outputTrigger = new OutputTrigger(); 248 249 try 250 { 251 admin.updateOutputTrigger(outputTriggerName, outputTrigger); 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 outputTriggerName = getSelectedOutputTriggerName(); 271 272 if (outputTriggerName.length() == 0) 273 { 274 JOptionPane.showMessageDialog(this, "No Output Trigger selected", "Warning", JOptionPane.WARNING_MESSAGE); 275 return; 276 } 277 278 OutputTrigger outputTrigger = null; 279 try 280 { 281 outputTrigger = admin.getOutputTrigger(outputTriggerName); 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 (outputTrigger == null) 290 { 291 JOptionPane.showMessageDialog(this, "Selected Output Trigger doesn't exist on the node anymore", "Error", JOptionPane.ERROR_MESSAGE); 292 return; 293 } 294 295 if (OutputTriggerEditDialog.showDialog(this, outputTrigger, "Output Trigger Editor")) 296 { 297 try 298 { 299 admin.updateOutputTrigger(outputTriggerName, outputTrigger); 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 deleteTriggersOfContractButton; 335 private javax.swing.JButton editButton; 336 private javax.swing.JButton generateTriggersOfContractButton; 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 |