use of javax.swing.JPopupMenu in project vcell by virtualcell.
the class BioModelEditorPathwayPanel method getAddPopupMenu.
private JPopupMenu getAddPopupMenu() {
if (addPopupMenu == null) {
addPopupMenu = new JPopupMenu();
addSelectedOnlyMenuItem = new JMenuItem("Selected Only");
addSelectedOnlyMenuItem.addActionListener(eventHandler);
addWithInteractionsMenuItem = new JMenuItem("Plus Interactions");
addWithInteractionsMenuItem.addActionListener(eventHandler);
// addWithComponentsMenueItem = new JMenuItem("Plus Components"); // we do it by default
// addWithComponentsMenueItem.addActionListener(eventHandler);
// addWithComplexesMenuItem = new JMenuItem("Plus Complexes"); // works but dubious need for it
// addWithComplexesMenuItem.addActionListener(eventHandler);
addPopupMenu.add(addSelectedOnlyMenuItem);
addPopupMenu.add(addWithInteractionsMenuItem);
// addPopupMenu.add(addWithComponentsMenueItem);
// addPopupMenu.add(addWithComplexesMenuItem);
}
return addPopupMenu;
}
use of javax.swing.JPopupMenu in project vcell by virtualcell.
the class BioModelParametersPanel method newApplicationButtonPressed.
protected void newApplicationButtonPressed() {
if (bioModel.getNumSimulationContexts() == 1) {
SimulationContext simContext = bioModel.getSimulationContext(0);
SimulationContextParameter newObject = simContext.createSimulationContextParameter();
// setTableSelections(new Object[]{modelParameter}, parametersFunctionsTable, parametersFunctionsTableModel);
if (newObject != null) {
for (int i = 0; i < parametersFunctionsTableModel.getRowCount(); i++) {
if (parametersFunctionsTableModel.getValueAt(i) == newObject) {
parametersFunctionsTable.setRowSelectionInterval(i, i);
break;
}
}
}
} else if (bioModel.getNumSimulationContexts() > 1) {
final JPopupMenu menu = new JPopupMenu("Choose Application");
for (int i = 0; i < bioModel.getNumSimulationContexts(); i++) {
SimulationContext simContext = bioModel.getSimulationContext(i);
String sName = simContext.getName();
JMenuItem menuItem = new JMenuItem("In " + sName);
Icon icon = null;
if (simContext.isRuleBased()) {
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appRbmNonspIcon;
}
} else if (simContext.isStoch()) {
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appStoNonspIcon;
} else {
icon = VCellIcons.appStoSpatialIcon;
}
} else {
// deterministic
if (simContext.getGeometry().getDimension() == 0) {
icon = VCellIcons.appDetNonspIcon;
} else {
icon = VCellIcons.appDetSpatialIcon;
}
}
if (icon != null) {
menuItem.setIcon(icon);
}
menu.add(menuItem);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SimulationContextParameter newObject = simContext.createSimulationContextParameter();
if (newObject != null) {
for (int i = 0; i < parametersFunctionsTableModel.getRowCount(); i++) {
if (parametersFunctionsTableModel.getValueAt(i) == newObject) {
parametersFunctionsTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
});
}
menu.show(addNewButton2, 0, addNewButton2.getHeight());
}
}
use of javax.swing.JPopupMenu in project vcell by virtualcell.
the class TestingFrameworkWindowManager method queryTCritCrossRef.
@SuppressWarnings("serial")
public void queryTCritCrossRef(final TestSuiteInfoNew tsin, final TestCriteriaNew tcrit, final String varName) {
try {
QueryTestCriteriaCrossRefOP queryTestCriteriaCrossRefOP = new QueryTestCriteriaCrossRefOP(tsin.getTSKey(), tcrit.getTCritKey(), varName);
TestCriteriaCrossRefOPResults testCriteriaCrossRefOPResults = (TestCriteriaCrossRefOPResults) getRequestManager().getDocumentManager().doTestSuiteOP(queryTestCriteriaCrossRefOP);
final Vector<TestCriteriaCrossRefOPResults.CrossRefData> xrefDataV = testCriteriaCrossRefOPResults.getCrossRefData();
final TestSuiteInfoNew[] testSuiteInfos = getRequestManager().getDocumentManager().getTestSuiteInfos();
Vector<TestSuiteInfoNew> missingTestSuites = new Vector<TestSuiteInfoNew>();
for (int i = 0; i < testSuiteInfos.length; i++) {
boolean bFound = false;
for (int j = 0; j < xrefDataV.size(); j++) {
if (xrefDataV.elementAt(j).tsVersion.equals(testSuiteInfos[i].getTSID())) {
bFound = true;
break;
}
}
if (!bFound) {
missingTestSuites.add(testSuiteInfos[i]);
}
}
TestCriteriaCrossRefOPResults.CrossRefData xrefDataSource = null;
for (int i = 0; i < xrefDataV.size(); i++) {
if (xrefDataV.elementAt(i).tcritKey.equals(tcrit.getTCritKey())) {
xrefDataSource = xrefDataV.elementAt(i);
break;
}
}
if (xrefDataSource == null) {
throw new RuntimeException("Couldn't find source Test Criteria in query results.");
}
final int numColumns = 8;
final int XREFDATA_ALLOWANCE = 1;
final int TSKEY_ALLOWANCE = 1;
final int XREFDATA_OFFSET = numColumns;
final int TSDATE_OFFSET = 1;
final int VARNAME_OFFSET = 3;
final int TSKEYMISSING_OFFSET = numColumns + 1;
final String[] colNames = new String[numColumns];
final Object[][] sourceRows = new Object[xrefDataV.size() + missingTestSuites.size()][numColumns + XREFDATA_ALLOWANCE + TSKEY_ALLOWANCE];
String sourceTestSuite = null;
colNames[0] = "tsVersion";
colNames[1] = "tsDate";
colNames[2] = "tsBaseVersion";
colNames[3] = "varName";
colNames[4] = "RelErorr";
colNames[5] = "limitRelErorr";
colNames[6] = "limitAbsErorr";
colNames[7] = "AbsErorr";
for (int i = 0; i < xrefDataV.size(); i++) {
sourceRows[i][colNames.length] = xrefDataV.elementAt(i);
if (xrefDataV.elementAt(i).tcritKey.equals(queryTestCriteriaCrossRefOP.getTestCriterium())) {
sourceTestSuite = xrefDataV.elementAt(i).tsVersion;
}
sourceRows[i][0] = xrefDataV.elementAt(i).tsVersion;
sourceRows[i][2] = (xrefDataV.elementAt(i).tsRefVersion == null ? (xrefDataV.elementAt(i).regressionModelID == null ? /* && xrefDataV.elementAt(i).regressionMMref==null*/
"" : "Ref Model exist BUT outside of TestSuites") : xrefDataV.elementAt(i).tsRefVersion);
sourceRows[i][6] = xrefDataV.elementAt(i).maxAbsErorr;
sourceRows[i][5] = xrefDataV.elementAt(i).maxRelErorr;
if (xrefDataV.elementAt(i).varName != null) {
sourceRows[i][VARNAME_OFFSET] = xrefDataV.elementAt(i).varName;
sourceRows[i][4] = xrefDataV.elementAt(i).varCompSummary.getRelativeError();
sourceRows[i][7] = xrefDataV.elementAt(i).varCompSummary.getAbsoluteError();
} else {
sourceRows[i][VARNAME_OFFSET] = "-No Report-";
// "No Report";
sourceRows[i][4] = null;
// "No Report";
sourceRows[i][7] = null;
}
for (int j = 0; j < testSuiteInfos.length; j++) {
if (xrefDataV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
sourceRows[i][1] = testSuiteInfos[j].getTSDate();
break;
}
}
}
for (int i = xrefDataV.size(); i < sourceRows.length; i++) {
sourceRows[i][0] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSID();
sourceRows[i][TSDATE_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSDate();
sourceRows[i][TSKEYMISSING_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSKey();
}
// Arrays.sort(rows,
// new Comparator<Object[]>(){
// public int compare(Object[] o1, Object[] o2) {
// return ((String)o1[0]).compareToIgnoreCase((String)o2[0]);
// // if(o1[0].equals(o2[0])){
// // return o1[3].compareToIgnoreCase(o2[3]);
// // }
// // return o1[0].compareToIgnoreCase(o2[0]);
// }
// }
// );
final VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(colNames) {
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == TSDATE_OFFSET) {
return Date.class;
} else if (columnIndex >= 4 && columnIndex <= 7) {
return Double.class;
}
return String.class;
}
public boolean isCellEditable(int row, int column) {
return false;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return getValueAt(rowIndex)[columnIndex];
}
public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
return new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if (o1[col] == null && o2[col] == null) {
return 0;
}
// if(ascending){
if (o1[col] == null) {
return 1;
}
if (o2[col] == null) {
return -1;
}
// }
if (getColumnClass(col).equals(String.class)) {
if (ascending) {
return ((String) o1[col]).compareToIgnoreCase(((String) o2[col]));
} else {
return ((String) o2[col]).compareToIgnoreCase(((String) o1[col]));
}
} else if (getColumnClass(col).equals(Date.class)) {
if (ascending) {
return ((Date) o1[col]).compareTo(((Date) o2[col]));
}
return ((Date) o2[col]).compareTo(((Date) o1[col]));
} else if (getColumnClass(col).equals(Double.class)) {
if (ascending) {
return ((Double) o1[col]).compareTo(((Double) o2[col]));
}
return ((Double) o2[col]).compareTo(((Double) o1[col]));
}
throw new RuntimeException("TestSuite XRef Query unexpecte column class " + getColumnClass(col).getName());
}
};
}
};
tableModel.setData(Arrays.asList(sourceRows));
// Create table
final JSortTable table = new JSortTable();
table.setModel(tableModel);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
final JScrollPane scrollPaneContentPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.getColumnModel().getColumn(TSDATE_OFFSET).setCellRenderer(new DefaultTableCellRenderer() {
// DateFormat formatter = DateFormat.getDateTimeInstance();
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return super.getTableCellRendererComponent(table, (value == null ? null : ((Date) value).toString()), /*formatter.format((Date)value)*/
isSelected, hasFocus, row, column);
}
});
DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return super.getTableCellRendererComponent(table, (value == null ? null : ((Double) value).toString()), /*formatter.format((Date)value)*/
isSelected, hasFocus, row, column);
}
};
table.getColumnModel().getColumn(4).setCellRenderer(dtcr);
table.getColumnModel().getColumn(5).setCellRenderer(dtcr);
table.getColumnModel().getColumn(6).setCellRenderer(dtcr);
table.getColumnModel().getColumn(7).setCellRenderer(dtcr);
// table.getColumnModel().getColumn(4).setCellRenderer(
// new DefaultTableCellRenderer(){
// public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// return super.getTableCellRendererComponent(table,(value == null?null:((Double)value).toString())/*formatter.format((Date)value)*/, isSelected, hasFocus, row, column);
// }
// }
// );
// table.getTableHeader().setReorderingAllowed(false);
// Popup Menu
final TestCriteriaCrossRefOPResults.CrossRefData xrefDataSourceFinal = xrefDataSource;
final JPopupMenu queryPopupMenu = new JPopupMenu();
final JMenuItem changeLimitsMenuItem = new JMenuItem("Change Selected Error Limits...");
final String OPEN_MODEL = "Open Model(s)";
final JMenuItem openModelMenuItem = new JMenuItem(OPEN_MODEL);
final String OPEN_REGRREFMODEL = "Open Regr Ref Model(s)";
final JMenuItem openRegrRefModelMenuItem = new JMenuItem(OPEN_REGRREFMODEL);
final String SELECT_REF_IN_TREE = "Select in Tree View";
final JMenuItem showInTreeMenuItem = new JMenuItem(SELECT_REF_IN_TREE);
final String SELECT_REGR_REF_IN_TREE = "Select RegrRef TCase in Tree View";
final JMenuItem showRegrRefInTreeMenuItem = new JMenuItem(SELECT_REGR_REF_IN_TREE);
queryPopupMenu.add(changeLimitsMenuItem);
queryPopupMenu.add(openModelMenuItem);
queryPopupMenu.add(openRegrRefModelMenuItem);
queryPopupMenu.add(showInTreeMenuItem);
queryPopupMenu.add(showRegrRefInTreeMenuItem);
ActionListener showInTreeActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int[] selectedRows = table.getSelectedRows();
if (selectedRows == null || selectedRows.length != 1) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Action " + actionEvent.getActionCommand() + " accepts only single selection!");
return;
}
TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[0], XREFDATA_OFFSET);
BigDecimal missingTSKey = (BigDecimal) tableModel.getValueAt(selectedRows[0], TSKEYMISSING_OFFSET);
if (actionEvent.getActionCommand().equals(SELECT_REF_IN_TREE)) {
getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.tsKey : missingTSKey), (xrefData != null ? xrefData.tcaseKey : null), (xrefData != null ? xrefData.tcritKey : null));
} else if (actionEvent.getActionCommand().equals(SELECT_REGR_REF_IN_TREE)) {
if (xrefData == null) {
PopupGenerator.showErrorDialog(getComponent(), "No Regression Reference info available.");
return;
}
getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.regressionModelTSuiteID : null), (xrefData != null ? xrefData.regressionModelTCaseID : null), (xrefData != null ? xrefData.regressionModelTCritID : null));
}
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
if (childWindow != null) {
childWindow.show();
}
}
};
showInTreeMenuItem.addActionListener(showInTreeActionListener);
showRegrRefInTreeMenuItem.addActionListener(showInTreeActionListener);
ActionListener openModelsActionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int[] selectedRows = table.getSelectedRows();
String failureS = "";
TestCriteriaCrossRefOPResults.CrossRefData xrefData = null;
int openCount = 0;
for (int i = 0; i < selectedRows.length; i++) {
try {
xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
if (xrefData != null && (actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID != null : true)) {
openCount += 1;
VCDocumentInfo vcDocInfo = null;
if (xrefData.isBioModel) {
vcDocInfo = getRequestManager().getDocumentManager().getBioModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
} else {
vcDocInfo = getRequestManager().getDocumentManager().getMathModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
}
getRequestManager().openDocument(vcDocInfo, TestingFrameworkWindowManager.this, true);
}
} catch (Exception e) {
failureS += failureS + "key=" + xrefData.modelID + " " + e.getMessage() + "\n";
e.printStackTrace();
}
}
if (failureS.length() > 0 || openCount == 0) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed to open some models\n" + failureS + (openCount == 0 ? "Selection(s) had no model(s)" : ""));
}
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
if (childWindow != null) {
childWindow.show();
}
}
};
openModelMenuItem.addActionListener(openModelsActionListener);
openRegrRefModelMenuItem.addActionListener(openModelsActionListener);
changeLimitsMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int[] selectedRows = table.getSelectedRows();
Vector<TestCriteriaCrossRefOPResults.CrossRefData> changeTCritV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
for (int i = 0; i < selectedRows.length; i++) {
TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
if (xrefData != null) {
boolean bFound = false;
for (int j = 0; j < changeTCritV.size(); j++) {
if (changeTCritV.elementAt(j).tcritKey.equals(xrefData.tcritKey)) {
bFound = true;
break;
}
}
if (!bFound) {
changeTCritV.add(xrefData);
}
}
}
if (changeTCritV.size() > 0) {
Double relativeErrorLimit = null;
Double absoluteErrorLimit = null;
while (true) {
try {
String ret = PopupGenerator.showInputDialog(getComponent(), "Enter new TestCriteria Error Limits for '" + xrefDataSourceFinal.simName + "'. '-'(dash) to keep original value.", "RelativeErrorLimit,AbsoluteErrorLimit");
int commaPosition = ret.indexOf(',');
if (commaPosition == -1) {
throw new Exception("No comma found separating RelativeErrorLimit AbsoluteErrorLimit");
}
if (commaPosition != ret.lastIndexOf(',')) {
throw new Exception("Only 1 comma allowed separating RelativeErrorLimit and AbsoluteErrorLimit");
}
final String KEEP_ORIGINAL_VALUE = "-";
String relativeErrorS = ret.substring(0, commaPosition);
String absoluteErrorS = ret.substring(commaPosition + 1, ret.length());
if (!relativeErrorS.equals(KEEP_ORIGINAL_VALUE)) {
relativeErrorLimit = Double.parseDouble(relativeErrorS);
}
if (!absoluteErrorS.equals(KEEP_ORIGINAL_VALUE)) {
absoluteErrorLimit = Double.parseDouble(absoluteErrorS);
}
if ((relativeErrorLimit != null && relativeErrorLimit <= 0) || (absoluteErrorLimit != null && absoluteErrorLimit <= 0)) {
throw new Exception("Error limits must be greater than 0");
}
break;
} catch (UserCancelException e) {
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
if (childWindow != null) {
childWindow.show();
}
return;
} catch (Exception e) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error parsing Error Limits\n" + e.getMessage());
}
}
double[] relErrorLimitArr = new double[changeTCritV.size()];
double[] absErrorLimitArr = new double[changeTCritV.size()];
Object[][] rows = new Object[changeTCritV.size()][5];
for (int j = 0; j < changeTCritV.size(); j++) {
relErrorLimitArr[j] = (relativeErrorLimit != null ? relativeErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxRelErorr);
absErrorLimitArr[j] = (absoluteErrorLimit != null ? absoluteErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxAbsErorr);
rows[j][2] = new Double(relErrorLimitArr[j]);
rows[j][4] = new Double(absErrorLimitArr[j]);
rows[j][1] = new Double(changeTCritV.elementAt(j).maxRelErorr);
rows[j][3] = new Double(changeTCritV.elementAt(j).maxAbsErorr);
rows[j][0] = changeTCritV.elementAt(j).tsVersion;
}
try {
PopupGenerator.showComponentOKCancelTableList(getComponent(), "Confirm Error Limit Changes", new String[] { "TSVersion", "Orig RelErrorLimit", "New RelErrorLimit", "Orig AbsErrorLimit", "New AbsErrorLimit" }, rows, null);
} catch (UserCancelException e) {
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
if (childWindow != null) {
childWindow.show();
}
return;
}
// Get information needed to generate new TestCriteria Reports
final String YES_ANSWER = "Yes";
Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>> genReportHash = null;
String genRepResult = PopupGenerator.showWarningDialog(getComponent(), "Generate Reports for changed Test Criterias?", new String[] { YES_ANSWER, "No" }, YES_ANSWER);
if (genRepResult != null && genRepResult.equals(YES_ANSWER)) {
genReportHash = new Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>>();
for (int i = 0; i < changeTCritV.size(); i++) {
boolean bFound = false;
for (int j = 0; j < testSuiteInfos.length; j++) {
if (changeTCritV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
bFound = true;
Vector<TestCriteriaCrossRefOPResults.CrossRefData> tempV = genReportHash.get(testSuiteInfos[j]);
if (tempV == null) {
tempV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
genReportHash.put(testSuiteInfos[j], tempV);
}
tempV.add(changeTCritV.elementAt(i));
}
}
if (!bFound) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Couldn't find testsuiteinfo for testcriteria");
return;
}
}
}
BigDecimal[] changeTCritBDArr = new BigDecimal[changeTCritV.size()];
for (int i = 0; i < changeTCritV.size(); i++) {
changeTCritBDArr[i] = changeTCritV.elementAt(i).tcritKey;
}
ChangeTestCriteriaErrorLimitOP changeTestCriteriaErrorLimitOP = new ChangeTestCriteriaErrorLimitOP(changeTCritBDArr, absErrorLimitArr, relErrorLimitArr);
try {
getTestingFrameworkWindowPanel().getDocumentManager().doTestSuiteOP(changeTestCriteriaErrorLimitOP);
} catch (Exception e) {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed Changing Error limits for selected " + xrefDataSourceFinal.simName + "\n" + e.getMessage());
return;
}
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
if (childWindow != null) {
childWindow.close();
}
getTestingFrameworkWindowPanel().refreshTree((TestSuiteInfoNew) null);
if (genReportHash != null) {
updateReports(genReportHash);
} else {
new Thread(new Runnable() {
public void run() {
TestingFrameworkWindowManager.this.queryTCritCrossRef(tsin, tcrit, varName);
}
}).start();
}
} else {
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "No selected rows contain Test Criteria.");
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
checkPopup(e);
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
checkPopup(e);
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
checkPopup(e);
}
private void checkPopup(MouseEvent mouseEvent) {
if (mouseEvent.isPopupTrigger()) {
// Not use because popupmenu will not show at edge
// if(table.getSelectedRowCount() <= 1){
// table.getSelectionModel().setSelectionInterval(table.rowAtPoint(mouseEvent.getPoint()),table.rowAtPoint(mouseEvent.getPoint()));
// }
doPopup(mouseEvent);
} else {
queryPopupMenu.setVisible(false);
}
}
private void doPopup(MouseEvent mouseEvent) {
// queryPopupMenu.add(showInTreeMenuItem);
if (table.getSelectedRowCount() == 0) {
changeLimitsMenuItem.setEnabled(false);
openModelMenuItem.setEnabled(false);
openRegrRefModelMenuItem.setEnabled(false);
showInTreeMenuItem.setEnabled(false);
showRegrRefInTreeMenuItem.setEnabled(false);
} else {
changeLimitsMenuItem.setEnabled(true);
openModelMenuItem.setEnabled(true);
openRegrRefModelMenuItem.setEnabled(true);
showInTreeMenuItem.setEnabled(true);
if (table.getSelectedRowCount() == 1) {
TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(table.getSelectedRow(), numColumns);
showRegrRefInTreeMenuItem.setEnabled(xrefData != null && xrefData.regressionModelID != null && xrefData.tsRefVersion != null);
}
}
queryPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
}
});
String title = (xrefDataSource.isBioModel ? "BM" : "MM") + " " + xrefDataSource.tcSolutionType + " (" + sourceTestSuite + ") " + " \"" + (xrefDataSource.isBioModel ? xrefDataSource.bmName : xrefDataSource.mmName) + "\" :: " + (xrefDataSource.isBioModel ? "app=\"" + xrefDataSource.bmAppName + "\" :: sim=\"" + xrefDataSource.simName + "\"" : "sim=\"" + xrefDataSource.simName + "\"");
ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).addChildWindow(scrollPaneContentPane, scrollPaneContentPane, title);
// childWindow.setSize(600,400);
childWindow.setIsCenteredOnParent();
childWindow.pack();
childWindow.setResizable(true);
childWindow.show();
} catch (DataAccessException e) {
e.printStackTrace();
PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error Query TestCriteria Cross Ref:\n" + e.getMessage());
}
}
use of javax.swing.JPopupMenu in project vcell by virtualcell.
the class MolecularTypePropertiesPanel method showPopupMenu.
private void showPopupMenu(MouseEvent e) {
if (!e.isPopupTrigger()) {
return;
}
if (popupMenu == null) {
popupMenu = new JPopupMenu();
}
if (popupMenu.isShowing()) {
return;
}
selectClickPath(e);
TreePath[] selectedPaths = molecularTypeTree.getSelectionPaths();
boolean bDelete = true;
boolean bAdd = true;
if (selectedPaths == null) {
return;
}
for (TreePath tp : selectedPaths) {
Object obj = tp.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
continue;
}
BioModelNode selectedNode = (BioModelNode) obj;
Object userObject = selectedNode.getUserObject();
if (userObject instanceof MolecularType) {
getAddFromTreeMenuItem().setText("Add " + MolecularComponent.typeName);
bAdd = true;
bDelete = false;
} else if (userObject instanceof MolecularComponent) {
getAddFromTreeMenuItem().setText("Add " + ComponentStateDefinition.typeName);
bAdd = true;
bDelete = true;
} else if (userObject instanceof ComponentStateDefinition) {
bAdd = false;
bDelete = true;
}
}
popupMenu.removeAll();
// everything can be renamed
popupMenu.add(getRenameFromTreeMenuItem());
if (bDelete) {
popupMenu.add(getDeleteFromTreeMenuItem());
}
popupMenu.add(new JSeparator());
if (bAdd) {
popupMenu.add(getAddFromTreeMenuItem());
}
Point mousePoint = e.getPoint();
popupMenu.show(molecularTypeTree, mousePoint.x, mousePoint.y);
}
use of javax.swing.JPopupMenu 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);
}
Aggregations