📄 catalogpanel.java
字号:
jbWheres.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int rowid = catalogTable.getRowHeader().getSelectedRow();
if (rowid >= 0) {
rowid = catalogTable.getSortedRowModelIndex(rowid);
CatalogTableModel ctm = catalogTable.getModel();
double lat = ((DataObject) ctm.getValueAt(rowid, ctm.findColumn("LAT"))).doubleValue();
double lon = ((DataObject) ctm.getValueAt(rowid, ctm.findColumn("LON"))).doubleValue();
long id = ((DataObject) ctm.getValueAt(rowid, ctm.findColumn("ID"))).longValue();
// String whereString = Wheres.where(lat, lon);
// String whereString = WheresFrom.where(lat, lon);
Connection conn = solutionList.getConnection();
if (conn != null) {
/****
* DK 11/05/2002
* Can't get a hook to the Jiggle configfile down in here(CatalogPanel)
* so we will call CreateWhereIsEngine() with no arguments, and hope
* that someone else has already called CreateWhereIsEngine and a
* default WhereIsEngine has been named
****/
if (whereFrom == null) whereFrom = WhereIsEngine.CreateWhereIsEngine();
String whereString = whereFrom.where(lat, lon);
logTextnl("Where id: " + id + "\n" + whereString);
JOptionPane.showMessageDialog(CatalogPanel.this,
whereString, "Where", JOptionPane.PLAIN_MESSAGE);
}
}
}
});
jbWheres.setToolTipText("Report closest to selected row in table.");
jbWheres.setEnabled(false);
jbWheres.setMargin(new Insets(2,2,2,2));
buttonPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) buttonPanel.getLayout();
flowLayout.setAlignment(FlowLayout.CENTER);
flowLayout.setHgap(0);
buttonPanel.add(jbInsert);
buttonPanel.add(jbCommit);
buttonPanel.add(jbDelete);
buttonPanel.add(jbFile);
buttonPanel.add(jbWheres);
TablePanel.this.add(buttonPanel, BorderLayout.NORTH);
// Debug.println("jpModify prefSize: " + jpModify.getPreferredSize().toString());
if (CatalogPanel.this.hasUpdateDisabled()) hideModifyButtons();
disableModifyButtons();
jbFile.setEnabled(false);
jbWheres.setEnabled(false);
// jbFile.setVisible(false);
}
private void enableModifyButtons() {
if (isNotModifiable()) return;
jbInsert.setEnabled(true);
jbDelete.setEnabled(true);
jbCommit.setEnabled(true);
}
private void disableModifyButtons() {
jbInsert.setEnabled(false);
jbDelete.setEnabled(false);
jbCommit.setEnabled(false);
}
private void showModifyButtons() {
jbInsert.setVisible(true);
jbDelete.setVisible(true);
jbCommit.setVisible(true);
}
private void hideModifyButtons() {
jbInsert.setVisible(false);
jbDelete.setVisible(false);
jbCommit.setVisible(false);
}
private void createTable() {
spane = catalogTable.createTable();
// spane.setToolTipText("Table results.");
// spane.setForeground(Color.black);
// spane.setBackground(Color.lightGray);
}
private boolean hasInvalidTable() {
return ! this.hasValidTable();
}
private boolean hasValidTable() {
if (catalogTable.getTable() == null || hasNullSolutionList()) {
// logTextnl("No rows in Catalog table - execute new request.");
// InfoDialog.informUser(CatalogPanel.this, "ERROR", "No rows in table - execute new request.", statusLabel);
return false;
}
else return true;
}
private boolean insertRow() {
tableRowHeadSelectionFlag = catalogTable.getRowHeader().getCellSelectionEnabled();
catalogTable.getRowHeader().setCellSelectionEnabled(true);
Solution sol = Solution.create();
// sol.id.setValue(SeqIds.getNextSeq(solutionList.getConnection(), "EVSEQ"));
sol.id.setValue(sol.getNextID());
int rowid = catalogTable.getRowHeader().getSelectedRow();
int modelRowId = 0;
if (rowid < 0) {
rowid = catalogTable.getModel().getList().size();
modelRowId = rowid;
}
else {
modelRowId = catalogTable.getSortedRowModelIndex(rowid);
}
boolean retVal = catalogTable.getModel().insertRow(modelRowId, sol);
if (retVal == true) {
logTextnl("Inserted row at index: " + rowid + " into table.");
catalogTable.getRowHeader().setCellSelectionEnabled(tableRowHeadSelectionFlag);
}
else logTextnl("Unable to insert row at index: " + rowid + " into table.");
catalogTable.getRowHeader().setRowSelectionInterval(rowid,rowid);
resetSelectedRowColumnSizes();
return retVal;
}
private void resetSelectedRowColumnSizes() {
int rowid = catalogTable.getRowHeader().getSelectedRow();
catalogTable.resetRowColumnSizes(catalogTable.getRowHeader(), rowid);
catalogTable.resetRowHeader(catalogTable.getRowHeader(), TablePanel.this.spane);
spane.revalidate();
}
protected int updateDB() {
if (hasInvalidTable()) {
InfoDialog.informUser(CatalogPanel.this, "ERROR", "Unable to update DB; no table to update.", statusLabel);
return -1;
}
if (isNotModifiable()) {
InfoDialog.informUser(CatalogPanel.this, "ERROR", "Unable to update DB; table not write back enabled.", statusLabel);
return -1;
}
/* Is not thread safe with multiple table panels and a static data source.
if (dataSource != null) {
Connection priorConnect = DataSource.getConnection();
boolean priorUpdatable = DataSource.isWriteBackEnabled();
dataSource = new DataSource(solutionList.getConnection(), updateDB);
}
*/
int nrow = catalogTable.updateDB();
// dataSource = new DataSource(priorConnect, priorUpdatable);
if (nrow < 0) {
InfoDialog.informUser(CatalogPanel.this, "ERROR", "Unable to update DB; re-edit table and retry.", statusLabel);
return -1;
}
else {
logTextnl("Updated " + nrow + " rows in catalog.");
}
unsetTableModified();
return nrow;
}
private boolean rejectAction(String action) {
return (JOptionPane.showConfirmDialog(CatalogPanel.this, action, "Confirm", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION);
}
private boolean deleteRow() {
int rowid = catalogTable.getRowHeader().getSelectedRow();
if (rowid < 0) {
// logTextnl("No selected row in table - make a selection and retry delete.");
InfoDialog.informUser(CatalogPanel.this, "ERROR", "No selected row in table - make a selection and retry delete.", statusLabel);
return false;
}
if (rejectAction("Delete")) return false;
boolean retVal = catalogTable.getModel().deleteRow(catalogTable.getSortedRowModelIndex(rowid));
if (retVal == true) logTextnl("Deleted row at index: " + rowid + " from table.");
else logTextnl("Unable to delete row at index: " + rowid + " from table.");
catalogTable.getTable().clearSelection();
catalogTable.getRowHeader().clearSelection();
// Is this next line necessary only if insertRow toggles flag?
catalogTable.getRowHeader().setCellSelectionEnabled(tableRowHeadSelectionFlag);
return retVal;
}
// TablePanel event listener inner classes
private class UpdateTablePanel implements Runnable {
public void run() {
tableTimer.stop();
if (nrows > 0) remove(waitRequestLabel);
else {
waitRequestLabel.setText("Table results displayed here");
waitRequestLabel.setIcon(null);
}
setCursor(defaultCursor);
if (nrows > 0) {
// Debug.println("DEBUG: hasModifiedTable(): " + hasModifiedTable());
statusLabel.setText("Table has " + nrows + " rows");
TablePanel.this.add(spane, BorderLayout.CENTER);
enableModifyButtons();
jbFile.setEnabled(true);
jbFile.setVisible(true);
jbWheres.setEnabled(true);
jbWheres.setVisible(true);
showModifyButtons();
}
else if (nrows < 0) {
InfoDialog.informUser(CatalogPanel.this, "ERROR",
"Table creation failed; check input.", statusLabel);
}
else if (nrows == 0) {
InfoDialog.informUser(CatalogPanel.this, "INFO",
"No table rows satisfy input properties", statusLabel);
}
// make sure selected sol is selected in JTable
final int selRow = CatalogPanel.this.solutionList.getSelectedIndex();
if (selRow >= 0) {
final JTable table = CatalogPanel.this.tablePanel.catalogTable.getTable();
/// scroll selected to visible
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
table.setRowSelectionInterval(selRow, selRow);
table.scrollRectToVisible(table.getCellRect(selRow, 0, true));
}
} );
}
CatalogPanel.this.tablePanel.revalidate();
tableThread = null;
interruptRequestFlag = false;
}
}
private class ModifyTableRowsActionListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
statusLabel.setText(" ");
String cmd = evt.getActionCommand();
// Object src = evt.getSource();
if (hasInvalidTable()) return;
if (cmd.equals("Insert")) {
insertRow();
}
else if (cmd.equals("Commit")) {
commit();
}
else if (cmd.equals("Delete")) {
deleteRow();
}
}
}
private class SaveTableActionListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
statusLabel.setText(" ");
if (catalogTable.getModel().getRowCount() > 0 ) {
SaveCatalogTableToASCII saveToTextFile = new SaveCatalogTableToASCII();
saveToTextFile.save (catalogTable, (Frame) getTopLevelAncestor());
}
else {
// logTextnl("No rows in table - execute new request.");
InfoDialog.informUser(CatalogPanel.this, "ERROR", "No rows in table - execute new request.", statusLabel);
}
}
}
private class tableTimerActionListener implements ActionListener {
public void actionPerformed(ActionEvent evt) {
waitRequestLabel.setText("table rendering wait...");
waitRequestLabel.setIcon(imageFlag ? LIGHT_BULB : DARK_BULB);
imageFlag = ! imageFlag;
waitRequestLabel.repaint();
}
}
} // end of TablePanel class
} // end of CatalogPanel class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -