• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 5521

Show
Ignore:
Timestamp:
06/23/08 17:04:21 (5 months ago)
Author:
will
Message:

ITreeManager is interface between Model and Tree.
NodeManagerMethods? is the new location of static node-manipulation methods.

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  
    3030 
    3131import ols.Observation; 
    32 import ols.ObservationCreator; 
    3332 
    3433import ui.XMLView; 
    … …  
    125124        } 
    126125         
    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         
    137127} 
  • branches/OmeroEditor/src/tree/Tree.java

    r5515 r5521  
    7474 
    7575public class Tree  
    76         implements ITreeModel { 
     76        implements   
     77        ITreeManager { 
    7778         
    7879        // this enum specifies a constructor that takes a String name, returned by toString(); 
    … …  
    320321                 
    321322                // 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); 
    324326                        undoSupport.postEdit(edit); 
    325327                        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); 
    332328                } 
    333329                 
    … …  
    338334        private void setRequiredFields() { 
    339335                // 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()); 
    348339                        undoSupport.postEdit(edit); 
    349340                        setTreeEdited(true); 
    … …  
    373364        } 
    374365 
     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         */ 
    375373        public void multiplyValueOfSelectedFields(float factor) { 
    376374                 
    … …  
    458456        } 
    459457 
    460         // duplicates all branches below oldNode, adding them to newNode 
    461         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          
    476458        // add a blank dataField 
    477459        private void addDataField() { 
    … …  
    481463                 
    482464                DataFieldNode newNode = new DataFieldNode(this);// make a new default-type field 
    483                 addDataField(newNode);  // adds after last highlighted field, or last child of root 
    484                  
    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 index 
    491          */ 
    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 name 
    498          * This is used for adding new OME-XML fields, therefore "inputType"=custom 
    499          */ 
    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 field 
    506                 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 root 
    509                  
    510                 UndoableEdit edit = new EditAddField(newNode); 
    511                 undoSupport.postEdit(edit); 
    512         } 
    513          
    514         /* 
    515          * Add a dataField of a defined inputType 
    516          */ 
    517         public void addDataFieldByType(String inputType) { 
    518                 setTreeEdited(true); 
    519                  
    520                 DataFieldNode newNode = new DataFieldNode(this);// make a new default-type field 
    521                 newNode.getDataField().setAttribute(DataFieldConstants.INPUT_TYPE, inputType, false); 
    522465                addDataField(newNode);  // adds after last highlighted field, or last child of root 
    523466                 
    … …  
    543486                } 
    544487                 
    545                 addDataField(newNode, parentNode, indexToInsert); 
     488                NodeManagerMethods.addDataField(newNode, parentNode, indexToInsert); 
    546489                 
    547490                nodeSelected(newNode, true); // select the new node 
    548491        } 
    549492 
     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         */ 
    550500        public void copyAndInsertDataFields(ArrayList<DataFieldNode> dataFieldNodes) { 
    551501                copyAndInsertDataFields(dataFieldNodes, highlightedFields); 
    … …  
    557507        } 
    558508         
    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) { 
    560518                 
    561519                int indexToInsert = 0; 
    … …  
    570528                        indexToInsert = lastHighlightedField.getMyIndexWithinSiblings() + 1; 
    571529                } 
    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                 
    623532        } 
    624533         
    … …  
    627536                 
    628537                try { 
    629                         demoteDataFields(highlightedFields); 
     538                        NodeManagerMethods.demoteDataFields(highlightedFields); 
    630539                         
    631540                        // add the undo action  
    … …  
    639548        } 
    640549         
    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 demote 
    650                 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 nodes 
    658                 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          
    668550        private void promoteDataFields() { 
    669551                if (highlightedFields.isEmpty()) return; 
    … …  
    673555                        UndoableEdit edit = new EditPromoteFields(highlightedFields); 
    674556                         
    675                         promoteDataFields(highlightedFields); 
     557                        NodeManagerMethods.promoteDataFields(highlightedFields); 
    676558                         
    677559                        // if promoting went OK, add the undo action  
    … …  
    685567        } 
    686568         
    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 
    741570        private void moveFieldsUp() { 
    742571                 
    … …  
    746575                        UndoableEdit edit = new EditMoveFieldsUp(highlightedFields); 
    747576                         
    748                         moveFieldsUp(highlightedFields); 
     577                        NodeManagerMethods.moveFieldsUp(highlightedFields); 
    749578                         
    750579                        undoSupport.postEdit(edit); 
    … …  
    755584        } 
    756585         
    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 
    771587        private void moveFieldsDown() { 
    772588                 
    … …  
    776592                        UndoableEdit edit = new EditMoveFieldsDown(highlightedFields); 
    777593                         
    778                         moveFieldsDown(highlightedFields); 
     594                        NodeManagerMethods.moveFieldsDown(highlightedFields); 
    779595                         
    780596                        undoSupport.postEdit(edit); 
    … …  
    783599                        // ignore 
    784600                } 
    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 node 
    798                 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                  
    803601        } 
    804602         
    … …  
    935733                setTreeEdited(true); 
    936734                 
    937                 deleteDataFields(highlightedFields); 
     735                NodeManagerMethods.deleteDataFields(highlightedFields); 
    938736                highlightedFields.clear(); 
    939737                 
    940738        } 
    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 
    953740        // called (via dataField) by clicking on FormField to highlight it 
    954741        public void nodeSelected(DataFieldNode selectedNode, boolean clearOthers) { 
    … …  
    1042829        } 
    1043830         
    1044         /* 
     831        /** 
    1045832         *  getSearchResults(searchWord) 
    1046833         *  returns an ArrayList of DataField objects that contain the seachWord 
    … …  
    1062849        } 
    1063850         
    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         */  
    1084857        public JPanel getFieldEditorToDisplay() { 
    1085858                 
    … …  
    1096869                 
    1097870                return currentFieldEditor; 
    1098         } 
    1099          
    1100         /* getNameOfCurrnentField() 
    1101          * returns name of current field if one is highlighted 
    1102          * otherwise, returns the name of the parent field 
    1103          */ 
    1104         public String getNameOfCurrentFieldsParent() { 
    1105                 if (highlightedFields.isEmpty()) { 
    1106                         return rootNode.getName(); 
    1107                 } else { 
    1108                         return (highlightedFields.get(0).getParentNode().getName()); 
    1109                 } 
    1110871        } 
    1111872         
    … …  
    1126887        } 
    1127888         
    1128         public void selectionChanged() { 
     889        private void selectionChanged() { 
    1129890                if (selectionObserver != null) { 
    1130891                        // System.out.println("Tree.selectionChanged"); 
    … …  
    1133894        } 
    1134895         
     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         */ 
    1135903        public ArrayList<DataFieldNode> getHighlightedFields() { 
    1136904                if (rootNode.isHighlighted()) { 
    … …  
    14021170        } 
    14031171         
    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         */  
    14051175        public void setFile (File file) { 
    14061176                this.file = file; 
    14071177        } 
     1178         
     1179        /** 
     1180         * Get the file that corresponds to this tree. 
     1181         * @return              The file that this tree is read from/saved to. 
     1182         */ 
    14081183        public File getFile () { 
    14091184                return file; 
    … …  
    14311206        } 
    14321207         
    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         */ 
    14421212        public void setTreeEdited(boolean edited) { 
    14431213                System.out.println("Tree Edited = " + edited); 
    … …  
    14451215        } 
    14461216         
     1217        /** 
     1218         * Used (for example) for seeing whether you need to save before closing.  
     1219         */ 
    14471220        public boolean isTreeEdited() { 
    14481221                return treeEdited; 
    14491222        } 
    14501223         
     1224        /** 
     1225         * For UI - Undo button 
     1226&n