Search in sources :

Example 11 with MPart

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);
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) Execute(org.eclipse.e4.core.di.annotations.Execute) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MessageFormat(com.ibm.icu.text.MessageFormat) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Messages(name.abuchen.portfolio.ui.Messages) Named(javax.inject.Named) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Shell(org.eclipse.swt.widgets.Shell) Job(org.eclipse.core.runtime.jobs.Job) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) FileDialog(org.eclipse.swt.widgets.FileDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) Display(org.eclipse.swt.widgets.Display) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) List(java.util.List) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) Client(name.abuchen.portfolio.model.Client) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Job(org.eclipse.core.runtime.jobs.Job) FileDialog(org.eclipse.swt.widgets.FileDialog) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) File(java.io.File)

Example 12 with MPart

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);
    }
}
Also used : NewClientWizard(name.abuchen.portfolio.ui.wizards.client.NewClientWizard) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) Client(name.abuchen.portfolio.model.Client) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 13 with MPart

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();
}
Also used : IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) TableViewer(org.eclipse.jface.viewers.TableViewer) Execute(org.eclipse.e4.core.di.annotations.Execute) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) Named(javax.inject.Named) Shell(org.eclipse.swt.widgets.Shell) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DesktopAPI(name.abuchen.portfolio.ui.util.DesktopAPI) Collectors(java.util.stream.Collectors) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) Consumer(java.util.function.Consumer) PopupDialog(org.eclipse.jface.dialogs.PopupDialog) List(java.util.List) Bookmark(name.abuchen.portfolio.model.Bookmark) SWT(org.eclipse.swt.SWT) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Bookmark(name.abuchen.portfolio.model.Bookmark) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 14 with MPart

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);
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 15 with MPart

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();
}
Also used : UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) Client(name.abuchen.portfolio.model.Client) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

Execute (org.eclipse.e4.core.di.annotations.Execute)20 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)19 Client (name.abuchen.portfolio.model.Client)12 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)11 File (java.io.File)7 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)7 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 PortfolioPart (name.abuchen.portfolio.ui.PortfolioPart)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 FileDialog (org.eclipse.swt.widgets.FileDialog)5 Dialog (org.eclipse.jface.dialogs.Dialog)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 StringWriter (java.io.StringWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 Named (javax.inject.Named)2 Extractor (name.abuchen.portfolio.datatransfer.Extractor)2