use of java.awt.event.MouseAdapter in project knime-core by knime.
the class ParameterizedDBQueryPanel method createColumnsAndVariablesPanel.
private JComponent createColumnsAndVariablesPanel() {
/* Create database column list */
final JPanel dbColumnsPanel = new JPanel(new BorderLayout());
dbColumnsPanel.setPreferredSize(new Dimension(200, 150));
final JLabel dbColumnsLabel = new JLabel("Database Column List");
dbColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
dbColumnsPanel.add(dbColumnsLabel, BorderLayout.NORTH);
dbColumnsPanel.add(new JScrollPane(m_dbColumnsList), BorderLayout.CENTER);
m_dbColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_dbColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_dbColumnsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInDatabaseList();
}
}
});
m_dbColumnsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInDatabaseList();
}
}
});
/* Create Knime column list */
final JPanel knimeColumnsPanel = new JPanel(new BorderLayout());
knimeColumnsPanel.setPreferredSize(new Dimension(200, 150));
final JLabel knimeColumnsLabel = new JLabel("Column List");
knimeColumnsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
knimeColumnsPanel.add(knimeColumnsLabel, BorderLayout.NORTH);
knimeColumnsPanel.add(new JScrollPane(m_knimeColumnsList), BorderLayout.CENTER);
m_knimeColumnsList.setCellRenderer(new DataColumnSpecListCellRenderer());
m_knimeColumnsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_knimeColumnsList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInColumnList();
}
}
});
m_knimeColumnsList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInColumnList();
}
}
});
final JSplitPane columnsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
columnsSplitPane.setResizeWeight(0.5);
columnsSplitPane.setOneTouchExpandable(true);
columnsSplitPane.setDividerSize(8);
columnsSplitPane.setTopComponent(dbColumnsPanel);
columnsSplitPane.setBottomComponent(knimeColumnsPanel);
columnsSplitPane.setDividerLocation(150);
/* Create flow variables list*/
final JPanel variablesPanel = new JPanel(new BorderLayout());
variablesPanel.setPreferredSize(new Dimension(200, 150));
final JLabel variablesLabel = new JLabel("Flow Variable List");
variablesLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
variablesPanel.add(variablesLabel, BorderLayout.NORTH);
variablesPanel.add(new JScrollPane(m_flowVariablesList), BorderLayout.CENTER);
m_flowVariablesList.setCellRenderer(new FlowVariableListCellRenderer());
m_flowVariablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_flowVariablesList.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void keyTyped(final KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
onSelectionInFlowVariableList();
}
}
});
m_flowVariablesList.addMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent evt) {
if (evt.getClickCount() == 2) {
onSelectionInFlowVariableList();
}
}
});
final JSplitPane columnsVariableSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
columnsVariableSplitPane.setResizeWeight(0.5);
columnsVariableSplitPane.setOneTouchExpandable(true);
columnsVariableSplitPane.setDividerSize(8);
columnsVariableSplitPane.setTopComponent(columnsSplitPane);
columnsVariableSplitPane.setBottomComponent(variablesPanel);
columnsVariableSplitPane.setDividerLocation(300);
return columnsVariableSplitPane;
}
use of java.awt.event.MouseAdapter in project vcell by virtualcell.
the class DialogUtils method getDBTreePanelSelection.
/**
* Return VersionInfo from JPanels implementing SelectableTreeVersionJPanel
* including MathModelDbTreePanel, BioModelDbTreePanel, GeometryTreePanel and ImageDbTreePanel
*
* @param requester parent component for dialog
* @param selectableTreeVersionJPanel component having a JTree user can select to define a VersionInfo
* @param okString label for button user presses when selection complete
* @param dialogTitle string displayed at top of dialog
* @return VersionInfo identifies a particular VCell document
* @throws UserCancelException
* @throws IllegalArgumentException
*/
public static VersionInfo getDBTreePanelSelection(Component requester, SelectableTreeVersionJPanel selectableTreeVersionJPanel, String okString, String dialogTitle) throws UserCancelException, IllegalArgumentException {
if (!(selectableTreeVersionJPanel instanceof JPanel)) {
throw new IllegalArgumentException("selectableTreeVersionJPanel must be of type JPanel");
}
final MouseListener[] mouseListener = new MouseListener[] { null };
// final JTree[] listenToJTree = new JTree[] {null};
try {
JPanel defaultSizedJPanel = new JPanel();
defaultSizedJPanel.setLayout(new BorderLayout());
defaultSizedJPanel.add((JPanel) selectableTreeVersionJPanel, BorderLayout.CENTER);
Dimension dim = new Dimension(300, 400);
defaultSizedJPanel.setPreferredSize(dim);
defaultSizedJPanel.setMinimumSize(dim);
defaultSizedJPanel.setMaximumSize(dim);
String result = DialogUtils.showOptionsDialog(requester, defaultSizedJPanel, JOptionPane.PLAIN_MESSAGE, new String[] { okString, getCancelText() }, okString, new DialogUtils.OKEnabler() {
@Override
public void setJOptionPane(JOptionPane joptionPane) {
DialogUtils.setInternalNotCancelEnabled(joptionPane, selectableTreeVersionJPanel.getSelectedVersionInfo() != null, false);
mouseListener[0] = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Component parentComponent = (Component) e.getSource();
while (parentComponent != selectableTreeVersionJPanel && parentComponent.getParent() != null) {
parentComponent = parentComponent.getParent();
}
if (parentComponent == selectableTreeVersionJPanel) {
if (selectableTreeVersionJPanel.getSelectedVersionInfo() != null) {
if (e.getClickCount() == 2) {
// enable OK and click OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, true, true);
} else {
// enable OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, true, false);
}
} else {
// disable OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, false, false);
}
}
}
};
selectableTreeVersionJPanel.addJTreeSelectionMouseListener(mouseListener[0]);
}
}, dialogTitle);
if (result == null || !result.equals(okString)) {
throw UserCancelException.CANCEL_GENERIC;
}
return selectableTreeVersionJPanel.getSelectedVersionInfo();
} finally {
selectableTreeVersionJPanel.removeJTreeSelectionMouseListener(mouseListener[0]);
}
}
use of java.awt.event.MouseAdapter in project vcell by virtualcell.
the class MIRIAMAnnotationEditor method getJTreeMIRIAM.
private JTree getJTreeMIRIAM() {
if (jTreeMIRIAM == null) {
try {
DefaultTreeSelectionModel ivjLocalSelectionModel;
ivjLocalSelectionModel = new DefaultTreeSelectionModel();
ivjLocalSelectionModel.setSelectionMode(1);
jTreeMIRIAM = new JTree();
jTreeMIRIAM.setName("JTree1");
jTreeMIRIAM.setToolTipText("");
jTreeMIRIAM.setBounds(0, 0, 357, 405);
jTreeMIRIAM.setMinimumSize(new java.awt.Dimension(100, 72));
jTreeMIRIAM.setSelectionModel(ivjLocalSelectionModel);
jTreeMIRIAM.setRowHeight(0);
// Add cellRenderer
DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// System.out.println(MIRIAMAnnotationEditor.this.getClass().getName()+".getJTreeMiriam():BioModelCellRenderer "+value.getClass()+" "+
// (value instanceof cbit.vcell.desktop.BioModelNode?
// ((cbit.vcell.desktop.BioModelNode)value).getUserObject().getClass():""));
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
component.setToolTipText("(Double-click to edit notes)");
Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
if (annotation.toString() == null || annotation.toString().length() == 0) {
component.setText("(Double-click to edit notes)");
}
}
return component;
}
};
jTreeMIRIAM.setCellRenderer(dtcr);
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseReleased(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
public void mousePressed(MouseEvent e) {
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
jTreeMIRIAM.setSelectionPath(closestMousePath);
showPopup(e, closestMousePath);
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeMIRIAM.getLastSelectedPathComponent();
if (node instanceof LinkNode) {
showBrowseToLink((LinkNode) node);
} else if (isNodeFreeHandTextEditable(node)) {
showEditFreehandText(node);
}
}
}
};
jTreeMIRIAM.addMouseListener(mouseListener);
} catch (java.lang.Throwable ivjExc) {
ivjExc.printStackTrace(System.out);
}
}
return jTreeMIRIAM;
}
use of java.awt.event.MouseAdapter in project vcell by virtualcell.
the class BioModelParametersPanel method initialize.
private void initialize() {
addNewButton = new JButton("New Global Parameter");
addNewButton.addActionListener(eventHandler);
addNewButton2 = new JButton("New Application Parameter");
// addNewButton2.setIcon(downArrow);
addNewButton2.setHorizontalTextPosition(SwingConstants.LEFT);
addNewButton2.addActionListener(eventHandler);
deleteButton = new JButton("Delete");
deleteButton.setEnabled(false);
deleteButton.addActionListener(eventHandler);
changeUnitsButton = new JButton("Change Unit System");
changeUnitsButton.addActionListener(eventHandler);
textFieldSearch = new JTextField(10);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
parametersFunctionsTable = new EditorScrollTable();
parametersFunctionsTableModel = new BioModelParametersTableModel(parametersFunctionsTable);
parametersFunctionsTable.setModel(parametersFunctionsTableModel);
globalParametersCheckBox = new JCheckBox("Global");
globalParametersCheckBox.setSelected(true);
globalParametersCheckBox.addActionListener(eventHandler);
reactionsCheckBox = new JCheckBox("Reactions and Rules");
reactionsCheckBox.setSelected(true);
reactionsCheckBox.addActionListener(eventHandler);
applicationsCheckBox = new JCheckBox("Applications");
applicationsCheckBox.setSelected(true);
applicationsCheckBox.addActionListener(eventHandler);
applicationComboBox = new JComboBox<ApplicationSelection>();
applicationComboBox.setSelectedItem("All");
applicationComboBox.addActionListener(eventHandler);
applicationComboBox.setModel(applicationComboBoxModel);
applicationComboBox.setRenderer(new ApplicationComboBoxRenderer());
constantsCheckBox = new JCheckBox("Parameters");
constantsCheckBox.setSelected(true);
constantsCheckBox.addActionListener(eventHandler);
functionsCheckBox = new JCheckBox("Functions");
functionsCheckBox.setSelected(true);
functionsCheckBox.addActionListener(eventHandler);
predefinedSymbolsTable = new EditorScrollTable();
predefinedSymbolsTableModel = new PredefinedSymbolsTableModel(predefinedSymbolsTable);
predefinedSymbolsTable.setModel(predefinedSymbolsTableModel);
GuiUtils.flexResizeTableColumns(predefinedSymbolsTable);
modelUnitSystemTable = new EditorScrollTable();
modelUnitSystemTableModel = new ModelUnitSystemTableModel(modelUnitSystemTable);
modelUnitSystemTable.setModel(modelUnitSystemTableModel);
GuiUtils.flexResizeTableColumns(modelUnitSystemTable);
tabbedPane = new JTabbedPaneEnhanced();
tabbedPane.addChangeListener(eventHandler);
ParametersPanelTab[] parametersPanelTabs = new ParametersPanelTab[ParametersPanelTabID.values().length];
parametersPanelTabs[ParametersPanelTabID.parameters_functions.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.parameters_functions, getParametersFunctionsPanel(), null);
parametersPanelTabs[ParametersPanelTabID.predefined.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.predefined, getPredefinedSymbolsPanel(), null);
parametersPanelTabs[ParametersPanelTabID.modelUnitSystem.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.modelUnitSystem, getModelUnitSystemPanel(), null);
for (ParametersPanelTab tab : parametersPanelTabs) {
tab.component.setBorder(GuiConstants.TAB_PANEL_BORDER);
tabbedPane.addTab(tab.id.title, tab.icon, tab.component);
}
JPanel buttonPanel = new JPanel(new GridBagLayout());
int gridy = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(addNewButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(addNewButton2, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(deleteButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(changeUnitsButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 50, 4, 4);
buttonPanel.add(new JLabel("Search"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
buttonPanel.add(textFieldSearch, gbc);
setLayout(new BorderLayout());
add(tabbedPane, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
parametersFunctionsTable.getSelectionModel().addListSelectionListener(eventHandler);
parametersFunctionsTable.setDefaultRenderer(NameScope.class, 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 (value instanceof NameScope) {
NameScope nameScope = (NameScope) value;
setText(nameScope.getPathDescription());
}
return this;
}
});
{
// make double click on units panel bring up editing box
JPanel p = getModelUnitSystemPanel();
VCAssert.assertValid(p);
EditorScrollTable est = GuiUtils.findFirstChild(p, EditorScrollTable.class);
VCAssert.assertValid(est);
MouseListener ml = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
changeUnitsButtonPressed();
}
}
};
est.addMouseListener(ml);
}
}
use of java.awt.event.MouseAdapter 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());
}
}
Aggregations