<commit_before>/*******************************************************************************
 * Copyright (c) 2014
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME>
 *******************************************************************************/
package org.splevo.ui.refinementbrowser;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wb.swt.SWTResourceManager;
import org.splevo.ui.util.UIUtil;
import org.splevo.vpm.refinement.Refinement;
import org.splevo.vpm.variability.Variant;
import org.splevo.vpm.variability.VariationPoint;

import com.google.common.base.Strings;

/**
 * Details view to show information about a currently selected refinement.
 */
public class RefinementDetailsView extends Composite {

    private static final String REFINEMENT_INFO_DEFAULT_TEXT = "Select refinement on the left to review details.";

    /** The internal tree viewer to present the refined variation points. */
    private TreeViewer refinementDetailsTreeViewer = null;

    /** The area to present info about a currently selected refinement in. */
    private StyledText refinementInfoArea = null;

    /**
     * Constructor to create the view.
     *
     * @param parent
     *            The parent ui element to present the view in.
     */
    public RefinementDetailsView(Composite parent) {
        super(parent, SWT.FILL);
        setLayout(new FillLayout(SWT.HORIZONTAL));

        SashForm sashForm = new SashForm(this, SWT.BORDER | SWT.FILL);
        sashForm.setSashWidth(1);
        sashForm.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));

        refinementDetailsTreeViewer = new TreeViewer(sashForm, SWT.BORDER);
        refinementDetailsTreeViewer.setLabelProvider(new ViewerLabelProvider());
        refinementDetailsTreeViewer.setContentProvider(new TreeContentProvider());
        refinementDetailsTreeViewer.addDoubleClickListener(new ExpandTreeListener());
        initContextMenu();

        refinementInfoArea = new StyledText(sashForm, SWT.WRAP);
        refinementInfoArea.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        refinementInfoArea.setText(REFINEMENT_INFO_DEFAULT_TEXT);

        sashForm.setWeights(new int[] { 7, 3 });
    }

    /**
     * Enables or disables the control.
     *
     * @param enable
     *            <code>true</code> to enable; <code>false</code> to disable.
     */
    public void setEnabled(boolean enable) {
        refinementDetailsTreeViewer.getControl().setEnabled(enable);
    }

    /**
     * Create contents of the details page.
     *
     * @param parent
     *            The parent ui element to create the view in.
     */
    public void createContents(Composite parent) {
        parent.setEnabled(true);

    }

    /**
     * Trigger the presentation of a specific refinement in the view.
     *
     * @param refinement
     *            The refinement to show.
     */
    public void showRefinement(Refinement refinement) {
        setEnabled(true);
        refinementDetailsTreeViewer.setInput(refinement);
        updateRefinementInfo(refinement);
    }

    private void updateRefinementInfo(Refinement refinement) {

        String headline = "Refinement Infos";
        String linebreak = "\r\n";
        String subHeadlineReason = "Recommendation Reason: ";

        StringBuilder text = new StringBuilder();
        text.append(headline);
        text.append(linebreak);
        text.append(linebreak);
        text.append(subHeadlineReason);
        text.append(linebreak);
        text.append(refinement.getSource());

        refinementInfoArea.setText(text.toString());

        StyleRange styleRange = new StyleRange();
        styleRange.start = 0;
        styleRange.length = headline.length();
        styleRange.fontStyle = SWT.BOLD | SWT.UNDERLINE_DOUBLE;
        refinementInfoArea.setStyleRange(styleRange);

        styleRange = new StyleRange();
        styleRange.start = headline.length() + (2 * linebreak.length());
        styleRange.length = subHeadlineReason.length();
        styleRange.fontStyle = SWT.UNDERLINE_SQUIGGLE;
        refinementInfoArea.setStyleRange(styleRange);
    }

    /**
     * The content provider for the tree providing access to the variation points and their child
     * elements.
     */
    private static class TreeContentProvider implements ITreeContentProvider {

        /** The refinement to display in the tree. */
        private Refinement refinement = null;

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            this.refinement = (Refinement) newInput;
        }<commit_msg>SPLEVO-241 Refinement Browser: Show Refinement Reason when selected Improved detected merge refinement info<commit_after>/*******************************************************************************
 * Copyright (c) 2014
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME>
 *******************************************************************************/
package org.splevo.ui.refinementbrowser;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wb.swt.SWTResourceManager;
import org.splevo.ui.util.UIUtil;
import org.splevo.vpm.refinement.Refinement;
import org.splevo.vpm.variability.Variant;
import org.splevo.vpm.variability.VariationPoint;

import com.google.common.base.Strings;

/**
 * Details view to show information about a currently selected refinement.
 */
public class RefinementDetailsView extends Composite {

    private static final String REFINEMENT_INFO_DEFAULT_TEXT = "Select refinement on the left to review details.";

    /** The internal tree viewer to present the refined variation points. */
    private TreeViewer refinementDetailsTreeViewer = null;

    /** The area to present info about a currently selected refinement in. */
    private StyledText refinementInfoArea = null;

    /**
     * Constructor to create the view.
     *
     * @param parent
     *            The parent ui element to present the view in.
     */
    public RefinementDetailsView(Composite parent) {
        super(parent, SWT.FILL);
        setLayout(new FillLayout(SWT.HORIZONTAL));

        SashForm sashForm = new SashForm(this, SWT.BORDER | SWT.FILL);
        sashForm.setSashWidth(1);
        sashForm.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));

        refinementDetailsTreeViewer = new TreeViewer(sashForm, SWT.BORDER);
        refinementDetailsTreeViewer.setLabelProvider(new ViewerLabelProvider());
        refinementDetailsTreeViewer.setContentProvider(new TreeContentProvider());
        refinementDetailsTreeViewer.addDoubleClickListener(new ExpandTreeListener());
        initContextMenu();

        refinementInfoArea = new StyledText(sashForm, SWT.WRAP);
        refinementInfoArea.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
        refinementInfoArea.setText(REFINEMENT_INFO_DEFAULT_TEXT);

        sashForm.setWeights(new int[] { 7, 3 });
    }

    /**
     * Enables or disables the control.
     *
     * @param enable
     *            <code>true</code> to enable; <code>false</code> to disable.
     */
    public void setEnabled(boolean enable) {
        refinementDetailsTreeViewer.getControl().setEnabled(enable);
    }

    /**
     * Create contents of the details page.
     *
     * @param parent
     *            The parent ui element to create the view in.
     */
    public void createContents(Composite parent) {
        parent.setEnabled(true);

    }

    /**
     * Trigger the presentation of a specific refinement in the view.
     *
     * @param refinement
     *            The refinement to show.
     */
    public void showRefinement(Refinement refinement) {
        setEnabled(true);
        refinementDetailsTreeViewer.setInput(refinement);
        updateRefinementInfo(refinement);
    }

    private void updateRefinementInfo(Refinement refinement) {

        String headline = "Refinement Infos";
        String linebreak = "\r\n";
        String subHeadlineReason = "Source: ";

        StringBuilder text = new StringBuilder();
        text.append(headline);
        text.append(linebreak);
        text.append(linebreak);
        text.append(subHeadlineReason);
        text.append(linebreak);
        text.append(refinement.getSource());

        refinementInfoArea.setText(text.toString());

        StyleRange styleRange = new StyleRange();
        styleRange.start = 0;
        styleRange.length = headline.length();
        styleRange.fontStyle = SWT.BOLD;
        styleRange.underline = true;
        styleRange.underlineStyle = SWT.UNDERLINE_DOUBLE;
        refinementInfoArea.setStyleRange(styleRange);

        styleRange = new StyleRange();
        styleRange.start = headline.length() + (2 * linebreak.length());
        styleRange.length = subHeadlineReason.length();
        styleRange.fontStyle = SWT.BOLD;
        styleRange.underline = true;
        styleRange.underlineStyle = SWT.UNDERLINE_SINGLE;
        refinementInfoArea.setStyleRange(styleRange);
    }

    /**
     * The content provider for the tree providing access to the variation points and their child
     * elements.
     */
    private static class TreeContentProvider implements ITreeContentProvider {

        /** The refinement to display in the tree. */
        private Refinement refinement = null;

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            this.refinement = (Refinement) newInput;
        }
{'fraction_non_alphanumeric': 0.11730566303200844, 'fraction_numerical': 0.0025501231093914877, 'mean_word_length': 3.3243346007604564, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2407868', 'n_tokens_mistral': 3205, 'n_tokens_neox': 3076, 'n_words': 724}