use of net.parostroj.timetable.model.ObjectWithId 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;
}
use of net.parostroj.timetable.model.ObjectWithId 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);
}
}
use of net.parostroj.timetable.model.ObjectWithId in project grafikon by jub77.
the class ImportModelAction method processItems.
private void processItems(Iterable<? extends ObjectWithId> list, Consumer<ObjectWithId> importProcess) {
List<ObjectWithId> batch = new LinkedList<>();
int cnt = 0;
for (ObjectWithId o : list) {
batch.add(o);
if (++cnt == CHUNK_SIZE) {
processChunk(batch, importProcess);
cnt = 0;
batch = new LinkedList<>();
}
}
if (!batch.isEmpty()) {
processChunk(batch, importProcess);
}
}
use of net.parostroj.timetable.model.ObjectWithId in project grafikon by jub77.
the class EditOutputDialog method setPresentationModel.
@Override
public void setPresentationModel(final OutputPM pModel) {
provider.setPresentationModel(pModel);
pModel.setOperationEditSelection(() -> {
Collection<? extends ObjectWithId> currentSelection = pModel.getSelection();
ElementSelectionDialog<ObjectWithId> dialog = new ElementSelectionDialog<>(this, true);
OutputTemplate template = pModel.getEditedOutput().getTemplate();
Collection<ObjectWithId> collection = template.getSelectionType().extract(template.getDiagram(), ObjectWithId.class);
dialog.setLocationRelativeTo(this);
List<ObjectWithId> newSelection = dialog.selectElements(collection, currentSelection);
if (newSelection != null) {
if (newSelection.isEmpty()) {
newSelection = null;
}
pModel.updateSelection(newSelection);
}
return true;
});
}
use of net.parostroj.timetable.model.ObjectWithId in project grafikon by jub77.
the class ExportImportSelectionPanel method setSelectionSource.
public void setSelectionSource(ExportImportSelectionSource source) {
typeComboBox.removeAllItems();
currentSelection = null;
selectionMap.clear();
for (ImportComponent type : source.getTypes()) {
Collection<ObjectWithId> elements = source.getElementsForType(type);
if (!elements.isEmpty()) {
Selection selection = new Selection(type, Wrapper.getWrapperList(elements), new ArrayList<>());
selectionMap.put(type, selection);
typeComboBox.addItem(Wrapper.getWrapper(type));
}
}
typeComboBox.setMaximumRowCount(source.getTypes().size());
}
Aggregations