Skip to content

Commit 49df3bf

Browse files
committed
add properties and listeners to show loading of configuration data
1 parent 58743ff commit 49df3bf

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/org/openlcb/cdi/impl/ConfigRepresentation.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class ConfigRepresentation extends DefaultPropertyListenerSupport {
6060
private final Map<String, CdiEntry> variables = new HashMap<>();
6161
// Last time the progressbar was updated from the load.
6262
private long lastProgress;
63+
64+
private int cacheMemoryRead;
6365

6466
public EventNameStore eventNameStore;
6567

@@ -98,10 +100,10 @@ private void triggerFetchCdi() {
98100
public void progressNotify(long bytesRead, long totalBytes) {
99101
lastProgress = new Date().getTime();
100102
if (totalBytes > 0) {
101-
setState(String.format("Loading: %.2f%% complete", bytesRead * 100.0 /
103+
setState(String.format("Loading display format: %.2f%% complete", bytesRead * 100.0 /
102104
totalBytes));
103105
} else {
104-
setState(String.format("Loading: %d bytes complete", bytesRead));
106+
setState(String.format("Loading display format: %d bytes complete", bytesRead));
105107
}
106108
}
107109

@@ -139,12 +141,18 @@ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
139141
.UPDATE_LOADING_COMPLETE)) {
140142
synchronized (this) {
141143
if (--pendingCacheFills == 0) {
142-
firePropertyChange(UPDATE_CACHE_COMPLETE, null, null);
144+
firePropertyChange(UPDATE_CACHE_COMPLETE, null, 1);
143145
for (MemorySpaceCache sp : spaces.values()) {
144146
sp.removePropertyChangeListener(prefillListener);
145147
}
146148
}
147149
}
150+
} else if (propertyChangeEvent.getPropertyName().equals(MemorySpaceCache
151+
.LOADING_RANGE)) {
152+
cacheMemoryRead += (Integer)propertyChangeEvent.getNewValue();
153+
setState(String.format("Loading configuration data: %d bytes complete", cacheMemoryRead));
154+
firePropertyChange(UPDATE_STATE, null, cacheMemoryRead);
155+
148156
}
149157
}
150158
};

src/org/openlcb/cdi/impl/MemorySpaceCache.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
public class MemorySpaceCache {
2525
// This event will be fired when the cache is completely pre-filled.
2626
public static final String UPDATE_LOADING_COMPLETE = "UPDATE_LOADING_COMPLETE";
27+
// This event will be fired as each range is read
28+
public static final String LOADING_RANGE = "LOADING_RANGE";
2729
// This event will be fired on the registered data listeners.
2830
public static final String UPDATE_DATA = "UPDATE_DATA";
2931
private static final Logger logger = Logger.getLogger(MemorySpaceCache.class.getName());
@@ -224,6 +226,7 @@ private void loadRange() {
224226
if (count > 64) {
225227
count = 64;
226228
}
229+
firePropertyChange(LOADING_RANGE, null, count);
227230
final int fcount = count;
228231
access.doRead(currentRangeNextOffset, space, count,
229232
new MemoryConfigurationService.McsReadHandler() {

src/org/openlcb/cdi/swing/CdiPanel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import util.CollapsiblePanel;
109109
import util.WrapLayout;
110110

111+
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_CACHE_COMPLETE;
111112
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_ENTRY_DATA;
112113
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_REP;
113114
import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_STATE;
@@ -670,7 +671,7 @@ private void addLoadingListener() {
670671
loadingListener = new PropertyChangeListener() {
671672
@Override
672673
public void propertyChange(PropertyChangeEvent event) {
673-
if (event.getPropertyName().equals(UPDATE_REP)) {
674+
if (event.getPropertyName().equals(UPDATE_CACHE_COMPLETE)) {
674675
displayCdi();
675676
} else if (event.getPropertyName().equals(UPDATE_STATE)) {
676677
loadingText.setText(rep.getStatus());

test/org/openlcb/cdi/impl/ConfigRepresentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testComplexCdiLoad() throws Exception {
4545
ConfigRepresentation rep = new ConfigRepresentation(iface, remoteNode);
4646
// Since all of our memory configuration commands execute inline, the representation will
4747
// be ready by the time it returns.
48-
Assert.assertEquals("Representation complete.", rep.getStatus());
48+
Assert.assertEquals("Loading configuration data: 73 bytes complete", rep.getStatus());
4949
Assert.assertNotNull(rep.getRoot());
5050

5151
ConfigRepresentation.CdiContainer cont = rep.getRoot();

0 commit comments

Comments
 (0)