use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class BioModelEditorTreeModel method populateApplicationsNode.
private void populateApplicationsNode(boolean bFromRoot) {
if (bioModel.getNumSimulationContexts() == 0 && childApplicationsNodeList.size() == 0) {
return;
}
boolean bSelected = false;
boolean bFoundSelected = false;
Map<String, Boolean> selectedInSimulationContextMap = new HashMap<String, Boolean>();
if (selectedBioModelNode != null && applicationsNode.isNodeDescendant(selectedBioModelNode)) {
bSelected = true;
for (BioModelNode node : childApplicationsNodeList) {
Object userObject = node.getUserObject();
if (userObject instanceof SimulationContext) {
SimulationContext simContext = (SimulationContext) userObject;
boolean nodeDescendant = node.isNodeDescendant(selectedBioModelNode);
selectedInSimulationContextMap.put(simContext.getName(), nodeDescendant);
}
}
}
applicationsNode.removeAllChildren();
childApplicationsNodeList.clear();
SimulationContext[] simulationContexts = bioModel.getSimulationContexts();
if (simulationContexts != null && simulationContexts.length > 0) {
simulationContexts = simulationContexts.clone();
Arrays.sort(simulationContexts, new Comparator<SimulationContext>() {
public int compare(SimulationContext o1, SimulationContext o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
for (SimulationContext simulationContext : simulationContexts) {
BioModelNode appNode = new BioModelNode(simulationContext, true);
applicationsNode.add(appNode);
childApplicationsNodeList.add(appNode);
Object selectedUserObject = null;
if (selectedBioModelNode != null) {
selectedUserObject = selectedBioModelNode.getUserObject();
}
if (bSelected && !bFoundSelected && selectedUserObject instanceof SimulationContext && ((SimulationContext) selectedUserObject).getName().equals(((SimulationContext) appNode.getUserObject()).getName())) {
bFoundSelected = true;
selectedBioModelNode = appNode;
}
Boolean bSelectedInChild = selectedInSimulationContextMap.get(simulationContext.getName());
boolean bSelectedInSimulationContext = false;
if (bSelectedInChild != null) {
bSelectedInSimulationContext = bSelectedInChild;
}
BioModelNode geometryNode = new BioModelNode(new DocumentEditorTreeFolderNode(DocumentEditorTreeFolderClass.GEOMETRY_NODE, true), false);
BioModelNode settingsNode = new BioModelNode(new DocumentEditorTreeFolderNode(DocumentEditorTreeFolderClass.SPECIFICATIONS_NODE, true), false);
BioModelNode protocolsNode = new BioModelNode(new DocumentEditorTreeFolderNode(DocumentEditorTreeFolderClass.PROTOCOLS_NODE, true), false);
BioModelNode simulationsNode = new BioModelNode(new DocumentEditorTreeFolderNode(DocumentEditorTreeFolderClass.SIMULATIONS_NODE, true), false);
BioModelNode fittingNode = new BioModelNode(new DocumentEditorTreeFolderNode(DocumentEditorTreeFolderClass.PARAMETER_ESTIMATION_NODE, true), false);
BioModelNode[] applicationChildNodes = null;
if (simulationContext.isValidForFitting()) {
simulationContext.createDefaultParameterEstimationTask();
applicationChildNodes = new BioModelNode[] { geometryNode, settingsNode, protocolsNode, simulationsNode, fittingNode };
} else {
applicationChildNodes = new BioModelNode[] { geometryNode, settingsNode, protocolsNode, simulationsNode };
}
for (BioModelNode node : applicationChildNodes) {
appNode.add(node);
if (bSelectedInSimulationContext && !bFoundSelected && selectedUserObject instanceof DocumentEditorTreeFolderNode && ((DocumentEditorTreeFolderNode) selectedUserObject).getName().equals(((DocumentEditorTreeFolderNode) node.getUserObject()).getName())) {
bFoundSelected = true;
selectedBioModelNode = node;
}
}
}
}
nodeStructureChanged(applicationsNode);
ownerTree.expandPath(new TreePath(applicationsNode.getPath()));
if (bSelected) {
if (!bFoundSelected) {
selectedBioModelNode = applicationsNode;
}
if (!bFromRoot) {
restoreTreeSelection();
}
}
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class BioModelsNetPanel method importFromBioModelsNet.
public void importFromBioModelsNet() {
Object obj = tree.getLastSelectedPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (!(userObject instanceof BioModelsNetModelInfo)) {
return;
}
final BioModelsNetModelInfo bioModelsNetInfo = (BioModelsNetModelInfo) userObject;
AsynchClientTask task1 = new AsynchClientTask("Importing " + bioModelsNetInfo.getName(), AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModelsWebServicesServiceLocator bioModelsWebServicesServiceLocator = new BioModelsWebServicesServiceLocator();
BioModelsWebServices bioModelsWebServices = bioModelsWebServicesServiceLocator.getBioModelsWebServices();
String bioModelSBML = bioModelsWebServices.getModelSBMLById(bioModelsNetInfo.getId());
ExternalDocInfo externalDocInfo = ExternalDocInfo.createBioModelsNetExternalDocInfo(bioModelSBML, bioModelsNetInfo.getName());
if (externalDocInfo != null) {
hashTable.put("externalDocInfo", externalDocInfo);
}
}
};
AsynchClientTask task2 = new AsynchClientTask("Opening", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ExternalDocInfo externalDocInfo = (ExternalDocInfo) hashTable.get("externalDocInfo");
if (externalDocInfo == null) {
return;
}
documentWindowManager.getRequestManager().openDocument(externalDocInfo, documentWindowManager, true);
}
};
ClientTaskDispatcher.dispatch(documentWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class DocumentEditor method selectClickPath.
private void selectClickPath(MouseEvent e) {
Point mousePoint = e.getPoint();
TreePath clickPath = documentEditorTree.getPathForLocation(mousePoint.x, mousePoint.y);
if (clickPath == null) {
return;
}
Object rightClickNode = clickPath.getLastPathComponent();
if (rightClickNode == null || !(rightClickNode instanceof BioModelNode)) {
return;
}
TreePath[] selectedPaths = documentEditorTree.getSelectionPaths();
if (selectedPaths == null || selectedPaths.length == 0) {
return;
}
boolean bFound = false;
for (TreePath tp : selectedPaths) {
if (tp.equals(clickPath)) {
bFound = true;
break;
}
}
if (!bFound) {
documentEditorTree.setSelectionPath(clickPath);
}
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class DocumentEditor method construcutPopupMenu.
private void construcutPopupMenu() {
popupMenu.removeAll();
TreePath[] selectedPaths = documentEditorTree.getSelectionPaths();
boolean bRename = false;
boolean bExpand = true;
boolean bAddNew = false;
boolean bAddNewApp = false;
boolean bCopyApp = false;
boolean bDelete = false;
boolean bNewBiomodel = false;
boolean bRemoveApps = false;
DocumentEditorTreeFolderClass folderClass = null;
for (TreePath tp : selectedPaths) {
Object obj = tp.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
continue;
}
if (documentEditorTree.getModel().isLeaf(obj)) {
bExpand = false;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (userObject instanceof DocumentEditorTreeFolderNode) {
folderClass = ((DocumentEditorTreeFolderNode) userObject).getFolderClass();
if (folderClass == DocumentEditorTreeFolderClass.APPLICATIONS_NODE) {
bAddNewApp = true;
if (selectedNode.getChildCount() > 0) {
bRemoveApps = true;
}
} else if (folderClass == DocumentEditorTreeFolderClass.REACTIONS_NODE || folderClass == DocumentEditorTreeFolderClass.STRUCTURES_NODE || folderClass == DocumentEditorTreeFolderClass.SPECIES_NODE || folderClass == DocumentEditorTreeFolderClass.MOLECULAR_TYPES_NODE || folderClass == DocumentEditorTreeFolderClass.OBSERVABLES_NODE || folderClass == DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE) {
bAddNew = (selectedPaths.length == 1);
bRename = false;
}
} else if (userObject instanceof SimulationContext) {
bRename = true;
bCopyApp = true;
bDelete = true;
bNewBiomodel = true;
}
}
if (selectedPaths.length != 1) {
bRename = false;
}
if (bAddNewApp) {
if (addNewAppMenu == null) {
addNewAppMenu = new JMenu("New Application");
addNewAppDeterministicMenuItem = new JMenuItem(GuiConstants.MENU_TEXT_DETERMINISTIC_APPLICATION);
addNewAppDeterministicMenuItem.addActionListener(eventHandler);
addNewAppStochasticMenuItem = new JMenuItem(GuiConstants.MENU_TEXT_STOCHASTIC_APPLICATION);
addNewAppStochasticMenuItem.addActionListener(eventHandler);
addNewAppRulebasedMenuItem = new JMenuItem(GuiConstants.MENU_TEXT_RULEBASED_APPLICATION);
addNewAppRulebasedMenuItem.addActionListener(eventHandler);
addNewAppMenu.add(addNewAppDeterministicMenuItem);
addNewAppMenu.add(addNewAppStochasticMenuItem);
addNewAppMenu.add(addNewAppRulebasedMenuItem);
}
popupMenu.add(addNewAppMenu);
}
if (bRemoveApps) {
if (removeAppsMenu == null) {
removeAppsMenu = new JMenuItem("Remove Apps...");
removeAppsMenu.addActionListener(eventHandler);
}
popupMenu.add(removeAppsMenu);
}
if (bAddNew) {
String addText = "New";
if (folderClass == DocumentEditorTreeFolderClass.REACTIONS_NODE) {
addText += " Reaction";
} else if (folderClass == DocumentEditorTreeFolderClass.STRUCTURES_NODE) {
addText += " Compartment";
} else if (folderClass == DocumentEditorTreeFolderClass.SPECIES_NODE) {
addText += " Species";
} else if (folderClass == DocumentEditorTreeFolderClass.MOLECULAR_TYPES_NODE) {
addText += " Molecule";
} else if (folderClass == DocumentEditorTreeFolderClass.OBSERVABLES_NODE) {
addText += " Observable";
} else if (folderClass == DocumentEditorTreeFolderClass.MATH_SIMULATIONS_NODE) {
addText += " Simulation";
}
addNewMenuItem = new javax.swing.JMenuItem(addText);
addNewMenuItem.addActionListener(eventHandler);
popupMenu.add(addNewMenuItem);
}
if (bRename) {
if (renameMenuItem == null) {
renameMenuItem = new javax.swing.JMenuItem("Rename");
renameMenuItem.addActionListener(eventHandler);
}
popupMenu.add(renameMenuItem);
}
if (bDelete) {
if (deleteMenuItem == null) {
deleteMenuItem = new javax.swing.JMenuItem("Delete");
deleteMenuItem.addActionListener(eventHandler);
}
popupMenu.add(deleteMenuItem);
}
if (bCopyApp) {
if (menuItemAppCopy == null) {
menuItemAppCopy = new JMenuItem(GuiConstants.MENU_TEXT_APP_COPY);
menuItemAppCopy.addActionListener(eventHandler);
menuItemAppCopy.setActionCommand(GuiConstants.ACTIONCMD_COPY_APPLICATION);
}
if (menuAppCopyAs == null) {
menuAppCopyAs = new JMenu(GuiConstants.MENU_TEXT_APP_COPYAS);
}
menuAppCopyAs.removeAll();
SimulationContext selectedSimContext = getSelectedSimulationContext();
if (selectedSimContext != null) {
if (selectedSimContext.getGeometry().getDimension() == 0) {
if (menuItemNonSpatialCopyDeterministic == null) {
menuItemNonSpatialCopyStochastic = new JMenuItem(GuiConstants.MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemNonSpatialCopyStochastic.setActionCommand(GuiConstants.ACTIONCMD_NON_SPATIAL_COPY_TO_STOCHASTIC_APPLICATION);
menuItemNonSpatialCopyStochastic.addActionListener(eventHandler);
menuItemNonSpatialCopyDeterministic = new javax.swing.JMenuItem(GuiConstants.MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemNonSpatialCopyDeterministic.setActionCommand(GuiConstants.ACTIONCMD_NON_SPATIAL_COPY_TO_DETERMINISTIC_APPLICATION);
menuItemNonSpatialCopyDeterministic.addActionListener(eventHandler);
menuItemNonSpatialCopyRulebased = new javax.swing.JMenuItem(GuiConstants.MENU_TEXT_RULEBASED_APPLICATION);
menuItemNonSpatialCopyRulebased.setActionCommand(GuiConstants.ACTIONCMD_NON_SPATIAL_COPY_TO_RULEBASED_APPLICATION);
menuItemNonSpatialCopyRulebased.addActionListener(eventHandler);
}
menuAppCopyAs.add(menuItemNonSpatialCopyDeterministic);
menuAppCopyAs.add(menuItemNonSpatialCopyStochastic);
menuAppCopyAs.add(menuItemNonSpatialCopyRulebased);
} else {
if (menuSpatialCopyAsNonSpatial == null) {
menuSpatialCopyAsNonSpatial = new JMenu(GuiConstants.MENU_TEXT_NON_SPATIAL_APPLICATION);
menuItemSpatialCopyAsNonSpatialDeterministic = new JMenuItem(GuiConstants.MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialDeterministic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_NON_SPATIAL_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialDeterministic.addActionListener(eventHandler);
menuItemSpatialCopyAsNonSpatialStochastic = new JMenuItem(GuiConstants.MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialStochastic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_NON_SPATIAL_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsNonSpatialStochastic.addActionListener(eventHandler);
menuItemSpatialCopyAsNonSpatialRulebased = new JMenuItem(GuiConstants.MENU_TEXT_RULEBASED_APPLICATION);
menuItemSpatialCopyAsNonSpatialRulebased.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_NON_SPATIAL_RULEBASED_APPLICATION);
menuItemSpatialCopyAsNonSpatialRulebased.addActionListener(eventHandler);
menuSpatialCopyAsNonSpatial.add(menuItemSpatialCopyAsNonSpatialDeterministic);
menuSpatialCopyAsNonSpatial.add(menuItemSpatialCopyAsNonSpatialStochastic);
menuSpatialCopyAsNonSpatial.add(menuItemSpatialCopyAsNonSpatialRulebased);
menuSpatialCopyAsSpatial = new JMenu(GuiConstants.MENU_TEXT_SPATIAL_APPLICATION);
menuItemSpatialCopyAsSpatialDeterministic = new JMenuItem(GuiConstants.MENU_TEXT_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsSpatialDeterministic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_SPATIAL_DETERMINISTIC_APPLICATION);
menuItemSpatialCopyAsSpatialDeterministic.addActionListener(eventHandler);
menuItemSpatialCopyAsSpatialStochastic = new JMenuItem(GuiConstants.MENU_TEXT_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsSpatialStochastic.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_SPATIAL_STOCHASTIC_APPLICATION);
menuItemSpatialCopyAsSpatialStochastic.addActionListener(eventHandler);
menuItemSpatialCopyAsSpatialRulebased = new JMenuItem(GuiConstants.MENU_TEXT_RULEBASED_APPLICATION);
menuItemSpatialCopyAsSpatialRulebased.setActionCommand(GuiConstants.ACTIONCMD_SPATIAL_COPY_TO_SPATIAL_RULEBASED_APPLICATION);
menuItemSpatialCopyAsSpatialRulebased.addActionListener(eventHandler);
menuSpatialCopyAsSpatial.add(menuItemSpatialCopyAsSpatialDeterministic);
menuSpatialCopyAsSpatial.add(menuItemSpatialCopyAsSpatialStochastic);
// menuSpatialCopyAsSpatial.add(menuItemSpatialCopyAsSpatialRulebased); // not supported yet, uncomment when time comes
}
menuAppCopyAs.add(menuSpatialCopyAsNonSpatial);
menuAppCopyAs.add(menuSpatialCopyAsSpatial);
}
}
if (popupMenu.getComponents().length > 0) {
popupMenu.add(new JSeparator());
}
popupMenu.add(menuItemAppCopy);
popupMenu.add(menuAppCopyAs);
}
if (bNewBiomodel) {
menuItemNewBiomodelFromApp = new JMenuItem(GuiConstants.MENU_TEXT_APP_NEWBIOMODEL);
menuItemNewBiomodelFromApp.addActionListener(eventHandler);
popupMenu.add(menuItemNewBiomodelFromApp);
}
if (bExpand) {
if (expandAllMenuItem == null) {
popupMenuSeparator = new JSeparator();
expandAllMenuItem = new javax.swing.JMenuItem("Expand All");
collapseAllMenuItem = new javax.swing.JMenuItem("Collapse All");
expandAllMenuItem.addActionListener(eventHandler);
collapseAllMenuItem.addActionListener(eventHandler);
}
if (popupMenu.getComponents().length > 0) {
popupMenu.add(popupMenuSeparator);
}
popupMenu.add(expandAllMenuItem);
popupMenu.add(collapseAllMenuItem);
}
}
use of cbit.vcell.desktop.BioModelNode in project vcell by virtualcell.
the class DocumentEditorTreeModel method valueForPathChanged.
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
if (!(newValue instanceof String)) {
return;
}
String newName = (String) newValue;
try {
if (newName == null || newName.length() == 0) {
return;
}
Object obj = path.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (userObject instanceof SimulationContext) {
((SimulationContext) userObject).setName(newName);
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
}
}
Aggregations