/******************************************************************************* | |
* Copyright (c) 2004-2010 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.IModelManager; | |
import org.eclipse.viatra2.core.tracebased.tracetree.ITraceTreeNode; | |
import org.eclipse.viatra2.framework.IFramework; | |
/** | |
* Manager for VIATRA2 traces | |
* | |
* responsible for: | |
* initializing trace tree and register | |
* saving and loading traces | |
* providing (limited) outside access to tree | |
* | |
* @author Abel Hegedus | |
* | |
*/ | |
public class TraceTreeManager { | |
protected ITraceTreeNode root; | |
protected ITraceTreeNode current; | |
protected TraceNotificationRegister register; | |
protected TraceNotificationProcessor traceProcessor; | |
/** | |
* | |
*/ | |
public TraceTreeManager(IFramework framework, IModelManager mManager) { | |
traceProcessor = new TraceNotificationProcessor(this, framework, mManager); | |
register = new TraceNotificationRegister(this); | |
register.setEnabled(true); | |
} | |
/** | |
* @return the current | |
*/ | |
public ITraceTreeNode getCurrent() { | |
return current; | |
} | |
/** | |
* @param current the current to set | |
*/ | |
public void setCurrent(ITraceTreeNode current) { | |
this.current = current; | |
} | |
/** | |
* @return the root | |
*/ | |
public ITraceTreeNode getRoot() { | |
return root; | |
} | |
/** | |
* @param root the root to set | |
*/ | |
public void setRoot(ITraceTreeNode root) { | |
this.root = root; | |
} | |
public void exportCompleteTrace(StringBuilder exportString){ | |
if(root != null){ | |
exportTrace(root, exportString, 0); | |
} | |
} | |
public void exportTrace(ITraceTreeNode node, StringBuilder exportString, int depth){ | |
exportString.append(node.toString()); | |
if(node.getChildren().size() > 0){ | |
depth++; | |
for (ITraceTreeNode child : node.getOrderedChildrenList()) { | |
exportString.append("\n"); | |
for(int i = 0; i < depth; i++){ | |
exportString.append(" "); | |
} | |
exportString.append("\\(").append(depth).append(")->"); | |
exportTrace(child, exportString,depth); | |
} | |
} | |
} | |
/** | |
* @return the traceProcessor | |
*/ | |
public TraceNotificationProcessor getTraceProcessor() { | |
return traceProcessor; | |
} | |
} |