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