Skip to content

Commit

Permalink
Move ReporterTableDataModel to own class
Browse files Browse the repository at this point in the history
  • Loading branch information
icklesteve committed Jul 21, 2021
1 parent 3785856 commit 86b8648
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 198 deletions.
208 changes: 10 additions & 198 deletions java/src/jmri/jmrit/beantable/ReporterTableAction.java
Expand Up @@ -5,15 +5,18 @@
import java.awt.event.ActionListener;
import javax.annotation.Nonnull;
import javax.swing.*;

import jmri.InstanceManager;
import jmri.Manager;
import jmri.Reporter;
import jmri.ReporterManager;
import jmri.UserPreferencesManager;
import jmri.swing.ManagerComboBox;
import jmri.swing.SystemNameValidator;
import jmri.util.JmriJFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;

/**
* Swing action to create and register a ReporterTable GUI.
Expand All @@ -39,7 +42,7 @@ public ReporterTableAction(String actionName) {
}
}

protected ReporterManager reporterManager = InstanceManager.getDefault(jmri.ReporterManager.class);
protected ReporterManager reporterManager = InstanceManager.getDefault(ReporterManager.class);

/**
* {@inheritDoc}
Expand All @@ -61,198 +64,7 @@ public ReporterTableAction() {
*/
@Override
protected void createModel() {
m = new BeanTableDataModel<Reporter>() {
public static final int LASTREPORTCOL = NUMCOLUMN;

/**
* {@inheritDoc}
*/
@Override
public String getValue(String name) {
Object value;
Reporter r = reporterManager.getBySystemName(name);
if (r == null) {
return "";
}
value = r.getCurrentReport();
if (value == null) {
return null;
} else if (value instanceof jmri.Reportable) {
return ((jmri.Reportable) value).toReportString();
} else {
return value.toString();
}
}

/**
* {@inheritDoc}
*/
@Override
public ReporterManager getManager() {
return reporterManager;
}

/**
* {@inheritDoc}
*/
@Override
public Reporter getBySystemName(@Nonnull String name) {
return reporterManager.getBySystemName(name);
}

/**
* {@inheritDoc}
*/
@Override
public Reporter getByUserName(@Nonnull String name) {
return reporterManager.getByUserName(name);
}

/**
* {@inheritDoc}
*/
@Override
protected String getMasterClassName() {
return getClassName();
}

/**
* {@inheritDoc}
*/
@Override
public void clickOn(Reporter t) {
// don't do anything on click; not used in this class, because
// we override setValueAt
}

/**
* {@inheritDoc}
*/
@Override
public void setValueAt(Object value, int row, int col) {
if (col == VALUECOL) {
Reporter t = getBySystemName(sysNameList.get(row));
t.setReport(value);
fireTableRowsUpdated(row, row);
}
if (col == LASTREPORTCOL) {
// do nothing
} else {
super.setValueAt(value, row, col);
}
}

/**
* {@inheritDoc}
*/
@Override
public int getColumnCount() {
return LASTREPORTCOL + getPropertyColumnCount() +1;
}

/**
* {@inheritDoc}
*/
@Override
public String getColumnName(int col) {
if (col == VALUECOL) {
return Bundle.getMessage("LabelReport");
}
if (col == LASTREPORTCOL) {
return Bundle.getMessage("LabelLastReport");
}
return super.getColumnName(col);
}

/**
* {@inheritDoc}
*/
@Override
public Class<?> getColumnClass(int col) {
if (col == VALUECOL) {
return String.class;
}
if (col == LASTREPORTCOL) {
return String.class;
}
return super.getColumnClass(col);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isCellEditable(int row, int col) {
if (col == LASTREPORTCOL) {
return false;
}
return super.isCellEditable(row, col);
}

/**
* {@inheritDoc}
*/
@Override
public Object getValueAt(int row, int col) {
if (col == LASTREPORTCOL) {
Reporter t = getBySystemName(sysNameList.get(row));
Object value = t.getLastReport();
if (value == null) {
return null;
} else if (value instanceof jmri.Reportable) {
return ((jmri.Reportable) value).toReportString();
} else {
return value.toString();
}
}
return super.getValueAt(row, col);
}

/**
* {@inheritDoc}
*/
@Override
public int getPreferredWidth(int col) {
if (col == LASTREPORTCOL) {
return super.getPreferredWidth(VALUECOL);
}
return super.getPreferredWidth(col);
}

/**
* {@inheritDoc}
*/
@Override
public void configValueColumn(JTable table) {
// value column isn't button, so config is null
}

/**
* {@inheritDoc}
*/
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
return true;
// return (e.getPropertyName().indexOf("Report")>=0);
}

/**
* {@inheritDoc}
*/
@Override
public JButton configureButton() {
log.error("configureButton should not have been called");
return null;
}

/**
* {@inheritDoc}
*/
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameReporter");
}
};
m = new ReporterTableDataModel(reporterManager);
}

/**
Expand Down Expand Up @@ -283,15 +95,15 @@ protected String helpTarget() {
private final JLabel statusBarLabel = new JLabel(Bundle.getMessage("HardwareAddStatusEnter"), JLabel.LEADING);
private final String userNameError = this.getClass().getName() + ".DuplicateUserName"; // only used in this package
private Manager<Reporter> connectionChoice = null;
private jmri.UserPreferencesManager pref;
private UserPreferencesManager pref;
private SystemNameValidator hardwareAddressValidator;

/**
* {@inheritDoc}
*/
@Override
protected void addPressed(ActionEvent e) {
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
pref = InstanceManager.getDefault(UserPreferencesManager.class);
if (addFrame == null) {
addFrame = new JmriJFrame(Bundle.getMessage("TitleAddReporter"), false, true);
addFrame.addHelpMenu("package.jmri.jmrit.beantable.ReporterAddEdit", true);
Expand Down Expand Up @@ -482,6 +294,6 @@ public String getClassDescription() {
return Bundle.getMessage("TitleReporterTable");
}

private final static Logger log = LoggerFactory.getLogger(ReporterTableAction.class);
// private final static Logger log = LoggerFactory.getLogger(ReporterTableAction.class);

}

0 comments on commit 86b8648

Please sign in to comment.