1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Admin.RMI.*; 10 import SOFA.SOFAnet.Repository.BundleInfo; 11 import SOFA.SOFAnode.TR.ComponentInfo; 12 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl; 13 import javax.swing.*; 14 import java.rmi.RemoteException ; 15 import java.util.*; 16 import java.awt.Component ; 17 import java.awt.Frame ; 18 19 23 public class CreateUserBundleDialog extends javax.swing.JDialog 24 { 25 private RMIAdminInterface admin; 26 private DefaultListModel content; 27 private SortedSet components; 28 private boolean isOK; 29 30 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultBundleName, ComponentInfo[] defaultComponents) 31 { 32 Frame frame = JOptionPane.getFrameForComponent(frameComp); 33 CreateUserBundleDialog dialog = new CreateUserBundleDialog(frame, true, admin, defaultBundleName, defaultComponents); 34 dialog.setLocationRelativeTo(frameComp); 35 dialog.setVisible(true); 36 return dialog.isOK(); 37 } 38 39 40 public CreateUserBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName, ComponentInfo[] defaultComponents) 41 { 42 super(parent, modal); 43 this.admin = admin; 44 isOK = false; 45 content = new DefaultListModel(); 46 components = new TreeSet(); 47 initComponents(); 48 49 bundleNameTextField.setText(defaultBundleName); 50 if (defaultComponents != null) 51 { 52 for (int i = 0; i < defaultComponents.length; i++) components.add(defaultComponents[i].getName() + "[" + defaultComponents[i].getImplementationVersion() + "]"); 53 reloadContent(); 54 } 55 } 56 57 public boolean isOK() 58 { 59 return isOK; 60 } 61 62 private void reloadContent() 63 { 64 content.clear(); 65 content.ensureCapacity(components.size()); 66 Iterator it = components.iterator(); 67 while (it.hasNext()) content.addElement(it.next()); 68 } 69 70 75 private void initComponents() { 77 jPanel4 = new javax.swing.JPanel (); 78 jPanel1 = new javax.swing.JPanel (); 79 jPanel5 = new javax.swing.JPanel (); 80 bundleNameLabel = new javax.swing.JLabel (); 81 bundleNameTextField = new javax.swing.JTextField (); 82 componentsLabel = new javax.swing.JLabel (); 83 jScrollPane1 = new javax.swing.JScrollPane (); 84 componentsList = new javax.swing.JList (); 85 jPanel6 = new javax.swing.JPanel (); 86 subcomponentsCheckBox = new javax.swing.JCheckBox (); 87 jPanel2 = new javax.swing.JPanel (); 88 addComponentsButton = new javax.swing.JButton (); 89 removeComponentsButton = new javax.swing.JButton (); 90 jPanel3 = new javax.swing.JPanel (); 91 createUserBundleButton = new javax.swing.JButton (); 92 cancelButton = new javax.swing.JButton (); 93 94 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 95 setTitle("Create User Bundle"); 96 jPanel4.setLayout(new java.awt.BorderLayout ()); 97 98 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 99 jPanel4.setPreferredSize(new java.awt.Dimension (400, 300)); 100 jPanel1.setLayout(new java.awt.BorderLayout ()); 101 102 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 103 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 104 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 105 jPanel5.setLayout(new java.awt.GridLayout (3, 0)); 106 107 bundleNameLabel.setText("Bundle Name:"); 108 jPanel5.add(bundleNameLabel); 109 110 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 111 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 112 jPanel5.add(bundleNameTextField); 113 114 componentsLabel.setText("Components:"); 115 jPanel5.add(componentsLabel); 116 117 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 118 119 componentsList.setModel(content); 120 jScrollPane1.setViewportView(componentsList); 121 122 jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER); 123 124 jPanel6.setLayout(new java.awt.GridLayout ()); 125 126 subcomponentsCheckBox.setText("Include Subcomponents"); 127 jPanel6.add(subcomponentsCheckBox); 128 129 jPanel1.add(jPanel6, java.awt.BorderLayout.SOUTH); 130 131 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 132 133 addComponentsButton.setText("Add Components from TR"); 134 addComponentsButton.addActionListener(new java.awt.event.ActionListener () 135 { 136 public void actionPerformed(java.awt.event.ActionEvent evt) 137 { 138 addComponentsButtonActionPerformed(evt); 139 } 140 }); 141 142 jPanel2.add(addComponentsButton); 143 144 removeComponentsButton.setText("Remove Selected Components"); 145 removeComponentsButton.addActionListener(new java.awt.event.ActionListener () 146 { 147 public void actionPerformed(java.awt.event.ActionEvent evt) 148 { 149 removeComponentsButtonActionPerformed(evt); 150 } 151 }); 152 153 jPanel2.add(removeComponentsButton); 154 155 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 156 157 createUserBundleButton.setText("Create User Bundle"); 158 createUserBundleButton.addActionListener(new java.awt.event.ActionListener () 159 { 160 public void actionPerformed(java.awt.event.ActionEvent evt) 161 { 162 createUserBundleButtonActionPerformed(evt); 163 } 164 }); 165 166 jPanel3.add(createUserBundleButton); 167 168 cancelButton.setText("Cancel"); 169 cancelButton.addActionListener(new java.awt.event.ActionListener () 170 { 171 public void actionPerformed(java.awt.event.ActionEvent evt) 172 { 173 cancelButtonActionPerformed(evt); 174 } 175 }); 176 177 jPanel3.add(cancelButton); 178 179 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 180 181 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 182 183 pack(); 184 } 186 private void removeComponentsButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selected = componentsList.getSelectedValues(); 189 for (int i = 0; i < selected.length; i++) 190 { 191 if (selected[i] instanceof String ) components.remove((String )selected[i]); 192 } 193 reloadContent(); 194 } 196 private void addComponentsButtonActionPerformed(java.awt.event.ActionEvent evt) { ComponentInfo[] componentInfos = null; 199 try 200 { 201 componentInfos = admin.componentsInTRList(); 202 } 203 catch (RemoteException e) 204 { 205 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 206 return; 207 } 208 209 String [] compNames = new String [componentInfos.length]; 210 int i; 211 for (i = 0; i < componentInfos.length; i++) compNames[i] = componentInfos[i].getName() + "[" + componentInfos[i].getImplementationVersion() + "]"; 212 213 Arrays.sort(compNames); 214 215 Object [] result = (Object [])ListDialog.showDialog(this, this, "Components in TR:", "Choose Components from TR to create User Bundle", (Object [])compNames, null, null, true, true); 216 if (result != null) for (i = 0; i < result.length; i++) components.add((String )result[i]); 217 218 reloadContent(); 219 } 221 private void createUserBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 224 boolean subcomponents = subcomponentsCheckBox.isSelected(); 225 226 BundleInfo bundleInfo = new BundleInfo(); 227 try 228 { 229 bundleInfo.fromBundleName(bundleName); 230 } 231 catch (BundleInfo.InvalidBundleNameException e) 232 { 233 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 234 return; 235 } 236 237 if (bundleInfo.isComponent()) 238 { 239 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\nName of User Bundle expected", "Error", JOptionPane.ERROR_MESSAGE); 240 return; 241 } 242 243 ComponentInfo[] componentInfos = new ComponentInfo[components.size()]; 244 int i = 0; 245 Iterator it = components.iterator(); 246 while (it.hasNext()) 247 { 248 String compName = (String )it.next(); 249 int leftBracket = compName.lastIndexOf('['); 250 int rightBracket = compName.lastIndexOf(']'); 251 componentInfos[i++] = new ComponentInfoImpl(compName.substring(0, leftBracket), compName.substring(leftBracket + 1, rightBracket)); 252 } 253 254 try 255 { 256 admin.createUserBundle(bundleName, componentInfos, subcomponents); 257 } 258 catch (RemoteException e) 259 { 260 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 261 dispose(); 262 return; 263 } 264 catch (RMIAdminException e) 265 { 266 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 267 dispose(); 268 return; 269 } 270 271 JOptionPane.showMessageDialog(this, "User Bundle '" + bundleName + "' successfully created"); 272 273 isOK = true; 274 dispose(); 275 } 277 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 280 } 282 283 private javax.swing.JButton addComponentsButton; 285 private javax.swing.JLabel bundleNameLabel; 286 private javax.swing.JTextField bundleNameTextField; 287 private javax.swing.JButton cancelButton; 288 private javax.swing.JLabel componentsLabel; 289 private javax.swing.JList componentsList; 290 private javax.swing.JButton createUserBundleButton; 291 private javax.swing.JPanel jPanel1; 292 private javax.swing.JPanel jPanel2; 293 private javax.swing.JPanel jPanel3; 294 private javax.swing.JPanel jPanel4; 295 private javax.swing.JPanel jPanel5; 296 private javax.swing.JPanel jPanel6; 297 private javax.swing.JScrollPane jScrollPane1; 298 private javax.swing.JButton removeComponentsButton; 299 private javax.swing.JCheckBox subcomponentsCheckBox; 300 302 } 303 | Popular Tags |