refactoring
This commit is contained in:
parent
a63f235f12
commit
d923175882
|
@ -8,20 +8,15 @@ import com.rusefi.enums.live_data_e;
|
||||||
*/
|
*/
|
||||||
public abstract class LiveDocHolder {
|
public abstract class LiveDocHolder {
|
||||||
private final live_data_e id;
|
private final live_data_e id;
|
||||||
private final RefreshActionsMap actions;
|
private final RefreshActions action;
|
||||||
|
|
||||||
public LiveDocHolder(live_data_e id, RefreshActionsMap actions) {
|
public LiveDocHolder(live_data_e id, RefreshActions action) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.actions = actions;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefreshActionsMap getActions() {
|
public void update(BinaryProtocol binaryProtocol, byte[] response) {
|
||||||
return actions;
|
action.refresh(binaryProtocol, response);
|
||||||
}
|
|
||||||
|
|
||||||
public void update(BinaryProtocol binaryProtocol, live_data_e context, byte[] response) {
|
|
||||||
for (RefreshActions action : actions.getActions().get(context))
|
|
||||||
action.refresh(binaryProtocol, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isVisible();
|
public abstract boolean isVisible();
|
||||||
|
|
|
@ -52,6 +52,6 @@ public enum LiveDocsRegistry {
|
||||||
|
|
||||||
System.arraycopy(responseWithCode, 1, response, 0, size);
|
System.arraycopy(responseWithCode, 1, response, 0, size);
|
||||||
|
|
||||||
holder.update(binaryProtocol, context, response);
|
holder.update(binaryProtocol, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.rusefi.ui.livedocs;
|
|
||||||
|
|
||||||
import com.rusefi.enums.live_data_e;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class RefreshActionsMap {
|
|
||||||
private final Map<live_data_e, List<RefreshActions>> actions = new HashMap<>();
|
|
||||||
|
|
||||||
public void put(live_data_e context, RefreshActions refreshAction) {
|
|
||||||
actions.putIfAbsent(context, new ArrayList<>());
|
|
||||||
actions.get(context).add(refreshAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAll(RefreshActionsMap actions) {
|
|
||||||
for (Map.Entry<live_data_e, List<RefreshActions>> e : actions.actions.entrySet()) {
|
|
||||||
for (RefreshActions action : e.getValue())
|
|
||||||
put(e.getKey(), action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<live_data_e, List<RefreshActions>> getActions() {
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@ import com.rusefi.ui.livedata.VariableValueSource;
|
||||||
import com.rusefi.ui.livedocs.LiveDocHolder;
|
import com.rusefi.ui.livedocs.LiveDocHolder;
|
||||||
import com.rusefi.ui.livedocs.LiveDocsRegistry;
|
import com.rusefi.ui.livedocs.LiveDocsRegistry;
|
||||||
import com.rusefi.ui.livedocs.RefreshActions;
|
import com.rusefi.ui.livedocs.RefreshActions;
|
||||||
import com.rusefi.ui.livedocs.RefreshActionsMap;
|
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
@ -262,8 +261,7 @@ public class LiveDataParserPanel {
|
||||||
return number != 0;
|
return number != 0;
|
||||||
}
|
}
|
||||||
}, fileName);
|
}, fileName);
|
||||||
RefreshActionsMap refreshActionsMap = new RefreshActionsMap();
|
RefreshActions refreshAction = new RefreshActions() {
|
||||||
refreshActionsMap.put(live_data_e, new RefreshActions() {
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
public void refresh(BinaryProtocol bp, byte[] response) {
|
||||||
if (log.debugEnabled())
|
if (log.debugEnabled())
|
||||||
|
@ -271,9 +269,9 @@ public class LiveDataParserPanel {
|
||||||
reference.set(response);
|
reference.set(response);
|
||||||
livePanel.refresh();
|
livePanel.refresh();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
LiveDocsRegistry.INSTANCE.register(new LiveDocHolder(live_data_e, refreshActionsMap) {
|
LiveDocsRegistry.INSTANCE.register(new LiveDocHolder(live_data_e, refreshAction) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
JPanel panel = livePanel.getContent();
|
JPanel panel = livePanel.getContent();
|
||||||
|
|
Loading…
Reference in New Issue