<commit_before>package de.setsoftware.reviewtool.ui.dialogs;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

import de.setsoftware.reviewtool.base.Util;
import de.setsoftware.reviewtool.model.IReviewPersistence;
import de.setsoftware.reviewtool.model.TicketInfo;

/**
 * Dialog to select a ticket to review. The normal usage is to select the ticket
 * from a list, but it's also possible to directly enter a custom ID.
 */
public class SelectTicketDialog extends Dialog {

    private static final String KEY_LAST_USED_FILTER_REVIEW = "filterReview";
    private static final String KEY_LAST_USED_FILTER_FIXING = "filterFixing";
    private static final int MAX_COLUMN_WIDTH = 600;

    private Combo filterCombo;
    private Table selectionTable;
    private Text keyField;

    private final boolean review;
    private final IReviewPersistence persistence;
    private final String oldValue;
    private String selectedKey;

    protected SelectTicketDialog(Shell parentShell, String oldValue, IReviewPersistence p, boolean review) {
        super(parentShell);
        this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
        this.persistence = p;
        this.review = review;
        this.oldValue = oldValue;
    }

    /**
     * Shows the dialog and lets the user select a ticket.
     * @return The ticket id, or null if none was selected.
     */
    public static String get(IReviewPersistence p, String oldValue, boolean forReview) {
        final Shell s = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        final SelectTicketDialog dialog = new SelectTicketDialog(s, oldValue, p, forReview);
        final int ret = dialog.open();
        if (ret != OK) {
            return null;
        }
        return dialog.selectedKey;
    }

    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("Choose ticket");
        DialogHelper.restoreSavedSize(newShell, this, 700, 500);
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        final Composite comp = (Composite) super.createDialogArea(parent);

        final GridLayout layout = (GridLayout) comp.getLayout();
        layout.numColumns = 1;

        this.filterCombo = new Combo(comp, SWT.READ_ONLY);
        final Set<String> possibleFilters =
                this.review ? this.persistence.getFilterNamesForReview() : this.persistence.getFilterNamesForFixing();
        this.filterCombo.setItems(possibleFilters.toArray(new String[possibleFilters.size()]));
        this.filterCombo.select(Arrays.asList().indexOf(DialogHelper.getSetting(this.filterKey())));
        if (this.filterCombo.getSelectionIndex() < 0) {
            this.filterCombo.select(0);
        }
        this.filterCombo.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                SelectTicketDialog.this.fillTable();<commit_msg>Fix selection of the last chosen filter in SelectTicketDialog<commit_after>package de.setsoftware.reviewtool.ui.dialogs;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

import de.setsoftware.reviewtool.base.Util;
import de.setsoftware.reviewtool.model.IReviewPersistence;
import de.setsoftware.reviewtool.model.TicketInfo;

/**
 * Dialog to select a ticket to review. The normal usage is to select the ticket
 * from a list, but it's also possible to directly enter a custom ID.
 */
public class SelectTicketDialog extends Dialog {

    private static final String KEY_LAST_USED_FILTER_REVIEW = "filterReview";
    private static final String KEY_LAST_USED_FILTER_FIXING = "filterFixing";
    private static final int MAX_COLUMN_WIDTH = 600;

    private Combo filterCombo;
    private Table selectionTable;
    private Text keyField;

    private final boolean review;
    private final IReviewPersistence persistence;
    private final String oldValue;
    private String selectedKey;

    protected SelectTicketDialog(Shell parentShell, String oldValue, IReviewPersistence p, boolean review) {
        super(parentShell);
        this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
        this.persistence = p;
        this.review = review;
        this.oldValue = oldValue;
    }

    /**
     * Shows the dialog and lets the user select a ticket.
     * @return The ticket id, or null if none was selected.
     */
    public static String get(IReviewPersistence p, String oldValue, boolean forReview) {
        final Shell s = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        final SelectTicketDialog dialog = new SelectTicketDialog(s, oldValue, p, forReview);
        final int ret = dialog.open();
        if (ret != OK) {
            return null;
        }
        return dialog.selectedKey;
    }

    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("Choose ticket");
        DialogHelper.restoreSavedSize(newShell, this, 700, 500);
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        final Composite comp = (Composite) super.createDialogArea(parent);

        final GridLayout layout = (GridLayout) comp.getLayout();
        layout.numColumns = 1;

        this.filterCombo = new Combo(comp, SWT.READ_ONLY);
        final Set<String> possibleFilters =
                this.review ? this.persistence.getFilterNamesForReview() : this.persistence.getFilterNamesForFixing();
        this.filterCombo.setItems(possibleFilters.toArray(new String[possibleFilters.size()]));
        this.filterCombo.select(
                Arrays.asList(this.filterCombo.getItems()).indexOf(DialogHelper.getSetting(this.filterKey())));
        if (this.filterCombo.getSelectionIndex() < 0) {
            this.filterCombo.select(0);
        }
        this.filterCombo.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                SelectTicketDialog.this.fillTable();
{'fraction_non_alphanumeric': 0.09235754793410748, 'fraction_numerical': 0.0032406157169862274, 'mean_word_length': 3.5386029411764706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6351118', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2072, 'n_words': 498}