Project

General

Profile

« Previous | Next » 

Revision 64377e70

Added by Andreas Müller over 10 years ago

some changes for sortindex handling

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
231 231

  
232 232
        child.setParentTreeNode(this, index);
233 233

  
234

  
235
//		child.setParent(this);
236
//		child.setClassification(this.getClassification());
237
//		childNodes.add(index, child);
234
		//TODO workaround (see sortIndex doc) => not really required anymore here, as it is done in child.setParentTreeNode already
235
		for(int i = 0; i < childNodes.size(); i++){
236
			childNodes.get(i).sortIndex = i;
237
		}
238
		child.sortIndex = index;
239
		
238 240
        //TODO workaround (see sortIndex doc)
239 241
        for(int i = 0; i < childNodes.size(); i++){
240 242
            childNodes.get(i).sortIndex = i;
......
243 245

  
244 246
        child.setReference(reference);
245 247
        child.setMicroReference(microReference);
246
//        childNode.setSynonymToBeUsed(synonymToBeUsed);
247 248

  
248 249
        return child;
249 250

  
......
516 517
        setClassificationRecursively(classification);
517 518

  
518 519
        // add this node to the parent child nodes
519
        List<TaxonNode> children = parent.getChildNodes();
520
        if (children.contains(this)){
521
            //avoid duplicates
522
            if (children.indexOf(this) < index){
523
                index = index -1;
524
            }
525
            children.remove(this);
526
            children.add(index, this);
520
        List<TaxonNode> parentChildren = parent.getChildNodes();
521
        if (parentChildren.contains(this)){
522
        	//avoid duplicates
523
        	if (parentChildren.indexOf(this) < index){
524
        		index = index -1;
525
        	}
526
        	parentChildren.remove(this);
527
        	parentChildren.add(index, this);
527 528
        }else{
528
            children.add(index, this);
529
        	parentChildren.add(index, this);
529 530
        }
530 531

  
531 532
        //TODO workaround (see sortIndex doc)
532
        //FIXME don't we need to update the parent's childNode index here??
533
        for(int i = 0; i < childNodes.size(); i++){
534
            childNodes.get(i).sortIndex = i;
535
        }
536
        this.sortIndex = index;
537

  
533
        //TODO check if it is correct to use the parentChildren here 
534
		for(int i = 0; i < parentChildren.size(); i++){
535
			parentChildren.get(i).sortIndex = i;
536
		}
537
//		this.sortIndex = index;
538
        
538 539
        // update the children count
539 540
        if(parent instanceof TaxonNode){
540 541
            TaxonNode parentTaxonNode = (TaxonNode) parent;

Also available in: Unified diff