Search in sources :

Example 1 with LibraryBuilder

use of net.parostroj.timetable.model.library.LibraryBuilder in project grafikon by jub77.

the class LSLibraryImpl method load.

@Override
public Library load(ZipInputStream is) throws LSException {
    try {
        ZipEntry entry = null;
        ModelVersion version = (ModelVersion) properties.get(VERSION_PROPERTY);
        LibraryBuilder libraryBuilder = new LibraryBuilder();
        while ((entry = is.getNextEntry()) != null) {
            if (entry.getName().equals(METADATA)) {
                // check major and minor version (do not allow load newer versions)
                Properties props = new Properties();
                props.load(is);
                version = checkVersion(METADATA_KEY_LIBRARY_VERSION, props);
                continue;
            }
            LSLibraryItem lsItem = lss.load(is, LSLibraryItem.class);
            lsItem.createLibraryItem(libraryBuilder);
        }
        log.debug("Loaded version: {}", version != null ? version : "<missing>");
        return libraryBuilder.build();
    } catch (IOException e) {
        throw new LSException(e);
    }
}
Also used : LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) ZipEntry(java.util.zip.ZipEntry) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) IOException(java.io.IOException) Properties(java.util.Properties) LSException(net.parostroj.timetable.model.ls.LSException)

Example 2 with LibraryBuilder

use of net.parostroj.timetable.model.library.LibraryBuilder in project grafikon by jub77.

the class LSLibraryItem method createLibraryItem.

public LibraryItem createLibraryItem(LibraryBuilder libraryBuilder) throws LSException {
    LibraryItemType type = LibraryItemType.valueOf(getType());
    ObjectWithId object = null;
    switch(type) {
        case ENGINE_CLASS:
            object = ((LSEngineClass) getObject()).createEngineClass(id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof LineClass ? (LineClass) foundObject : null;
            });
            break;
        case LINE_CLASS:
            object = ((LSLineClass) getObject()).createLineClass();
            break;
        case NODE:
            object = ((LSNode) getObject()).createNode(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case OUTPUT_TEMPLATE:
            object = ((LSOutputTemplate) getObject()).createOutputTemplate(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
            break;
        case TRAIN_TYPE:
            object = ((LSTrainType) getObject()).createTrainType(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById, id -> {
                ObjectWithId foundObject = libraryBuilder.getObjectById(id);
                return foundObject instanceof TrainTypeCategory ? (TrainTypeCategory) foundObject : null;
            });
            break;
        case TRAIN_TYPE_CATEGORY:
            object = ((LSTrainTypeCategory) getObject()).createTrainTypeCategory();
            break;
    }
    LibraryItem item = libraryBuilder.addObject(object);
    item.getAttributes().add(this.getAttributes().createAttributes(libraryBuilder::getObjectById));
    return item;
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Node(net.parostroj.timetable.model.Node) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) XmlType(javax.xml.bind.annotation.XmlType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) XmlElements(javax.xml.bind.annotation.XmlElements) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) LSException(net.parostroj.timetable.model.ls.LSException) EngineClass(net.parostroj.timetable.model.EngineClass) TrainType(net.parostroj.timetable.model.TrainType) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) LineClass(net.parostroj.timetable.model.LineClass) XmlElement(javax.xml.bind.annotation.XmlElement) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 3 with LibraryBuilder

use of net.parostroj.timetable.model.library.LibraryBuilder in project grafikon by jub77.

the class ExportAction method createLibrary.

private Library createLibrary(ExportImportSelection selection) {
    LibraryBuilder libBuilder = new LibraryBuilder(new LibraryBuilder.Config().setAddMissing(true));
    selection.getObjectMap().values().stream().flatMap(item -> item.stream()).forEach(object -> libBuilder.importObject(object));
    return libBuilder.build();
}
Also used : CloseableFileChooser(net.parostroj.timetable.gui.actions.impl.CloseableFileChooser) ApplicationModel(net.parostroj.timetable.gui.ApplicationModel) Frame(java.awt.Frame) Logger(org.slf4j.Logger) ActionHandler(net.parostroj.timetable.gui.actions.execution.ActionHandler) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) LoggerFactory(org.slf4j.LoggerFactory) EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) FileChooserFactory(net.parostroj.timetable.gui.actions.impl.FileChooserFactory) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ExportImportSelectionSource(net.parostroj.timetable.gui.components.ExportImportSelectionSource) File(java.io.File) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) AbstractAction(javax.swing.AbstractAction) ModelUtils(net.parostroj.timetable.gui.actions.impl.ModelUtils) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) ExportImportSelectionBaseDialog(net.parostroj.timetable.gui.dialogs.ExportImportSelectionBaseDialog) LSException(net.parostroj.timetable.model.ls.LSException) JFileChooser(javax.swing.JFileChooser) ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction) Library(net.parostroj.timetable.model.library.Library) ResourceLoader(net.parostroj.timetable.utils.ResourceLoader) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder)

Aggregations

LibraryBuilder (net.parostroj.timetable.model.library.LibraryBuilder)3 LSException (net.parostroj.timetable.model.ls.LSException)3 Component (java.awt.Component)1 Frame (java.awt.Frame)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ZipEntry (java.util.zip.ZipEntry)1 AbstractAction (javax.swing.AbstractAction)1 JFileChooser (javax.swing.JFileChooser)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 ApplicationModel (net.parostroj.timetable.gui.ApplicationModel)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)1 ActionHandler (net.parostroj.timetable.gui.actions.execution.ActionHandler)1 EventDispatchAfterModelAction (net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction)1