00001 package GuiComponents.SctConf;
00002
00003 import java.util.Enumeration;
00004 import java.util.Vector;
00005 import java.awt.Dimension;
00006 import java.awt.BorderLayout;
00007 import java.awt.event.ActionEvent;
00008 import java.awt.event.ActionListener;
00009 import java.awt.event.MouseAdapter;
00010 import java.awt.event.MouseEvent;
00011 import java.awt.event.WindowAdapter;
00012 import java.awt.event.WindowEvent;
00013 import javax.swing.JComponent;
00014 import javax.swing.JFrame;
00015 import javax.swing.JPanel;
00016 import javax.swing.JLabel;
00017 import javax.swing.JMenuItem;
00018 import javax.swing.JPopupMenu;
00019 import javax.swing.JOptionPane;
00020 import javax.swing.JScrollPane;
00021 import javax.swing.JTree;
00022 import javax.swing.tree.*;
00023 import javax.swing.event.TreeModelListener;
00024 import javax.swing.event.TreeModelEvent;
00025
00026 import org.omg.CORBA.IntHolder;
00027
00028 import sctConf.*;
00029 import ipc.*;
00030 import Sct.gui.SelectionDialog;
00031
00032 public class TreeView extends JPanel {
00033 private Proxies configGui;
00034 private sctConf.Configuration config;
00035
00036 private JTree tree;
00037
00038 private JPopupMenu popup;
00039
00040 private MyModel treeModel;
00041
00042 public TreeView(Proxies cGui, Configuration conf) {
00043 configGui = cGui;
00044 config = conf;
00045
00046 treeModel = new MyModel(config);
00047
00048 tree = new JTree(treeModel);
00049
00050 JScrollPane treeView = new JScrollPane(tree);
00051
00052 enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK);
00053 tree.addMouseListener(new MouseClickHandler());
00054
00055 setLayout(new BorderLayout());
00056
00057 popup = new JPopupMenu();
00058 popup.add(new JMenuItem("Do nothing"));
00059
00060 treeView.setPreferredSize(new Dimension(500, 300));
00061 add(treeView, BorderLayout.CENTER);
00062
00063 System.out.println("Set up GUI, wait for it to run");
00064 }
00065
00066 private class MouseClickHandler extends MouseAdapter {
00067 private JMenuItem menuWithAction(String name, Object thing) {
00068 JMenuItem result = new JMenuItem(name);
00069 result.addActionListener(new ActionHandler(name, thing));
00070
00071 return result;
00072 }
00073
00074 private void checkPopup(MouseEvent event) {
00075 if(event.isPopupTrigger()){
00076 TreePath path = tree.getPathForLocation(event.getX(), event.getY());
00077 if(path != null){
00078 tree.setSelectionPath(path);
00079 Object thing = path.getLastPathComponent();
00080
00081 System.out.println("Last in path is: " + thing);
00082
00083 try {
00084 while(true) {
00085 popup.remove(0);
00086 }
00087 } catch(IllegalArgumentException e) {
00088
00089 }
00090
00091 if(thing == null) {
00092 } else if(thing == "Partitions") {
00093 popup.add(menuWithAction("Add ROD", thing));
00094 popup.add(menuWithAction("Add TIM", thing));
00095 popup.add(menuWithAction("Clear everything", thing));
00096 } else if(thing instanceof Proxies.PartitionProxy) {
00097 popup.add(menuWithAction("Clear crates", thing));
00098
00099 } else if(thing instanceof Proxies.CrateProxy) {
00100 popup.add(menuWithAction("Clear RODs in crate", thing));
00101 popup.add(menuWithAction("Add ROD to crate", thing));
00102 } else if(thing instanceof Proxies.RodProxy) {
00103 popup.add(menuWithAction("View ROD info", thing));
00104 popup.add(menuWithAction("Add MUR to ROD", thing));
00105 } else if(thing instanceof Proxies.MurProxy) {
00106 popup.add(menuWithAction("Add Module to MUR", thing));
00107 popup.add(menuWithAction("Edit MUR mappings", thing));
00108 } else if(thing instanceof Proxies.ModuleProxy) {
00109 popup.add(menuWithAction("View module configuration", thing));
00110 popup.add(menuWithAction("Edit module mappings", thing));
00111 popup.add(menuWithAction("Unmap module", thing));
00112 popup.add(menuWithAction("Refresh", thing));
00113 } else if(thing instanceof String) {
00114 String name = (String)thing;
00115 }
00116 if(popup.getComponents().length > 0) {
00117 popup.show(tree, event.getX(), event.getY());
00118 }
00119 }
00120 }
00121 }
00122 public void mousePressed(MouseEvent event){
00123 checkPopup(event);
00124 }
00125 public void mouseReleased(MouseEvent event){
00126 checkPopup(event);
00127 }
00128 }
00129
00130 private class ActionHandler implements ActionListener {
00131 Object target;
00132 public ActionHandler(String name, Object thing) {
00133 target = thing;
00134 }
00135
00136 public void actionPerformed(ActionEvent e) {
00137 String action = e.getActionCommand();
00138
00139 System.out.println("Do " + action + " on " + target);
00140
00141 if(target instanceof Proxies.CrateProxy) {
00142 Proxies.CrateProxy crate = (Proxies.CrateProxy)target;
00143 if(action.equals("Clear RODs in crate")) {
00144 JOptionPane.showMessageDialog(null, "Don't know that one yet");
00145 } else if(action.equals("Add ROD to crate")) {
00146 try {
00147 int [] RODs = config.listRodsInCrate(crate.partition(), crate.index());
00148 RodConfig rConf = new RodConfig();
00149
00150 rConf.slaves = new sctConf.SlaveConfig[4];
00151 for(int i=0; i<4; i++) {
00152 rConf.slaves[i] = new SlaveConfig();
00153 rConf.slaves[i].ipramFile = "";
00154 rConf.slaves[i].idramFile = "";
00155 rConf.slaves[i].extFile = "";
00156 }
00157
00158 config.configureROD(crate.partition(), crate.index(), RODs.length, rConf);
00159
00160 Object [] path = new Object[3];
00161
00162 path[0] = "Partitions";
00163 path[1] = configGui.getPartition(crate.partition());
00164 path[2] = target;
00165
00166 treeModel.modified(path);
00167 } catch(ConfigurationException c) {
00168 JOptionPane.showMessageDialog(null, "ROD creation failed: " + c.detail);
00169 }
00170 } else {
00171 System.out.println("Unknown action " + action + " on Crate " + crate);
00172 }
00173 } else if(target instanceof Proxies.RodProxy) {
00174 Proxies.RodProxy r = (Proxies.RodProxy)target;
00175 if(action.equals("View ROD info")) {
00176 JFrame frame = new JFrame("Modules in a ROD");
00177 frame.getContentPane().add(new RODView(config, r));
00178
00179 frame.addWindowListener(new WindowAdapter() {
00180 public void windowClosing(WindowEvent e) {
00181 e.getWindow().dispose();
00182 }
00183 });
00184 frame.pack();
00185 frame.setVisible(true);
00186 } else if(action.equals("Add MUR to ROD")) {
00187
00188
00189 int [] myConf;
00190 myConf = new int[100];
00191
00192
00193
00194 System.out.println("Adding MUR in ROD " + r);
00195
00196 String [] labels = {"MUR index", "MUR position with ROD (0-7)"};
00197 String [] defaults = {"0", "0"};
00198
00199 SelectionDialog dialog = new SelectionDialog(null, "Select MUR for ROD", labels, defaults);
00200
00201 dialog.pack();
00202 dialog.setVisible(true);
00203
00204 try {
00205 System.out.println("Got back some selections");
00206 for(int i=0; i<2; i++) {
00207 System.out.println(labels[i] + ": " + dialog.getIntFieldValue(i));
00208 }
00209
00210 try {
00211 config.mapRODMUR(r.partition(), r.crate(), r.index(),
00212 dialog.getIntFieldValue(0), dialog.getIntFieldValue(1));
00213
00214 Object [] path = new Object[4];
00215
00216 path[0] = "Partitions";
00217 path[1] = configGui.getPartition(r.partition());
00218 path[2] = configGui.getCrate(r.crate(), r.partition());
00219 path[3] = target;
00220
00221 treeModel.modified(path);
00222 } catch(ConfigurationException ex) {
00223 JOptionPane.showMessageDialog(null, "mapRODMUR failed with: " + ex.detail);
00224 }
00225 } catch(SelectionDialog.InvalidDialogException ide) {
00226 JOptionPane.showMessageDialog(null, "Invalid entry for MUR");
00227 } catch(SelectionDialog.CancelledDialogException i) {
00228
00229 }
00230 } else {
00231 System.out.println("Unknown action " + action + " on ROD ");
00232 }
00233 } else if(target instanceof Proxies.MurProxy) {
00234 Proxies.MurProxy mur = (Proxies.MurProxy)target;
00235 if(action.equals("Add Module to MUR")) {
00236 String moduleName = null;
00237 int position = -1;
00238 {
00239 ModuleListView moduleList = new ModuleListView(config);
00240
00241 Vector list = moduleList.getList();
00242
00243 if(list.size() == 0) {
00244 JOptionPane.showMessageDialog(null, "No modules to select, add in module list");
00245 return;
00246 } else {
00247 Object [] objList = new Object[list.size()];
00248
00249 list.copyInto(objList);
00250
00251 String item = (String)JOptionPane.showInputDialog((JComponent)(e.getSource()),
00252 "Select an unused module",
00253 "Module selector",
00254 JOptionPane.OK_CANCEL_OPTION,
00255 null,
00256 objList,
00257 objList[0]);
00258
00259 System.out.println("Found a module! " + item);
00260
00261 moduleName = item;
00262 }
00263 }
00264
00265 try {
00266 String [] modules = config.listModulesInMUR(mur.partition(), mur.id());
00267
00268 int [] check = new int[6];
00269 for(int i=0; i<modules.length; i++) {
00270 IntHolder MUR = new IntHolder(), mod = new IntHolder();
00271 config.translateFromSN(modules[i].toString(), MUR, mod);
00272 check[mod.value-1] = 1;
00273 }
00274
00275 Integer [] numList = new Integer[6 - modules.length];
00276 int index = 0;
00277 for(int i = 1; i<=6; i++) {
00278 if(check[i-1] == 0) {
00279 numList[index++] = new Integer(i);
00280 }
00281 }
00282
00283 if(modules.length < 6) {
00284 Integer item = (Integer)JOptionPane.showInputDialog((JComponent)(e.getSource()),
00285 "Select an unused position",
00286 "Position selector",
00287 JOptionPane.OK_CANCEL_OPTION,
00288 null,
00289 numList,
00290 numList[0]);
00291
00292 position = item.intValue();
00293 } else {
00294 JOptionPane.showMessageDialog(null, "No positions free in selected MUR");
00295 }
00296
00297 System.out.println("Got position " + position);
00298 } catch(ConfigurationException c) {
00299 JOptionPane.showMessageDialog(null, "Bad configuration for getting MUR list: " + c.detail);
00300 }
00301
00302 if(moduleName != null && position != -1) {
00303 System.out.println("Mapping module " + moduleName + " in MUR " + mur.id() + " to number " + position);
00304 try {
00305 config.mapModuleMUR(mur.id(), position, mur.id(), (position%6)+1, moduleName);
00306
00307 Object [] path = new Object[5];
00308
00309 path[0] = "Partitions";
00310 path[1] = configGui.getPartition(mur.partition());
00311 path[2] = configGui.getCrate(mur.crate(), mur.partition());
00312 path[3] = configGui.getRod(mur.rod(), mur.partition(), mur.crate());
00313 path[4] = target;
00314
00315 for(int i=0; i<5; i++) {
00316 System.out.println(i + ": " + path[i]);
00317 }
00318
00319 treeModel.modified(path);
00320 } catch(ConfigurationException c) {
00321 JOptionPane.showMessageDialog(null, "Failed to map module to MUR: " + c.detail);
00322 }
00323 }
00324 } else if(action.equals("Edit MUR mappings")) {
00325 System.out.println("Unsupported action " + action + " on MUR " + mur);
00326 } else {
00327 System.out.println("Unknown action " + action + " on MUR " + mur);
00328 }
00329 } else if(target instanceof Proxies.ModuleProxy) {
00330 Proxies.ModuleProxy module = (Proxies.ModuleProxy)target;
00331 if(action.equals("View module configuration")) {
00332 JFrame frame = new JFrame("Module view");
00333
00334 frame.getContentPane().add(new GuiComponents.Panels.ModuleConfigurationPanel(module.getSN()));
00335
00336 frame.addWindowListener(new WindowAdapter() {
00337 public void windowClosing(WindowEvent e) {
00338 e.getWindow().dispose();
00339 }
00340 });
00341
00342 frame.pack();
00343
00344 frame.setVisible(true);
00345 } else if(action.equals("Edit module mappings")) {
00346 JFrame frame = new JFrame("Module " + module);
00347 frame.getContentPane().add(new ModuleView(config, module));
00348
00349 frame.addWindowListener(new WindowAdapter() {
00350 public void windowClosing(WindowEvent e) {
00351 e.getWindow().dispose();
00352 }
00353 });
00354
00355 frame.pack();
00356
00357 frame.setVisible(true);
00358 } else if(action.equals("Unmap module")) {
00359 try {
00360 IntHolder MUR = new IntHolder(), num = new IntHolder();
00361 config.translateFromSN(module.toString(), MUR, num);
00362
00363 Object [] path = new Object[6];
00364
00365 int realLength = 1;
00366
00367 path[0] = "Partitions";
00368
00369 try {
00370 path[1] = configGui.getPartition(module.partition());
00371 realLength ++;
00372 path[2] = configGui.getCrate(module.crate(), module.partition());
00373 realLength ++;
00374 path[3] = configGui.getRod(module.rod(), module.partition(), module.crate());
00375 realLength ++;
00376 path[4] = configGui.getMUR(module.getMUR());
00377 realLength ++;
00378 } catch(ConfigurationException c) {
00379
00380 }
00381
00382 Object [] realPath = new Object[realLength];
00383 for(int i=0; i<realLength; i++) {
00384 realPath[i] = path[i];
00385 System.out.println(i + ": " + realPath[i]);
00386 }
00387
00388 config.unmapModuleMUR(MUR.value, num.value);
00389
00390 treeModel.modified(realPath);
00391 } catch(ConfigurationException c) {
00392
00393 }
00394 } else if(action.equals("Refresh")) {
00395 Object [] path = new Object[6];
00396
00397 int realLength = 1;
00398
00399 path[0] = "Partitions";
00400
00401 try {
00402 path[1] = configGui.getPartition(module.partition());
00403 realLength ++;
00404 path[2] = configGui.getCrate(module.crate(), module.partition());
00405 realLength ++;
00406 path[3] = configGui.getRod(module.rod(), module.partition(), module.crate());
00407 realLength ++;
00408 path[4] = configGui.getMUR(module.getMUR());
00409 realLength ++;
00410 path[5] = target;
00411 realLength ++;
00412 } catch(ConfigurationException c) {
00413
00414 }
00415
00416 Object [] realPath = new Object[realLength];
00417 for(int i=0; i<realLength; i++) {
00418 realPath[i] = path[i];
00419 System.out.println(i + ": " + realPath[i]);
00420 }
00421
00422 treeModel.modified(realPath);
00423 } else {
00424 System.out.println("Unknown action " + action + " on module " + module);
00425 }
00426 } else if(target.equals("Partitions")) {
00427 if(action.equals("Clear everything")) {
00428 try {
00429 config.clearAll();
00430
00431 Object [] path = new Object[1];
00432 path[0] = "Partitions";
00433 treeModel.modified(path);
00434
00435 } catch(ConfigurationException c) {
00436 JOptionPane.showMessageDialog(null, "Failed to clear all! " + c.detail);
00437 }
00438 } else if(action.equals("Add ROD")) {
00439 String [] labels = {"Partition", "Crate", "Index"};
00440 String [] defaults = {"0", "0", "0"};
00441 SelectionDialog dia = new SelectionDialog(null, "Add ROD", labels, defaults);
00442
00443 dia.pack();
00444 dia.setVisible(true);
00445
00446 try {
00447 for(int i=0; i<3; i++) {
00448 System.out.println(labels[i] + ": " + dia.getIntFieldValue(i));
00449 }
00450
00451 try {
00452 sctConf.RodConfig rodConf = new sctConf.RodConfig();
00453 rodConf.baseAddress = 0x01000000 * dia.getIntFieldValue(2);
00454
00455 rodConf.slaves = new sctConf.SlaveConfig[4];
00456 for(int s=0; s<4; s++) {
00457 rodConf.slaves[s] = new sctConf.SlaveConfig();
00458 rodConf.slaves[s].ipramFile = "slaveRun_IPRAM.bin";
00459 rodConf.slaves[s].idramFile = "slaveRun_IDRAM.bin";
00460 rodConf.slaves[s].extFile = "slaveRun_xcode.bin";
00461 }
00462
00463 config.configureROD(dia.getIntFieldValue(0), dia.getIntFieldValue(1), dia.getIntFieldValue(2),
00464 rodConf);
00465
00466 System.out.println("ROD created");
00467
00468 Object [] path = new Object[1];
00469 path[0] = "Partitions";
00470 treeModel.modified(path);
00471 } catch(ConfigurationException cex) {
00472 JOptionPane.showMessageDialog(null, "Failed to create ROD: " + cex.detail);
00473 }
00474 } catch(SelectionDialog.InvalidDialogException ide) {
00475 JOptionPane.showMessageDialog(null, "Invalid dialog values, ROD creating aborted");
00476 } catch(SelectionDialog.CancelledDialogException i) {
00477
00478 }
00479 } else if(action.equals("Add TIM")) {
00480 String [] labels = {"Partition", "Crate"};
00481 String [] defaults = {"0", "0"};
00482 SelectionDialog dia = new SelectionDialog(null, "Add TIM", labels, defaults);
00483
00484 dia.pack();
00485 dia.setVisible(true);
00486
00487 try {
00488 for(int i=0; i<2; i++) {
00489 System.out.println(labels[i] + ": " + dia.getIntFieldValue(i));
00490 }
00491
00492 try {
00493 sctConf.TimConfig timConf = new sctConf.TimConfig();
00494 timConf.baseAddress = 0x0d000000;
00495 timConf.trigFrequency = 60;
00496 timConf.resetFrequency = 10;
00497
00498 config.configureTIM(dia.getIntFieldValue(0), dia.getIntFieldValue(1),
00499 timConf);
00500
00501 System.out.println("Tim created");
00502
00503 Object [] path = new Object[1];
00504 path[0] = "Partitions";
00505 treeModel.modified(path);
00506 } catch(ConfigurationException cex) {
00507 JOptionPane.showMessageDialog(null, "Failed to create TIM: " + cex.detail);
00508 }
00509 } catch(SelectionDialog.InvalidDialogException ide) {
00510 JOptionPane.showMessageDialog(null, "Invalid dialog values, TIM creation aborted");
00511 } catch(SelectionDialog.CancelledDialogException i) {
00512
00513 }
00514 } else {
00515 System.out.println("Unknown action " + action + " on Tree Root");
00516 }
00517 } else {
00518 System.out.println("Can't do that yet!");
00519 }
00520 }
00521 }
00522
00523 public class MyModel implements TreeModel {
00524 Configuration conf;
00525
00526 java.util.Vector listeners;
00527
00528 public MyModel(Configuration c) {
00529
00530 conf = c;
00531 listeners = new java.util.Vector();
00532 }
00533
00534 public Object getRoot() {
00535 return "Partitions";
00536 }
00537
00538 public Object getChild(Object parent, int index) {
00539 System.out.print("getChild " + index + " of \"" + parent + "\": ");
00540
00541 Object ret = null;
00542 try {
00543 if(parent.equals("Partitions")) {
00544 ret = configGui.getPartition(index);
00545 } else if(parent instanceof Proxies.PartitionProxy) {
00546 Proxies.PartitionProxy p = (Proxies.PartitionProxy)parent;
00547 ret = configGui.getCrate(index, p.index());
00548 } else if(parent instanceof Proxies.CrateProxy) {
00549 Proxies.CrateProxy c = (Proxies.CrateProxy)parent;
00550 int[] RODs = config.listRodsInCrate(c.partition(), c.index());
00551 ret = configGui.getRod(RODs[index], c.index(), c.partition());
00552 } else if(parent instanceof Proxies.RodProxy) {
00553 Proxies.RodProxy r = (Proxies.RodProxy)parent;
00554 int[] MURs = config.listMURSInRod(r.partition(), r.crate(), r.index());
00555
00556 IntHolder mapPart = new IntHolder(), mapCrate = new IntHolder(), mapROD = new IntHolder(), mapOrder = new IntHolder();
00557 config.getMapMURROD(MURs[index], mapPart, mapCrate, mapROD, mapOrder);
00558
00559
00560
00561 ret = configGui.getMUR(mapOrder.value, MURs[index], r.partition(), r.crate(), r.index());
00562 } else if(parent instanceof Proxies.MurProxy) {
00563 Proxies.MurProxy mur = (Proxies.MurProxy)parent;
00564
00565 System.out.print(" Asked for child " + index + " of MUR " + mur);
00566
00567 int moduleCount = 0;
00568 String[] modules = config.listModulesInMUR(mur.partition(), mur.id());
00569
00570 ret = configGui.getModule(modules[index]);
00571 } else if(parent instanceof Proxies.ModuleProxy) {
00572 Proxies.ModuleProxy m = (Proxies.ModuleProxy)parent;
00573 IntHolder MUR = new IntHolder(), num = new IntHolder();
00574 config.translateFromSN(m.toString(), MUR, num);
00575 switch(index) {
00576 case 0:
00577 {
00578 try {
00579 MURType type = config.getMURType(MUR.value);
00580
00581 if(type == sctConf.MURType.BARREL) {
00582 IntHolder barrel = new IntHolder(), row = new IntHolder(), number = new IntHolder();
00583 config.translateToBarrel(MUR.value, num.value,
00584 barrel, row, number);
00585 ret = "Barrel " + barrel.value + " Row " + row.value + " Number " + number.value;
00586 } else if(type == sctConf.MURType.ENDCAP) {
00587 IntHolder disk = new IntHolder(), quadrant = new IntHolder(), number = new IntHolder();
00588 config.translateToEndcap(MUR.value, num.value,
00589 disk, quadrant, number);
00590 ret = "Disk " + disk.value + " quadrant " + quadrant.value + " Number " + number.value;
00591 } else {
00592 ret = "Unknown physical mapping";
00593 }
00594 } catch(ConfigurationException e) {
00595 ret = "Inconsistent physical mapping";
00596 }
00597 break;
00598 }
00599 case 1:
00600 {
00601 try {
00602 IntHolder partition = new IntHolder(), crate = new IntHolder(),
00603 rod = new IntHolder(), channel = new IntHolder();
00604 config.translateToROD(MUR.value, num.value,
00605 partition, rod, crate, channel);
00606 ret = partition.value + " " + rod.value + " " + crate.value + " " + channel.value;
00607 } catch(ConfigurationException e) {
00608 ret = "No ROD mapping defined";
00609 }
00610 break;
00611 }
00612 case 2:
00613 {
00614 try {
00615 IntHolder partition = new IntHolder(), crate = new IntHolder(),
00616 channel = new IntHolder();
00617 config.translateToPowerSupply(MUR.value, num.value,
00618 partition, crate, channel);
00619 ret = "Power: " + partition.value + " " + crate.value + " " + channel.value;
00620 } catch(ConfigurationException e) {
00621 ret = "No power mapping defined";
00622 }
00623 break;
00624 }
00625 case 3:
00626 {
00627 ret = "MUR " + MUR.value + ": " + num.value;
00628 break;
00629 }
00630 case 4:
00631 {
00632 try {
00633 config.getModuleConfig(m.getSN());
00634 ret = "Module Configuration defined";
00635 } catch(ConfigurationException e) {
00636 ret = "No module configuration defined!";
00637 }
00638 break;
00639 }
00640 default:
00641 }
00642 } else if(parent instanceof String) {
00643
00644 }
00645 } catch(ConfigurationException e) {
00646 ret = "Exception getting result";
00647 }
00648
00649 System.out.println(".");
00650 return ret;
00651 }
00652
00653 public int getChildCount(Object parent) {
00654 System.out.print("getChildCount of " + parent + ": ");
00655
00656 int ret = 0;
00657 try {
00658 if(parent == null) {
00659 ret = 0;
00660 } else if(parent.equals("Partitions")) {
00661 int[] parts = config.listPartitions();
00662 ret = parts.length;
00663 } else if(parent instanceof Proxies.PartitionProxy) {
00664 Proxies.PartitionProxy p = (Proxies.PartitionProxy)parent;
00665 int[] crates = config.listCratesInPartition(p.index());
00666 ret = crates.length;
00667 } else if(parent instanceof Proxies.CrateProxy) {
00668 Proxies.CrateProxy c = (Proxies.CrateProxy)parent;
00669 int[] rods = config.listRodsInCrate(c.partition(), c.index());
00670 ret = rods.length;
00671 } else if(parent instanceof Proxies.RodProxy) {
00672 Proxies.RodProxy r = (Proxies.RodProxy)parent;
00673 int[] MURs = config.listMURSInRod(r.partition(), r.crate(), r.index());
00674 ret = MURs.length;
00675 } else if(parent instanceof Proxies.MurProxy) {
00676 Proxies.MurProxy mur = (Proxies.MurProxy)parent;
00677
00678 ret = config.listModulesInMUR(mur.partition(), mur.id()).length;
00679 } else if(parent instanceof Proxies.ModuleProxy) {
00680 ret = 5;
00681 } else if(parent instanceof String) {
00682 ret = 0;
00683 }
00684 } catch(ConfigurationException e) {
00685 ret = 0;
00686 }
00687
00688 System.out.println(" " + ret + ".");
00689 return ret;
00690 }
00691
00692 public int getIndexOfChild(Object parent,
00693 Object child) {
00694 System.out.print("getIndexOfChild (" + child + " within " + parent + "): ");
00695 int ret = -1;
00696
00697 try {
00698 if(parent == null) {
00699 ret = -1;
00700 } else if(parent.equals("Partitions")) {
00701 int[] parts = config.listPartitions();
00702 int partition = ((Proxies.PartitionProxy)child).index();
00703 for(int i=0; i<parts.length; i++) {
00704 if(parts[i] == partition)
00705 ret = i;
00706 }
00707 } else if(parent instanceof Proxies.PartitionProxy) {
00708 Proxies.CrateProxy c = (Proxies.CrateProxy)child;
00709 Proxies.PartitionProxy p = (Proxies.PartitionProxy)parent;
00710 int[] crates = config.listCratesInPartition(p.index());
00711
00712 int crate = c.index();
00713 for(int i=0; i<crates.length; i++) {
00714 if(crates[i] == crate)
00715 ret = i;
00716 }
00717 } else if(parent instanceof Proxies.CrateProxy) {
00718 Proxies.RodProxy r = (Proxies.RodProxy)child;
00719 Proxies.CrateProxy c = (Proxies.CrateProxy)parent;
00720 int[] rods = config.listRodsInCrate(c.partition(), c.index());
00721
00722 int rod = r.index();
00723 for(int i=0; i<rods.length; i++) {
00724 if(rods[i] == rod)
00725 ret = i;
00726 }
00727 } else if(parent instanceof Proxies.RodProxy) {
00728 Proxies.MurProxy mur = (Proxies.MurProxy)child;
00729 Proxies.RodProxy r = (Proxies.RodProxy)parent;
00730 int[] murs = config.listMURSInRod(r.partition(), r.crate(), r.index());
00731
00732 int murId = mur.id();
00733 for(int i=0; i<murs.length; i++) {
00734 if(murs[i] == murId)
00735 ret = i;
00736 }
00737 } else if(parent instanceof Proxies.MurProxy) {
00738 Proxies.ModuleProxy module = (Proxies.ModuleProxy)child;
00739 Proxies.MurProxy mur = (Proxies.MurProxy)parent;
00740 String[] modules = config.listModulesInMUR(mur.partition(), mur.index());
00741
00742 String sn = module.getSN();
00743 for(int i=0; i<modules.length; i++) {
00744 if(modules[i].equals(sn)) {
00745 ret = i;
00746 break;
00747 }
00748 }
00749
00750
00751 IntHolder MUR = new IntHolder(), mod = new IntHolder();
00752 config.translateFromSN(module.toString(), MUR, mod);
00753
00754 if(MUR.value != mur.id()) {
00755 System.out.print("\n (translateFromSN returned MUR " + MUR.value + " Stored is " + mur.id() + "!)");
00756 }
00757 } else if(parent instanceof Proxies.ModuleProxy) {
00758 ret = 0;
00759
00760 System.out.print("(Count strings...)");
00761
00762 for(int i=0; i<5; i++) {
00763 if(getChild(parent, i).equals(child)) {
00764 ret = i;
00765 break;
00766 }
00767 }
00768 } else if(parent instanceof String) {
00769
00770 ret = -1;
00771 }
00772 } catch(ConfigurationException e) {
00773 ret = 0;
00774 }
00775 System.out.println(" " + ret + ".");
00776 return ret;
00777 }
00778
00779 public boolean isLeaf(Object node) {
00780 if(node instanceof String) {
00781 if(node != "Partitions") {
00782 return true;
00783 }
00784 }
00785 return false;
00786 }
00787
00788 public void valueForPathChanged(TreePath path,
00789 Object newValue) {
00790 }
00791
00792 public void addTreeModelListener(TreeModelListener l) {
00793 System.out.println("Add listener " + l);
00794 listeners.add(l);
00795 }
00796
00797 public void removeTreeModelListener(TreeModelListener l) {
00798 System.out.println("Remove listener " + l);
00799 listeners.remove(l);
00800 }
00801
00802
00803 public void modified(Object o) {
00804 for(Enumeration e = listeners.elements(); e.hasMoreElements(); ) {
00805 TreeModelListener t = (TreeModelListener)e.nextElement();
00806
00807 Object [] path = new Object[1];
00808
00809 path[0] = "Partitions";
00810
00811 TreeModelEvent ev = new TreeModelEvent(this, path);
00812
00813 t.treeStructureChanged(ev);
00814 }
00815 }
00816
00817
00818 public void modified(Object [] path) {
00819 for(Enumeration e = listeners.elements(); e.hasMoreElements(); ) {
00820 TreeModelListener t = (TreeModelListener)e.nextElement();
00821
00822 TreeModelEvent ev = new TreeModelEvent(this, path);
00823
00824
00825 t.treeStructureChanged(ev);
00826 }
00827 }
00828 }
00829 }