Search in sources :

Example 1 with Group

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

the class LSGroup method createGroup.

public Group createGroup(TrainDiagram diagram) throws LSException {
    Group group = diagram.getPartFactory().createGroup(id);
    // expected value -> null (for compatibility before version 4.18.2)
    group.setName(name);
    group.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
    return group;
}
Also used : Group(net.parostroj.timetable.model.Group)

Example 2 with Group

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

the class GroupsComboBox method updateGroups.

/**
 * updates combobox.
 *
 * @param diagram diagram
 * @param groupSelect selected group (depends on type)
 */
public void updateGroups(TrainDiagram diagram, GroupSelect groupSelect) {
    if (groupSelect.getType() == Type.ALL && !allOption)
        throw new IllegalArgumentException("Cannot set ALL.");
    // clear
    removeAllItems();
    // add no and all
    if (allOption) {
        addItem(all);
    }
    addItem(none);
    List<Group> groups = new ArrayList<Group>(diagram.getGroups());
    this.sortGroups(groups);
    for (Group group : groups) {
        this.addItem(new Wrapper<Group>(group));
    }
    switch(groupSelect.getType()) {
        case ALL:
            setSelectedItem(all);
            break;
        case NONE:
            setSelectedItem(none);
            break;
        default:
            Wrapper<Group> w = new Wrapper<Group>(groupSelect.getGroup());
            setSelectedItem(w);
            break;
    }
}
Also used : Group(net.parostroj.timetable.model.Group) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper)

Example 3 with Group

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

the class ImportModelAction method backgroundAction.

@Override
protected void backgroundAction() {
    setWaitMessage(ResourceLoader.getString("wait.message.import"));
    setWaitDialogVisible(true);
    long time = System.currentTimeMillis();
    try {
        ExportImportSelection selection = context.getAttribute("selection", ExportImportSelection.class);
        TrainDiagram diagram = context.getAttribute("diagramImport", TrainDiagram.class);
        TrainImportConfig trainImportConfig = context.getAttribute("trainImport", TrainImportConfig.class);
        Map<ImportComponent, Collection<ObjectWithId>> map = selection.getObjectMap();
        imports = new TrainDiagramPartImport(diagram, selection.getImportMatch(), selection.isImportOverwrite());
        List<ObjectWithId> list = map.values().stream().sequential().flatMap(item -> item.stream().sequential()).collect(Collectors.toList());
        if (list.isEmpty()) {
            return;
        }
        if (trainImportConfig != null && trainImportConfig.isRemoveExisting()) {
            // remove existing trains in group
            Consumer<ObjectWithId> deleteProcess = item -> diagram.getTrains().remove(item);
            Iterable<Train> filteredTrains = Iterables.filter(diagram.getTrains(), ModelPredicates.inGroup(trainImportConfig.getToGroup()));
            processItems(filteredTrains, deleteProcess);
        }
        // import new objects
        Consumer<ObjectWithId> importProcess = item -> {
            ImportComponent i = ImportComponent.getByComponentClass(item.getClass());
            if (i != null) {
                ObjectWithId imported = imports.importPart(item);
                processImportedObject(imported, trainImportConfig);
            } else {
                log.warn("No import for class {}", item.getClass().getName());
            }
        };
        processItems(list, importProcess);
    } finally {
        log.debug("Import finished in {}ms", System.currentTimeMillis() - time);
        setWaitDialogVisible(false);
    }
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) Collection(java.util.Collection) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) LoggerFactory(org.slf4j.LoggerFactory) ImportError(net.parostroj.timetable.model.imports.Import.ImportError) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) Node(net.parostroj.timetable.model.Node) Consumer(java.util.function.Consumer) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) List(java.util.List) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport) Map(java.util.Map) LinkedList(java.util.LinkedList) TrainType(net.parostroj.timetable.model.TrainType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Group(net.parostroj.timetable.model.Group) Train(net.parostroj.timetable.model.Train) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) Collection(java.util.Collection) Train(net.parostroj.timetable.model.Train) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport)

Example 4 with Group

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

the class EditGroupsDialog method createNew.

@Override
protected Group createNew(String name) {
    TrainDiagramPartFactory factory = element.getPartFactory();
    Group newGroup = factory.createGroup(factory.createId());
    newGroup.setName(name);
    return newGroup;
}
Also used : Group(net.parostroj.timetable.model.Group) TrainDiagramPartFactory(net.parostroj.timetable.model.TrainDiagramPartFactory)

Example 5 with Group

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

the class ImportModelAction method processImportedObject.

private void processImportedObject(ObjectWithId o, TrainImportConfig trainImportConfig) {
    // if train import -> move to appropriate group
    if (o instanceof Train && trainImportConfig != null) {
        Group destGroup = trainImportConfig.getToGroup();
        ((Train) o).getAttributes().setRemove(Train.ATTR_GROUP, destGroup);
    }
}
Also used : Group(net.parostroj.timetable.model.Group) Train(net.parostroj.timetable.model.Train)

Aggregations

Group (net.parostroj.timetable.model.Group)8 Train (net.parostroj.timetable.model.Train)2 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)2 Predicate (com.google.common.base.Predicate)1 Iterables (com.google.common.collect.Iterables)1 Component (java.awt.Component)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 JOptionPane (javax.swing.JOptionPane)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)1 ActionHandler (net.parostroj.timetable.gui.actions.execution.ActionHandler)1 EventDispatchModelAction (net.parostroj.timetable.gui.actions.execution.EventDispatchModelAction)1 ImportModelAction (net.parostroj.timetable.gui.actions.execution.ImportModelAction)1 ImportSelectionModelAction (net.parostroj.timetable.gui.actions.impl.ImportSelectionModelAction)1