use of org.vcell.util.Displayable in project vcell by virtualcell.
the class BioModelEditorModelPanel method deleteButtonPressed.
private void deleteButtonPressed() {
try {
ArrayList<Object> deleteList = new ArrayList<Object>();
int selectedIndex = tabbedPane.getSelectedIndex();
if (selectedIndex == ModelPanelTabID.reaction_diagram.ordinal()) {
deleteList.addAll(Arrays.asList(reactionCartoonEditorPanel.getReactionCartoon().getSelectedObjects()));
// } else if (selectedIndex == ModelPanelTabID.structure_diagram.ordinal()) {
// deleteList.addAll(Arrays.asList(cartoonEditorPanel.getStructureCartoon().getSelectedObjects()));
} else {
computeCurrentSelectedTable();
int[] rows = currentSelectedTable.getSelectedRows();
if (rows == null || rows.length == 0) {
return;
}
if (currentSelectedTable == speciesTable) {
for (int r : rows) {
if (r < speciesTableModel.getRowCount()) {
SpeciesContext speciesContext = speciesTableModel.getValueAt(r);
if (speciesContext != null) {
deleteList.add(speciesContext);
}
}
}
} else if (currentSelectedTable == molecularTypeTable) {
// TODO: delete stuff
for (int r : rows) {
if (r < molecularTypeTableModel.getRowCount()) {
MolecularType mt = molecularTypeTableModel.getValueAt(r);
if (mt != null) {
deleteList.add(mt);
}
}
}
} else if (currentSelectedTable == observablesTable) {
for (int r : rows) {
if (r < observableTableModel.getRowCount()) {
RbmObservable o = observableTableModel.getValueAt(r);
if (o != null) {
deleteList.add(o);
}
}
}
} else if (currentSelectedTable == structuresTable) {
for (int r : rows) {
if (r < structureTableModel.getRowCount()) {
Structure rowValue = structureTableModel.getValueAt(r);
if (rowValue instanceof Feature || rowValue instanceof Membrane) {
deleteList.add(rowValue);
}
}
}
} else if (currentSelectedTable == reactionsTable) {
for (int r : rows) {
if (r < reactionTableModel.getRowCount()) {
ModelProcess reaction = reactionTableModel.getValueAt(r);
if (reaction != null) {
deleteList.add(reaction);
}
}
}
}
}
if (deleteList.size() == 0) {
return;
}
StringBuilder deleteListText = new StringBuilder();
for (Object object : deleteList) {
if (object instanceof SpeciesContext) {
deleteListText.append("Species\t'" + ((SpeciesContext) object).getName() + "'\n");
} else if (object instanceof MolecularType) {
deleteListText.append(((MolecularType) object).getDisplayType() + "\t'" + ((MolecularType) object).getDisplayName() + "'\n");
} else if (object instanceof RbmObservable) {
deleteListText.append("Observable\t'" + ((RbmObservable) object).getName() + "'\n");
} else if (object instanceof ReactionStep) {
deleteListText.append("Reaction\t'" + ((ReactionStep) object).getName() + "'\n");
} else if (object instanceof ReactionRule) {
deleteListText.append("Reaction rule\t'" + ((ReactionRule) object).getName() + "'\n");
} else if (object instanceof Structure) {
deleteListText.append("Structure\t'" + ((Structure) object).getName() + "'\n");
}
}
// TODO: once we display reaction rules in the carton editor panel we'll have to change the way we delete reaction rules
if (deleteList.get(0) instanceof SpeciesContext || deleteList.get(0) instanceof ReactionStep) {
try {
ArrayList<SpeciesContext> speciesContextArrList = new ArrayList<SpeciesContext>();
ArrayList<ReactionStep> reactionStepArrList = new ArrayList<ReactionStep>();
for (Object obj : deleteList) {
if (obj instanceof SpeciesContext) {
speciesContextArrList.add((SpeciesContext) obj);
} else if (obj instanceof ReactionStep) {
reactionStepArrList.add((ReactionStep) obj);
} else {
throw new Exception("Unexpected delete object " + obj.getClass().getName());
}
}
ReactionCartoonTool.deleteReactionsAndSpecies(reactionCartoonEditorPanel, reactionStepArrList.toArray(new ReactionStep[0]), speciesContextArrList.toArray(new SpeciesContext[0]));
} catch (UserCancelException uce) {
return;
}
return;
} else {
String confirm = DialogUtils.showOKCancelWarningDialog(this, "Deleting", "You are going to delete the following:\n\n" + deleteListText + "\n Continue?");
if (confirm.equals(UserMessage.OPTION_CANCEL)) {
return;
}
for (Object object : deleteList) {
if (object instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) object;
bioModel.getModel().getRbmModelContainer().removeReactionRule(rr);
} else if (object instanceof MolecularType) {
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
MolecularType mt = (MolecularType) object;
if (!bioModel.getModel().getRbmModelContainer().isDeleteAllowed(mt, usedHere)) {
String errMsg = mt.getDisplayType() + " <b>'" + mt + "'</b> cannot be deleted because it's already being used by:<br>";
final int MaxListSize = 7;
int count = 0;
for (String key : usedHere.keySet()) {
System.out.println(key);
if (count >= MaxListSize) {
errMsg += "<br> ... and more.";
break;
}
Pair<Displayable, SpeciesPattern> o = usedHere.get(key);
Displayable e = o.one;
SpeciesPattern sp = o.two;
errMsg += "<br> - " + e.getDisplayType().toLowerCase() + " <b>" + e.getDisplayName() + "</b>";
errMsg += ", " + sp.getDisplayType().toLowerCase() + " " + " <b>" + sp.getDisplayName() + "</b>";
count++;
}
errMsg = "<html>" + errMsg + "</html>";
throw new RuntimeException(errMsg);
}
bioModel.getModel().getRbmModelContainer().removeMolecularType(mt);
} else if (object instanceof RbmObservable) {
RbmObservable o = (RbmObservable) object;
bioModel.getModel().getRbmModelContainer().removeObservable(o);
} else {
bioModel.getModel().removeObject(object);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
DialogUtils.showErrorDialog(this, ex.getMessage());
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method deleteFromTree.
public void deleteFromTree() {
Object obj = molecularTypeTree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
TreeNode parent = selectedNode.getParent();
if (!(parent instanceof BioModelNode)) {
return;
}
BioModelNode parentNode = (BioModelNode) parent;
Object selectedUserObject = selectedNode.getUserObject();
if (selectedUserObject instanceof MolecularComponent) {
MolecularComponent mc = (MolecularComponent) selectedUserObject;
Object userObject = parentNode.getUserObject();
if (userObject instanceof MolecularType) {
MolecularType mt = (MolecularType) userObject;
// 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(this.getParent().getParent(), 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(mt, 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(this.getParent().getParent(), errMsg, "Delete " + mc.getDisplayType(), dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
mt.removeMolecularComponent(mc);
}
} else {
return;
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
mt.removeMolecularComponent(mc);
}
}
}
} else if (selectedUserObject instanceof ComponentStateDefinition) {
ComponentStateDefinition csd = (ComponentStateDefinition) selectedUserObject;
Object userObject = parentNode.getUserObject();
if (!(userObject instanceof MolecularComponent)) {
System.out.println("Unexpected parent in tree hierarchy for " + ComponentStateDefinition.typeName + " " + csd.getDisplayName() + "!");
return;
}
MolecularComponent mc = (MolecularComponent) userObject;
TreeNode grandParent = parentNode.getParent();
BioModelNode grandParentNode = (BioModelNode) grandParent;
userObject = grandParentNode.getUserObject();
if (!(userObject instanceof MolecularType)) {
System.out.println("Unexpected parent in tree hierarchy for " + mc.getDisplayType() + " " + mc.getDisplayName() + "!");
return;
}
MolecularType mt = (MolecularType) userObject;
Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
bioModel.getModel().getRbmModelContainer().findStateUsage(mt, 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(this.getParent().getParent(), errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
if (returnCode == JOptionPane.YES_OPTION) {
// keep this code in sync with MolecularTypeTableModel.setValueAt
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
// this stays
mc.deleteComponentStateDefinition(csd);
}
} else {
return;
}
} else {
if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
// this stays
mc.deleteComponentStateDefinition(csd);
}
}
// mc.deleteComponentStateDefinition(csd);
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class RbmObservable method findComponentUsage.
public void findComponentUsage(MolecularType mt, MolecularComponent mc, 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
String key = sp.getDisplayName();
key = getDisplayType() + getDisplayName() + key;
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class ReactionRule method findComponentUsage.
// TODO: almost identical to findStateUsage() below - pay attention to keep both in sync
public void findComponentUsage(MolecularType mt, MolecularComponent mc, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
for (ProductPattern pp : getProductPatterns()) {
SpeciesPattern sp = pp.getSpeciesPattern();
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
String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
for (ReactantPattern rp : getReactantPatterns()) {
SpeciesPattern sp = rp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.isImplied()) {
continue;
}
if (mcp.getMolecularComponent() == mc) {
String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
use of org.vcell.util.Displayable in project vcell by virtualcell.
the class ReactionRule method findStateUsage.
public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
for (ProductPattern pp : getProductPatterns()) {
SpeciesPattern sp = pp.getSpeciesPattern();
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 = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
for (ReactantPattern rp : getReactantPatterns()) {
SpeciesPattern sp = rp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.isImplied()) {
continue;
}
if (mcp.getMolecularComponent() == mc) {
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.getComponentStateDefinition() == csd) {
String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
}
Aggregations