use of org.vcell.util.Issue in project vcell by virtualcell.
the class BioCartoonTool method getMoleculesFromStrict.
// returns a list with the "from" molecules we need to add to the modelTo
// it's a "strict" list, where we have eliminated any conflicting molecules and the ones already present
private static Set<MolecularType> getMoleculesFromStrict(ReactionSpeciesCopy rsCopy, Model modelTo, Vector<Issue> issueVector, IssueContext issueContext) {
// molecular types
Set<MolecularType> mtFromListStrict = new HashSet<>();
Set<MolecularType> mtConflictList = new HashSet<>();
Set<MolecularType> mtAlreadyList = new HashSet<>();
RbmModelContainer rbmmcTo = modelTo.getRbmModelContainer();
if (rsCopy.getMolecularTypeArr() != null) {
for (MolecularType mtFrom : rsCopy.getMolecularTypeArr()) {
// the molecules we try to paste here
MolecularType mtTo = rbmmcTo.getMolecularType(mtFrom.getName());
if (mtTo == null) {
// mtTo = new MolecularType(mtFrom, modelTo);
mtFromListStrict.add(mtFrom);
} else {
if (!mtTo.compareEqual(mtFrom)) {
// conflict: a different mt with the same name already exists
String msg = "Molecule " + RbmUtils.toBnglString(mtFrom, null, CompartmentMode.hide);
msg += " to be pasted conflicts with an existing molecule " + RbmUtils.toBnglString(mtTo, null, CompartmentMode.hide) + ".";
Issue issue = new Issue(mtFrom, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
mtConflictList.add(mtFrom);
} else {
mtAlreadyList.add(mtFrom);
}
}
}
if (!mtConflictList.isEmpty()) {
System.out.println("Found " + mtConflictList.size() + " conflicting molecule(s).");
}
if (!mtAlreadyList.isEmpty()) {
System.out.println("Found " + mtAlreadyList.size() + " molecule(s) already there.");
}
}
return mtFromListStrict;
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class BioCartoonTool method checkStructuresCompatibility.
// --------------------------------------------------------------------------------------------------------------------------------------
private static void checkStructuresCompatibility(ReactionSpeciesCopy rsCopy, Model modelTo, Structure structTo, Vector<Issue> issueVector, IssueContext issueContext) {
Structure fromStruct = rsCopy.getFromStructure();
if (rsCopy.getFromStructure().getDimension() != structTo.getDimension()) {
// the source and destination structures need to have the same dimension, can't paste from compartment to membrane or vice-versa
String msg = "Unable to paste from a " + fromStruct.getTypeName() + " to a " + structTo.getTypeName();
msg += ". Both source and destination Structures need to have the same dimension.";
Issue issue = new Issue(fromStruct, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
}
for (Structure from : rsCopy.getStructuresArr()) {
Structure to = modelTo.getStructure(from.getName());
if (to != null && from.getDimension() != to.getDimension()) {
String msg = "Unable to paste " + from.getTypeName() + " " + from.getName();
msg += " because a " + to.getTypeName() + " with the same name already exists.";
Issue issue = new Issue(from, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
}
}
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class BioCartoonTool method mapStructures.
// map the structures to be pasted to existing structures in the cloned model
// we may need to generate some name iteratively until we solve all naming conflicts
private static Map<Structure, String> mapStructures(Component requester, ReactionSpeciesCopy rsCopy, Model modelTo, Structure structTo, IssueContext issueContext) {
// use internally only; we exit the dialog when there are no issues left
Vector<Issue> issueVector = new Vector<>();
Structure structFrom = rsCopy.getFromStructure();
Map<Structure, String> fullyMappedStructures = new LinkedHashMap<>();
fullyMappedStructures.put(structFrom, structTo.getName());
StructurePasteMappingPanel structureMappingPanel = null;
do {
issueVector.clear();
if (structureMappingPanel == null) {
structureMappingPanel = new StructurePasteMappingPanel(rsCopy, modelTo, structTo, issueVector, issueContext);
structureMappingPanel.setPreferredSize(new Dimension(400, 220));
}
int result = DialogUtils.showComponentOKCancelDialog(requester, structureMappingPanel, "Assign 'From' structures to 'To' structures");
if (result != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} while (structureMappingPanel.hasErrors());
for (Map.Entry<Structure, JComboBox<String>> entry : structureMappingPanel.getStructureMap().entrySet()) {
if (entry.getValue().getSelectedItem().equals(StructurePasteMappingPanel.MAKE_NEW)) {
// we generate a "to" structure name based on the "from" name
String newNameTo = entry.getKey().getName();
while (modelTo.getStructure(newNameTo) != null) {
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
for (Structure sFrom : rsCopy.getStructuresArr()) {
if (newNameTo.equals(sFrom.getName())) {
// the new name must not match any existing "from" name either
newNameTo = org.vcell.util.TokenMangler.getNextEnumeratedToken(newNameTo);
break;
}
}
}
try {
// as to avoid risk of duplicates / conflicting names
if (entry.getKey() instanceof Membrane) {
modelTo.addMembrane(newNameTo);
} else {
modelTo.addFeature(newNameTo);
}
} catch (ModelException | PropertyVetoException e) {
throw new RuntimeException("Failed to generate the missing 'from' Structures in the cloned model, " + e.getMessage());
}
fullyMappedStructures.put(entry.getKey(), newNameTo);
} else {
// name of an existing "to" structure
fullyMappedStructures.put(entry.getKey(), (String) entry.getValue().getSelectedItem());
}
}
return fullyMappedStructures;
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class BioCartoonTool method printIssues.
/**
* printIssues : using the issue list passed as argument, gethers them in a string buffer and uses PopupGenerator.showWarning dialog to display
* the issues to user.
* @param issueVector : vector of 'Issue's to be printed
* @param guiRequestComponent : the parent component required to be passed to showWarningDialog
* @return
*/
public static boolean printIssues(Vector<Issue> issueVector, Component guiRequestComponent) {
// now print out the issue List as a warning popup
if (issueVector.size() > 0) {
boolean hasErrors = false;
StringBuffer messageBuffer = new StringBuffer("Issues encountered during pasting selected reactions:\n\n");
for (int j = 0; j < issueVector.size(); j++) {
Issue issue = issueVector.get(j);
if (issue.getSeverity() == Issue.Severity.ERROR || issue.getSeverity() == Issue.Severity.WARNING) {
if (issue.getSeverity() == Issue.Severity.ERROR) {
hasErrors = true;
}
messageBuffer.append(j + 1 + ". " + issue.getCategory() + " " + issue.getSeverity() + " : " + issue.getMessage() + "\n\n");
}
}
if (issueVector.size() > 0) {
String[] choices;
if (hasErrors) {
choices = new String[] { "Cancel" };
} else {
choices = new String[] { "Paste Anyway", "Cancel" };
}
String resultStr = DialogUtils.showWarningDialog(guiRequestComponent, messageBuffer.toString(), choices, "Cancel");
if (resultStr != null && resultStr.equals("Paste Anyway")) {
return true;
}
}
}
return false;
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class DefaultScrollTableCellRenderer method issueRenderer.
public static void issueRenderer(JLabel renderer, String defaultToolTipText, JTable table, int row, int column, SortTableModel tableModel) {
List<Issue> issueListError = tableModel.getIssues(row, column, Issue.Severity.ERROR);
List<Issue> issueListWarning = tableModel.getIssues(row, column, Issue.Severity.WARNING);
Icon icon = null;
Point mousePosition = table.getMousePosition();
// hue, saturation, brightness
Color red = Color.getHSBColor(0f, 0.4f, 1.0f);
if (issueListError.size() > 0) {
if (column == 0) {
icon = VCellIcons.issueErrorIcon;
if (mousePosition != null && mousePosition.getX() > LEFT_ICON_MARGIN && mousePosition.getX() <= (icon.getIconWidth() + LEFT_ICON_MARGIN)) {
String tt = Issue.getHtmlIssueMessage(issueListError);
renderer.setToolTipText(tt);
} else {
renderer.setToolTipText(defaultToolTipText);
}
// Color.red
renderer.setBorder(new MatteBorder(1, 1, 1, 0, red));
} else if (column == table.getColumnCount() - 1) {
renderer.setBorder(new MatteBorder(1, 0, 1, 1, red));
} else {
renderer.setBorder(new MatteBorder(1, 0, 1, 0, red));
}
} else if (issueListWarning.size() > 0) {
if (column == 0) {
icon = VCellIcons.issueWarningIcon;
if (mousePosition != null && mousePosition.getX() > LEFT_ICON_MARGIN && mousePosition.getX() <= (icon.getIconWidth() + LEFT_ICON_MARGIN)) {
renderer.setToolTipText(Issue.getHtmlIssueMessage(issueListWarning));
} else {
renderer.setToolTipText(defaultToolTipText);
}
renderer.setBorder(new MatteBorder(1, 1, 1, 0, Color.orange));
} else if (column == table.getColumnCount() - 1) {
renderer.setBorder(new MatteBorder(1, 0, 1, 1, Color.orange));
} else {
renderer.setBorder(new MatteBorder(1, 0, 1, 0, Color.orange));
}
} else {
if (column == 0) {
icon = VCellIcons.issueGoodIcon;
// no tooltip for column 0 when we have no issues on that line
renderer.setToolTipText(null);
}
if (column != 0 && defaultToolTipText != null && !defaultToolTipText.isEmpty()) {
renderer.setToolTipText(defaultToolTipText);
} else {
renderer.setToolTipText(null);
}
renderer.setBorder(DEFAULT_GAP);
}
if (column == 0 && icon != null) {
// for some tables we combine (concatenate) the issue icon with an entity icon
if (tableModel instanceof SpatialProcessTableModel) {
Icon icon2 = null;
SpatialProcess spatialProcess = (SpatialProcess) (((SpatialProcessTableModel) tableModel).getValueAt(row));
if (spatialProcess instanceof PointLocation) {
icon2 = VCellIcons.spatialLocationIcon;
} else if (spatialProcess instanceof PointKinematics) {
icon2 = VCellIcons.spatialKinematicsIcon;
} else if (spatialProcess instanceof SurfaceKinematics) {
icon2 = VCellIcons.spatialKinematicsIcon;
} else {
icon2 = VCellIcons.spatialKinematicsIcon;
}
icon = VCellIcons.addIcon(icon, icon2);
} else if (tableModel instanceof SpatialObjectTableModel) {
Icon icon2 = null;
SpatialObject spatialObject = (SpatialObject) (((SpatialObjectTableModel) tableModel).getValueAt(row));
if (spatialObject instanceof PointObject) {
icon2 = VCellIcons.spatialPointIcon;
} else if (spatialObject instanceof SurfaceRegionObject) {
icon2 = VCellIcons.spatialMembraneIcon;
} else if (spatialObject instanceof VolumeRegionObject) {
icon2 = VCellIcons.spatialVolumeIcon;
} else {
icon2 = VCellIcons.spatialVolumeIcon;
}
icon = VCellIcons.addIcon(icon, icon2);
}
}
renderer.setIcon(icon);
}
Aggregations