use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class BioModelEditor method popupMenuActionPerformed.
@Override
protected void popupMenuActionPerformed(DocumentEditorPopupMenuAction action, String actionCommand) {
Model model = bioModel.getModel();
final SimulationContext selectedSimulationContext = getSelectedSimulationContext();
switch(action) {
case add_new:
try {
Object obj = documentEditorTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (userObject instanceof DocumentEditorTreeFolderNode) {
DocumentEditorTreeFolderClass folderClass = ((DocumentEditorTreeFolderNode) userObject).getFolderClass();
Object newObject = null;
switch(folderClass) {
case REACTIONS_NODE:
// TODO: should add a Add New Rule menu item
newObject = model.createSimpleReaction(model.getStructure(0));
break;
case STRUCTURES_NODE:
newObject = model.createFeature();
break;
case SPECIES_NODE:
newObject = model.createSpeciesContext(model.getStructure(0));
break;
case MOLECULAR_TYPES_NODE:
MolecularType mt = model.getRbmModelContainer().createMolecularType();
model.getRbmModelContainer().addMolecularType(mt, true);
newObject = mt;
break;
case OBSERVABLES_NODE:
if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
return;
}
RbmObservable o = model.getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
model.getRbmModelContainer().addObservable(o);
SpeciesPattern sp = new SpeciesPattern();
o.addSpeciesPattern(sp);
newObject = o;
break;
case SIMULATIONS_NODE:
if (selectedSimulationContext != null) {
AsynchClientTask task1 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
selectedSimulationContext.refreshMathDescription(callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
}
};
AsynchClientTask task2 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
Object newsim = selectedSimulationContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
selectionManager.setSelectedObjects(new Object[] { newsim });
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
break;
default:
break;
}
if (newObject != null) {
selectionManager.setSelectedObjects(new Object[] { newObject });
}
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(this, ex.getMessage());
}
break;
case add_new_app_deterministic:
newApplication(Application.NETWORK_DETERMINISTIC);
break;
case add_new_app_stochastic:
newApplication(Application.NETWORK_STOCHASTIC);
break;
case add_new_app_rulebased:
{
// if(model.getStructures().length > 1) {
// DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
// return;
// }
newApplication(Application.RULE_BASED_STOCHASTIC);
break;
}
case copyName:
String name = bioModel.getName();
StringSelection data = new StringSelection(name);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(data, data);
break;
case copy_app:
ApplicationActionCommand acc = ApplicationActionCommand.lookup(actionCommand);
switch(acc.actionType()) {
case COPY_AS_IS:
copyApplication();
break;
case COPY_CHANGE:
boolean bothSpatial = acc.isSourceSpatial() && acc.isDestSpatial();
// if(acc.getAppType().equals(SimulationContext.Application.RULE_BASED_STOCHASTIC) && model.getStructures().length > 1) {
// DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
// return;
// }
copyApplication(bothSpatial, acc.getAppType());
break;
case CREATE:
// not used in this menu
throw new UnsupportedOperationException();
}
break;
case app_new_biomodel:
if (actionCommand.equals(GuiConstants.MENU_TEXT_APP_NEWBIOMODEL)) {
createNewBiomodelFromApp();
}
break;
case delete:
try {
if (selectedSimulationContext != null) {
String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application", "You are going to delete the Application '" + selectedSimulationContext.getName() + "'. Continue?");
if (confirm.equals(UserMessage.OPTION_CANCEL)) {
return;
}
deleteSimulationcontexts(new SimulationContext[] { selectedSimulationContext });
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(this, ex.getMessage());
}
break;
case deleteChoose:
try {
SimulationContext[] allSimContexts = Arrays.copyOf(getBioModelWindowManager().getVCDocument().getSimulationContexts(), getBioModelWindowManager().getVCDocument().getSimulationContexts().length);
Arrays.sort(allSimContexts, new Comparator<SimulationContext>() {
@Override
public int compare(SimulationContext o1, SimulationContext o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
String[][] rowDataOrig = new String[allSimContexts.length][2];
for (int i = 0; i < allSimContexts.length; i++) {
rowDataOrig[i][0] = allSimContexts[i].getName();
rowDataOrig[i][1] = allSimContexts[i].getSimulations().length + "";
}
final String DELETE = "Delete";
final String CANCEL = "Cancel";
TableListResult result = DialogUtils.showComponentOptionsTableList(this, "Select Applications (and associated Simulations) to delete.", new String[] { "Application", "# of Sims" }, rowDataOrig, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, null, new String[] { DELETE, CANCEL }, CANCEL, null);
if (result != null && result.selectedOption != null && result.selectedOption.equals(DELETE) && result.selectedTableRows != null && result.selectedTableRows.length > 0) {
ArrayList<SimulationContext> deleteTheseSimcontexts = new ArrayList<SimulationContext>();
for (int i = 0; i < result.selectedTableRows.length; i++) {
deleteTheseSimcontexts.add(allSimContexts[result.selectedTableRows[i]]);
}
deleteSimulationcontexts(deleteTheseSimcontexts.toArray(new SimulationContext[0]));
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(this, ex.getMessage());
}
break;
default:
break;
}
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class ApplicationsPropertiesPanel method setBioModel.
/**
* Sets the speciesContext property (cbit.vcell.model.SpeciesContext) value.
* @param speciesContext The new value for the property.
* @see #getSpeciesContext
*/
public void setBioModel(BioModel newValue) {
if (newValue == bioModel) {
return;
}
BioModel oldValue = bioModel;
if (oldValue != null) {
oldValue.removePropertyChangeListener(eventHandler);
for (SimulationContext simContext : oldValue.getSimulationContexts()) {
simContext.removePropertyChangeListener(eventHandler);
}
}
bioModel = newValue;
if (newValue != null) {
newValue.addPropertyChangeListener(eventHandler);
for (SimulationContext simContext : newValue.getSimulationContexts()) {
simContext.addPropertyChangeListener(eventHandler);
}
}
updateInterface();
}
use of cbit.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class ApplicationsPropertiesPanel method updateInterface.
/**
* Comment
*/
private void updateInterface() {
if (bioModel == null) {
return;
}
applicationsPanel.removeAll();
int gridy = 0;
SimulationContext[] simulationContexts = bioModel.getSimulationContexts();
if (simulationContexts != null) {
for (int i = 0; i < simulationContexts.length; i++) {
SimulationContext simContext = simulationContexts[i];
JLabel label = new JLabel(simContext.getName());
label.setFont(label.getFont().deriveFont(Font.BOLD));
label.setIcon(simulationContextIcon);
GridBagConstraints gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy++;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
if (i > 0) {
gbc.insets = new Insets(4, 0, 0, 0);
}
applicationsPanel.add(label, gbc);
Geometry geometry = simContext.getGeometry();
String geometryText = "Compartmental geometry";
if (geometry != null) {
Version geometryVersion = geometry.getVersion();
int dimension = geometry.getDimension();
if (dimension > 0) {
String description = geometry.getDimension() + "D " + (geometry.getGeometrySpec().hasImage() ? "image" : "analytic") + " geometry";
geometryText = description;
if (geometryVersion != null) {
geometryText += " - " + geometryVersion.getName();
}
}
}
JLabel geometryLabel = new JLabel(geometryText);
geometryLabel.setIcon(geometryIcon);
JLabel detStochLabel = new JLabel(simContext.getMathType().getDescription());
detStochLabel.setIcon(appTypeIcon);
gbc.insets = new Insets(2, 20, 2, 2);
gbc.gridy = gridy++;
applicationsPanel.add(detStochLabel, gbc);
gbc.gridy = gridy++;
if (i == simulationContexts.length - 1) {
gbc.weighty = 1.0;
}
applicationsPanel.add(geometryLabel, gbc);
}
}
}
use of cbit.vcell.mapping.SimulationContext 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.vcell.mapping.SimulationContext in project vcell by virtualcell.
the class BioModelEditorApplicationsPanel method deleteButtonPressed.
protected void deleteButtonPressed() {
int[] rows = table.getSelectedRows();
if (rows == null || rows.length == 0) {
return;
}
String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application(s)", "Are you sure you want to delete selected application(s)?");
if (confirm.equals(UserMessage.OPTION_CANCEL)) {
return;
}
ArrayList<SimulationContext> deleteList = new ArrayList<SimulationContext>();
for (int r : rows) {
SimulationContext simContext = tableModel.getValueAt(r);
if (simContext != null) {
deleteList.add(simContext);
}
}
try {
for (SimulationContext sc : deleteList) {
deleteApplication(sc);
}
} catch (PropertyVetoException ex) {
ex.printStackTrace();
DialogUtils.showErrorDialog(BioModelEditorApplicationsPanel.this, ex.getMessage());
}
}
Aggregations