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 {
|
||||
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.actions = actions;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public RefreshActionsMap getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void update(BinaryProtocol binaryProtocol, live_data_e context, byte[] response) {
|
||||
for (RefreshActions action : actions.getActions().get(context))
|
||||
action.refresh(binaryProtocol, response);
|
||||
public void update(BinaryProtocol binaryProtocol, byte[] response) {
|
||||
action.refresh(binaryProtocol, response);
|
||||
}
|
||||
|
||||
public abstract boolean isVisible();
|
||||
|
|
|
@ -52,6 +52,6 @@ public enum LiveDocsRegistry {
|
|||
|
||||
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.LiveDocsRegistry;
|
||||
import com.rusefi.ui.livedocs.RefreshActions;
|
||||
import com.rusefi.ui.livedocs.RefreshActionsMap;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
@ -262,8 +261,7 @@ public class LiveDataParserPanel {
|
|||
return number != 0;
|
||||
}
|
||||
}, fileName);
|
||||
RefreshActionsMap refreshActionsMap = new RefreshActionsMap();
|
||||
refreshActionsMap.put(live_data_e, new RefreshActions() {
|
||||
RefreshActions refreshAction = new RefreshActions() {
|
||||
@Override
|
||||
public void refresh(BinaryProtocol bp, byte[] response) {
|
||||
if (log.debugEnabled())
|
||||
|
@ -271,9 +269,9 @@ public class LiveDataParserPanel {
|
|||
reference.set(response);
|
||||
livePanel.refresh();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
LiveDocsRegistry.INSTANCE.register(new LiveDocHolder(live_data_e, refreshActionsMap) {
|
||||
LiveDocsRegistry.INSTANCE.register(new LiveDocHolder(live_data_e, refreshAction) {
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
JPanel panel = livePanel.getContent();
|
||||
|
|
Loading…
Reference in New Issue