use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSRoute method createRoute.
public Route createRoute(Net net) throws LSException {
Route route = new Route(id, net.getDiagram());
route.setName(name);
route.setNetPart(netPart);
route.setTrainRoute(trainRoute);
// create segments
boolean node = true;
if (this.segments != null) {
for (String segment : this.segments) {
RouteSegment<?> routeSegment = null;
if (node) {
routeSegment = net.getNodeById(segment);
} else {
routeSegment = net.getLineById(segment);
}
if (routeSegment == null) {
String message = String.format("Segment with id:%s not found. Cannot create route with id:%s.", segment, id);
log.warn(message);
throw new LSException(message);
}
route.getSegments().add(routeSegment);
node = !node;
}
}
return route;
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LoadDiagramModelAction method backgroundAction.
@Override
protected void backgroundAction() {
selectedFile = (File) getActionContext().getAttribute("diagramFile");
if (selectedFile == null) {
// skip
return;
}
setWaitMessage(ResourceLoader.getString("wait.message.loadmodel"));
setWaitDialogVisible(true);
long time = System.currentTimeMillis();
try {
try {
LSFile ls = LSFileFactory.getInstance().createForLoad(selectedFile);
context.setAttribute("diagram", ls.load(selectedFile));
} catch (LSException e) {
log.warn("Error loading model.", e);
if (e.getCause() instanceof FileNotFoundException) {
errorMessage = ResourceLoader.getString("dialog.error.filenotfound");
} else {
errorMessage = ResourceLoader.getString("dialog.error.loading");
}
} catch (Exception e) {
log.warn("Error loading model.", e);
errorMessage = ResourceLoader.getString("dialog.error.loading");
}
} finally {
log.debug("Library loaded in {}ms", System.currentTimeMillis() - time);
setWaitDialogVisible(false);
}
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class ModelUtils method saveModelData.
public static void saveModelData(final ApplicationModel model, File file) throws LSException {
// update author and date before save
TrainDiagram diagram = model.getDiagram();
boolean originalSkip = diagram.getAttributes().isSkipListeners();
diagram.getAttributes().setSkipListeners(true);
String user = model.getProgramSettings().getUserNameOrSystemUser();
diagram.setSaveUser(user);
final ChangesTracker tracker = diagram.getChangesTracker();
final DiagramChangeSet set = tracker.getCurrentChangeSet();
if (set != null && tracker.isTrackingEnabled()) {
try {
// do the update in event dispatch thread (because of events)
SwingUtilities.invokeAndWait(() -> {
tracker.updateCurrentChangeSet(set.getVersion(), user, Calendar.getInstance());
});
} catch (Exception e) {
log.warn("Error updating values for current diagram change set.", e);
}
}
log.info("Saving: {}", file);
LSFile ls = LSFileFactory.getInstance().createForSave();
ls.save(diagram, file);
diagram.getAttributes().setSkipListeners(originalSkip);
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class DefaultTrainTypeListSource method getDefaultTypeList.
public static Pair<TrainsDataDto, List<TrainType>> getDefaultTypeList() throws LSException {
try {
LSTrainTypeSerializer serializer = LSTrainTypeSerializer.getLSTrainTypeSerializer(LSSerializer.getLatestVersion());
LSTrainTypeList lsList = serializer.load(new InputStreamReader(DefaultTrainTypeListSource.getDefaultTypesInputStream(), "utf-8"));
return new Pair<TrainsDataDto, List<TrainType>>(lsList.getTrainsData(), lsList.getTrainTypeList());
} catch (UnsupportedEncodingException e) {
throw new LSException("Cannot load default train type list.", e);
}
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSSerializerImpl1 method load.
@Override
public TrainDiagram load(Reader reader, LSTrainTypeList trainTypeList) throws LSException {
try {
LSTrainDiagram lsDiagram = (LSTrainDiagram) unmarshaller.unmarshal(new NoCloseAllowedReader(reader));
LSVisitorBuilder builderVisitor = new LSVisitorBuilder(trainTypeList);
lsDiagram.visit(builderVisitor);
return builderVisitor.getTrainDiagram();
} catch (JAXBException e) {
throw new LSException("Cannot load train diagram.", e);
}
}
Aggregations