use of org.vcell.util.Displayable in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e, PointLocationInShapeContext locationContext) {
if (popupFromShapeMenu == null) {
popupFromShapeMenu = new JPopupMenu();
}
if (popupFromShapeMenu.isShowing()) {
return;
}
final Object deepestShape = locationContext.getDeepestShape();
final Object selectedObject;
if (deepestShape == null) {
selectedObject = null;
// when cursor is outside there's nothing to do ???
System.out.println("outside");
return;
} else if (deepestShape instanceof ComponentStateLargeShape) {
System.out.println("inside state");
if (((ComponentStateLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((ComponentStateLargeShape) deepestShape).getComponentStateDefinition();
} else {
// right click only works on highlighted entity, if it's not highlighted we simply return
return;
}
} else if (deepestShape instanceof MolecularComponentLargeShape) {
System.out.println("inside component");
if (((MolecularComponentLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularComponentLargeShape) deepestShape).getMolecularComponent();
} else {
return;
}
} else if (deepestShape instanceof MolecularTypeLargeShape) {
System.out.println("inside molecule");
if (((MolecularTypeLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((MolecularTypeLargeShape) deepestShape).getMolecularType();
} else {
return;
}
} else if (deepestShape instanceof SpeciesPatternLargeShape) {
// this cannot happen, here just for symmetry
System.out.println("inside species pattern");
if (((SpeciesPatternLargeShape) deepestShape).isHighlighted()) {
selectedObject = ((SpeciesPatternLargeShape) deepestShape).getSpeciesPattern();
} else {
return;
}
} else {
selectedObject = null;
System.out.println("inside something else?");
return;
}
System.out.println(selectedObject);
boolean bDelete = false;
boolean bAdd = false;
popupFromShapeMenu.removeAll();
Point mousePoint = e.getPoint();
if (selectedObject instanceof MolecularType) {
// rename, add
if (selectedObject != molecularType) {
throw new RuntimeException("The selected object from shape different from the current object");
}
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem addMenuItem = new JMenuItem("Add " + MolecularComponent.typeName);
// Icon icon = new MolecularTypeSmallShape(1, 4, mt, gc, mt);
// menuItem.setIcon(icon);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(addMenuItem);
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent molecularComponent = molecularType.createMolecularComponent();
molecularType.addMolecularComponent(molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
// editInPlace((LargeShape)deepestShape);
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
} else if (selectedObject instanceof MolecularComponent) {
// move left / right / separator / rename, delete, separator, add
String moveRightMenuText = "Move <b>" + "right" + "</b>";
moveRightMenuText = "<html>" + moveRightMenuText + "</html>";
JMenuItem moveRightMenuItem = new JMenuItem(moveRightMenuText);
Icon icon = VCellIcons.moveRightIcon;
moveRightMenuItem.setIcon(icon);
moveRightMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent from = (MolecularComponent) selectedObject;
List<MolecularComponent> mcList = molecularType.getComponentList();
int fromIndex = mcList.indexOf(from);
if (mcList.size() == fromIndex + 1) {
// already the last element
return;
}
int toIndex = fromIndex + 1;
MolecularComponent to = mcList.remove(toIndex);
mcList.add(fromIndex, to);
molecularTypeTreeModel.populateTree();
molecularType.firePropertyChange("entityChange", null, "bbb");
}
});
popupFromShapeMenu.add(moveRightMenuItem);
String moveLeftMenuText = "Move <b>" + "left" + "</b>";
moveLeftMenuText = "<html>" + moveLeftMenuText + "</html>";
JMenuItem moveLeftMenuItem = new JMenuItem(moveLeftMenuText);
icon = VCellIcons.moveLeftIcon;
moveLeftMenuItem.setIcon(icon);
moveLeftMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent from = (MolecularComponent) selectedObject;
List<MolecularComponent> mcList = molecularType.getComponentList();
int fromIndex = mcList.indexOf(from);
if (fromIndex == 0) {
// already the first element
return;
}
int toIndex = fromIndex - 1;
MolecularComponent to = mcList.remove(toIndex);
mcList.add(fromIndex, to);
molecularTypeTreeModel.populateTree();
molecularType.firePropertyChange("entityChange", null, "bbb");
}
});
popupFromShapeMenu.add(moveLeftMenuItem);
popupFromShapeMenu.add(new JSeparator());
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem addMenuItem = new JMenuItem("Add " + ComponentStateDefinition.typeName);
JMenuItem deleteMenuItem = new JMenuItem("Delete ");
popupFromShapeMenu.add(deleteMenuItem);
popupFromShapeMenu.add(new JSeparator());
popupFromShapeMenu.add(addMenuItem);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent mc = (MolecularComponent) selectedObject;
// detailed verifications will be done there, to see if they are being used in reactions, species, observables
if (!mc.getComponentStateDefinitions().isEmpty()) {
String[] options = { "OK" };
String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
errMsg += "<br>Please delete each individual State first.";
errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
errMsg = "<html>" + errMsg + "</html>";
JOptionPane.showOptionDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
return;
}
// we find and display component usage information to help the user decide
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findComponentUsage(molecularType, mc, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = mc.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + mc.getDisplayType(), dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
molecularType.removeMolecularComponent(mc);
}
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc) == true) {
molecularType.removeMolecularComponent(mc);
}
}
}
});
addMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MolecularComponent mc = (MolecularComponent) selectedObject;
ComponentStateDefinition componentStateDefinition = mc.createComponentStateDefinition();
mc.addComponentStateDefinition(componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, mc, componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, mc, componentStateDefinition);
bioModel.getModel().getRbmModelContainer().adjustSpeciesPatterns(molecularType, mc, componentStateDefinition);
// editInPlace((LargeShape)deepestShape);
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
} else if (selectedObject instanceof ComponentStateDefinition) {
// rename, delete
JMenuItem renamMenuItem = new JMenuItem("Rename");
popupFromShapeMenu.add(renamMenuItem);
JMenuItem deleteMenuItem = new JMenuItem("Delete");
popupFromShapeMenu.add(deleteMenuItem);
deleteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ComponentStateDefinition csd = (ComponentStateDefinition) selectedObject;
// must exist, we're deleting one of its states
MolecularComponent mc = locationContext.mcs.getMolecularComponent();
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findStateUsage(molecularType, mc, csd, usedHere);
if (!usedHere.isEmpty()) {
String errMsg = csd.dependenciesToHtml(usedHere);
errMsg += "<br><br>Delete anyway?";
errMsg = "<html>" + errMsg + "</html>";
int dialogButton = JOptionPane.YES_NO_OPTION;
int returnCode = JOptionPane.showConfirmDialog(shapePanel, errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
mc.deleteComponentStateDefinition(csd);
}
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(molecularType, mc, csd) == true) {
mc.deleteComponentStateDefinition(csd);
}
}
}
});
renamMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editInPlace((LargeShape) deepestShape);
}
});
}
popupFromShapeMenu.show(e.getComponent(), mousePoint.x, mousePoint.y);
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class MolecularTypeTableModel method checkInputValue.
@Override
public String checkInputValue(String inputValue, int row, int columnIndex) {
String errMsg = null;
final Column col = Column.values()[columnIndex];
MolecularType selectedMolecularType = getValueAt(row);
switch(col) {
case name:
{
if (!inputValue.equals(TokenMangler.fixTokenStrict(inputValue))) {
errMsg = "'" + inputValue + "' not legal identifier, try '" + TokenMangler.fixTokenStrict(inputValue) + "'.";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
inputValue = TokenMangler.fixTokenStrict(inputValue);
MolecularType mt = getModel().getRbmModelContainer().getMolecularType(inputValue);
if (mt != null && mt != selectedMolecularType) {
errMsg = mt.getDisplayType() + " '" + inputValue + "' already exists!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
case bngl_pattern:
{
try {
inputValue = inputValue.trim();
if (inputValue.length() > 0) {
MolecularType mt = RbmUtils.parseMolecularType(inputValue);
MolecularType mt1 = getModel().getRbmModelContainer().getMolecularType(mt.getName());
if (mt1 != null && getRowIndex(mt1) != row) {
// molecular type with this name exists already on another row
errMsg = mt.getDisplayType() + " '" + mt.getDisplayName() + "' already exists!";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
// need to check if any Component we try to delete is not already in use elsewhere
for (MolecularComponent selectedMolecularComponent : selectedMolecularType.getComponentList()) {
if (mt.getMolecularComponent(selectedMolecularComponent.getName()) == null) {
// the user tries to delete this mc
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findComponentUsage(selectedMolecularType, selectedMolecularComponent, usedHere);
if (!usedHere.isEmpty()) {
errMsg = selectedMolecularComponent.dependenciesToHtml(usedHere);
errMsg += "<br><br>Deleting and Renaming a Component can be done in the Object Properties tree below.";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
}
// need to check if any State we try to delete is not already in use elsewhere
for (MolecularComponent selectedMolecularComponent : selectedMolecularType.getComponentList()) {
for (ComponentStateDefinition selectedComponentStateDefinition : selectedMolecularComponent.getComponentStateDefinitions()) {
MolecularComponent mc = mt.getMolecularComponent(selectedMolecularComponent.getName());
if (mc.getComponentStateDefinition(selectedComponentStateDefinition.getName()) == null) {
// new list is missing a state which was present in the original
if (!getModel().getRbmModelContainer().isDeleteAllowed(selectedMolecularType, selectedMolecularComponent, selectedComponentStateDefinition)) {
errMsg = "State '" + selectedComponentStateDefinition + "' cannot be deleted because it's already being used.";
errMsg += "<br>Deleting and Renaming a State can be done in the Object Properties tree below.";
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
}
}
}
}
} catch (Exception ex) {
errMsg = ex.getMessage();
errMsg += VCellErrorMessages.PressEscToUndo;
errMsg = "<html>" + errMsg + "</html>";
return errMsg;
}
break;
}
}
return null;
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class MolecularTypeTreeModel method valueForPathChanged.
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
Object obj = path.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
try {
if (newValue instanceof String) {
String inputString = (String) newValue;
if (inputString == null || inputString.length() == 0) {
return;
}
if (userObject instanceof MolecularType) {
String mangled = TokenMangler.fixTokenStrict(inputString);
if (!mangled.equals(inputString)) {
String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
throw new RuntimeException(errMsg);
}
((MolecularType) userObject).setName(inputString);
} else if (userObject instanceof MolecularComponent) {
String mangled = TokenMangler.fixTokenStrict(inputString);
if (!mangled.equals(inputString)) {
String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
throw new RuntimeException(errMsg);
}
((MolecularComponent) userObject).setName(inputString);
} else if (userObject instanceof ComponentStateDefinition) {
if (inputString.matches("[A-Z_a-z0-9]+")) {
((ComponentStateDefinition) userObject).setName(inputString);
}
}
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class ParameterContext method gatherIssues.
public void gatherIssues(IssueContext issueContext, List<Issue> issueList, ParameterRoleEnum userDefinedRole) {
//
for (int i = 0; fieldUnresolvedParameters != null && i < fieldUnresolvedParameters.length; i++) {
issueList.add(new Issue(fieldUnresolvedParameters[i], issueContext, IssueCategory.UnresolvedParameter, "Unresolved parameter '" + fieldUnresolvedParameters[i].getName(), Issue.SEVERITY_ERROR));
}
//
for (int i = 0; fieldParameters != null && i < fieldParameters.length; i++) {
if (fieldParameters[i].getRole() == userDefinedRole) {
try {
if (!isReferenced(fieldParameters[i], 0)) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsUnreferencedParameter, "Unreferenced Kinetic Parameter '" + fieldParameters[i].getName(), Issue.SEVERITY_WARNING));
}
} catch (ExpressionException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsExpressionError, "error resolving expression " + e.getMessage(), Issue.SEVERITY_WARNING));
}
}
}
//
if (fieldParameters != null) {
for (LocalParameter parameter : this.fieldParameters) {
if (parameter.getExpression() == null) {
issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionMissing, "expression is missing", Issue.SEVERITY_INFO));
} else {
Expression exp = parameter.getExpression();
String[] symbols = exp.getSymbols();
String issueMessagePrefix = "parameter '" + parameter.getName() + "' ";
if (symbols != null) {
for (int j = 0; j < symbols.length; j++) {
SymbolTableEntry ste = exp.getSymbolBinding(symbols[j]);
if (ste instanceof LocalProxyParameter) {
ste = ((LocalProxyParameter) ste).getTarget();
}
if (ste == null) {
issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined symbol '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
// } else if (ste instanceof SpeciesContext) {
// if (!getReactionStep().getModel().contains((SpeciesContext)ste)) {
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined species '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
// }
// if (reactionStep.countNumReactionParticipants((SpeciesContext)ste) == 0){
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionNonParticipantSymbol, issueMessagePrefix + "references species context '"+symbols[j]+"', but it is not a reactant/product/catalyst of this reaction",Issue.SEVERITY_WARNING));
// }
// } else if (ste instanceof ModelParameter) {
// if (!getReactionStep().getModel().contains((ModelParameter)ste)) {
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined global parameter '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
// }
}
}
}
}
}
// looking for local param which masks a global and issueing a warning
for (LocalParameter parameter : fieldParameters) {
String name = parameter.getName();
SymbolTableEntry ste = nameScope.getExternalEntry(name, this);
String steName;
if (ste != null) {
if (ste instanceof Displayable) {
steName = ((Displayable) ste).getDisplayType() + " " + ste.getName();
} else {
steName = ste.getClass().getSimpleName() + " " + ste.getName();
}
String msg = steName + " is overriden by a local parameter " + name;
issueList.add(new Issue(parameter, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
}
}
}
try {
//
// determine unit consistency for each expression
//
VCUnitSystem unitSystem = unitSystemProvider.getUnitSystem();
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(unitSystem);
for (int i = 0; i < fieldParameters.length; i++) {
if (fieldParameters[i].getExpression() == null) {
continue;
}
try {
VCUnitDefinition paramUnitDef = fieldParameters[i].getUnitDefinition();
VCUnitDefinition expUnitDef = unitEvaluator.getUnitDefinition(fieldParameters[i].getExpression());
if (paramUnitDef == null) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "defined unit is null", Issue.SEVERITY_WARNING));
} else if (paramUnitDef.isTBD()) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "undefined unit " + unitSystem.getInstance_TBD().getSymbol(), Issue.SEVERITY_WARNING));
} else if (expUnitDef == null) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "computed unit is null", Issue.SEVERITY_WARNING));
} else if (paramUnitDef.isTBD() || (!paramUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD())) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "inconsistent units, defined=[" + fieldParameters[i].getUnitDefinition().getSymbol() + "], computed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
}
} catch (VCUnitException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
} catch (ExpressionException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
}
}
} catch (Throwable e) {
issueList.add(new Issue(parameterPolicy.getIssueSource(), issueContext, IssueCategory.Units, "unexpected exception: " + e.getMessage(), Issue.SEVERITY_INFO));
}
//
for (int i = 0; i < fieldParameters.length; i++) {
RealInterval simpleBounds = parameterPolicy.getConstraintBounds(fieldParameters[i].getRole());
if (simpleBounds != null) {
String parmName = fieldParameters[i].getName();
issueList.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
}
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class RbmObservable method findStateUsage.
public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
for (SpeciesPattern sp : getSpeciesPatternList()) {
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.isImplied()) {
// we don't care about these
continue;
}
if (mcp.getMolecularComponent() == mc) {
// found mc in use
// now let's look at component state definition
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.getComponentStateDefinition() == csd) {
String key = sp.getDisplayName();
key = getDisplayType() + getDisplayName() + key;
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
}
Aggregations