+ /**
+ * Method that subclasses can override to handle posted command events.
+ *
+ * @param command command event
+ */
+ @Override
+ public void onCommand(final TCommandEvent command) {
+ if (command.equals(cmOpen)) {
+ try {
+ String filename = fileOpenBox(".");
+ if (filename != null) {
+ try {
+ new TTableWindow(getApplication(), new File(filename));
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorReadingFile"), e.getMessage()));
+ }
+ }
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorOpeningFileDialog"), e.getMessage()));
+ }
+ return;
+ }
+
+ if (command.equals(cmSave)) {
+ try {
+ String filename = fileSaveBox(".");
+ if (filename != null) {
+ tableField.saveToCsvFilename(filename);
+ }
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorWritingFile"), e.getMessage()));
+ }
+ return;
+ }
+
+ // Didn't handle it, let children get it instead
+ super.onCommand(command);
+ }
+
+ /**
+ * Handle posted menu events.
+ *
+ * @param menu menu event
+ */
+ @Override
+ public void onMenu(final TMenuEvent menu) {
+ TInputBox inputBox = null;
+ String filename = null;
+
+ switch (menu.getId()) {
+ case TMenu.MID_TABLE_RENAME_COLUMN:
+ inputBox = inputBox(i18n.getString("renameColumnInputTitle"),
+ i18n.getString("renameColumnInputCaption"),
+ tableField.getColumnLabel(tableField.getSelectedColumnNumber()),
+ TMessageBox.Type.OKCANCEL);
+ if (inputBox.isOk()) {
+ tableField.setColumnLabel(tableField.getSelectedColumnNumber(),
+ inputBox.getText());
+ }
+ return;
+ case TMenu.MID_TABLE_RENAME_ROW:
+ inputBox = inputBox(i18n.getString("renameRowInputTitle"),
+ i18n.getString("renameRowInputCaption"),
+ tableField.getRowLabel(tableField.getSelectedRowNumber()),
+ TMessageBox.Type.OKCANCEL);
+ if (inputBox.isOk()) {
+ tableField.setRowLabel(tableField.getSelectedRowNumber(),
+ inputBox.getText());
+ }
+ return;
+ case TMenu.MID_TABLE_VIEW_ROW_LABELS:
+ tableField.setShowRowLabels(getApplication().getMenuItem(
+ menu.getId()).getChecked());
+ return;
+ case TMenu.MID_TABLE_VIEW_COLUMN_LABELS:
+ tableField.setShowColumnLabels(getApplication().getMenuItem(
+ menu.getId()).getChecked());
+ return;
+ case TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW:
+ tableField.setHighlightRow(getApplication().getMenuItem(
+ menu.getId()).getChecked());
+ return;
+ case TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN:
+ tableField.setHighlightColumn(getApplication().getMenuItem(
+ menu.getId()).getChecked());
+ return;
+ case TMenu.MID_TABLE_BORDER_NONE:
+ tableField.setBorderAllNone();
+ return;
+ case TMenu.MID_TABLE_BORDER_ALL:
+ tableField.setBorderAllSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_CELL_NONE:
+ tableField.setBorderCellNone();
+ return;
+ case TMenu.MID_TABLE_BORDER_CELL_ALL:
+ tableField.setBorderCellSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_RIGHT:
+ tableField.setBorderColumnRightSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_LEFT:
+ tableField.setBorderColumnLeftSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_TOP:
+ tableField.setBorderRowAboveSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_BOTTOM:
+ tableField.setBorderRowBelowSingle();
+ return;
+ case TMenu.MID_TABLE_BORDER_DOUBLE_BOTTOM:
+ tableField.setBorderRowBelowDouble();
+ return;
+ case TMenu.MID_TABLE_BORDER_THICK_BOTTOM:
+ tableField.setBorderRowBelowThick();
+ return;
+ case TMenu.MID_TABLE_DELETE_LEFT:
+ tableField.deleteCellShiftLeft();
+ return;
+ case TMenu.MID_TABLE_DELETE_UP:
+ tableField.deleteCellShiftUp();
+ return;
+ case TMenu.MID_TABLE_DELETE_ROW:
+ tableField.deleteRow(tableField.getSelectedRowNumber());
+ return;
+ case TMenu.MID_TABLE_DELETE_COLUMN:
+ tableField.deleteColumn(tableField.getSelectedColumnNumber());
+ return;
+ case TMenu.MID_TABLE_INSERT_LEFT:
+ tableField.insertColumnLeft(tableField.getSelectedColumnNumber());
+ return;
+ case TMenu.MID_TABLE_INSERT_RIGHT:
+ tableField.insertColumnRight(tableField.getSelectedColumnNumber());
+ return;
+ case TMenu.MID_TABLE_INSERT_ABOVE:
+ tableField.insertRowAbove(tableField.getSelectedColumnNumber());
+ return;
+ case TMenu.MID_TABLE_INSERT_BELOW:
+ tableField.insertRowBelow(tableField.getSelectedColumnNumber());
+ return;
+ case TMenu.MID_TABLE_COLUMN_NARROW:
+ tableField.setColumnWidth(tableField.getSelectedColumnNumber(),
+ tableField.getColumnWidth(tableField.getSelectedColumnNumber()) - 1);
+ return;
+ case TMenu.MID_TABLE_COLUMN_WIDEN:
+ tableField.setColumnWidth(tableField.getSelectedColumnNumber(),
+ tableField.getColumnWidth(tableField.getSelectedColumnNumber()) + 1);
+ return;
+ case TMenu.MID_TABLE_FILE_OPEN_CSV:
+ try {
+ filename = fileOpenBox(".");
+ if (filename != null) {
+ try {
+ new TTableWindow(getApplication(), new File(filename));
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorReadingFile"), e.getMessage()));
+ }
+ }
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorOpeningFileDialog"), e.getMessage()));
+ }
+ return;
+ case TMenu.MID_TABLE_FILE_SAVE_CSV:
+ try {
+ filename = fileSaveBox(".");
+ if (filename != null) {
+ tableField.saveToCsvFilename(filename);
+ }
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorWritingFile"), e.getMessage()));
+ }
+ return;
+ case TMenu.MID_TABLE_FILE_SAVE_TEXT:
+ try {
+ filename = fileSaveBox(".");
+ if (filename != null) {
+ tableField.saveToTextFilename(filename);
+ }
+ } catch (IOException e) {
+ messageBox(i18n.getString("errorDialogTitle"),
+ MessageFormat.format(i18n.
+ getString("errorWritingFile"), e.getMessage()));
+ }
+ return;
+ default:
+ break;
+ }
+
+ super.onMenu(menu);
+ }
+