4 * Created on March 29, 2008, 2:42 AM
6 * To change this template, choose Tools | Template Manager
7 * and open the template in the editor.
10 package javaapplication1;
13 import javax.swing.JPanel;
21 public class DisplayHandle {
23 /** Creates a new instance of DisplayHandle */
24 public DisplayHandle(BufferedWriter outCommand) {
25 this.outCommand = outCommand;
27 createCompListSlice();
32 private void createCompListNode(){
33 compList_node = new GuiComponent[33];
34 GuiComponent[] compList = compList_node;
35 String[] tmplist1 = {"readable","pl"};
36 String[] tmplist2 = {"writable","pl"};
37 String[] tmplist3 = {"readable","geni"};
38 String[] tmplist4 = {"writable","geni"};
39 compList[0] = new GuiComponent("node_id", tmplist1, "text", "Node Id", "");
40 compList[1] = new GuiComponent("last_updated", tmplist1, "text", "Last Updated", "");
41 compList[2] = new GuiComponent("boot_state", tmplist2, "combo", "Boot state", "boot, dbg, inst, new, rcnf, rins");
42 compList[3] = new GuiComponent("site_id", tmplist1, "num", "Site Id", "");
43 compList[4] = new GuiComponent("pcu_ids", tmplist2, "num", "PCU Ids", "");
44 compList[5] = new GuiComponent("session", tmplist1, "text", "Session", "");
45 compList[6] = new GuiComponent("key", tmplist2, "key", "Key", "");
46 compList[7] = new GuiComponent("conf_file_ids", tmplist2, "text", "Conf file Ids", "");
47 compList[8] = new GuiComponent("ssh_rsa_key", tmplist1, "text", "SSH RSA Key", "");
48 compList[9] = new GuiComponent("ssh_rsa_key_write", tmplist2, "key", "SSH RSA Key", "");
49 compList[10] = new GuiComponent("uuid", tmplist1, "text", "UUID", "");
50 compList[11] = new GuiComponent("nodegroup_ids", tmplist2, "num", "Node Group Ids", "");
51 compList[12] = new GuiComponent("slice_ids_whitelist", tmplist2, "text", "Slice Ids Whitelist", "");
52 compList[13] = new GuiComponent("last_contact", tmplist2, "text", "Last Contact", "");
53 compList[14] = new GuiComponent("nodenetwork_ids", tmplist2, "text", "Node Network Ids", "");
54 compList[15] = new GuiComponent("peer_node_id", tmplist2, "num", "Peer Node Id", "");
55 compList[16] = new GuiComponent("hostname", tmplist2, "text", "Hostname", "randomsite.edu");
56 compList[17] = new GuiComponent("slice_ids", tmplist1, "num", "Slice Ids", "");
57 compList[18] = new GuiComponent("boot_nonce", tmplist2, "text", "Boot Nonce", "");
58 compList[19] = new GuiComponent("version", tmplist2, "text", "Version", "PlanetLab BootCD 3.1");
59 compList[20] = new GuiComponent("date_created", tmplist1, "text", "Date Created", "");
60 compList[21] = new GuiComponent("model", tmplist2, "text", "Model", "Dell OptiPlex GX280");
61 compList[22] = new GuiComponent("peer_id", tmplist1, "num", "Peer Id", "");
62 compList[23] = new GuiComponent("ports", tmplist2, "text", "Ports", "");
63 compList[24] = new GuiComponent("description", tmplist4, "text", "Description", "New node for testing purposes");
64 compList[25] = new GuiComponent("rights", tmplist4, "text", "Rights", "");
65 compList[26] = new GuiComponent("pubkey", tmplist3, "text", "GENI Public key", "");
66 compList[27] = new GuiComponent("pubkey_write", tmplist4, "key", "GENI Public key", "");
67 compList[28] = new GuiComponent("wrapperurl", tmplist4, "text", "Wrapper URL", "local");
68 compList[29] = new GuiComponent("disabled", tmplist3, "bool", "Disabled", "Yes, No");
69 compList[30] = new GuiComponent("userlist", tmplist4, "text", "User List", "");
70 compList[31] = new GuiComponent("pointer", tmplist3, "num", "PL Pointer", "");
71 compList[32] = new GuiComponent("g_uuid", tmplist3, "text", "GENI UUID", "");
75 private void createCompListUser(){
76 compList_user = new GuiComponent[28];
77 GuiComponent[] compList = compList_user;
78 String[] tmplist1 = {"readable","pl"};
79 String[] tmplist2 = {"writable","pl"};
80 String[] tmplist3 = {"readable","geni"};
81 String[] tmplist4 = {"writable","geni"};
82 compList[0] = new GuiComponent("person_id", tmplist1, "num", "Person Id", "");
83 compList[1] = new GuiComponent("bio", tmplist2, "text", "Bio", "");
84 compList[2] = new GuiComponent("first_name", tmplist2, "text", "First Name", "");
85 compList[3] = new GuiComponent("last_name", tmplist2, "text", "Last Name", "");
86 compList[4] = new GuiComponent("last_updated", tmplist1, "text", "Last Updated", "");
87 compList[5] = new GuiComponent("key_ids", tmplist2, "num", "Key Ids", "");
88 compList[6] = new GuiComponent("phone", tmplist2, "text", "Phone", "");
89 compList[7] = new GuiComponent("peer_person_id", tmplist2, "num", "Peer Person Id", "");
90 compList[8] = new GuiComponent("role_ids", tmplist2, "num", "Role Ids", "");
91 compList[9] = new GuiComponent("site_ids", tmplist1, "num", "Site Ids", "");
92 compList[10] = new GuiComponent("uuid", tmplist1, "text", "UUID", "");
93 compList[11] = new GuiComponent("roles", tmplist2, "num", "Roles", "");
94 compList[12] = new GuiComponent("title", tmplist2, "text", "Title", "");
95 compList[13] = new GuiComponent("url", tmplist2, "text", "Url", "someuser.dom.edu");
96 compList[14] = new GuiComponent("enabled", tmplist2, "bool", "Enabled", "Yes, No");
97 compList[15] = new GuiComponent("slice_ids", tmplist2, "num", "Slice Ids", "");
98 compList[16] = new GuiComponent("date_created", tmplist1, "text", "Date Created", "");
99 compList[17] = new GuiComponent("peer_id", tmplist2, "num", "Peer Id", "");
100 compList[18] = new GuiComponent("email", tmplist2, "text", "Email", "someuser@domain.edu");
101 compList[19] = new GuiComponent("description", tmplist4, "text", "Description", "test user");
102 compList[20] = new GuiComponent("rights", tmplist2, "text", "Rights", "");
103 compList[21] = new GuiComponent("pubkey", tmplist3, "text", "GENI Public key", "");
104 compList[22] = new GuiComponent("pubkey_write", tmplist4, "key", "GENI Public key", "");
105 compList[23] = new GuiComponent("wrapperurl", tmplist4, "text", "Wrapper URL", "local");
106 compList[24] = new GuiComponent("disabled", tmplist3, "bool", "Disabled", "Yes, No");
107 compList[25] = new GuiComponent("userlist", tmplist4, "text", "User List", "");
108 compList[26] = new GuiComponent("pointer", tmplist3, "text", "PL Pointer", "");
109 compList[27] = new GuiComponent("g_uuid", tmplist3, "text", "GENI UUID", "");
113 private void createCompListSlice(){
114 compList_slice = new GuiComponent[24];
115 GuiComponent[] compList = compList_slice;
116 String[] tmplist1 = {"readable","pl"};
117 String[] tmplist2 = {"writable","pl"};
118 String[] tmplist3 = {"readable","geni"};
119 String[] tmplist4 = {"writable","geni"};
120 compList[0] = new GuiComponent("slice_id", tmplist1, "num", "Slice Id", "");
121 compList[1] = new GuiComponent("description", tmplist2, "text", "Description", "");
122 compList[2] = new GuiComponent("node_ids", tmplist1, "num", "Node Ids", "");
123 compList[3] = new GuiComponent("expires", tmplist2, "text", "Expires", "");
124 compList[4] = new GuiComponent("site_id", tmplist1, "num", "Site Id", "");
125 compList[5] = new GuiComponent("uuid", tmplist1, "text", "UUID", "");
126 compList[6] = new GuiComponent("creator_person_id", tmplist2, "text", "Creator Person Id", "");
127 compList[7] = new GuiComponent("instantiation", tmplist2, "combo", "Instantiation", "delegated, not-instantiated, plc-instantiated");
128 compList[8] = new GuiComponent("name", tmplist2, "text", "Name", "");
129 compList[9] = new GuiComponent("created", tmplist1, "text", "Created", "");
130 compList[10] = new GuiComponent("url", tmplist2, "text", "Url", "");
131 compList[11] = new GuiComponent("max_nodes", tmplist2, "num", "Max Nodes", "10");
132 compList[12] = new GuiComponent("person_ids", tmplist2, "num", "Person Ids", "");
133 compList[13] = new GuiComponent("slice_attribute_ids", tmplist2, "text", "Slice Attribute Ids", "");
134 compList[14] = new GuiComponent("peer_id", tmplist1, "num", "Peer Id", "");
135 compList[15] = new GuiComponent("description", tmplist4, "text", "Description", "test slice");
136 compList[16] = new GuiComponent("rights", tmplist2, "text", "Rights", "");
137 compList[17] = new GuiComponent("pubkey", tmplist3, "text", "GENI Public key", "");
138 compList[18] = new GuiComponent("pubkey_write", tmplist4, "key", "GENI Public key", "");
139 compList[19] = new GuiComponent("wrapperurl", tmplist4, "text", "Wrapper URL", "local");
140 compList[20] = new GuiComponent("disabled", tmplist3, "bool", "Disabled", "Yes, No");
141 compList[21] = new GuiComponent("userlist", tmplist4, "text", "User List", "");
142 compList[22] = new GuiComponent("pointer", tmplist3, "num", "PL Pointer", "");
143 compList[23] = new GuiComponent("g_uuid", tmplist3, "text", "GENI UUID", "");
147 private void createCompListSite(){
148 compList_site = new GuiComponent[31];
149 GuiComponent[] compList = compList_site;
150 String[] tmplist1 = {"readable","pl"};
151 String[] tmplist2 = {"writable","pl"};
152 String[] tmplist3 = {"readable","geni"};
153 String[] tmplist4 = {"writable","geni"};
155 compList[0] = new GuiComponent("last_updated", tmplist1, "text", "Last Updated", "");
156 compList[1] = new GuiComponent("node_ids", tmplist2, "num", "Node Ids", "");
157 compList[2] = new GuiComponent("site_id", tmplist1, "num", "Site Id", "");
158 compList[3] = new GuiComponent("pcu_ids", tmplist2, "num", "PCU Ids", "");
159 compList[4] = new GuiComponent("max_slices", tmplist2, "num", "Max Slices", "");
160 compList[5] = new GuiComponent("ext_consortium_id", tmplist2, "text", "Ext Consortium Id", "");
161 compList[6] = new GuiComponent("max_slivers", tmplist2, "num", "Max Slivers", "5");
162 compList[7] = new GuiComponent("is_public", tmplist2, "bool", "Public", "Yes, No");
163 compList[8] = new GuiComponent("peer_site_id", tmplist1, "num", "Peer Site Id", "");
164 compList[9] = new GuiComponent("abbreviated_name", tmplist2, "text", "Abbreviated Name", "");
165 compList[10] = new GuiComponent("name", tmplist2, "text", "Name", "");
166 compList[11] = new GuiComponent("address_ids", tmplist2, "num", "Address Ids", "");
167 compList[12] = new GuiComponent("uuid", tmplist1, "text", "UUID", "");
168 compList[13] = new GuiComponent("url", tmplist2, "text", "Url", "");
169 compList[14] = new GuiComponent("person_ids", tmplist2, "num", "Person Ids", "");
170 compList[15] = new GuiComponent("enabled", tmplist2, "bool", "Enabled", "Yes, No");
171 compList[16] = new GuiComponent("longitude", tmplist2, "num", "Longitude", "34.3");
172 compList[17] = new GuiComponent("latitude", tmplist2, "num", "Latitude", "45.4");
173 compList[18] = new GuiComponent("slice_ids", tmplist2, "num", "Slice Ids", "");
174 compList[19] = new GuiComponent("login_base", tmplist2, "text", "Login Base", "");
175 compList[20] = new GuiComponent("date_created", tmplist1, "text", "Date Created", "");
176 compList[21] = new GuiComponent("peer_id", tmplist1, "num", "Peer Id", "");
177 compList[22] = new GuiComponent("description", tmplist4, "text", "Description", "test slice");
178 compList[23] = new GuiComponent("rights", tmplist2, "text", "Rights", "");
179 compList[24] = new GuiComponent("pubkey", tmplist3, "text", "GENI Public key", "");
180 compList[25] = new GuiComponent("pubkey_write", tmplist4, "key", "GENI Public key", "");
181 compList[26] = new GuiComponent("wrapperurl", tmplist4, "text", "Wrapper URL", "local");
182 compList[27] = new GuiComponent("disabled", tmplist3, "bool", "Disabled", "Yes, No");
183 compList[28] = new GuiComponent("userlist", tmplist4, "text", "User List", "");
184 compList[29] = new GuiComponent("pointer", tmplist3, "num", "PL Pointer", "");
185 compList[30] = new GuiComponent("g_uuid", tmplist3, "text", "GENI UUID", "");
188 //input is in format: {"'field1_name':value1", "'field2_name':value2", ...}
189 public void FillComponentList(String recordType, String[] dict){
190 GuiComponent[] complist = null;
191 if (recordType.equals("user")){
192 complist = compList_user;
194 else if (recordType.equals("slice")){
195 complist = compList_slice;
197 else if (recordType.equals("node")){
198 complist = compList_node;
200 else if (recordType.equals("SA/MA")){
201 complist = compList_site;
204 for (int i=0; i<dict.length; i++){
205 String[] line = dict[i].split("':");
206 String comp_name = line[0].split("'")[1];
207 String comp_value = "";
209 comp_value = line[1];
210 if (comp_value.equals("None"))
213 for(j = 0; j<complist.length; j++){
214 if (complist[j].getName().equals(comp_name)){
218 if (j == complist.length)
221 String type = complist[j].getType();
222 if (type.equals("text") || type.equals("num"))
223 complist[j].setValue(comp_value);
224 else if (type.equals("bool"))
225 if (comp_value.equals("True"))
226 complist[j].setValue("Yes, No");
228 complist[j].setValue("No, Yes");
229 else if (type.equals("combo")){
230 String[] curVal = complist[j].getValue().split(", ");
231 String nextVal = comp_value;
232 for(int k=0; k<curVal.length; k++)
233 if (curVal[k] != comp_value)
234 nextVal += (", "+curVal[k]);
235 complist[j].setValue(nextVal);
237 else if (type.equals("key")){
238 complist[j].setValue(comp_value);
244 private void keyChooserActionPerformed(JTextField t, java.awt.event.ActionEvent evt) {
245 // TODO add your handling code here:
247 javax.swing.JFileChooser fc = (javax.swing.JFileChooser)evt.getSource();
248 java.io.File f = fc.getSelectedFile();
250 if(keySelectFrame!=null)
251 keySelectFrame.dispose();
254 String fname = f.getAbsolutePath();
257 //extract the pubkey from the specified file into temp file
258 outCommand.write("./certutil.py "+fname+" > tmp_key_file.txt\n");
261 //get key from temp file
263 File file = new File("tmp_key_file.txt");
265 while(!file.exists() && i<5){
268 Thread.currentThread().sleep(200);
269 } catch (InterruptedException ex) {
270 ex.printStackTrace();
274 Thread.currentThread().sleep(100);
275 } catch (InterruptedException ex) {
276 ex.printStackTrace();
279 BufferedReader in = new BufferedReader(new FileReader("tmp_key_file.txt"));
280 String tmp = in.readLine();
281 while(tmp!=null && tmp.length() > 0){
287 outCommand.write("rm tmp_key_file.txt\n");
290 //write the result in the textfield
292 }catch (Exception ex) {
293 ex.printStackTrace();
299 public void displayComponentList(String recordType, JPanel panel1, JPanel panel2){
301 GuiComponent[] complist = null;
302 if (recordType.equals("user")){
303 complist = compList_user;
305 else if (recordType.equals("slice")){
306 complist = compList_slice;
308 else if (recordType.equals("node")){
309 complist = compList_node;
311 else if (recordType.equals("SA/MA")){
312 complist = compList_site;
316 panel1.setLayout(new SpringLayout());
319 for (int i=0;i<complist.length;i++){
320 if (complist[i].getProperty()[0].equals("readable") && complist[i].getProperty()[1].equals("geni")){
321 String type = complist[i].getType();
322 if (type.equals("text") || type.equals("num")){
323 JLabel l = new JLabel(complist[i].getLabel(), JLabel.TRAILING);
324 l.setName(complist[i].getName());
326 JTextField t = new JTextField();
327 t.setText(complist[i].getValue());
328 t.setEditable(false);
336 for (int i=0;i<complist.length;i++){
337 if (complist[i].getProperty()[0].equals("readable") && complist[i].getProperty()[1].equals("pl")){
338 String type = complist[i].getType();
339 if (type.equals("text") || type.equals("num")){
340 JLabel l = new JLabel(complist[i].getLabel(), JLabel.TRAILING);
341 l.setName(complist[i].getName());
343 JTextField t = new JTextField();
344 t.setText(complist[i].getValue());
345 t.setEditable(false);
352 int parts = 2*(count1+count2);
353 while(parts != (parts/6)*6){
354 JLabel l = new JLabel("", JLabel.TRAILING);
359 SpringUtilities.makeCompactGrid(panel1,
360 parts/6, 6, //rows, cols
367 //fill the second(writable) panel
369 panel2.setLayout(new SpringLayout());
372 for (int i=0;i<complist.length;i++){
373 if (complist[i].getProperty()[0].equals("writable") && complist[i].getProperty()[1].equals("geni")){
374 JLabel l = new JLabel(complist[i].getLabel(), JLabel.TRAILING);
375 final String name = complist[i].getName();
378 String type = complist[i].getType();
379 if (type.equals("text") || type.equals("num")){
380 JTextField t = new JTextField();
381 t.setText(complist[i].getValue());
386 else if (type.equals("combo") || type.equals("bool")){
387 JComboBox cb = new JComboBox(complist[i].getValue().split(", "));
392 else if (type.equals("key")){
393 final JTextField t = new JTextField();
394 t.setText(complist[i].getValue());
395 t.setEditable(false);
399 t.addMouseListener(new java.awt.event.MouseAdapter() {
400 public void mousePressed(java.awt.event.MouseEvent evt) {
401 //Create and set up the window.
402 if(keySelectFrame!=null)
403 keySelectFrame.dispose();
404 keySelectFrame = new JFrame("Key Select");
405 keySelectFrame.setSize(600,400);
406 keySelectFrame.setLocation(200,100);
408 //Set up the content pane.
409 Container contentPane = keySelectFrame.getContentPane();
410 SpringLayout layout = new SpringLayout();
411 contentPane.setLayout(layout);
413 JFileChooser fc = new JFileChooser();
414 fc.addActionListener(new java.awt.event.ActionListener() {
415 public void actionPerformed(java.awt.event.ActionEvent evt) {
416 keyChooserActionPerformed(t, evt);
422 //Display the window.
423 keySelectFrame.pack();
424 keySelectFrame.setVisible(true);
432 for (int i=0;i<complist.length;i++){
433 if (complist[i].getProperty()[0].equals("writable") && complist[i].getProperty()[1].equals("pl")){
434 JLabel l = new JLabel(complist[i].getLabel(), JLabel.TRAILING);
435 l.setName(complist[i].getName());
437 String type = complist[i].getType();
438 if (type.equals("text") || type.equals("num")){
439 JTextField t = new JTextField();
440 t.setText(complist[i].getValue());
445 else if (type.equals("combo") || type.equals("bool")){
446 JComboBox cb = new JComboBox(complist[i].getValue().split(", "));
451 else if (type.equals("key")){
452 JTextField t = new JTextField();
453 t.setText(complist[i].getValue());
460 parts = 2*(count1+count2);
461 while(parts != (parts/6)*6){
462 JLabel l = new JLabel("", JLabel.TRAILING);
467 SpringUtilities.makeCompactGrid(panel2,
468 parts/6, 6, //rows, cols
477 //construct a clientstub message out of the given panel
478 public String PanelToString(String type, JPanel panel){
479 GuiComponent[] targetCompList = null;
480 String g_params = "";
481 String p_params = "";
483 if (type.equals("user"))
484 targetCompList = compList_user;
485 else if (type.equals("slice"))
486 targetCompList = compList_slice;
487 else if (type.equals("node"))
488 targetCompList = compList_node;
489 else if (type.equals("SA/MA"))
490 targetCompList = compList_site;
492 //serialize the components on the component list
493 Component carr[] = panel.getComponents();
494 for(int i = 0; i<carr.length; i++){
495 Component nextcomp = carr[i];
496 String comp_name = nextcomp.getName();
498 for(j = 0; j<targetCompList.length; j++){
499 String cur_name = targetCompList[j].getName();
500 if (cur_name.equals(comp_name)){
504 if (j == targetCompList.length)
507 String comp_type = targetCompList[j].getType();
508 String comp_content = "";
509 if (comp_type.equals("text") || comp_type.equals("num")){
510 JTextField tf = (JTextField)carr[i+1];
511 String tf_content = tf.getText();
512 if (tf_content.length() == 0)
514 else if(comp_type.equals("text"))
515 comp_content = "'"+tf_content+"'";
517 comp_content = tf_content;
519 else if (comp_type.equals("bool")){
520 JComboBox cb = (JComboBox)carr[i+1];
521 String cb_content = (String) cb.getSelectedItem();
522 if (cb_content.equals("Yes"))
523 comp_content = "True";
525 comp_content = "False";
527 else if (comp_type.equals("combo")){
528 JComboBox cb = (JComboBox)carr[i+1];
529 String cb_content = (String) cb.getSelectedItem();
530 comp_content = "'"+cb_content+"'";
532 else if (comp_type.equals("key")){
533 JTextField tf = (JTextField)carr[i+1];
534 String tf_content = tf.getText();
536 if (tf_content.length() == 0)
539 comp_content = "'"+tf_content+"'";
541 //add to dictionary string
542 if (comp_name.equals("key_write"))
544 else if (comp_name.equals("pubkey_write"))
545 comp_name = "pubkey";
546 if (targetCompList[j].getProperty()[1].equals("geni")){
547 if (g_params.length() == 0)
548 g_params += ("'"+comp_name+"':"+comp_content);
550 g_params += (", '"+comp_name+"':"+comp_content);
553 if (p_params.length() == 0)
554 p_params += ("'"+comp_name+"':"+comp_content);
556 p_params += (", '"+comp_name+"':"+comp_content);
560 return "'g_params':{"+g_params+"}, 'p_params':{"+p_params+"}";
563 private BufferedWriter outCommand = null;
564 private JFrame keySelectFrame = null;
565 private GuiComponent[] compList_slice;
566 private GuiComponent[] compList_user;
567 private GuiComponent[] compList_node;
568 private GuiComponent[] compList_site;