Package name.abuchen.portfolio.ui.views.columns

Source Code of name.abuchen.portfolio.ui.views.columns.IsinColumn$IsinEditingSupport

package name.abuchen.portfolio.ui.views.columns;

import java.text.MessageFormat;

import name.abuchen.portfolio.model.Adaptor;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.util.Column;
import name.abuchen.portfolio.ui.util.ColumnEditingSupport;
import name.abuchen.portfolio.ui.util.ColumnViewerSorter;
import name.abuchen.portfolio.util.Isin;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT;

public class IsinColumn extends Column
{
    public static class IsinEditingSupport extends ColumnEditingSupport
    {
        @Override
        public boolean canEdit(Object element)
        {
            Security s = Adaptor.adapt(Security.class, element);
            return s != null;
        }

        @Override
        public Object getValue(Object element)
        {
            Security s = Adaptor.adapt(Security.class, element);
            return s.getIsin();
        }

        @Override
        public void setValue(Object element, Object value)
        {
            String newValue = ((String) value).trim();

            if (newValue.length() > 0 && !Isin.isValid(newValue))
                throw new IllegalArgumentException(MessageFormat.format(Messages.MsgDialogNotAValidISIN, newValue));

            Security security = Adaptor.adapt(Security.class, element);
            String oldValue = security.getIsin();

            if (!newValue.equals(oldValue))
            {
                security.setIsin(newValue);
                notify(element, newValue, oldValue);
            }
        }
    }

    public IsinColumn()
    {
        this("isin"); //$NON-NLS-1$
    }

    public IsinColumn(String id)
    {
        super(id, Messages.ColumnISIN, SWT.LEFT, 100);

        setLabelProvider(new ColumnLabelProvider()
        {
            @Override
            public String getText(Object e)
            {
                Security s = Adaptor.adapt(Security.class, e);
                return s != null ? s.getIsin() : null;
            }
        });
        setSorter(ColumnViewerSorter.create(Security.class, "isin")); //$NON-NLS-1$
        new IsinEditingSupport().attachTo(this);
    }

}
TOP

Related Classes of name.abuchen.portfolio.ui.views.columns.IsinColumn$IsinEditingSupport

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.