/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dae.prefabs.prefab.undo;

import com.jme3.scene.Node;
import dae.prefabs.Prefab;
import dae.prefabs.standard.UpdateObject;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotUndoException;

/**
 *
 * @author samyn_000
 */
public class UndoPrefabPropertyEdit extends AbstractUndoableEdit {

    private Node node;
    private String property;
    private Object oldValue;
    private Object newValue;
    private boolean significant = true;

    public UndoPrefabPropertyEdit(Node node, String property, Object oldValue, Object newValue) {
        this.node = node;
        this.property = property;
        this.oldValue = oldValue;
        this.newValue = newValue;
    }

    @Override
    public boolean canUndo() {
        return node instanceof Prefab;
    }

    @Override
    public boolean isSignificant() {
        return significant;
    }

    @Override
    public void undo() throws CannotUndoException {
        super.undo();
        if (node instanceof Prefab) {
            Prefab p = (Prefab) node;
            p.addUpdateObject(new UpdateObject(property,oldValue,false));
            //GlobalObjects.getInstance().postEvent(new PrefabChangedEvent(p));
        }
    }

    @Override
    public void redo() throws CannotUndoException {
        super.redo();
        if (node instanceof Prefab) {
            Prefab p = (Prefab) node;
            p.addUpdateObject(new UpdateObject(property,newValue,false));
            //GlobalObjects.getInstance().postEvent(new PrefabChangedEvent(p));
        }
    }

    public boolean compareEdit(UndoPrefabPropertyEdit toCompare) {
        return node == toCompare.node && property.equals(toCompare.property);
    }

    public void setSignificant(boolean significant) {
        this.significant = significant;
    }
    
    @Override
    public String toString(){
        return this.property + ":" + oldValue + " changed to " + newValue;
    }
}

@@ -1,108 +1,4 @@
-/*%0D%0A * To change this template, choose Tools %7C Templates%0D%0A * and open the template in the editor.%0D%0A */%0D%0A
 pack
@@ -86,16 +86,58 @@
 refab;%0D%0A
+import dae.prefabs.parameters.Parameter;%0D%0A
 import d
@@ -290,17 +290,18 @@
 hor 
-samyn_000
+Koen Samyn
 %0D%0A *
@@ -409,31 +409,35 @@
 private 
-String property
+Parameter parameter
 ;%0D%0A    p
@@ -583,23 +583,27 @@
 de, 
-String property
+Parameter parameter
 , Ob
@@ -682,26 +682,28 @@
 is.p
-roperty = property
+arameter = parameter
 ;%0D%0A 
@@ -1184,23 +1184,24 @@
 Object(p
-roperty
+arameter
 ,oldValu
@@ -1530,23 +1530,24 @@
 Object(p
-roperty
+arameter
 ,newValu
@@ -1769,23 +1769,24 @@
 ode && p
-roperty
+arameter
 .equals(
@@ -1796,23 +1796,24 @@
 ompare.p
-roperty
+arameter
 );%0D%0A    
@@ -1993,23 +1993,35 @@
 n this.p
-roperty
+arameter.toString()
  + %22:%22 +

Undo now uses the parameter to reset properties to their previous value.