use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.
the class XmlHelper method compareMerge.
/**
* compareMerge method comment.
*/
public static cbit.xml.merge.XmlTreeDiff compareMerge(String xmlBaseString, String xmlModifiedString, DiffConfiguration comparisonSetting, boolean ignoreVersionInfo) throws XmlParseException {
try {
if (xmlBaseString == null || xmlModifiedString == null || xmlBaseString.length() == 0 || xmlModifiedString.length() == 0 || (!DiffConfiguration.COMPARE_DOCS_SAVED.equals(comparisonSetting) && !DiffConfiguration.COMPARE_DOCS_OTHER.equals(comparisonSetting))) {
throw new XmlParseException("Invalid XML comparison params.");
}
XMLSource xmlBaseSource = new XMLSource(xmlBaseString);
XMLSource xmlModifiedSource = new XMLSource(xmlModifiedString);
// default setting, no validation
Element baselineRoot = xmlBaseSource.getXmlDoc().getRootElement();
Element modifiedRoot = xmlModifiedSource.getXmlDoc().getRootElement();
// Merge the Documents
XmlTreeDiff merger = new XmlTreeDiff(ignoreVersionInfo);
@SuppressWarnings("unused") NodeInfo top = merger.merge(baselineRoot.getDocument(), modifiedRoot.getDocument(), comparisonSetting);
// return the tree-diff instead of the root node.
return merger;
} catch (Exception e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.
the class BioModelEditorApplicationsPanel method compareButtonPressed.
private void compareButtonPressed() {
int[] rows = table.getSelectedRows();
if (rows == null || rows.length != 2) {
return;
}
try {
SimulationContext simContext1 = tableModel.getValueAt(rows[0]);
SimulationContext simContext2 = tableModel.getValueAt(rows[1]);
BioModel bioModel = simContext1.getBioModel();
MathMappingCallback callback = new MathMappingCallback() {
@Override
public void setProgressFraction(float fractionDone) {
Thread.dumpStack();
System.out.println("---> stdout mathMapping: progress = " + (fractionDone * 100.0) + "% done");
}
@Override
public void setMessage(String message) {
Thread.dumpStack();
System.out.println("---> stdout mathMapping: message = " + message);
}
@Override
public boolean isInterrupted() {
return false;
}
};
simContext1.refreshMathDescription(callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
simContext2.refreshMathDescription(callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
Xmlproducer xmlProducer = new Xmlproducer(false);
String simContext1XML = XmlUtil.xmlToString(xmlProducer.getXML(simContext1, bioModel));
String simContext2XML = XmlUtil.xmlToString(xmlProducer.getXML(simContext2, bioModel));
DiffConfiguration comparisonSetting = DiffConfiguration.COMPARE_DOCS_OTHER;
XmlTreeDiff diffTree = XmlHelper.compareMerge(simContext1XML, simContext2XML, comparisonSetting, true);
String baselineDesc = "application " + simContext1.getName();
String modifiedDesc = "application " + simContext2.getName();
TMLPanel comparePanel = new TMLPanel();
comparePanel.setXmlTreeDiff(diffTree);
comparePanel.setBaselineVersionDescription(baselineDesc);
comparePanel.setModifiedVersionDescription(modifiedDesc);
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(this);
String title = "comparing application " + simContext1.getName() + " and " + simContext2.getName();
ChildWindow childWindow = childWindowManager.addChildWindow(comparePanel, diffTree, title, true);
childWindow.setSize(new Dimension(600, 600));
childWindow.show();
} catch (XmlParseException e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, "failed to compare applications: \n\n" + e.getMessage());
}
}
use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.
the class MathDebuggerPanel method compareTree.
private void compareTree() throws PropertyVetoException, XmlParseException {
MathModel mathModel1 = getMathModel1();
MathModel mathModel2 = getMathModel2();
if (mathModel1 != null && mathModel2 != null) {
String math1XML = XmlHelper.mathModelToXML(mathModel1);
String math2XML = XmlHelper.mathModelToXML(mathModel2);
boolean ignoreVersion = true;
XmlTreeDiff diffTree = cbit.vcell.xml.XmlHelper.compareMerge(math1XML, math2XML, DiffConfiguration.COMPARE_DOCS_OTHER, ignoreVersion);
getTMLPanel().setXmlTreeDiff(diffTree);
} else {
DialogUtils.showErrorDialog(MathDebuggerPanel.this, "failed");
}
}
use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.
the class TMLPanel method associate.
/**
* This function associates two NodeInfo nodes if they share the same type and parent.
*/
private void associate() {
TreePath[] paths = getTree().getSelectionPaths();
if (getTree().getSelectionCount() != 2) {
throw new IllegalArgumentException("Invalid number of selected paths: " + getTree().getSelectionCount());
}
// get the two selected nodes
NodeInfo firstNode = (NodeInfo) paths[0].getLastPathComponent();
NodeInfo secondNode = (NodeInfo) paths[1].getLastPathComponent();
NodeInfo parent = (NodeInfo) firstNode.getParent();
if (firstNode.isAttribute() || secondNode.isAttribute()) {
displayMessage(this, "Can only merge elements, not attributes.");
}
if (parent == secondNode.getParent()) {
if (firstNode.getName().equalsIgnoreCase(secondNode.getName())) {
if (firstNode.getStatus() != secondNode.getStatus()) {
// merge the two nodes
NodeInfo result = null;
try {
// this diff tree is different from the instance variable.
XmlTreeDiff partialDiffTree = XmlHelper.compareMerge(firstNode.toXmlString(), secondNode.toXmlString(), DiffConfiguration.COMPARE_DOCS_SAVED, fieldDiffTree.isIgnoringVersionInfo());
result = partialDiffTree.getMergedRootNode();
} catch (Throwable e) {
//
// can give more feedback ... like a JOptionPane.showMessage()
//
handleException(e);
}
if (result != null) {
// erase the original nodes
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) (getTree().getModel());
defaultTreeModel.removeNodeFromParent(firstNode);
defaultTreeModel.removeNodeFromParent(secondNode);
// add the resulting node
parent.add(result);
defaultTreeModel.reload(parent);
} else {
displayMessage(this, "The merge operation could not be performed!");
}
} else {
displayMessage(this, "Can only merge nodes with different status!");
}
} else {
// they do not have the same type!
displayMessage(this, "These nodes cannot be merged because they do not have the same type!");
}
} else {
// they do not have the same parent!
displayMessage(this, "These nodes cannot be merged because they do not share the same node parent!");
}
}
use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.
the class ClientRequestManager method compareDocuments.
private XmlTreeDiff compareDocuments(final VCDocument doc1, final VCDocument doc2, DiffConfiguration comparisonSetting) throws Exception {
VCellThreadChecker.checkCpuIntensiveInvocation();
if ((DiffConfiguration.COMPARE_DOCS_SAVED != comparisonSetting) && (DiffConfiguration.COMPARE_DOCS_OTHER != comparisonSetting)) {
throw new RuntimeException("Unsupported comparison setting: " + comparisonSetting);
}
if (doc1.getDocumentType() != doc2.getDocumentType()) {
throw new RuntimeException("Only comparison of documents of the same type is currently supported");
}
String doc1XML = null;
String doc2XML = null;
switch(doc1.getDocumentType()) {
case BIOMODEL_DOC:
{
doc1XML = XmlHelper.bioModelToXML((BioModel) doc1);
doc2XML = XmlHelper.bioModelToXML((BioModel) doc2);
break;
}
case MATHMODEL_DOC:
{
doc1XML = XmlHelper.mathModelToXML((MathModel) doc1);
doc2XML = XmlHelper.mathModelToXML((MathModel) doc2);
break;
}
case GEOMETRY_DOC:
{
doc1XML = XmlHelper.geometryToXML((Geometry) doc1);
doc2XML = XmlHelper.geometryToXML((Geometry) doc2);
break;
}
}
final XmlTreeDiff diffTree = XmlHelper.compareMerge(doc1XML, doc2XML, comparisonSetting, true);
return diffTree;
}
Aggregations