<commit_before>package name.abuchen.portfolio.ui.util;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

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

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.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

public class CellEditorFactory
{
    public interface ModificationListener
    {
        void onModified(Object element, String property);
    }

    private Class<?> subjectType;
    private ColumnViewer viewer;
    private ModificationListener listener = new ModificationListener()
    {
        public void onModified(Object element, String property)
        {}
    };

    private List<String> properties = new ArrayList<String>();
    private List<CellEditor> cellEditors = new ArrayList<CellEditor>();
    private List<Modifier> modifiers = new ArrayList<Modifier>();

    public CellEditorFactory(ColumnViewer viewer, Class<?> subject)
    {
        this.subjectType = subject;
        this.viewer = viewer;
    }

    public CellEditorFactory notify(ModificationListener listener)
    {
        this.listener = listener;
        return this;
    }

    public CellEditorFactory editable(String name)
    {
        PropertyDescriptor descriptor = descriptorFor(name);

        properties.add(name);
        cellEditors.add(cellEditorFor(descriptor));
        modifiers.add(modifierFor(descriptor));

        return this;
    }

    public CellEditorFactory month(String name)
    {
        final PropertyDescriptor descriptor = descriptorFor(name);
        if (descriptor.getPropertyType() != int.class)
            throw new UnsupportedOperationException(String.format(
                            "Property %s needs to be of type int to serve as month", name)); //$NON-NLS-1$

        // determine number of months (some calendars have 13)
        int numMonths = Calendar.getInstance().getActualMaximum(Calendar.MONTH) + 1;
        final String[] months = new String[numMonths];
        System.arraycopy(new DateFormatSymbols().getMonths(), 0, months, 0, numMonths);<commit_msg>Enable tabbing between cells when editing<commit_after>package name.abuchen.portfolio.ui.util;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

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

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.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerEditor;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

public final class CellEditorFactory
{
    public interface ModificationListener
    {
        void onModified(Object element, String property);
    }

    private final Class<?> subjectType;
    private final ColumnViewer viewer;

    private ModificationListener listener = new ModificationListener()
    {
        public void onModified(Object element, String property)
        {}
    };

    private final List<String> properties = new ArrayList<String>();
    private final List<CellEditor> cellEditors = new ArrayList<CellEditor>();
    private final List<Modifier> modifiers = new ArrayList<Modifier>();

    public CellEditorFactory(ColumnViewer viewer, Class<?> subject)
    {
        this.subjectType = subject;
        this.viewer = viewer;

        ColumnViewerEditorActivationStrategy support = new ColumnViewerEditorActivationStrategy(viewer)
        {
            protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event)
            {
                return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                                || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
                                || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
                                || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
            }
        };

        int feature = ColumnViewerEditor.TABBING_HORIZONTAL
                    | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL
                    | ColumnViewerEditor.KEYBOARD_ACTIVATION;
        if (viewer instanceof TableViewer)
            TableViewerEditor.create((TableViewer) viewer, null, support, feature);
        else if (viewer instanceof TreeViewer)
            TreeViewerEditor.create((TreeViewer) viewer, support, feature);
    }

    public CellEditorFactory notify(ModificationListener listener)
    {
        this.listener = listener;
        return this;
    }

    public CellEditorFactory editable(String name)
    {
        PropertyDescriptor descriptor = descriptorFor(name);

        properties.add(name);
        cellEditors.add(cellEditorFor(descriptor));
        modifiers.add(modifierFor(descriptor));

        return this;
    }

    public CellEditorFactory month(String name)
    {
        final PropertyDescriptor descriptor = descriptorFor(name);
        if (descriptor.getPropertyType() != int.class)
            throw new UnsupportedOperationException(String.format(
                            "Property %s needs to be of type int to serve as month", name)); //$NON-NLS-1$

        // determine number of months (some calendars have 13)
        int numMonths = Calendar.getInstance().getActualMaximum(Calendar.MONTH) + 1;
        final String[] months = new String[numMonths];
        System.arraycopy(new DateFormatSymbols().getMonths(), 0, months, 0, numMonths);
{'fraction_non_alphanumeric': 0.08966914247130317, 'fraction_numerical': 0.0016205266711681297, 'mean_word_length': 3.646173149309912, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3876592', 'n_tokens_mistral': 2081, 'n_tokens_neox': 2037, 'n_words': 425}