Package name.abuchen.portfolio.ui.util

Source Code of name.abuchen.portfolio.ui.util.ColumnEditingSupportWrapper

package name.abuchen.portfolio.ui.util;

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

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

public class ColumnEditingSupportWrapper extends EditingSupport
{
    private ColumnViewer viewer;
    private ColumnEditingSupport proxy;
    private CellEditor editor;

    public ColumnEditingSupportWrapper(ColumnViewer viewer, ColumnEditingSupport proxy)
    {
        super(viewer);
        this.viewer = viewer;
        this.proxy = proxy;
        this.editor = proxy.createEditor((Composite) viewer.getControl());
    }

    @Override
    protected CellEditor getCellEditor(Object element)
    {
        return editor;
    }

    @Override
    protected boolean canEdit(Object element)
    {
        return proxy.canEdit(element);
    }

    @Override
    protected Object getValue(Object element)
    {
        try
        {
            return proxy.getValue(element);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void setValue(Object element, Object value)
    {
        try
        {
            proxy.setValue(element, value);
            viewer.update(element, null);
        }
        catch (Exception e)
        {
            PortfolioPlugin.log(e);
            ErrorDialog dialog = new ErrorDialog(Display.getDefault().getActiveShell(), Messages.LabelError,
                            Messages.LabelInputValidationFailed, new Status(Status.ERROR, PortfolioPlugin.PLUGIN_ID,
                                            e.getMessage(), e), IStatus.ERROR);
            dialog.setBlockOnOpen(false);
            dialog.open();
        }
    }
}
TOP

Related Classes of name.abuchen.portfolio.ui.util.ColumnEditingSupportWrapper

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.