Changeset 5521
- Timestamp:
- 06/23/08 17:04:21 (5 months ago)
- Location:
- branches/OmeroEditor/src
- Files:
-
- 2 added
- 1 removed
- 13 modified
-
main/ProtocolEditor.java (modified) (2 diffs)
-
ols/ObservationCreator.java (deleted)
-
tree/ITreeManager.java (added)
-
tree/NodeManagerMethods.java (added)
-
tree/Tree.java (modified) (28 diffs)
-
tree/edit/EditAddField.java (modified) (2 diffs)
-
tree/edit/EditDeleteField.java (modified) (2 diffs)
-
tree/edit/EditDemoteFields.java (modified) (2 diffs)
-
tree/edit/EditDuplicateFields.java (modified) (2 diffs)
-
tree/edit/EditImportFields.java (modified) (2 diffs)
-
tree/edit/EditMoveFieldsDown.java (modified) (2 diffs)
-
tree/edit/EditMoveFieldsUp.java (modified) (2 diffs)
-
tree/edit/EditPasteFields.java (modified) (2 diffs)
-
tree/edit/EditPromoteFields.java (modified) (3 diffs)
-
ui/XMLView.java (modified) (1 diff)
-
xmlMVC/XMLModel.java (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/OmeroEditor/src/main/ProtocolEditor.java
r5206 r5521 30 30 31 31 import ols.Observation; 32 import ols.ObservationCreator;33 32 34 33 import ui.XMLView; … … 125 124 } 126 125 127 /** 128 * Returns a list of <code>Observation</code> objects 129 * These are fields that the user chooses, to correspond to observations they intend to make from their results. 130 * An external application, such as Phenote, will use these to create a results table, for collection of data. 131 * 132 * @return a list of Observation objects 133 */ 134 public List<Observation> getObservations() { 135 return ObservationCreator.getObservations(model); 136 } 126 137 127 } -
branches/OmeroEditor/src/tree/Tree.java
r5515 r5521 74 74 75 75 public class Tree 76 implements ITreeModel { 76 implements 77 ITreeManager { 77 78 78 79 // this enum specifies a constructor that takes a String name, returned by toString(); … … 320 321 321 322 // if fields are highlighted, lock them. 322 if (highlightedFields.size() > 0) { 323 UndoableEdit edit = new EditLockFields(highlightedFields, lockingAttributes); 323 if (getHighlightedFields().size() > 0) { 324 UndoableEdit edit = new EditLockFields(getHighlightedFields(), 325 lockingAttributes); 324 326 undoSupport.postEdit(edit); 325 327 setTreeEdited(true); 326 327 // or if the root node is highlighted, lock it.328 } else if (rootNode.isHighlighted()) {329 UndoableEdit edit = new EditLockFields(rootNode, lockingAttributes);330 undoSupport.postEdit(edit);331 setTreeEdited(true);332 328 } 333 329 … … 338 334 private void setRequiredFields() { 339 335 // if fields are highlighted, set required for them. 340 if (highlightedFields.size() > 0) { 341 UndoableEdit edit = new EditRequiredField(highlightedFields); 342 undoSupport.postEdit(edit); 343 setTreeEdited(true); 344 345 // or if the root node is highlighted, make required! 346 } else if (rootNode.isHighlighted()) { 347 UndoableEdit edit = new EditRequiredField(rootNode); 336 337 if (getHighlightedFields().size() > 0) { 338 UndoableEdit edit = new EditRequiredField(getHighlightedFields()); 348 339 undoSupport.postEdit(edit); 349 340 setTreeEdited(true); … … 373 364 } 374 365 366 /** 367 * For all highlighted fields that are Number Fields, the numerical value 368 * they contain is multiplied by the factor argument. 369 * Fields of other types are ignored. 370 * 371 * @param factor The value to multiply numerical field values by. 372 */ 375 373 public void multiplyValueOfSelectedFields(float factor) { 376 374 … … 458 456 } 459 457 460 // duplicates all branches below oldNode, adding them to newNode461 private static void duplicateDataFieldTree(DataFieldNode oldNode, DataFieldNode newNode) {462 463 ArrayList<DataFieldNode> children = oldNode.getChildren();464 if (children.size() == 0) return;465 466 for (DataFieldNode copyThisChild: children){467 468 DataFieldNode newChild = new DataFieldNode(copyThisChild);469 470 newNode.addChild(newChild);471 472 duplicateDataFieldTree(copyThisChild, newChild);473 }474 }475 476 458 // add a blank dataField 477 459 private void addDataField() { … … 481 463 482 464 DataFieldNode newNode = new DataFieldNode(this);// make a new default-type field 483 addDataField(newNode); // adds after last highlighted field, or last child of root484 485 UndoableEdit edit = new EditAddField(newNode);486 undoSupport.postEdit(edit);487 }488 489 /**490 * add the newNode as a child of parentNode at the specified index491 */492 public static void addDataField(DataFieldNode newNode, DataFieldNode parentNode, int indexToInsert) {493 newNode.setParent(parentNode);494 parentNode.addChild(indexToInsert, newNode);495 }496 497 /* add a blank dataField, by name498 * This is used for adding new OME-XML fields, therefore "inputType"=custom499 */500 public void addDataField(String fieldName) {501 // add the undo action (include rootNode reference, in case no highlighted fields)502 // undoActions.push(new TreeAction(Actions.ADD_NEW_FIELD, highlightedFields, rootNode));503 setTreeEdited(true);504 505 DataFieldNode newNode = new DataFieldNode(this);// make a new default-type field506 newNode.getDataField().setAttribute(DataFieldConstants.ELEMENT_NAME, fieldName, false);507 newNode.getDataField().setAttribute(DataFieldConstants.INPUT_TYPE, DataFieldConstants.CUSTOM, false);508 addDataField(newNode); // adds after last highlighted field, or last child of root509 510 UndoableEdit edit = new EditAddField(newNode);511 undoSupport.postEdit(edit);512 }513 514 /*515 * Add a dataField of a defined inputType516 */517 public void addDataFieldByType(String inputType) {518 setTreeEdited(true);519 520 DataFieldNode newNode = new DataFieldNode(this);// make a new default-type field521 newNode.getDataField().setAttribute(DataFieldConstants.INPUT_TYPE, inputType, false);522 465 addDataField(newNode); // adds after last highlighted field, or last child of root 523 466 … … 543 486 } 544 487 545 addDataField(newNode, parentNode, indexToInsert);488 NodeManagerMethods.addDataField(newNode, parentNode, indexToInsert); 546 489 547 490 nodeSelected(newNode, true); // select the new node 548 491 } 549 492 493 /** 494 * Used to take a list of Nodes, eg from clip-board, or another tree, 495 * to duplicate them, then insert them after the last highlighted 496 * field (or after last child of root if none highlighted) 497 * 498 * @param dataFieldNodes 499 */ 550 500 public void copyAndInsertDataFields(ArrayList<DataFieldNode> dataFieldNodes) { 551 501 copyAndInsertDataFields(dataFieldNodes, highlightedFields); … … 557 507 } 558 508 559 public void copyAndInsertDataFields(ArrayList<DataFieldNode> dataFieldNodes, ArrayList<DataFieldNode> selectedFields) { 509 /** 510 * Duplicates the dataFieldNodes, and inserts them as siblings to 511 * selectedFields (after the last selected field) 512 * 513 * @param dataFieldNodes The nodes to duplicate 514 * @param selectedFields Add as siblings to these nodes, after last one. 515 */ 516 private void copyAndInsertDataFields(ArrayList<DataFieldNode> dataFieldNodes, 517 ArrayList<DataFieldNode> selectedFields) { 560 518 561 519 int indexToInsert = 0; … … 570 528 indexToInsert = lastHighlightedField.getMyIndexWithinSiblings() + 1; 571 529 } 572 copyAndInsertDataFields(dataFieldNodes, parentNode, indexToInsert); 573 574 } 575 576 // copy and add new dataFields 577 // used by import, paste, and duplicate functions 578 public static void copyAndInsertDataFields(ArrayList<DataFieldNode> dataFieldNodes,DataFieldNode parentNode, int indexToInsert) { 579 580 if (dataFieldNodes.isEmpty()) return; 581 582 583 //remember the first node added, so all new nodes can be selected when done 584 DataFieldNode firstNewNode = null; 585 DataFieldNode newNode = null; 586 587 for (int i=0; i< dataFieldNodes.size(); i++){ 588 589 newNode = new DataFieldNode(dataFieldNodes.get(i)); 590 duplicateDataFieldTree(dataFieldNodes.get(i), newNode); 591 592 addDataField(newNode, parentNode, indexToInsert); 593 indexToInsert++; 594 595 if (i == 0) firstNewNode = newNode; 596 } 597 598 newNode.nodeClicked(true); 599 firstNewNode.nodeClicked(false); // will select the range 600 } 601 602 // don't copy DataFields, just insert the same ones 603 public static void insertTheseDataFields(ArrayList<DataFieldNode> dataFieldNodes,DataFieldNode parentNode, int indexToInsert) { 604 605 if (dataFieldNodes.isEmpty()) return; 606 607 //remember the first node added, so all new nodes can be selected when done 608 DataFieldNode firstNewNode = null; 609 DataFieldNode newNode = null; 610 611 for (int i=0; i< dataFieldNodes.size(); i++){ 612 613 newNode = dataFieldNodes.get(i); 614 615 addDataField(newNode, parentNode, indexToInsert); 616 indexToInsert++; 617 618 if (i == 0) firstNewNode = newNode; 619 } 620 621 newNode.nodeClicked(true); 622 firstNewNode.nodeClicked(false); // will select the range 530 NodeManagerMethods.copyAndInsertDataFields(dataFieldNodes, parentNode, indexToInsert); 531 623 532 } 624 533 … … 627 536 628 537 try { 629 demoteDataFields(highlightedFields);538 NodeManagerMethods.demoteDataFields(highlightedFields); 630 539 631 540 // add the undo action … … 639 548 } 640 549 641 public static void demoteDataFields(ArrayList<DataFieldNode> fields) {642 643 if (fields.isEmpty()) return;644 645 // fields need to become children of their preceding sibling (if they have one)646 DataFieldNode firstNode = fields.get(0);647 int indexOfFirstSibling = firstNode.getMyIndexWithinSiblings();648 649 // if no preceding sibling, can't demote650 if (indexOfFirstSibling == 0) {651 throw (new NullPointerException("Can't demote because no preceding sibling"));652 }653 654 DataFieldNode parentNode = firstNode.getParentNode();655 DataFieldNode preceedingSiblingNode = parentNode.getChild(indexOfFirstSibling-1);656 657 // move nodes658 for (DataFieldNode highlightedField: fields) {659 preceedingSiblingNode.addChild(highlightedField);660 }661 // delete them from the end (reverse order)662 for (int i=fields.size()-1; i>=0; i--) {663 parentNode.removeChild(fields.get(i));664 }665 }666 667 668 550 private void promoteDataFields() { 669 551 if (highlightedFields.isEmpty()) return; … … 673 555 UndoableEdit edit = new EditPromoteFields(highlightedFields); 674 556 675 promoteDataFields(highlightedFields);557 NodeManagerMethods.promoteDataFields(highlightedFields); 676 558 677 559 // if promoting went OK, add the undo action … … 685 567 } 686 568 687 public static void promoteDataFields(ArrayList<DataFieldNode> fields) { 688 689 if (fields.isEmpty()) return; 690 691 DataFieldNode node = fields.get(0); 692 DataFieldNode parentNode = node.getParentNode(); 693 DataFieldNode grandParentNode = parentNode.getParentNode(); 694 // if parent is root (grandparent null) then can't promote 695 if (grandParentNode == null) { 696 throw (new NullPointerException("Can't promote because grandparent is null")); 697 } 698 699 // any fields that are children of the last to be promoted, 700 // must first become children of that node. 701 DataFieldNode lastNode = fields.get(fields.size()-1); 702 DataFieldNode lastNodeParent = lastNode.getParentNode(); 703 704 int indexOfLast = lastNodeParent.indexOfChild(lastNode); 705 int numChildren = lastNodeParent.getChildren().size(); 706 707 // copy children in correct order 708 for (int i=indexOfLast+1; i< numChildren; i++) { 709 DataFieldNode nodeToCopy = lastNodeParent.getChild(i); 710 lastNode.addChild(nodeToCopy); 711 } 712 // delete them from the end (reverse order) 713 for (int i=numChildren-1; i>indexOfLast; i--) { 714 lastNodeParent.removeChild(lastNodeParent.getChild(i)); 715 } 716 717 // loop backwards so that the top field is last added, next to parent 718 for (int i=fields.size()-1; i >=0; i--) { 719 promoteDataField(fields.get(i)); 720 } 721 722 } 723 724 // promotes a dataField to become a sibling of it's parent 725 public static void promoteDataField(DataFieldNode node) { 726 727 DataFieldNode parentNode = node.getParentNode(); 728 DataFieldNode grandParentNode = parentNode.getParentNode(); 729 730 // if parent is root (grandparent null) then can't promote 731 // if (grandParentNode == null) return; catch any null pointer exception later 732 733 int indexOfParent = grandParentNode.indexOfChild(parentNode); 734 735 grandParentNode.addChild(indexOfParent + 1, node); // adds after parent 736 node.setParent(grandParentNode); 737 parentNode.removeChild(node); 738 } 739 740 // if the highlighted fields have a preceding sister, move it below the highlighted fields 569 // if the highlighted fields have a preceding sister, move it below the highlighted fields 741 570 private void moveFieldsUp() { 742 571 … … 746 575 UndoableEdit edit = new EditMoveFieldsUp(highlightedFields); 747 576 748 moveFieldsUp(highlightedFields);577 NodeManagerMethods.moveFieldsUp(highlightedFields); 749 578 750 579 undoSupport.postEdit(edit); … … 755 584 } 756 585 757 public static void moveFieldsUp(ArrayList<DataFieldNode> fields) throws IndexOutOfBoundsException { 758 int numFields = fields.size(); 759 760 DataFieldNode firstNode = fields.get(0); 761 int firstNodeIndex = firstNode.getMyIndexWithinSiblings(); 762 763 DataFieldNode parentNode = firstNode.getParentNode(); 764 DataFieldNode preceedingNode = parentNode.getChild(firstNodeIndex - 1); 765 // add the preceding node after the last node 766 parentNode.addChild(firstNodeIndex + numFields, preceedingNode); 767 parentNode.removeChild(preceedingNode); 768 } 769 770 // if the highlighted fields have a preceding sister, move it below the highlighted fields 586 // if the highlighted fields have a preceding sister, move it below the highlighted fields 771 587 private void moveFieldsDown() { 772 588 … … 776 592 UndoableEdit edit = new EditMoveFieldsDown(highlightedFields); 777 593 778 moveFieldsDown(highlightedFields);594 NodeManagerMethods.moveFieldsDown(highlightedFields); 779 595 780 596 undoSupport.postEdit(edit); … … 783 599 // ignore 784 600 } 785 }786 787 public static void moveFieldsDown(ArrayList<DataFieldNode> fields) throws IndexOutOfBoundsException {788 789 int numFields = fields.size();790 791 DataFieldNode lastNode = fields.get(numFields-1);792 DataFieldNode parentNode = lastNode.getParentNode();793 794 int lastNodeIndex = lastNode.getMyIndexWithinSiblings();795 796 DataFieldNode succeedingNode = parentNode.getChild(lastNodeIndex + 1);797 // add the succeeding node before the first node798 int indexToMoveTo = lastNodeIndex - numFields + 1;799 parentNode.addChild(indexToMoveTo, succeedingNode);800 // remove the succeeding node (now 1 more position down the list - after inserting above)801 parentNode.removeChild(lastNodeIndex + 2);802 803 601 } 804 602 … … 935 733 setTreeEdited(true); 936 734 937 deleteDataFields(highlightedFields);735 NodeManagerMethods.deleteDataFields(highlightedFields); 938 736 highlightedFields.clear(); 939 737 940 738 } 941 // delete the highlighted dataFields 942 public static void deleteDataFields(ArrayList<DataFieldNode> fields) { 943 for (DataFieldNode node: fields) { 944 deleteDataField(node); 945 } 946 } 947 public static void deleteDataField(DataFieldNode node) { 948 DataFieldNode parentNode = node.getParentNode(); 949 parentNode.removeChild(node); 950 } 951 952 739 953 740 // called (via dataField) by clicking on FormField to highlight it 954 741 public void nodeSelected(DataFieldNode selectedNode, boolean clearOthers) { … … 1042 829 } 1043 830 1044 /* 831 /** 1045 832 * getSearchResults(searchWord) 1046 833 * returns an ArrayList of DataField objects that contain the seachWord … … 1062 849 } 1063 850 1064 /* 1065 * Goes through the Tree, adding the observation fields to a list 1066 */ 1067 public ArrayList<IAttributeSaver> getObservationFields() { 1068 ArrayList<IAttributeSaver> observationFields = new ArrayList<IAttributeSaver>(); 1069 1070 Iterator <DataFieldNode>iterator = rootNode.iterator(); 1071 1072 while (iterator.hasNext()) { 1073 DataFieldNode node = iterator.next(); 1074 IAttributeSaver field = node.getDataField(); 1075 if (field.getAttribute(DataFieldConstants.INPUT_TYPE).equals(DataFieldConstants.OBSERVATION_DEFINITION)) { 1076 observationFields.add(field); 1077 } 1078 } 1079 return observationFields; 1080 } 1081 1082 // called when the UI needs to display the FieldEditor 1083 // if only one field is currently selected, return it. Else return blank 851 852 /** 853 * called when the UI needs to display the FieldEditor. 854 * If only one field is currently selected, return it. Else return 855 * a blank panel 856 */ 1084 857 public JPanel getFieldEditorToDisplay() { 1085 858 … … 1096 869 1097 870 return currentFieldEditor; 1098 }1099 1100 /* getNameOfCurrnentField()1101 * returns name of current field if one is highlighted1102 * otherwise, returns the name of the parent field1103 */1104 public String getNameOfCurrentFieldsParent() {1105 if (highlightedFields.isEmpty()) {1106 return rootNode.getName();1107 } else {1108 return (highlightedFields.get(0).getParentNode().getName());1109 }1110 871 } 1111 872 … … 1126 887 } 1127 888 1128 p ublicvoid selectionChanged() {889 private void selectionChanged() { 1129 890 if (selectionObserver != null) { 1130 891 // System.out.println("Tree.selectionChanged"); … … 1133 894 } 1134 895 896 /** 897 * Gets a list of the currently highlighted nodes. 898 * Used by other classes for copy and paste, or within this 899 * class for applying tree edits. 900 * 901 * @return The highlighted nodes. 902 */ 1135 903 public ArrayList<DataFieldNode> getHighlightedFields() { 1136 904 if (rootNode.isHighlighted()) { … … 1402 1170 } 1403 1171 1404 // keep a note of the file that corresponds to this tree 1172 /** 1173 * keep a note of the file that corresponds to this tree 1174 */ 1405 1175 public void setFile (File file) { 1406 1176 this.file = file; 1407 1177 } 1178 1179 /** 1180 * Get the file that corresponds to this tree. 1181 * @return The file that this tree is read from/saved to. 1182 */ 1408 1183 public File getFile () { 1409 1184 return file; … … 1431 1206 } 1432 1207 1433 // turn on/off xmlValidation 1434 public void setXmlValidation(boolean validationOn) { 1435 this.xmlValidationOn = validationOn; 1436 } 1437 public boolean getXmlValidation() { 1438 return xmlValidationOn; 1439 } 1440 1441 // when the data structure changes, edited = true. When saved, edited = false 1208 /** 1209 * when the data structure changes, edited = true. 1210 * When saved, edited = false 1211 */ 1442 1212 public void setTreeEdited(boolean edited) { 1443 1213 System.out.println("Tree Edited = " + edited); … … 1445 1215 } 1446 1216 1217 /** 1218 * Used (for example) for seeing whether you need to save before closing. 1219 */ 1447 1220 public boolean isTreeEdited() { 1448 1221 return treeEdited; 1449 1222 } 1450 1223 1224 /** 1225 * For UI - Undo button 1226 &n
