use of net.parostroj.timetable.model.ls.LSException 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.ls.LSException in project grafikon by jub77.
the class LSTrainType method createTrainType.
public TrainType createTrainType(TrainDiagram diagram) throws LSException {
TrainType type = diagram.getPartFactory().createTrainType(id);
type.setAbbr(LocalizedString.fromString(abbr));
type.setColor(Conversions.convertTextToColor(color));
type.setDesc(LocalizedString.fromString(desc));
type.setPlatform(platform);
type.setCategory(this.convertToCategory(diagram));
try {
type.setTrainCompleteNameTemplate(trainCompleteNameTemplate != null ? TextTemplate.createTextTemplate(trainCompleteNameTemplate, TextTemplate.Language.MVEL) : null);
type.setTrainNameTemplate(trainNameTemplate != null ? TextTemplate.createTextTemplate(trainNameTemplate, TextTemplate.Language.MVEL) : null);
} catch (GrafikonException e) {
throw new LSException(e);
}
return type;
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSAttributesItem method convertScript.
private Object convertScript(String value, String valueType) throws LSException {
String languageStr = valueType.substring(SCRIPT_KEY_PREFIX.length());
Script.Language language = Script.Language.valueOf(languageStr);
try {
return Script.createScript(value, language);
} catch (GrafikonException e) {
throw new LSException("Cannot convert script: " + e.getMessage(), e);
}
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSAttributesItem method convertTextTemplate.
private Object convertTextTemplate(String value, String valueType) throws LSException {
String languageStr = valueType.substring(TEXT_TEMPLATE_KEY_PREFIX.length());
TextTemplate.Language language = TextTemplate.Language.valueOf(languageStr);
try {
return TextTemplate.createTextTemplate(value, language);
} catch (GrafikonException e) {
throw new LSException("Cannot convert template: " + e.getMessage(), e);
}
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class FileLoadSaveImpl method checkVersion.
private ModelVersion checkVersion(Properties props) throws LSException {
ModelVersion current = ModelVersion.parseModelVersion(METADATA_MODEL_VERSION);
ModelVersion loaded = ModelVersion.parseModelVersion(props.getProperty(METADATA_KEY_MODEL_VERSION));
if (current.compareTo(loaded) < 0) {
throw new LSException(String.format("Current version [%s] is older than the version of loaded file [%s].", current.toString(), loaded.toString()));
}
return loaded;
}
Aggregations