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 CreateComponentBundleDialog extends javax.swing.JDialog 24 { 25 private RMIAdminInterface admin; 26 private boolean isOK; 27 28 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultComponentName) 29 { 30 Frame frame = JOptionPane.getFrameForComponent(frameComp); 31 CreateComponentBundleDialog dialog = new CreateComponentBundleDialog(frame, true, admin, defaultComponentName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public CreateComponentBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultComponentName) 39 { 40 super(parent, modal); 41 this.admin = admin; 42 isOK = false; 43 initComponents(); 44 45 componentNameTextField.setText(defaultComponentName); 46 } 47 48 public boolean isOK() 49 { 50 return isOK; 51 } 52 53 58 private void initComponents() { 60 jPanel4 = new javax.swing.JPanel (); 61 jPanel1 = new javax.swing.JPanel (); 62 jPanel5 = new javax.swing.JPanel (); 63 componentNameLabel = new javax.swing.JLabel (); 64 componentNameTextField = new javax.swing.JTextField (); 65 completeComponentCheckBox = new javax.swing.JCheckBox (); 66 jPanel2 = new javax.swing.JPanel (); 67 chooseComponentButton = new javax.swing.JButton (); 68 jPanel3 = new javax.swing.JPanel (); 69 createComponentBundleButton = new javax.swing.JButton (); 70 cancelButton = new javax.swing.JButton (); 71 72 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 73 setTitle("Create Component Bundle"); 74 jPanel4.setLayout(new java.awt.BorderLayout ()); 75 76 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 77 jPanel4.setPreferredSize(new java.awt.Dimension (400, 150)); 78 jPanel1.setLayout(new java.awt.BorderLayout ()); 79 80 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 81 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 82 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 83 jPanel5.setLayout(new java.awt.GridLayout (3, 0)); 84 85 componentNameLabel.setText("Component Name:"); 86 jPanel5.add(componentNameLabel); 87 88 componentNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 89 componentNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 90 jPanel5.add(componentNameTextField); 91 92 completeComponentCheckBox.setText("Complete Component (including subcomponents)"); 93 jPanel5.add(completeComponentCheckBox); 94 95 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 96 97 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 98 99 chooseComponentButton.setText("Choose Component from TR"); 100 chooseComponentButton.addActionListener(new java.awt.event.ActionListener () 101 { 102 public void actionPerformed(java.awt.event.ActionEvent evt) 103 { 104 chooseComponentButtonActionPerformed(evt); 105 } 106 }); 107 108 jPanel2.add(chooseComponentButton); 109 110 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 111 112 createComponentBundleButton.setText("Create Component Bundle"); 113 createComponentBundleButton.addActionListener(new java.awt.event.ActionListener () 114 { 115 public void actionPerformed(java.awt.event.ActionEvent evt) 116 { 117 createComponentBundleButtonActionPerformed(evt); 118 } 119 }); 120 121 jPanel3.add(createComponentBundleButton); 122 123 cancelButton.setText("Cancel"); 124 cancelButton.addActionListener(new java.awt.event.ActionListener () 125 { 126 public void actionPerformed(java.awt.event.ActionEvent evt) 127 { 128 cancelButtonActionPerformed(evt); 129 } 130 }); 131 132 jPanel3.add(cancelButton); 133 134 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 135 136 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 137 138 pack(); 139 } 141 private void chooseComponentButtonActionPerformed(java.awt.event.ActionEvent evt) { ComponentInfo[] componentInfos = null; 144 try 145 { 146 componentInfos = admin.componentsInTRList(); 147 } 148 catch (RemoteException e) 149 { 150 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 151 return; 152 } 153 154 String [] compNames = new String [componentInfos.length]; 155 int i; 156 for (i = 0; i < componentInfos.length; i++) compNames[i] = componentInfos[i].getName() + "[" + componentInfos[i].getImplementationVersion() + "]"; 157 158 Arrays.sort(compNames); 159 160 String result = ListDialog.showDialog(this, this, "Components in TR:", "Choose Components from TR to create Component Bundle", compNames, null, null, false, true); 161 if (result.length() != 0) componentNameTextField.setText(result); 162 163 } 165 private void createComponentBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String componentName = componentNameTextField.getText(); 168 boolean completeComponent = completeComponentCheckBox.isSelected(); 169 170 BundleInfo bundleInfo = new BundleInfo(); 171 try 172 { 173 bundleInfo.fromBundleName(componentName); 174 } 175 catch (BundleInfo.InvalidBundleNameException e) 176 { 177 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 178 return; 179 } 180 181 if (!bundleInfo.isComponent() || bundleInfo.isCompleteComponent()) 182 { 183 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\nName of Component expected", "Error", JOptionPane.ERROR_MESSAGE); 184 return; 185 } 186 187 ComponentInfo componentInfo = new ComponentInfoImpl(bundleInfo.getShortName(), bundleInfo.getVersion()); 188 String bundleName = null; 189 try 190 { 191 bundleName = admin.createComponentBundle(componentInfo, completeComponent); 192 } 193 catch (RemoteException e) 194 { 195 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 196 dispose(); 197 return; 198 } 199 catch (RMIAdminException e) 200 { 201 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 202 dispose(); 203 return; 204 } 205 206 JOptionPane.showMessageDialog(this, "Component Bundle '" + bundleName + "' successfully created"); 207 208 isOK = true; 209 dispose(); 210 } 212 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 215 } 217 218 private javax.swing.JButton cancelButton; 220 private javax.swing.JButton chooseComponentButton; 221 private javax.swing.JCheckBox completeComponentCheckBox; 222 private javax.swing.JLabel componentNameLabel; 223 private javax.swing.JTextField componentNameTextField; 224 private javax.swing.JButton createComponentBundleButton; 225 private javax.swing.JPanel jPanel1; 226 private javax.swing.JPanel jPanel2; 227 private javax.swing.JPanel jPanel3; 228 private javax.swing.JPanel jPanel4; 229 private javax.swing.JPanel jPanel5; 230 232 } 233 | Popular Tags |