Skip to content
Permalink
Browse files

MERG CBUS Event Table Save Restore

Adds option to save restore between sessions
Uses the xml technique based upon timetable
Improved tests for other CBUS
  • Loading branch information...
icklesteve committed May 5, 2019
1 parent 6c736be commit 54f19939b3dab59f7ce1621beb722fe35b7a03bf
@@ -5,6 +5,7 @@
import jmri.GlobalProgrammerManager;
import jmri.InstanceManager;
import jmri.jmrix.can.cbus.node.CbusNodeTableDataModel;
import jmri.jmrix.can.cbus.eventtable.CbusEventTableDataModel;
import jmri.ThrottleManager;
import jmri.jmrix.can.CanSystemConnectionMemo;

@@ -68,6 +69,8 @@ public void configureManagers() {

InstanceManager.setDefault(CabSignalManager.class,getCabSignalManager());

InstanceManager.setDefault(CbusEventTableDataModel.class,getCbusEventTableDataModel());

}

/**
@@ -106,6 +109,8 @@ public boolean provides(Class<?> type) {
return true;
} else if (type.equals(CabSignalManager.class)) {
return true;
} else if (type.equals(CbusEventTableDataModel.class)) {
return true;
}

return false; // nothing, by default
@@ -144,6 +149,8 @@ public boolean provides(Class<?> type) {
return (T) getCbusNodeTableDataModel();
} else if (T.equals(CabSignalManager.class)) {
return (T) getCabSignalManager();
} else if (T.equals(CbusEventTableDataModel.class)) {
return (T) getCbusEventTableDataModel();
}
return null; // nothing, by default
}
@@ -299,7 +306,18 @@ public CbusNodeTableDataModel getCbusNodeTableDataModel() {
return cbusNodeTableDataModel;
}

private CbusEventTableDataModel cbusEventTable = null;

public CbusEventTableDataModel getCbusEventTableDataModel(){
if (adapterMemo.getDisabled()) {
return null;
}
if (cbusEventTable == null) {
cbusEventTable = new CbusEventTableDataModel(adapterMemo, 5, CbusEventTableDataModel.MAX_COLUMN);
InstanceManager.store(cbusEventTable, CbusEventTableDataModel.class);
}
return cbusEventTable;
}

protected CbusCabSignalManager cabSignalManager;

@@ -316,6 +334,10 @@ public CbusCabSignalManager getCabSignalManager() {

@Override
public void dispose() {

if ( cbusEventTable != null ){
InstanceManager.deregister(cbusEventTable, CbusEventTableDataModel.class);
}
if (cf != null) {
InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
}
@@ -25,6 +25,7 @@
private long _nodeBackgroundFetchDelay = 100L; // needs to match an option in NodeConfigToolPane
private boolean _startupSearchForCs = true;
private boolean _startupSearchForNodes = true;
private boolean _saveRestoreEventTable = true;

public CbusPreferences() {
super(ProfileManager.getDefault().getActiveProfile());
@@ -34,14 +35,16 @@ public CbusPreferences() {

private void readPreferences(Preferences sharedPreferences) {


this._addCommandStations = sharedPreferences.getBoolean("_addCommandStations",this.getAddCommandStations());
this._addNodes = sharedPreferences.getBoolean("_addNodes",this.getAddNodes());
this._allocateNnListener = sharedPreferences.getBoolean("_allocateNnListener",this.getAllocateNNListener());
this._nodeBackgroundFetchDelay = sharedPreferences.getLong("_nodeBgFetchDelay",this.getNodeBackgroundFetchDelay());

this._startupSearchForCs = sharedPreferences.getBoolean("_startupSearchForCs",this.getStartupSearchForCs());
this._startupSearchForNodes = sharedPreferences.getBoolean("_startupSearchForNodes",this.getStartupSearchForNodes());

this._saveRestoreEventTable = sharedPreferences.getBoolean(
"saveRestoreEventTable",this.getSaveRestoreEventTable() );

}

@@ -57,12 +60,14 @@ public void savePreferences() {
sharedPreferences.putBoolean("_startupSearchForCs", this.getStartupSearchForCs() );
sharedPreferences.putBoolean("_startupSearchForNodes", this.getStartupSearchForNodes() );

sharedPreferences.putBoolean("saveRestoreEventTable", this.getSaveRestoreEventTable() );

try {
sharedPreferences.sync();
log.info("Updated Cbus Preferences");
log.debug("Updated Cbus Preferences");
// setIsDirty(false); // Resets only when stored
} catch (BackingStoreException ex) {
log.error("Exception while saving web server preferences", ex);
log.error("Exception while saving preferences", ex);
}
}

@@ -123,7 +128,16 @@ public boolean getStartupSearchForNodes(){
public void setStartupSearchForNodes( boolean newVal ){
_startupSearchForNodes = newVal;
savePreferences();
}
}

public boolean getSaveRestoreEventTable(){
return _saveRestoreEventTable;
}

public void setSaveRestoreEventTable( boolean newVal ){
_saveRestoreEventTable = newVal;
savePreferences();
}

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

0 comments on commit 54f1993

Please sign in to comment.
You can’t perform that action at this time.