1 6 7 package SOFA.SOFAnet.Browser; 8 9 import javax.swing.*; 10 import SOFA.SOFAnet.Admin.RMI.*; 11 import SOFA.SOFAnode.TR.ComponentInfo; 12 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl; 13 import java.rmi.RemoteException ; 14 import java.util.Arrays ; 15 16 20 public class TRPanel extends javax.swing.JPanel 21 { 22 private RMIAdminInterface admin; 23 private DefaultListModel content; 24 25 private static class CompInfo implements Comparable 26 { 27 public ComponentInfo componentInfo; 28 public String componentName; 29 30 CompInfo(ComponentInfo componentInfo) 31 { 32 this.componentInfo = componentInfo; 33 this.componentName = componentInfo.getName() + "[" + componentInfo.getImplementationVersion() + "]"; 34 } 35 36 public boolean equals(Object o) 37 { 38 if (this == o) return true; 39 if (o instanceof CompInfo) 40 { 41 CompInfo compInfo = (CompInfo)o; 42 return componentName.compareTo(compInfo.componentName) == 0; 43 } 44 else return false; 45 } 46 47 public int compareTo(Object o) 48 { 49 CompInfo compInfo = (CompInfo)o; 50 return componentName.compareTo(compInfo.componentName); 51 } 52 53 public String toString() 54 { 55 return componentName; 56 } 57 } 58 59 60 public TRPanel(RMIAdminInterface admin) 61 { 62 this.admin = admin; 63 content = new DefaultListModel(); 64 initComponents(); 65 } 66 67 private void reload() 68 { 69 content.clear(); 70 71 ComponentInfo[] componentInfos = null; 72 try 73 { 74 componentInfos = admin.componentsInTRList(); 75 } 76 catch (RemoteException e) 77 { 78 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 79 return; 80 } 81 82 CompInfo[] compInfos = new CompInfo[componentInfos.length]; 83 for (int i = 0; i < compInfos.length; i++) compInfos[i] = new CompInfo(componentInfos[i]); 84 Arrays.sort(compInfos); 85 86 content.ensureCapacity(compInfos.length); 87 for (int i = 0; i < compInfos.length; i++) content.addElement(compInfos[i]); 88 } 89 90 95 private void initComponents() { 97 jPanel2 = new javax.swing.JPanel (); 98 jPanel4 = new javax.swing.JPanel (); 99 createUserBundleButton = new javax.swing.JButton (); 100 createComponentBundleButton = new javax.swing.JButton (); 101 deleteButton = new javax.swing.JButton (); 102 jPanel1 = new javax.swing.JPanel (); 103 jPanel3 = new javax.swing.JPanel (); 104 refreshButton = new javax.swing.JButton (); 105 jScrollPane1 = new javax.swing.JScrollPane (); 106 contentList = new javax.swing.JList (); 107 108 setLayout(new java.awt.BorderLayout ()); 109 110 addComponentListener(new java.awt.event.ComponentAdapter () 111 { 112 public void componentShown(java.awt.event.ComponentEvent evt) 113 { 114 formComponentShown(evt); 115 } 116 }); 117 118 jPanel2.setLayout(new java.awt.BorderLayout ()); 119 120 jPanel2.setPreferredSize(new java.awt.Dimension (200, 154)); 121 jPanel4.setLayout(new java.awt.GridLayout (3, 0)); 122 123 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Components Specific")); 124 createUserBundleButton.setText("Create User Bundle"); 125 createUserBundleButton.addActionListener(new java.awt.event.ActionListener () 126 { 127 public void actionPerformed(java.awt.event.ActionEvent evt) 128 { 129 createUserBundleButtonActionPerformed(evt); 130 } 131 }); 132 133 jPanel4.add(createUserBundleButton); 134 135 createComponentBundleButton.setText("Create Component Bundle"); 136 createComponentBundleButton.addActionListener(new java.awt.event.ActionListener () 137 { 138 public void actionPerformed(java.awt.event.ActionEvent evt) 139 { 140 createComponentBundleButtonActionPerformed(evt); 141 } 142 }); 143 144 jPanel4.add(createComponentBundleButton); 145 146 deleteButton.setText("Delete Components"); 147 deleteButton.addActionListener(new java.awt.event.ActionListener () 148 { 149 public void actionPerformed(java.awt.event.ActionEvent evt) 150 { 151 deleteButtonActionPerformed(evt); 152 } 153 }); 154 155 jPanel4.add(deleteButton); 156 157 jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH); 158 159 jPanel1.setLayout(new java.awt.BorderLayout ()); 160 161 jPanel1.setBorder(new javax.swing.border.TitledBorder ("General")); 162 jPanel3.setLayout(new java.awt.GridLayout (1, 0)); 163 164 refreshButton.setText("Refresh"); 165 refreshButton.addActionListener(new java.awt.event.ActionListener () 166 { 167 public void actionPerformed(java.awt.event.ActionEvent evt) 168 { 169 refreshButtonActionPerformed(evt); 170 } 171 }); 172 173 jPanel3.add(refreshButton); 174 175 jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH); 176 177 jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER); 178 179 add(jPanel2, java.awt.BorderLayout.EAST); 180 181 contentList.setModel(content); 182 contentList.setVisibleRowCount(-1); 183 jScrollPane1.setViewportView(contentList); 184 185 add(jScrollPane1, java.awt.BorderLayout.CENTER); 186 187 } 189 private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) { reload(); 192 } 194 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selectedCompInfos = contentList.getSelectedValues(); 197 ComponentInfo[] componentInfos = null; 198 if (selectedCompInfos != null) 199 { 200 componentInfos = new ComponentInfo[selectedCompInfos.length]; 201 for (int i = 0; i < selectedCompInfos.length; i++) componentInfos[i] = ((CompInfo)selectedCompInfos[i]).componentInfo; 202 if (DeleteComponentsDialog.showDialog(this, admin, componentInfos)) reload(); 203 } 204 } 206 private void createComponentBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { CompInfo selectedCompInfo = (CompInfo)contentList.getSelectedValue(); 209 String componentName = ""; 210 if (selectedCompInfo != null) componentName = selectedCompInfo.componentName; 211 CreateComponentBundleDialog.showDialog(this, admin, componentName); 212 } 214 private void createUserBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selectedCompInfos = contentList.getSelectedValues(); 217 ComponentInfo[] componentInfos = null; 218 if (selectedCompInfos != null) 219 { 220 componentInfos = new ComponentInfo[selectedCompInfos.length]; 221 for (int i = 0; i < selectedCompInfos.length; i++) componentInfos[i] = ((CompInfo)selectedCompInfos[i]).componentInfo; 222 } 223 CreateUserBundleDialog.showDialog(this, admin, "", componentInfos); 224 } 226 private void formComponentShown(java.awt.event.ComponentEvent evt) { reload(); 229 } 231 232 private javax.swing.JList contentList; 234 private javax.swing.JButton createComponentBundleButton; 235 private javax.swing.JButton createUserBundleButton; 236 private javax.swing.JButton deleteButton; 237 private javax.swing.JPanel jPanel1; 238 private javax.swing.JPanel jPanel2; 239 private javax.swing.JPanel jPanel3; 240 private javax.swing.JPanel jPanel4; 241 private javax.swing.JScrollPane jScrollPane1; 242 private javax.swing.JButton refreshButton; 243 245 } 246 | Popular Tags |