Search in sources :

Example 26 with LSException

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;
}
Also used : Route(net.parostroj.timetable.model.Route) LSException(net.parostroj.timetable.model.ls.LSException)

Example 27 with LSException

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);
    }
}
Also used : LSFile(net.parostroj.timetable.model.ls.LSFile) FileNotFoundException(java.io.FileNotFoundException) LSException(net.parostroj.timetable.model.ls.LSException) LSException(net.parostroj.timetable.model.ls.LSException) FileNotFoundException(java.io.FileNotFoundException)

Example 28 with LSException

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);
}
Also used : LSFile(net.parostroj.timetable.model.ls.LSFile) ChangesTracker(net.parostroj.timetable.model.changes.ChangesTracker) DiagramChangeSet(net.parostroj.timetable.model.changes.DiagramChangeSet) IOException(java.io.IOException) LSException(net.parostroj.timetable.model.ls.LSException)

Example 29 with LSException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TrainType(net.parostroj.timetable.model.TrainType) LSException(net.parostroj.timetable.model.ls.LSException) Pair(net.parostroj.timetable.utils.Pair)

Example 30 with LSException

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);
    }
}
Also used : NoCloseAllowedReader(net.parostroj.timetable.model.save.NoCloseAllowedReader) JAXBException(javax.xml.bind.JAXBException) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

LSException (net.parostroj.timetable.model.ls.LSException)38 IOException (java.io.IOException)8 JAXBException (javax.xml.bind.JAXBException)7 LSFile (net.parostroj.timetable.model.ls.LSFile)7 FileNotFoundException (java.io.FileNotFoundException)6 ZipEntry (java.util.zip.ZipEntry)6 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)6 ZipInputStream (java.util.zip.ZipInputStream)5 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)5 Properties (java.util.Properties)4 TrainType (net.parostroj.timetable.model.TrainType)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)3 Route (net.parostroj.timetable.model.Route)3 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 URL (java.net.URL)2 EngineClass (net.parostroj.timetable.model.EngineClass)2 DiagramChangeSet (net.parostroj.timetable.model.changes.DiagramChangeSet)2