use of org.eclipse.e4.ui.model.application.ui.basic.MPart 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 org.eclipse.e4.ui.model.application.ui.basic.MPart in project portfolio by buchen.
the class NewFileHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, //
@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MApplication app, EPartService partService, EModelService modelService) {
NewClientWizard wizard = new NewClientWizard();
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() == Window.OK) {
MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
part.setLabel(Messages.LabelUnnamedXml);
part.getTransientData().put(Client.class.getName(), wizard.getClient());
if (activePart != null)
activePart.getParent().getChildren().add(part);
else
((MPartStack) modelService.find(UIConstants.PartStack.MAIN, app)).getChildren().add(part);
part.setVisible(true);
part.getParent().setVisible(true);
partService.showPart(part, PartState.ACTIVATE);
}
}
use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project portfolio by buchen.
the class OpenBookmarksHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, ESelectionService selectionService) {
Object object = selectionService.getSelection();
if (!(object instanceof SecuritySelection))
return;
SecuritySelection selection = (SecuritySelection) object;
if (selection.getClient().getSettings().getBookmarks().isEmpty())
return;
List<Bookmark> bookmarks = selection.getClient().getSettings().getBookmarks().stream().filter(b -> !b.isSeparator()).collect(Collectors.toList());
BookmarkPopup<Bookmark> popup = new //
BookmarkPopup<>(//
shell, //
selection.getSecurity().getName(), //
bookmarks, //
Bookmark::getLabel, bm -> DesktopAPI.browse(bm.constructURL(selection.getClient(), selection.getSecurity())));
popup.open();
}
use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project portfolio by buchen.
the class OpenPartHandler method execute.
@Execute
public void execute(EPartService partService, @Named(UIConstants.Parameter.PART) String partname) {
MPart part = partService.findPart(partname);
part.setVisible(true);
partService.activate(part, true);
}
use of org.eclipse.e4.ui.model.application.ui.basic.MPart in project portfolio by buchen.
the class UpdateHistoricQuotesHandler 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;
new UpdateQuotesJob(client, EnumSet.of(UpdateQuotesJob.Target.HISTORIC)).schedule();
}
Aggregations