<commit_before>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2017 <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ui.controls;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ui.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Image combo
 */
public class CSmartCombo<ITEM_TYPE> extends Composite {

    public interface TableFilter<FILTER_ITEM_TYPE> {
        String getFilterLabel();
        String getDefaultLabel();
        boolean isEnabled();
        boolean setEnabled(boolean enabled);
        boolean filter(FILTER_ITEM_TYPE item);
    }

    protected final ILabelProvider labelProvider;
    protected final List<ITEM_TYPE> items = new ArrayList<>();
    private TableFilter<ITEM_TYPE> tableFilter = null;
    private ITEM_TYPE selectedItem;
    private Label imageLabel;
    private StyledText text;
    private Table dropDownControl;
    private int visibleItemCount = 10;
    private int widthHint = SWT.DEFAULT;
    private Shell popup;
    private long disposeTime = -1;
    private Button arrow;
    private boolean hasFocus;
    private Listener listener, filter;
    private Font font;
    private Point sizeHint;
    // Size of Text with border. Needed for calc of height in computeSize
    // On MacOS edit with border is much higher
    private final Point borderTextSize;

    public CSmartCombo(Composite parent, int style, ILabelProvider labelProvider)
    {
        super(parent, style = checkStyle(style));
        this.labelProvider = labelProvider;
        if (parent.getLayout() instanceof GridLayout) {
            this.setLayoutData(new GridData(GridData.FILL_VERTICAL));
        }

        GridLayout gridLayout = new GridLayout(3, false);
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginTop = 0;
        gridLayout.marginBottom = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.verticalSpacing = 0;
        this.setLayout(gridLayout);

        int heightHint = 0;
        {
            Text sampleText = new Text(this, SWT.BORDER);
            borderTextSize = sampleText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            heightHint = borderTextSize.y - sampleText.getBorderWidth() * 2;
            sampleText.dispose();
        }

        this.imageLabel = new Label(this, SWT.NONE);<commit_msg>Smart combo height fix<commit_after>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2017 <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ui.controls;

import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ui.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Image combo
 */
public class CSmartCombo<ITEM_TYPE> extends Composite {

    public interface TableFilter<FILTER_ITEM_TYPE> {
        String getFilterLabel();
        String getDefaultLabel();
        boolean isEnabled();
        boolean setEnabled(boolean enabled);
        boolean filter(FILTER_ITEM_TYPE item);
    }

    protected final ILabelProvider labelProvider;
    protected final List<ITEM_TYPE> items = new ArrayList<>();
    private TableFilter<ITEM_TYPE> tableFilter = null;
    private ITEM_TYPE selectedItem;
    private Label imageLabel;
    private StyledText text;
    private Table dropDownControl;
    private int visibleItemCount = 10;
    private int widthHint = SWT.DEFAULT;
    private Shell popup;
    private long disposeTime = -1;
    private Button arrow;
    private boolean hasFocus;
    private Listener listener, filter;
    private Font font;
    private Point sizeHint;
    // Size of Text with border. Needed for calc of height in computeSize
    // On MacOS edit with border is much higher
    private final Point borderTextSize;

    public CSmartCombo(Composite parent, int style, ILabelProvider labelProvider)
    {
        super(parent, style = checkStyle(style));
        this.labelProvider = labelProvider;
        if (parent.getLayout() instanceof GridLayout) {
            this.setLayoutData(new GridData(GridData.FILL_VERTICAL));
        }

        GridLayout gridLayout = new GridLayout(3, false);
        gridLayout.marginHeight = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginTop = 0;
        gridLayout.marginBottom = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.verticalSpacing = 0;
        this.setLayout(gridLayout);

        int heightHint = 0;
        {
            Text sampleText = new Text(this, SWT.NONE);
            sampleText.setText("X");
            borderTextSize = sampleText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            heightHint = borderTextSize.y + 2;
            sampleText.dispose();
        }

        this.imageLabel = new Label(this, SWT.NONE);
{'fraction_non_alphanumeric': 0.08647654093836246, 'fraction_numerical': 0.007359705611775529, 'mean_word_length': 3.1975546975546973, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1119336', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1775, 'n_words': 552}