use of net.parostroj.timetable.model.freight.TrainPath in project grafikon by jub77.
the class FreightTrainPathPanel method updateView.
public void updateView(Node from, Node to, int shuntDuration, int startTime) {
// update selection
if (fromNode.getSelectedObject() != from) {
fromNode.setSelectedObject(from);
}
if (toNode.getSelectedObject() != to) {
toNode.setSelectedObject(to);
}
tableModel.clear();
stateIconLabel.setIcon(null);
if (from != null && to != null && from != to) {
DataModel model = new DataModel();
RxActionHandler.getInstance().newExecution("freight_path", GuiComponentUtils.getTopLevelComponent(this), diagram).addConsumer((c, diagram) -> {
c.setWaitMessage(ResourceLoader.getString("wait.message.processing"));
c.setWaitDialogVisible(true);
}).onBackground().addConsumer((c, diagram) -> {
FreightConnectionAnalyser connectionAnalyser = new FreightConnectionAnalyser(diagram.getFreightNet().getConnectionStrategy());
Set<NodeFreightConnection> conns = connectionAnalyser.analyse(from, to);
TrainPath trainPath = connectionAnalyser.getTrainPath(conns, startTime, shuntDuration);
stateIconLabel.setIcon(!trainPath.isEmpty() ? okIcon : errorIcon);
Integer time = null;
for (TrainConnection tc : trainPath) {
String right = convertConnectionTrain(tc);
String left = convertNode(tc.getFrom().getOwnerAsNode(), time == null ? null : TimeUtil.difference(time, tc.getStartTime()));
time = tc.getEndTime();
model.addLine(left, right);
}
if (!trainPath.isEmpty()) {
model.addLine(convertNode(to, null), "");
}
}).onEdt().addConsumer((c, diagram) -> {
tableModel.addLines(model);
adjustColumnWidth.run();
}).execute();
}
}
Aggregations