blob: 2bdbaed59bf83b738d9bd14715a2532e3b1b720f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2011 Abel Hegedus and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Abel Hegedus - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.core.tracebased;
import org.eclipse.viatra2.core.EDeleteSemantics;
import org.eclipse.viatra2.core.IEntity;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IModelManager;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.core.notification.ICoreNotificationObject;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectCreateEntity;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectCreateInstanceOf;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectCreateRelation;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectCreateSupertypeOf;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectDeleteContainment;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectDeleteEntity;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectDeleteInstanceOf;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectDeleteRelation;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectDeleteSupertypeOf;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectMoveTo;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectSetName;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectSetRelationFrom;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectSetRelationTo;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectSetValue;
import org.eclipse.viatra2.core.notification.ICoreNotificationObjectSetViewInfo;
import org.eclipse.viatra2.core.notification.NotificationType;
import org.eclipse.viatra2.core.simple.SimpleEntity;
import org.eclipse.viatra2.core.simple.SimpleModelElement;
import org.eclipse.viatra2.core.simple.SimpleRelation;
import org.eclipse.viatra2.errors.VPMCoreException;
import org.eclipse.viatra2.errors.VPMCoreNullParameterException;
import org.eclipse.viatra2.framework.IFramework;
import org.eclipse.viatra2.logger.Logger;
/**
* @author Abel Hegedus
*
*/
public class TraceNotificationProcessor {
private TraceModelManager mManager;
private Logger logger;
/**
*
*/
public TraceNotificationProcessor(TraceTreeManager manager, IFramework fw, IModelManager mManager) {
this.mManager = (TraceModelManager) mManager;
logger = fw.getLogger();
}
public boolean doExecuteEvent(ICoreNotificationObject note) throws TraceException{
// based on the event type and contents, manipulate the model
try{
NotificationType action = note.getActionTypeEnum();
switch(action){
case ACTION_ATOMIC_STEP_READY:
return false;
case ACTION_CREATE_ENTITY:
ICoreNotificationObjectCreateEntity _note = (ICoreNotificationObjectCreateEntity) note;
IEntity ent = _note.getCreated();
mManager.undoCreateEntity((SimpleEntity)ent, (SimpleEntity)_note.getContainer());
mManager.undoCreateContainment((SimpleEntity) _note.getContainer(), (SimpleEntity) ent);
return true;
case ACTION_DELETE_ENTITY:
ICoreNotificationObjectDeleteEntity _note1 = (ICoreNotificationObjectDeleteEntity) note;
IEntity ent1 = _note1.getDeleted();
mManager.deleteEntity(ent1, EDeleteSemantics.DELETE_SEMANTICS_FORCE);
return true;
case ACTION_CREATE_RELATION:
ICoreNotificationObjectCreateRelation _note2 = (ICoreNotificationObjectCreateRelation) note;
IRelation rel = _note2.getNewRelation();
mManager.undoCreateRelation((SimpleRelation) rel,
(SimpleModelElement) _note2.getFrom(),
(SimpleModelElement) _note2.getTo());
return true;
case ACTION_DELETE_RELATION:
ICoreNotificationObjectDeleteRelation _note3 = (ICoreNotificationObjectDeleteRelation) note;
mManager.deleteRelation(_note3.getDeleted(), EDeleteSemantics.DELETE_SEMANTICS_FORCE);
return true;
case ACTION_CREATE_INSTANCEOF:
ICoreNotificationObjectCreateInstanceOf _note4 = (ICoreNotificationObjectCreateInstanceOf) note;
SimpleModelElement sup = (SimpleModelElement) _note4.getType();
SimpleModelElement sub = (SimpleModelElement) _note4.getInstance();
mManager.newInstanceOfEditor(sup, sub);
return true;
case ACTION_DELETE_INSTANCEOF:
ICoreNotificationObjectDeleteInstanceOf _note5 = (ICoreNotificationObjectDeleteInstanceOf) note;
sup = (SimpleModelElement) _note5.getType();
sub = (SimpleModelElement) _note5.getInstance();
mManager.deleteInstanceOfEditor(sup, sub);
return true;
case ACTION_CREATE_SUPERTYPEOF:
ICoreNotificationObjectCreateSupertypeOf _note6 = (ICoreNotificationObjectCreateSupertypeOf) note;
sup = (SimpleModelElement) _note6.getSuper();
sub = (SimpleModelElement) _note6.getSub();
mManager.newSupertypeOfEditor(sup, sub);
return true;
case ACTION_DELETE_SUPERTYPEOF:
ICoreNotificationObjectDeleteSupertypeOf _note7 = (ICoreNotificationObjectDeleteSupertypeOf) note;
sup = (SimpleModelElement) _note7.getSuper();
sub = (SimpleModelElement) _note7.getSub();
mManager.deleteSupertypeOfEditor(sup, sub);
return true;
case ACTION_DELETE_CONTAINMENT:
// ICoreNotificationObjectDeleteContainment _note8 = (ICoreNotificationObjectDeleteContainment) note;
// SimpleEntity container = (SimpleEntity) _note8.getParent();
// SimpleEntity child = (SimpleEntity) _note8.getChild();
// mManager.undoCreateContainment(container, child);
// FIXME only called from delete entity, we can ignore it
return false;
case ACTION_MOVE_ELEMENT_TO:
ICoreNotificationObjectMoveTo _note11 = (ICoreNotificationObjectMoveTo) note;
ent = (SimpleEntity) _note11.getElement();
SimpleEntity to = (SimpleEntity) _note11.getNewContainer();
mManager.moveEntityTo(ent, to);
return true;
case ACTION_SET_VALUE:
ICoreNotificationObjectSetValue _note9 = (ICoreNotificationObjectSetValue) note;
ent = (SimpleEntity) _note9.getEntity();
String newValue = _note9.getNewValue();
mManager.setValue(ent, newValue);
return true;
case ACTION_SET_NAME:
ICoreNotificationObjectSetName _note10 = (ICoreNotificationObjectSetName) note;
SimpleModelElement elem = (SimpleModelElement) _note10.getElement();
String newName = _note10.getNewName();
mManager.setName(elem, newName);
return true;
case ACTION_SET_RELATION_FROM:
ICoreNotificationObjectSetRelationFrom _note12 = (ICoreNotificationObjectSetRelationFrom) note;
rel = (SimpleRelation) _note12.getRelation();
SimpleModelElement newFrom = (SimpleModelElement) _note12
.getNewFrom();
mManager.setRelationFrom(rel, newFrom);
return true;
case ACTION_SET_RELATION_TO:
ICoreNotificationObjectSetRelationTo _note13 = (ICoreNotificationObjectSetRelationTo) note;
rel = (SimpleRelation) _note13.getRelation();
SimpleModelElement newTo = (SimpleModelElement) _note13.getNewTo();
mManager.setRelationTo(rel, newTo);
return true;
case ACTION_SET_VIEW_INFO:
ICoreNotificationObjectSetViewInfo _note14 = (ICoreNotificationObjectSetViewInfo) note;
mManager.setViewInfo(_note14.getElement(), _note14.getNewViewInfo());
return true;
case USER_MARK:
return false;
}
}catch (VPMCoreNullParameterException e) {
logger.fatal("Error performing doExecute; [VPMNullParameterException] message: "
+ e.getMessage());
} catch (VPMCoreException e) {
throw (TraceException) new TraceException("Error performing doExecute; [VPMCoreException] message: "
+ e.getMessage()).fillInStackTrace();
}
/*
* Added a comment to this code to stop the undo manager from throwing unnecessary error messages
* which slowes down undo operations.
throw new VPMCoreRuntimeException("undo step not defined for step:"
+ note.toString());
*/
//logger.warning("undo step not defined for step:"+ note.toString());
return false;
}
public boolean undoEvent(ICoreNotificationObject note) throws TraceException{
// based on the event type and contents, reverse the model manipulation (see undo manager)
try{
NotificationType action = note.getActionTypeEnum();
switch(action){
case ACTION_ATOMIC_STEP_READY:
return false;
case ACTION_CREATE_ENTITY:
ICoreNotificationObjectCreateEntity _note = (ICoreNotificationObjectCreateEntity) note;
IEntity ent = _note.getCreated();
mManager
.deleteEntity(ent, EDeleteSemantics.DELETE_SEMANTICS_FORCE);
return true;
case ACTION_DELETE_ENTITY:
ICoreNotificationObjectDeleteEntity _note1 = (ICoreNotificationObjectDeleteEntity) note;
IEntity ent1 = _note1.getDeleted();
IEntity parent = _note1.getParent();
mManager
.undoCreateEntity((SimpleEntity) ent1, (SimpleEntity) parent);
return true;
case ACTION_CREATE_RELATION:
ICoreNotificationObjectCreateRelation _note2 = (ICoreNotificationObjectCreateRelation) note;
IRelation rel = _note2.getNewRelation();
mManager.deleteRelation(rel,
EDeleteSemantics.DELETE_SEMANTICS_FORCE);
return true;
case ACTION_DELETE_RELATION:
ICoreNotificationObjectDeleteRelation _note3 = (ICoreNotificationObjectDeleteRelation) note;
mManager.undoCreateRelation((SimpleRelation) _note3.getDeleted(),
(SimpleModelElement) _note3.getFrom(),
(SimpleModelElement) _note3.getTo());
return true;
case ACTION_CREATE_INSTANCEOF:
ICoreNotificationObjectCreateInstanceOf _note4 = (ICoreNotificationObjectCreateInstanceOf) note;
SimpleModelElement sup = (SimpleModelElement) _note4.getType();
SimpleModelElement sub = (SimpleModelElement) _note4.getInstance();
mManager.deleteInstanceOfEditor(sup, sub);
return true;
case ACTION_DELETE_INSTANCEOF:
ICoreNotificationObjectDeleteInstanceOf _note5 = (ICoreNotificationObjectDeleteInstanceOf) note;
sup = (SimpleModelElement) _note5.getType();
sub = (SimpleModelElement) _note5.getInstance();
mManager.newInstanceOfEditor(sup, sub);
return true;
case ACTION_CREATE_SUPERTYPEOF:
ICoreNotificationObjectCreateSupertypeOf _note6 = (ICoreNotificationObjectCreateSupertypeOf) note;
sup = (SimpleModelElement) _note6.getSuper();
sub = (SimpleModelElement) _note6.getSub();
mManager.deleteSupertypeOfEditor(sup, sub);
return true;
case ACTION_DELETE_SUPERTYPEOF:
ICoreNotificationObjectDeleteSupertypeOf _note7 = (ICoreNotificationObjectDeleteSupertypeOf) note;
sup = (SimpleModelElement) _note7.getSuper();
sub = (SimpleModelElement) _note7.getSub();
mManager.newSupertypeOfEditor(sup, sub);
return true;
case ACTION_DELETE_CONTAINMENT:
ICoreNotificationObjectDeleteContainment _note8 = (ICoreNotificationObjectDeleteContainment) note;
SimpleEntity container = (SimpleEntity) _note8.getParent();
SimpleEntity child = (SimpleEntity) _note8.getChild();
mManager.undoCreateContainment(container, child);
return true;
case ACTION_SET_VALUE:
ICoreNotificationObjectSetValue _note9 = (ICoreNotificationObjectSetValue) note;
ent = (SimpleEntity) _note9.getEntity();
String oldValue = _note9.getOldValue();
mManager.setValue(ent, oldValue);
return true;
case ACTION_SET_NAME:
ICoreNotificationObjectSetName _note10 = (ICoreNotificationObjectSetName) note;
SimpleModelElement elem = (SimpleModelElement) _note10.getElement();
String oldName = _note10.getOldName();
mManager.setName(elem, oldName);
return true;
case ACTION_MOVE_ELEMENT_TO:
ICoreNotificationObjectMoveTo _note11 = (ICoreNotificationObjectMoveTo) note;
ent = (SimpleEntity) _note11.getElement();
SimpleEntity from = (SimpleEntity) _note11.getOldContainer();
mManager.moveEntityTo(ent, from);
return true;
case ACTION_SET_RELATION_FROM:
ICoreNotificationObjectSetRelationFrom _note12 = (ICoreNotificationObjectSetRelationFrom) note;
rel = (SimpleRelation) _note12.getRelation();
SimpleModelElement oldFrom = (SimpleModelElement) _note12
.getOldFrom();
mManager.setRelationFrom(rel, oldFrom);
return true;
case ACTION_SET_RELATION_TO:
ICoreNotificationObjectSetRelationTo _note13 = (ICoreNotificationObjectSetRelationTo) note;
rel = (SimpleRelation) _note13.getRelation();
SimpleModelElement oldTo = (SimpleModelElement) _note13.getOldTo();
mManager.setRelationTo(rel, oldTo);
return true;
case ACTION_SET_VIEW_INFO:
undoSetViewInfo((ICoreNotificationObjectSetViewInfo) note);
return true;
case USER_MARK:
return false;
}
}catch (VPMCoreNullParameterException e) {
logger.fatal("Error performing undo; [VPMNullParameterException] message: "
+ e.getMessage());
} catch (VPMCoreException e) {
throw (TraceException) new TraceException("Error performing undo; [VPMCoreException] message: "
+ e.getMessage()).fillInStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
/*
* Added a comment to this code to stop the undo manager from throwing unnecessary error messages
* which slowes down undo operations.
throw new VPMCoreRuntimeException("undo step not defined for step:"
+ note.toString());
*/
//logger.warning("undo step not defined for step:"+ note.toString());
return false;
}
void undoSetViewInfo(ICoreNotificationObjectSetViewInfo note) {
IModelElement me = note.getElement();
String oldViewInfo = note.getOldViewInfo();
try {
mManager.setViewInfo(me, oldViewInfo);
} catch (VPMCoreException e) {
logger.fatal("Error performing undo; message: " + e.getMessage());
// e.printStackTrace();
}
}
}