Package name.abuchen.portfolio.ui.handlers

Source Code of name.abuchen.portfolio.ui.handlers.UpdateHandler

package name.abuchen.portfolio.ui.handlers;

import java.lang.reflect.InvocationTargetException;

import javax.inject.Named;

import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.PortfolioPlugin;
import name.abuchen.portfolio.ui.update.UpdateHelper;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class UpdateHandler
{
    @Execute
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, final IWorkbench workbench)
    {
        try
        {
            new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress()
            {
                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
                {
                    try
                    {
                        UpdateHelper updateHelper = new UpdateHelper(workbench);
                        updateHelper.runUpdate(monitor, false);
                    }
                    catch (CoreException e)
                    {
                        throw new InvocationTargetException(e);
                    }
                }
            });

        }
        catch (InvocationTargetException e)
        {
            PortfolioPlugin.log(e.getCause());

            IStatus status = e.getCause() instanceof CoreException ? ((CoreException) e.getCause()).getStatus()
                            : new Status(Status.ERROR, PortfolioPlugin.PLUGIN_ID, e.getCause().getMessage(),
                                            e.getCause());

            ErrorDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError,
                            Messages.MsgErrorUpdating, status);
        }
        catch (InterruptedException ignore)
        {}
    }
}
TOP

Related Classes of name.abuchen.portfolio.ui.handlers.UpdateHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.