1 5 package SOFA.SOFAnode.InOut.Impl; 6 7 import java.awt.Container ; 8 import java.awt.GridBagConstraints ; 9 import java.awt.GridBagLayout ; 10 import java.awt.Insets ; 11 import java.awt.event.ActionEvent ; 12 import java.awt.event.ActionListener ; 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 import java.util.Set ; 17 import java.util.Vector ; 18 19 import javax.swing.JButton ; 20 import javax.swing.JComponent ; 21 import javax.swing.JDialog ; 22 import javax.swing.JLabel ; 23 import javax.swing.JList ; 24 import javax.swing.JScrollPane ; 25 26 import SOFA.SOFAnode.InOut.InOut2Client; 27 import SOFA.SOFAnode.TR.ComponentInfo; 28 29 40 class DistributeDialog extends JDialog implements ActionListener { 41 42 45 private JList components; 46 47 50 private JList nodes; 51 52 55 private JButton yesButton; 56 57 60 private JButton noButton; 61 62 66 private Map from; 67 68 71 private Set to; 72 73 76 private boolean pushMethod; 77 78 81 private boolean descriptionOnly; 82 83 91 DistributeDialog (Map from, Set to, boolean pushMethod, boolean descriptionOnly) { 92 this.from = from; 93 this.to = to; 94 this.pushMethod = pushMethod; 95 this.descriptionOnly = descriptionOnly; 96 97 Vector v = new Vector (); 98 for (Iterator iterator = from.keySet().iterator(); iterator.hasNext();) { 99 SOFANode node = (SOFANode) iterator.next(); 100 Set set = (Set ) from.get(node); for (Iterator iter2 = set.iterator(); iter2.hasNext();) { 103 ComponentInfo info = (ComponentInfo) iter2.next(); 104 v.add(node.getName() + " - " + info.getName() + "[" + info.getImplementationVersion() + "]"); 105 } 106 } 107 components = new JList (v); 108 109 nodes = new JList (to.toArray()); 110 111 yesButton = new JButton ("Yes"); 112 yesButton.addActionListener(this); 113 114 noButton = new JButton ("No"); 115 noButton.addActionListener(this); 116 117 GridBagLayout gb = new GridBagLayout (); 118 GridBagConstraints c = new GridBagConstraints (); 119 Container panel = getContentPane(); 120 panel.setLayout(gb); 121 122 c.fill = GridBagConstraints.BOTH; 123 c.weightx = 1.0; 124 c.weighty = 1.0; 125 c.gridwidth = GridBagConstraints.REMAINDER; 126 c.insets = new Insets (1, 1, 1, 1); 127 128 JLabel question; 129 question = new JLabel ("Really distribute " + 130 ((descriptionOnly) ? "the description of " : "") + 131 "listed components to nodes below? " + 132 ((pushMethod) ? "(Push method)" : ("Pull method")) 133 ); 134 gb.setConstraints(question, c); 135 panel.add(question); 136 137 JComponent comp = new JScrollPane (components); 138 gb.setConstraints(comp, c); 139 panel.add(comp); 140 141 comp = new JScrollPane (nodes); 142 gb.setConstraints(comp, c); 143 panel.add(comp); 144 145 c.fill = GridBagConstraints.NONE; 146 c.gridwidth = GridBagConstraints.RELATIVE; 147 c.weighty = 0.0; 148 c.anchor = GridBagConstraints.EAST; 149 gb.setConstraints(yesButton, c); 150 panel.add(yesButton); 151 152 c.gridwidth = GridBagConstraints.REMAINDER; 153 c.anchor = GridBagConstraints.WEST; 154 gb.setConstraints(noButton, c); 155 panel.add(noButton); 156 157 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 158 setModal(true); 159 pack(); 160 setVisible(true); 161 } 162 163 169 public void actionPerformed (ActionEvent e) { 170 if (e.getSource() == noButton) { 171 dispose(); 172 } 173 if (e.getSource() == yesButton) { 174 if (pushMethod) { 175 String [] nodes = new String [to.size()]; int i = 0; 177 for (Iterator iterator = to.iterator(); iterator.hasNext();) { 178 SOFANode node = (SOFANode) iterator.next(); 179 nodes[i++] = node.getReference().toString().replaceAll("InOut2ClientRMISkel", "InOut2InOutRMISkel"); 184 } 185 Set fromSet = from.keySet(); 186 for (Iterator iterator = fromSet.iterator(); iterator.hasNext();) { SOFANode node = (SOFANode) iterator.next(); 188 InOut2Client destInOut = node.getInOut(); 189 if (destInOut != null) { 190 HashSet comps = (HashSet ) from.get(node); 191 String [] compsFullNames = new String [comps.size()]; 192 int i2 = 0; 193 for (Iterator iter2 = comps.iterator(); iter2.hasNext();) { ComponentInfo info = (ComponentInfo) iter2.next(); 195 compsFullNames[i2++] = info.getName() + "[" + info.getImplementationVersion() + "]"; 196 } 197 if (descriptionOnly) { 198 destInOut.distributeOffers(compsFullNames, nodes); 199 } else { 200 destInOut.distributeComponents(compsFullNames, nodes); 201 } 202 } 203 } 204 } else { for (Iterator iter1 = to.iterator(); iter1.hasNext();) { SOFANode destNode = (SOFANode) iter1.next(); 207 InOut2Client destInOut = destNode.getInOut(); 208 if (destInOut != null) { 209 Set fromSet = from.keySet(); 210 for (Iterator iter2 = fromSet.iterator(); iter2.hasNext();) { SOFANode sourceNode = (SOFANode) iter2.next(); 212 HashSet comps = (HashSet ) from.get(sourceNode); 213 214 String [] compsFullNames = new String [comps.size()]; 215 int i2 = 0; 216 for (Iterator iter3 = comps.iterator(); iter3.hasNext();) { ComponentInfo info = (ComponentInfo) iter3.next(); 218 compsFullNames[i2++] = info.getName() + "[" + info.getImplementationVersion() + "]"; 219 } 220 String node = sourceNode.getReference().toString().replaceAll("InOut2ClientRMISkel", "InOut2InOutRMISkel"); 225 if (descriptionOnly) { 226 destInOut.obtainOffers(compsFullNames, node); 227 } else { 228 destInOut.obtainComponents(compsFullNames, node); 229 } 230 } 231 } 232 } } } dispose(); 236 } 237 } 238 | Popular Tags |