package org.ovirt.engine.ui.uicommonweb.models;

import java.util.List;

import org.ovirt.engine.core.common.mode.ApplicationMode;
import org.ovirt.engine.ui.uicommonweb.TreeNodeInfo;
import org.ovirt.engine.ui.uicompat.ObservableCollection;
import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;

public class SystemTreeItemModel extends EntityModel implements TreeNodeInfo {

    private SystemTreeItemType type = SystemTreeItemType.values()[0];
    private ApplicationMode applicationMode = ApplicationMode.AllModes;

    public ApplicationMode getApplicationMode() {
        return applicationMode;
    }

    public void setApplicationMode(ApplicationMode applicationMode) {
        this.applicationMode = applicationMode;
    }

    public SystemTreeItemType getType()
    {
        return type;
    }

    public void setType(SystemTreeItemType value)
    {
        if (type != value)
        {
            type = value;
            onPropertyChanged(new PropertyChangedEventArgs("Type")); //$NON-NLS-1$
        }
    }

    private List<SystemTreeItemModel> privateChildren;

    @Override
    public List<SystemTreeItemModel> getChildren()
    {
        return privateChildren;
    }

    public void setChildren(List<SystemTreeItemModel> value)
    {
        privateChildren = value;
    }

    public void addChild(SystemTreeItemModel value) {
        privateChildren.add(value);
        if (value != null) {
            value.setParent(this);
        }
    }

    private SystemTreeItemModel privateParent;

    @Override
    public SystemTreeItemModel getParent()
    {
        return privateParent;
    }

    private void setParent(SystemTreeItemModel value)
    {
        privateParent = value;
    }

    private boolean isExpanded;

    public boolean getIsExpanded()
    {
        return isExpanded;
    }

    public void setIsExpanded(boolean value)
    {
        if (isExpanded != value)
        {
            isExpanded = value;
            onPropertyChanged(new PropertyChangedEventArgs("IsExpanded")); //$NON-NLS-1$
        }
    }

    public SystemTreeItemModel()
    {
        setChildren(new ObservableCollection<SystemTreeItemModel>());
    }

    public static SystemTreeItemModel findAncestor(SystemTreeItemType type, SystemTreeItemModel root)
    {
        if (root != null && root.getType() != type)
        {
            if (root.getParent() != null)
            {
                return findAncestor(type, root.getParent());
            }

            return null;
        }

        return root;
    }

    @Override
    public boolean equals(Object other) {
        return equals(other, false);
    }

    public boolean equals(Object other, boolean deepCompare) {
        if (other == this) {
            return true;
        }
        if (other == null || other.getClass() != getClass()) {
            return false;
        }
        boolean result = true;
        SystemTreeItemModel otherModel = (SystemTreeItemModel) other;
        if (getChildren().size() > 0 && deepCompare) {
            if (otherModel.getChildren().size() == getChildren().size()) {
                for (int i = 0; i < getChildren().size(); i++) {
                    result = getChildren().get(i).equals(otherModel.getChildren().get(i), deepCompare);
                    if (!result) {
                        break;
                    }
                }
            } else {
                result = false;
            }
        }
        if (result) {
            if (!((otherModel.getEntity() == null && getEntity() == null)
                    || (otherModel.getEntity() != null && otherModel.getEntity().equals(getEntity())
                    && ((otherModel.getTitle() == null && getTitle() == null)
                            || (otherModel.getTitle() != null && otherModel.getTitle().equals(getTitle())))))) {
                result = false;
            }
        }
        return result;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((getEntity() == null) ? 0 : getEntity().hashCode());
        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
        return result;
    }

}

@@ -124,16 +124,71 @@
 onMode;%0A
+import org.ovirt.engine.core.common.utils.ObjectUtils;%0A
 import o
@@ -2925,39 +2925,8 @@
   %7D%0A
-        boolean result = true;%0A
     
@@ -3003,308 +3003,225 @@
     
-if (getChildren().size() %3E 0 && deepCompare) %7B%0A            if (otherModel.getChildren().size() == getChildren().size()) %7B%0A                for (int i = 0; i %3C getChildren().size(); i++) %7B%0A                    result = getChildren().get(i).equals(otherModel.getChildren().get(i), deepCompare);%0A         
+boolean result = true;%0A%0A        // Compare item's attributes%0A        if (!ObjectUtils.objectsEqual(getType(), otherModel.getType())%0A                %7C%7C !ObjectUtils.objectsEqual(getEntity(), otherModel.getEntity())) %7B%0A
     
@@ -3231,34 +3231,33 @@
     
-if (!
+ 
 result
-) %7B%0A   
+ = false;%0A
         
     
@@ -3248,32 +3248,35 @@
 se;%0A        
+%7D%0A%0A
         
      break;%0A
@@ -3267,531 +3267,502 @@
     
-     break;%0A                    %7D%0A                %7D%0A            %7D else %7B%0A                result = false;%0A            %7D%0A        %7D%0A        if (result) %7B%0A            if (!((otherModel.getEntity() == null && getEntity() == null)%0A                    %7C%7C (otherModel.getEntity() != null && otherModel.getEntity().equals(getEntity())%0A                    && ((otherModel.getTitle() == null && getTitle() == null)%0A                            %7C%7C (otherModel.getTitle() != null && otherModel.getTitle().equals(getTitle())))))) %7B%0A
+// Compare item's children, if necessary%0A        if (result && getChildren().size() %3E 0 && deepCompare) %7B%0A            if (getChildren().size() != otherModel.getChildren().size()) %7B%0A                result = false;%0A            %7D else %7B%0A                for (int i = 0; i %3C getChildren().size(); i++) %7B%0A                    if (!getChildren().get(i).equals(otherModel.getChildren().get(i), deepCompare)) %7B%0A                        result = false;%0A                        break;%0A             
       
+ %7D%0A
     
@@ -3763,39 +3763,31 @@
 %7D%0A          
-result = false;
+      %7D
 %0A           
@@ -3791,32 +3791,33 @@
     %7D%0A        %7D%0A
+%0A
         return r
@@ -3980,22 +3980,20 @@
  + ((get
-Entity
+Type
 () == nu
@@ -4005,22 +4005,20 @@
  0 : get
-Entity
+Type
 ().hashC
@@ -4064,21 +4064,22 @@
  + ((get
-Title
+Entity
 () == nu
@@ -4095,13 +4095,14 @@
  get
-Title
+Entity
 ().h

Fix SystemTreeItemModel equals method