use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel 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 cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class ViewObservablesMapPanel method initialize.
private void initialize() {
try {
// --------------------------------------- the split panels
setName("ViewGeneratedSpeciesPanel");
setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.setLayout(new GridBagLayout());
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new GridBagLayout());
JSplitPane splitPaneHorizontal = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPaneHorizontal.setDividerSize(10);
splitPaneHorizontal.setOneTouchExpandable(true);
splitPaneHorizontal.setDividerLocation(260);
splitPaneHorizontal.setResizeWeight(0.5);
splitPaneHorizontal.setTopComponent(topPanel);
splitPaneHorizontal.setBottomComponent(bottomPanel);
add(splitPaneHorizontal, BorderLayout.CENTER);
// ---------------------------------------- species shape panel
shapePanelSpecies = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spls != null) {
spls.paintSelf(g);
}
}
@Override
public DisplayMode getDisplayMode() {
return DisplayMode.other;
}
@Override
public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleParticipantSignature getSignature() {
return null;
}
@Override
public GroupingCriteria getCriteria() {
return null;
}
@Override
public boolean isViewSingleRow() {
return true;
}
};
shapePanelSpecies.setLayout(new GridBagLayout());
shapePanelSpecies.setBackground(Color.white);
// not really editable but we don't want the brown contours here
shapePanelSpecies.setEditable(true);
shapePanelSpecies.setShowMoleculeColor(true);
shapePanelSpecies.setShowNonTrivialOnly(true);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
JScrollPane scrollPaneSpecies = new JScrollPane(shapePanelSpecies);
scrollPaneSpecies.setBorder(loweredBevelBorder);
scrollPaneSpecies.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneSpecies.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanelSpecies = new JPanel();
optionsPanelSpecies.setLayout(new GridBagLayout());
getZoomSmallerButtonSpecies().setEnabled(true);
getZoomLargerButtonSpecies().setEnabled(true);
shapePanelSpecies.zoomSmaller();
shapePanelSpecies.zoomSmaller();
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelSpecies.add(getZoomLargerButtonSpecies(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelSpecies.add(getZoomSmallerButtonSpecies(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanelSpecies.add(new JLabel(""), gbc);
JPanel containerOfScrollPanelSpecies = new JPanel();
containerOfScrollPanelSpecies.setLayout(new BorderLayout());
containerOfScrollPanelSpecies.add(optionsPanelSpecies, BorderLayout.WEST);
containerOfScrollPanelSpecies.add(scrollPaneSpecies, BorderLayout.CENTER);
Dimension dimS = new Dimension(500, 125);
// dimension of shape panel
containerOfScrollPanelSpecies.setPreferredSize(dimS);
containerOfScrollPanelSpecies.setMinimumSize(dimS);
containerOfScrollPanelSpecies.setMaximumSize(dimS);
shapePanelObservable = new LargeShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternLargeShape sps : spsList) {
if (sps == null) {
continue;
}
sps.paintSelf(g);
}
}
@Override
public DisplayMode getDisplayMode() {
return DisplayMode.other;
}
@Override
public RuleAnalysisChanged hasStateChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasStateChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(String reactionRuleName, MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasBondChanged(MolecularComponentPattern molecularComponentPattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(String reactionRuleName, MolecularTypePattern mtp) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleAnalysisChanged hasNoMatch(MolecularTypePattern molecularTypePattern) {
return RuleAnalysisChanged.UNCHANGED;
}
@Override
public RuleParticipantSignature getSignature() {
return null;
}
@Override
public GroupingCriteria getCriteria() {
return null;
}
@Override
public boolean isViewSingleRow() {
return true;
}
};
//
DefaultScrollTableCellRenderer rbmSpeciesPatternCellRenderer = new DefaultScrollTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof GeneratedSpeciesTableModel2) {
Object selectedObject = null;
if (table.getModel() == speciesTableModel) {
selectedObject = speciesTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow && value instanceof String) {
SpeciesPattern sp = ((GeneratedSpeciesTableRow) selectedObject).getSpecies().getSpeciesPattern();
String text = "<html>";
text += RbmTableRenderer.toHtml(sp, isSelected);
text += "</html>";
setText(text);
}
}
}
return this;
}
};
// shapePanelObservable.setLayout(null);
shapePanelObservable.setLayout(new GridBagLayout());
shapePanelObservable.setBackground(Color.white);
shapePanelObservable.setEditable(true);
shapePanelObservable.setShowMoleculeColor(true);
shapePanelObservable.setShowNonTrivialOnly(true);
JScrollPane scrollPaneObservable = new JScrollPane(shapePanelObservable);
scrollPaneObservable.setBorder(loweredBevelBorder);
scrollPaneObservable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPaneObservable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanelObservable = new JPanel();
optionsPanelObservable.setLayout(new GridBagLayout());
getZoomSmallerButtonObservable().setEnabled(true);
getZoomLargerButtonObservable().setEnabled(true);
shapePanelObservable.zoomSmaller();
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelObservable.add(getZoomLargerButtonObservable(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanelObservable.add(getZoomSmallerButtonObservable(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanelObservable.add(new JLabel(""), gbc);
JPanel containerOfScrollPanelObservable = new JPanel();
containerOfScrollPanelObservable.setLayout(new BorderLayout());
containerOfScrollPanelObservable.add(optionsPanelObservable, BorderLayout.WEST);
containerOfScrollPanelObservable.add(scrollPaneObservable, BorderLayout.CENTER);
Dimension dimO = new Dimension(500, 100);
// dimension of shape panel
containerOfScrollPanelObservable.setPreferredSize(dimO);
containerOfScrollPanelObservable.setMinimumSize(dimO);
containerOfScrollPanelObservable.setMaximumSize(dimO);
// -------------- connection between tables, table models, selection models, renderers, event handlers
speciesTable = new EditorScrollTable();
speciesTableModel = new GeneratedSpeciesTableModel2(speciesTable, owner);
speciesTable.setModel(speciesTableModel);
speciesTable.getSelectionModel().addListSelectionListener(eventHandlerS);
speciesTable.getModel().addTableModelListener(eventHandlerS);
observablesTable = new EditorScrollTable();
observablesTableModel = new ObservablesGroupTableModel(observablesTable, owner, speciesTableModel);
observablesTable.setModel(observablesTableModel);
observablesTable.getSelectionModel().addListSelectionListener(eventHandlerO);
observablesTable.getModel().addTableModelListener(eventHandlerO);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setCellRenderer(rbmSpeciesPatternCellRenderer);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
// speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setCellRenderer(rightRenderer); // right align
// left column wide enough for title
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColMultiplier).setMaxWidth(70);
speciesTable.addMouseMotionListener(new // add toolTipText for each table cell
MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int row = speciesTable.rowAtPoint(p);
int column = speciesTable.columnAtPoint(p);
speciesTable.setToolTipText(String.valueOf(speciesTable.getValueAt(row, column)));
}
});
// ---------------------------------------------- top panel
int gridy = 0;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
observablesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
topPanel.add(observablesTable.getEnclosingScrollPane(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
topPanel.add(new JLabel("Search "), gbc);
textFieldSearchObservables = new JTextField(70);
textFieldSearchObservables.addActionListener(eventHandlerO);
textFieldSearchObservables.getDocument().addDocumentListener(eventHandlerO);
textFieldSearchObservables.putClientProperty("JTextField.variant", "search");
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
topPanel.add(textFieldSearchObservables, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
topPanel.add(totalObservablesLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
gbc.gridwidth = 8;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
topPanel.add(containerOfScrollPanelObservable, gbc);
// -------------------------------------------- bottom panel
gridy = 0;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
speciesTable.setPreferredScrollableViewportSize(new Dimension(400, 200));
bottomPanel.add(speciesTable.getEnclosingScrollPane(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
bottomPanel.add(new JLabel("Search "), gbc);
textFieldSearchSpecies = new JTextField(70);
textFieldSearchSpecies.addActionListener(eventHandlerS);
textFieldSearchSpecies.getDocument().addDocumentListener(eventHandlerS);
textFieldSearchSpecies.putClientProperty("JTextField.variant", "search");
gbc = new java.awt.GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
bottomPanel.add(textFieldSearchSpecies, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
bottomPanel.add(totalSpeciesLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
gbc.gridwidth = 8;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
bottomPanel.add(containerOfScrollPanelSpecies, gbc);
// rendering the small shapes of the flattened species in the Depiction column of this viewer table)
// TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
// of a species context in the Depiction column of the species table)
DefaultScrollTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == speciesTableModel) {
selectedObject = speciesTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedSpeciesTableRow) {
SpeciesContext sc = ((GeneratedSpeciesTableRow) selectedObject).getSpecies();
// sp cannot be null
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, panelContext, sc, isSelected, issueManager);
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setCellRenderer(rbmSpeciesShapeDepictionCellRenderer);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setPreferredWidth(400);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDepiction).setMinWidth(400);
speciesTable.getColumnModel().getColumn(GeneratedSpeciesTableModel2.iColDefinition).setPreferredWidth(30);
speciesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
DefaultScrollTableCellRenderer rbmObservableShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == observablesTableModel) {
selectedObject = observablesTableModel.getValueAt(row);
}
if (selectedObject != null && selectedObject instanceof ObservablesGroupTableRow) {
ObservablesGroupTableRow ogtr = ((ObservablesGroupTableRow) selectedObject);
String obsName = ogtr.getObservableGroupObject().getObservableGroupName();
RbmObservable observable = ogtr.getObservable(obsName);
Graphics panelContext = table.getGraphics();
int xPos = 4;
spssList.clear();
for (int i = 0; i < observable.getSpeciesPatternList().size(); i++) {
SpeciesPattern sp = observable.getSpeciesPatternList().get(i);
spss = new SpeciesPatternSmallShape(xPos, 2, sp, panelContext, observable, isSelected, issueManager);
xPos += spss.getWidth() + 6;
spssList.add(spss);
}
} else {
spssList.clear();
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternSmallShape spss : spssList) {
if (spss == null) {
continue;
}
spss.paintSelf(g);
}
}
};
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setCellRenderer(rbmObservableShapeDepictionCellRenderer);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setPreferredWidth(150);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDepiction).setMinWidth(150);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColDefinition).setPreferredWidth(80);
observablesTable.getColumnModel().getColumn(ObservablesGroupTableModel.iColExpression).setPreferredWidth(100);
observablesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class InitialConditionsPanel method initialize.
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("InitialConditionsPanel");
setLayout(new BorderLayout());
add(getRadioButtonAndCheckboxPanel(), BorderLayout.NORTH);
add(getScrollPaneTable().getEnclosingScrollPane(), BorderLayout.CENTER);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
getJMenuItemPaste().addActionListener(ivjEventHandler);
getJMenuItemCopy().addActionListener(ivjEventHandler);
getJMenuItemCopyAll().addActionListener(ivjEventHandler);
getJMenuItemPasteAll().addActionListener(ivjEventHandler);
getAmountRadioButton().addActionListener(ivjEventHandler);
getConcentrationRadioButton().addActionListener(ivjEventHandler);
getRandomizeInitCondnCheckbox().addActionListener(ivjEventHandler);
DefaultTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setIcon(null);
defaultToolTipText = null;
if (value instanceof Species) {
setText(((Species) value).getCommonName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof SpeciesContext) {
setText(((SpeciesContext) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof Structure) {
setText(((Structure) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
} else if (value instanceof ScopedExpression) {
SpeciesContextSpec scSpec = tableModel.getValueAt(row);
VCUnitDefinition unit = null;
if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_INITIAL.label)) {
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
unit = initialConditionParameter.getUnitDefinition();
} else if (table.getColumnName(column).equals(SpeciesContextSpecsTableModel.ColumnType.COLUMN_DIFFUSION.label)) {
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
unit = diffusionParameter.getUnitDefinition();
}
if (unit != null) {
setHorizontalTextPosition(JLabel.LEFT);
setIcon(new TextIcon("[" + unit.getSymbolUnicode() + "]", DefaultScrollTableCellRenderer.uneditableForeground));
}
int rgb = 0x00ffffff & DefaultScrollTableCellRenderer.uneditableForeground.getRGB();
defaultToolTipText = "<html>" + StringEscapeUtils.escapeHtml4(getText()) + " <font color=#" + Integer.toHexString(rgb) + "> [" + unit.getSymbolUnicode() + "] </font></html>";
setToolTipText(defaultToolTipText);
if (unit != null) {
setText(defaultToolTipText);
}
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
setHorizontalTextPosition(JLabel.TRAILING);
}
return this;
}
};
DefaultTableCellRenderer rbmSpeciesShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
// sp may be null for "plain" species contexts
SpeciesPattern sp = sc.getSpeciesPattern();
Graphics panelContext = table.getGraphics();
spss = new SpeciesPatternSmallShape(4, 2, sp, shapeManager, panelContext, sc, isSelected, issueManager);
}
} else {
spss = null;
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (spss != null) {
spss.paintSelf(g);
}
}
};
DefaultScrollTableCellRenderer rulesTableCellRenderer = new DefaultScrollTableCellRenderer() {
final Color lightBlueBackground = new Color(214, 234, 248);
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof SpeciesContextSpecsTableModel) {
Icon icon = VCellIcons.issueGoodIcon;
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (isSelected) {
setBackground(lightBlueBackground);
}
if (selectedObject instanceof SpeciesContextSpec) {
SpeciesContextSpec scs = (SpeciesContextSpec) selectedObject;
SpeciesContext sc = scs.getSpeciesContext();
boolean foundRuleMatch = false;
if (fieldSimulationContext.getRateRules() != null && fieldSimulationContext.getRateRules().length > 0) {
for (RateRule rr : fieldSimulationContext.getRateRules()) {
if (rr.getRateRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getRateRuleVar().getName())) {
foundRuleMatch = true;
icon = VCellIcons.ruleRateIcon;
break;
}
}
}
if (!foundRuleMatch && fieldSimulationContext.getAssignmentRules() != null && fieldSimulationContext.getAssignmentRules().length > 0) {
for (AssignmentRule rr : fieldSimulationContext.getAssignmentRules()) {
if (rr.getAssignmentRuleVar() == null) {
continue;
}
if (sc.getName().equals(rr.getAssignmentRuleVar().getName())) {
icon = VCellIcons.ruleAssignIcon;
break;
}
}
}
}
}
setIcon(icon);
}
return this;
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesContext.class, renderer);
getScrollPaneTable().setDefaultRenderer(Structure.class, renderer);
// depiction icons
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmSpeciesShapeDepictionCellRenderer);
getScrollPaneTable().setDefaultRenderer(Species.class, renderer);
getScrollPaneTable().setDefaultRenderer(ScopedExpression.class, renderer);
getScrollPaneTable().setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
// rules icons
getScrollPaneTable().setDefaultRenderer(SpeciesContextSpecsTableModel.RulesProvenance.class, rulesTableCellRenderer);
// TODO: find out why the code below is not working properly
// int ordinal = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(ordinal).setCellRenderer(rulesTableCellRenderer);
// final int rulesWidth = 50; // fixed max size, there's no point to enlarge some columns
// int index = SpeciesContextSpecsTableModel.ColumnType.COLUMN_RULES.ordinal();
// getScrollPaneTable().getColumnModel().getColumn(index).setPreferredWidth(rulesWidth);
// getScrollPaneTable().getColumnModel().getColumn(index).setMaxWidth(rulesWidth);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class ModelProcessSpecsPanel method initConnections.
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
this.addPropertyChangeListener(ivjEventHandler);
getScrollPaneTable().setModel(getModelProcessSpecsTableModel());
getScrollPaneTable().setDefaultRenderer(ModelProcess.class, new DefaultScrollTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
defaultToolTipText = null;
if (value instanceof ModelProcess) {
setText(((ModelProcess) value).getName());
defaultToolTipText = getText();
setToolTipText(defaultToolTipText);
}
TableModel tableModel = table.getModel();
if (tableModel instanceof SortTableModel) {
DefaultScrollTableCellRenderer.issueRenderer(this, defaultToolTipText, table, row, column, (SortTableModel) tableModel);
}
return this;
}
});
DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == ivjModelProcessSpecsTableModel) {
selectedObject = ivjModelProcessSpecsTableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof ModelProcessSpec) {
ModelProcessSpec mps = (ModelProcessSpec) selectedObject;
ModelProcess mp = (ModelProcess) mps.getModelProcess();
if (mp instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) mp;
Graphics panelContext = table.getGraphics();
spssList.clear();
List<ReactantPattern> rpList = rr.getReactantPatterns();
int xPos = 4;
for (int i = 0; i < rpList.size(); i++) {
SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rr, isSelected, issueManager);
if (i < rpList.size() - 1) {
spss.addEndText("+");
} else {
if (rr.isReversible()) {
spss.addEndText("<->");
xPos += 7;
} else {
spss.addEndText("->");
}
}
xPos += spss.getWidth() + 15;
spssList.add(spss);
}
List<ProductPattern> ppList = rr.getProductPatterns();
xPos += 7;
for (int i = 0; i < ppList.size(); i++) {
SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rr, isSelected, issueManager);
if (i < ppList.size() - 1) {
spss.addEndText("+");
}
xPos += spss.getWidth() + 15;
spssList.add(spss);
}
} else {
ReactionStep rs = (ReactionStep) mp;
Graphics panelContext = table.getGraphics();
spssList.clear();
int xPos = 4;
int extraSpace = 0;
for (int i = 0; i < rs.getNumReactants(); i++) {
SpeciesPattern sp = rs.getReactant(i).getSpeciesContext().getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i < rs.getNumReactants() - 1) {
spss.addEndText("+");
} else {
if (rs.isReversible()) {
spss.addEndText("<->");
extraSpace += 7;
} else {
spss.addEndText("->");
}
}
int offset = sp == null ? 17 : 15;
offset += extraSpace;
int w = spss.getWidth();
xPos += w + offset;
spssList.add(spss);
}
xPos += 8;
for (int i = 0; i < rs.getNumProducts(); i++) {
SpeciesPattern sp = rs.getProduct(i).getSpeciesContext().getSpeciesPattern();
if (i == 0 && rs.getNumReactants() == 0) {
xPos += 14;
}
spss = new SpeciesPatternSmallShape(xPos, 2, sp, shapeManager, panelContext, rs, isSelected, issueManager);
if (i == 0 && rs.getNumReactants() == 0) {
spss.addStartText("->");
}
if (i < rs.getNumProducts() - 1) {
spss.addEndText("+");
}
int offset = sp == null ? 17 : 15;
int w = spss.getWidth();
xPos += w + offset;
spssList.add(spss);
}
}
}
} else {
spssList.clear();
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternSmallShape spss : spssList) {
if (spss == null) {
continue;
}
spss.paintSelf(g);
}
}
};
getScrollPaneTable().setDefaultRenderer(SpeciesPattern.class, rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
// ivjScrollPaneTable.getColumnModel().getColumn(ModelProcessSpecsTableModel.ColumnType.COLUMN_DEPICTION.ordinal()).setPreferredWidth(180);
getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
}
use of cbit.vcell.client.desktop.biomodel.VCellSortTableModel in project vcell by virtualcell.
the class DialogUtils method showComponentOptionsTableList.
public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
// //Create hidden column with original row index so original row index can
// //be returned for user selections even if rows are sorted
// final int hiddenColumnIndex = rowDataOrig[0].length;
// final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
// for (int i = 0; i < rowDataHiddenIndex.length; i++) {
// for (int j = 0; j < rowDataOrig[i].length; j++) {
// rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
// }
// rowDataHiddenIndex[i][hiddenColumnIndex] = i;
// }
Producer<TableListResult> prod = () -> {
// Create hidden column with original row index so original row index can
// be returned for user selections even if rows are sorted
int hiddenColumnIndex = rowDataOrig[0].length;
Object[][] rowDataHiddenIndex = rowDataOrig;
if (rowSortComparator != null) {
rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
for (int i = 0; i < rowDataHiddenIndex.length; i++) {
for (int j = 0; j < rowDataOrig[i].length; j++) {
rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
}
rowDataHiddenIndex[i][hiddenColumnIndex] = i;
}
}
@SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {
@Override
public boolean isSortable(int col) {
if (rowSortComparator != null) {
return true;
}
return false;
}
public Object getValueAt(int row, int column) {
return getValueAt(row)[column];
}
@Override
public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
return new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if (ascending) {
return rowSortComparator.compare(o1[col], o2[col]);
}
return rowSortComparator.compare(o2[col], o1[col]);
}
};
}
};
final JSortTable table = new JSortTable();
// table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setModel(tableModel);
tableModel.setData(Arrays.asList(rowDataHiddenIndex));
if (listSelectionModel_SelectMode != null) {
table.setSelectionMode(listSelectionModel_SelectMode);
} else {
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
}
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.disableUneditableForeground();
OKEnabler tableListOKEnabler = null;
if (listSelectionModel_SelectMode != null) {
tableListOKEnabler = new OKEnabler() {
private JOptionPane jop;
public void setJOptionPane(JOptionPane joptionPane) {
jop = joptionPane;
setInternalNotCancelEnabled(joptionPane, false, false);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
if (table.getSelectedRowCount() != 0) {
setInternalNotCancelEnabled(jop, true, false);
} else {
setInternalNotCancelEnabled(jop, false, false);
}
}
}
});
}
};
}
if (listSelectionListener != null) {
table.getSelectionModel().addListSelectionListener(listSelectionListener);
}
TableListResult tableListResult = new TableListResult();
// HACK to fix horizontal scrollbar not showing for large horizontal tables
// workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
Component[] components = table.getEnclosingScrollPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof JScrollPane) {
jScrollPaneArr[0] = (JScrollPane) components[i];
break;
}
}
if (jScrollPaneArr[0] != null) {
jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
});
}
if (options == null) {
if (bModal) {
if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} else {
// display non-modal
JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
JDialog jDialog = jOptionPane.createDialog(requester, title);
jDialog.setResizable(true);
jDialog.setModal(false);
jDialog.pack();
jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog.setVisible(true);
}
tableListResult.selectedTableRows = table.getSelectedRows();
} else {
tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
tableListResult.selectedTableRows = table.getSelectedRows();
}
if (rowSortComparator != null) {
// return the index of the original unsorted object array that corresponds to the user row selections
for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
}
}
return tableListResult;
};
return VCSwingFunction.executeAsRuntimeException(prod);
}
Aggregations