use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.
the class ImportIBHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) throws IOException {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
try {
Extractor extractor = new IBFlexStatementExtractor(client);
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
fileDialog.setText(extractor.getLabel());
fileDialog.setFilterNames(new String[] { // $NON-NLS-1$
MessageFormat.format("{0} ({1})", extractor.getLabel(), extractor.getFilterExtension()) });
fileDialog.setFilterExtensions(new String[] { extractor.getFilterExtension() });
fileDialog.open();
String[] filenames = fileDialog.getFileNames();
if (filenames.length == 0)
return;
List<Extractor.InputFile> files = new ArrayList<>();
for (String filename : filenames) files.add(new Extractor.InputFile(new File(fileDialog.getFilterPath(), filename)));
IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
Dialog wizwardDialog = new WizardDialog(Display.getDefault().getActiveShell(), new ImportExtractedItemsWizard(client, extractor, preferences, files));
wizwardDialog.open();
} catch (IllegalArgumentException e) {
PortfolioPlugin.log(e);
MessageDialog.openError(shell, Messages.LabelError, e.getMessage());
}
}
use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.
the class ImportPDFHandler method doExecute.
/* package */
void doExecute(MPart part, Shell shell, boolean isLegacyMode) {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
fileDialog.setText(Messages.PDFImportWizardAssistant);
fileDialog.setFilterNames(new String[] { Messages.PDFImportFilterName });
// $NON-NLS-1$
fileDialog.setFilterExtensions(new String[] { "*.pdf" });
fileDialog.open();
String[] filenames = fileDialog.getFileNames();
if (filenames.length == 0)
return;
List<Extractor.InputFile> files = new ArrayList<>();
for (String filename : filenames) files.add(new PDFInputFile(new File(fileDialog.getFilterPath(), filename)));
IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
try {
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(Messages.PDFImportWizardMsgExtracting, files.size());
for (Extractor.InputFile inputFile : files) {
monitor.setTaskName(inputFile.getName());
try {
((PDFInputFile) inputFile).parse();
} catch (IOException e) {
throw new IllegalArgumentException(MessageFormat.format(Messages.PDFImportErrorParsingDocument, inputFile.getName()), e);
}
monitor.worked(1);
}
// if we just run this async, then the main window on macOS does
// not regain focus and the menus are not usable
new // $NON-NLS-1$
Job(// $NON-NLS-1$
"") {
@Override
protected IStatus run(IProgressMonitor monitor) {
shell.getDisplay().asyncExec(() -> openWizard(shell, client, files, preferences, isLegacyMode));
return Status.OK_STATUS;
}
}.schedule(50);
};
new ProgressMonitorDialog(shell).run(true, true, operation);
} catch (IllegalArgumentException | InvocationTargetException | InterruptedException e) {
PortfolioPlugin.log(e);
String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
MessageDialog.openError(shell, Messages.LabelError, message);
}
}
use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.
the class SaveFileHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
// trigger part to save file
((PortfolioPart) part.getObject()).save(part, shell);
}
use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.
the class SaveAsFileHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(UIConstants.Parameter.EXTENSION) String extension, @Named(UIConstants.Parameter.ENCRYPTION_METHOD) @Optional String encryptionMethod) {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
if (extension == null)
// $NON-NLS-1$
throw new IllegalArgumentException("Missing file extension parameter");
// check whether encryption is supported
if (// $NON-NLS-1$
"AES256".equals(encryptionMethod) && !ClientFactory.isKeyLengthSupported(256)) {
new JurisdictionFilesDownloadDialog(shell).open();
return;
}
// trigger part to save file
((PortfolioPart) part.getObject()).doSaveAs(part, shell, extension, encryptionMethod);
}
use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.
the class ImportCSVHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
Client client = MenuHelper.getActiveClient(part);
if (client == null)
return;
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
fileDialog.setFilterNames(new String[] { Messages.CSVImportLabelFileCSV, Messages.CSVImportLabelFileAll });
// $NON-NLS-1$ //$NON-NLS-2$
fileDialog.setFilterExtensions(new String[] { "*.csv", "*.*" });
String fileName = fileDialog.open();
if (fileName == null)
return;
IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
Dialog wizwardDialog = new WizardDialog(shell, new CSVImportWizard(client, preferences, new File(fileName)));
wizwardDialog.open();
}
Aggregations