Search in sources :

Example 1 with Focus

use of org.eclipse.e4.ui.di.Focus 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 2 with Focus

use of org.eclipse.e4.ui.di.Focus in project AGREE by loonwerks.

the class VariablesView method beforeCreateStepArguments.

@Inject
@Optional
void beforeCreateStepArguments(@UIEventTopic(SimulatorUIEvents.BEFORE_STEP_FORWARD) final BeforeStepForwardEvent event) {
    // Take the focus away from cell editors widgets
    if (treeViewer != null) {
        final Control focusControl = Display.getCurrent().getFocusControl();
        final Tree tree = treeViewer.getTree();
        for (Control c = focusControl; c != null; c = c.getParent()) {
            if (c == tree) {
                treeViewer.getTree().forceFocus();
                break;
            }
        }
    }
    // Cancel the step
    if (elementToConstraintErrorMap.size() > 0) {
        event.cancelStep(new Throwable("One or more user constraints is invalid."));
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Tree(org.eclipse.swt.widgets.Tree) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 3 with Focus

use of org.eclipse.e4.ui.di.Focus in project portfolio by buchen.

the class ImportPDFHandler method runImportWithFiles.

public static void runImportWithFiles(PortfolioPart part, Shell shell, Client client, Account account, Portfolio portfolio, List<File> files) {
    files.sort((File lhs, File rhs) -> {
        int modDiff = (int) (lhs.lastModified() - rhs.lastModified());
        return modDiff == 0 ? lhs.getPath().compareTo(rhs.getPath()) : modDiff;
    });
    IPreferenceStore preferences = part.getPreferenceStore();
    try {
        IRunnableWithProgress operation = monitor -> {
            PDFImportAssistant assistent = new PDFImportAssistant(client, files);
            Map<File, List<Exception>> errors = new HashMap<>();
            Map<Extractor, List<Extractor.Item>> result = assistent.run(monitor, errors);
            // 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(() -> {
                        ImportExtractedItemsWizard wizard = new ImportExtractedItemsWizard(client, preferences, result, errors);
                        if (account != null)
                            wizard.setTarget(account);
                        if (portfolio != null)
                            wizard.setTarget(portfolio);
                        Dialog wizwardDialog = new WizardDialog(shell, wizard);
                        wizwardDialog.open();
                    });
                    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 : ZipInputStream(java.util.zip.ZipInputStream) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) HashMap(java.util.HashMap) Execute(org.eclipse.e4.core.di.annotations.Execute) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) Named(javax.inject.Named) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) PortfolioPart(name.abuchen.portfolio.ui.editor.PortfolioPart) Portfolio(name.abuchen.portfolio.model.Portfolio) Shell(org.eclipse.swt.widgets.Shell) Account(name.abuchen.portfolio.model.Account) Files(java.nio.file.Files) Job(org.eclipse.core.runtime.jobs.Job) 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) FileInputStream(java.io.FileInputStream) 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) Paths(java.nio.file.Paths) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) PDFImportAssistant(name.abuchen.portfolio.datatransfer.pdf.PDFImportAssistant) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) PDFImportAssistant(name.abuchen.portfolio.datatransfer.pdf.PDFImportAssistant) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 4 with Focus

use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.

the class PartActivationHistory method getNextActivationCandidate.

MPart getNextActivationCandidate(Collection<MPart> validParts, MPart part) {
    MArea area = isInArea(part);
    if (area != null) {
        // focus should stay in the area if possible
        MPart candidate = getSiblingActivationCandidate(part);
        if (candidate != null) {
            return candidate;
        }
        // no sibling candidate, find another part in the area to activate
        candidate = findActivationCandidate(modelService.findElements(area, null, MPart.class), part);
        if (candidate != null) {
            return candidate;
        }
    }
    // check activation history, since the history is global, we need to filter it down first
    Collection<MPart> validCandidates = new ArrayList<>();
    for (MPart validPart : generalActivationHistory) {
        if (validParts.contains(validPart)) {
            validCandidates.add(validPart);
        }
    }
    MPart candidate = findActivationCandidate(validCandidates, part);
    return candidate == null ? getActivationCandidate(part) : candidate;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) ArrayList(java.util.ArrayList)

Example 5 with Focus

use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.

the class SplitHost method setFocus.

@Focus
void setFocus() {
    MPart ap = findInnerActive(myPart);
    if (ap == null) {
        if (Policy.DEBUG_FOCUS) {
            // $NON-NLS-1$
            WorkbenchSWTActivator.trace(// $NON-NLS-1$
            Policy.DEBUG_FOCUS_FLAG, // $NON-NLS-1$
            "Focus not set, no selected element in: " + myPart, new IllegalStateException());
        }
        return;
    }
    Control ctrl = (Control) ap.getWidget();
    Object object = ap.getObject();
    if (object != null && ctrl != null && !ctrl.isDisposed()) {
        ContextInjectionFactory.invoke(object, Focus.class, ap.getContext(), null);
    } else if (Policy.DEBUG_FOCUS) {
        WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focus not set, object is null or widget is disposed: " + object, // $NON-NLS-1$
        new IllegalStateException());
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Control(org.eclipse.swt.widgets.Control) Focus(org.eclipse.e4.ui.di.Focus)

Aggregations

MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)9 ArrayList (java.util.ArrayList)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)3 EObject (org.eclipse.emf.ecore.EObject)3 Control (org.eclipse.swt.widgets.Control)3 Shell (org.eclipse.swt.widgets.Shell)3 File (java.io.File)2 List (java.util.List)2 Named (javax.inject.Named)2 Extractor (name.abuchen.portfolio.datatransfer.Extractor)2 Client (name.abuchen.portfolio.model.Client)2 Messages (name.abuchen.portfolio.ui.Messages)2 PortfolioPlugin (name.abuchen.portfolio.ui.PortfolioPlugin)2 ImportExtractedItemsWizard (name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2