use of name.abuchen.portfolio.util.TokenReplacingReader in project portfolio by buchen.
the class OpenSampleHandler method execute.
@Execute
public void execute(//
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, //
final MApplication app, final EPartService partService, final EModelService modelService, @Named(UIConstants.Parameter.SAMPLE_FILE) final String sampleFile) {
try {
IRunnableWithProgress loadResourceOperation = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try (InputStream in = this.getClass().getResourceAsStream(sampleFile)) {
InputStream inputStream = new ProgressMonitorInputStream(in, monitor);
Reader replacingReader = new TokenReplacingReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), buildResourcesTokenResolver());
final Client client = ClientFactory.load(replacingReader);
fixTaxonomyLabels(client);
sync.asyncExec(() -> {
MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
part.setLabel(sampleFile.substring(sampleFile.lastIndexOf('/') + 1));
part.getTransientData().put(Client.class.getName(), client);
MPartStack stack = (MPartStack) modelService.find(UIConstants.PartStack.MAIN, app);
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
});
} catch (IOException ignore) {
PortfolioPlugin.log(ignore);
}
}
};
new ProgressMonitorDialog(shell).run(true, true, loadResourceOperation);
} catch (InvocationTargetException | InterruptedException e) {
PortfolioPlugin.log(e);
}
}
Aggregations