<commit_before>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2019 <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.dashboard.control;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dashboard.model.*;
import org.jkiss.dbeaver.ui.dashboard.model.data.DashboardDataset;

import java.util.Date;
import java.util.List;

public class DashboardItem extends Composite implements DashboardContainer {

    public static final int DEFAULT_HEIGHT = 200;
    private DashboardList groupContainer;
    private final DashboardItemViewConfiguration dashboardConfig;

    private Date lastUpdateTime;
    private DashboardRenderer renderer;
    private DashboardChartComposite dashboardControl;
    private final Label titleLabel;

    public DashboardItem(DashboardList parent, String dashboardId) {
        super(parent, SWT.DOUBLE_BUFFERED);
        this.groupContainer = parent;
        this.dashboardConfig = groupContainer.getView().getViewConfiguration().getDashboardConfig(dashboardId);

        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 3;
        layout.marginWidth = 3;
        layout.verticalSpacing = 0;
        layout.horizontalSpacing = 0;
        this.setLayout(layout);

        {
            Composite titleComposite = new Composite(this, SWT.NONE);
            titleComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            FillLayout fillLayout = new FillLayout();
            fillLayout.marginHeight = 3;
            fillLayout.marginWidth = 3;
            titleComposite.setLayout(fillLayout);
            titleLabel = new Label(titleComposite, SWT.NONE);
            titleLabel.setFont(parent.getTitleFont());
            //GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            //titleLabel.setLayoutData(gd);
            //titleLabel.setForeground(titleLabel.getDisplay().getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
            //titleLabel.setBackground(titleLabel.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
            titleLabel.setText("  " + dashboardConfig.getDashboardDescriptor().getName());
        }

        try {
            Composite chartComposite = new Composite(this, SWT.NONE);
            chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
            chartComposite.setLayout(new FillLayout());
            renderer = dashboardConfig.getDashboardDescriptor().getType().createRenderer();
            dashboardControl = renderer.createDashboard(chartComposite, this, groupContainer.getView(), computeSize(-1, -1));

        } catch (DBException e) {
            // Something went wrong
            Text errorLabel = new Text(this, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
            errorLabel.setText("Error creating " + dashboardConfig.getDashboardDescriptor().getName() + " renderer: " + e.getMessage());
            errorLabel.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));
        }

        if (dashboardControl != null) {
            Canvas chartCanvas = dashboardControl.getChartCanvas();
            MouseAdapter mouseAdapter = new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    chartCanvas.setFocus();
                }
            };
            this.addMouseListener(mouseAdapter);
            chartCanvas.addMouseListener(mouseAdapter);
            titleLabel.addMouseListener(mouseAdapter);

            chartCanvas.addFocusListener(new FocusListener() {
                @Override
                public void focusGained(FocusEvent e) {
                    groupContainer.setSelection(DashboardItem.this);
                    redraw();
                }

                @Override
                public void focusLost(FocusEvent e) {

                }
            });
        }

        groupContainer.addItem(this);
        addDisposeListener(e -> groupContainer.removeItem(this));

        this.addPaintListener(this::paintItem);
    }

    public Label getTitleLabel() {
        return titleLabel;
    }

    private void paintItem(PaintEvent e) {
        Point itemSize = getSize();
        if (groupContainer.getSelectedItem() == this) {
            e.gc.setLineWidth(2);
            e.gc.setLineStyle(SWT.LINE_SOLID);
        } else {<commit_msg>Border color fix<commit_after>/*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2019 <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.dashboard.control;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dashboard.model.*;
import org.jkiss.dbeaver.ui.dashboard.model.data.DashboardDataset;

import java.util.Date;
import java.util.List;

public class DashboardItem extends Composite implements DashboardContainer {

    public static final int DEFAULT_HEIGHT = 200;
    private DashboardList groupContainer;
    private final DashboardItemViewConfiguration dashboardConfig;

    private Date lastUpdateTime;
    private DashboardRenderer renderer;
    private DashboardChartComposite dashboardControl;
    private final Label titleLabel;

    public DashboardItem(DashboardList parent, String dashboardId) {
        super(parent, SWT.DOUBLE_BUFFERED);
        this.groupContainer = parent;
        this.dashboardConfig = groupContainer.getView().getViewConfiguration().getDashboardConfig(dashboardId);

        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 3;
        layout.marginWidth = 3;
        layout.verticalSpacing = 0;
        layout.horizontalSpacing = 0;
        this.setLayout(layout);

        {
            Composite titleComposite = new Composite(this, SWT.NONE);
            titleComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            FillLayout fillLayout = new FillLayout();
            fillLayout.marginHeight = 3;
            fillLayout.marginWidth = 3;
            titleComposite.setLayout(fillLayout);
            titleLabel = new Label(titleComposite, SWT.NONE);
            titleLabel.setFont(parent.getTitleFont());
            //GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            //titleLabel.setLayoutData(gd);
            //titleLabel.setForeground(titleLabel.getDisplay().getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
            //titleLabel.setBackground(titleLabel.getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
            titleLabel.setText("  " + dashboardConfig.getDashboardDescriptor().getName());
        }

        try {
            Composite chartComposite = new Composite(this, SWT.NONE);
            chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
            chartComposite.setLayout(new FillLayout());
            renderer = dashboardConfig.getDashboardDescriptor().getType().createRenderer();
            dashboardControl = renderer.createDashboard(chartComposite, this, groupContainer.getView(), computeSize(-1, -1));

        } catch (DBException e) {
            // Something went wrong
            Text errorLabel = new Text(this, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
            errorLabel.setText("Error creating " + dashboardConfig.getDashboardDescriptor().getName() + " renderer: " + e.getMessage());
            errorLabel.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));
        }

        if (dashboardControl != null) {
            Canvas chartCanvas = dashboardControl.getChartCanvas();
            MouseAdapter mouseAdapter = new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    chartCanvas.setFocus();
                }
            };
            this.addMouseListener(mouseAdapter);
            chartCanvas.addMouseListener(mouseAdapter);
            titleLabel.addMouseListener(mouseAdapter);

            chartCanvas.addFocusListener(new FocusListener() {
                @Override
                public void focusGained(FocusEvent e) {
                    groupContainer.setSelection(DashboardItem.this);
                    redraw();
                }

                @Override
                public void focusLost(FocusEvent e) {

                }
            });
        }

        groupContainer.addItem(this);
        addDisposeListener(e -> groupContainer.removeItem(this));

        this.addPaintListener(this::paintItem);
    }

    public Label getTitleLabel() {
        return titleLabel;
    }

    private void paintItem(PaintEvent e) {
        Point itemSize = getSize();
        e.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        if (groupContainer.getSelectedItem() == this) {
            e.gc.setLineWidth(2);
            e.gc.setLineStyle(SWT.LINE_SOLID);
        } else {
{'fraction_non_alphanumeric': 0.09494257132271211, 'fraction_numerical': 0.004631344942571323, 'mean_word_length': 2.7990851513019, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4632850', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2881, 'n_words': 619}