<commit_before>
package de.uni_hildesheim.sse.qmApp.editors;

import java.util.HashMap;

import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
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.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolTip;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;

import de.uni_hildesheim.sse.easy_producer.instantiator.Bundle;
import de.uni_hildesheim.sse.model.confModel.Configuration;
import de.uni_hildesheim.sse.model.confModel.IDecisionVariable;
import de.uni_hildesheim.sse.model.management.VarModel;
import de.uni_hildesheim.sse.model.varModel.Project;
import de.uni_hildesheim.sse.qmApp.images.IconManager;
import de.uni_hildesheim.sse.qmApp.model.Reasoning;
import de.uni_hildesheim.sse.utils.logger.EASyLoggerFactory;
import de.uni_hildesheim.sse.utils.modelManagement.IModelListener;

/**
 * This class is responsible for providing Editors for given elements which are shown in the 
 * {@link de.uni_hildesheim.sse.qmApp.treeView.ConfigurableElementsView}.
 * Requires {@link DecisionVariableEditorInput} as input.
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class VariableEditor extends AbstractVarModelEditor implements IModelListener<Project> {

    public static final String ID = "de.uni_hildesheim.sse.qmApp.VariableEditor";
    
    private static HashMap<Control, ControlDecoration> flawedControls = new HashMap<Control, ControlDecoration>();
    
    private static final String COMPOSITE_STRING = "class org.eclipse.swt.widgets.Composite";
    private static final int PREFERRED_WIDTH = 400;
    
    private DecisionVariableEditorInput input;
    private IDecisionVariable var;
    
    
    @Override
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        super.init(site, input);
        if (input instanceof DecisionVariableEditorInput) {
            this.input = (DecisionVariableEditorInput) input;
            var = this.input.getVariable();
            if (null != var) {
                VarModel.INSTANCE.events().addModelListener(var.getConfiguration().getProject(), this);
                setConfiguration(var.getConfiguration());
            }
        } else {
            throw new PartInitException("wrong editor input");
        }
    }
    
    @Override
    public void dispose() {
        if (null != var) {
            VarModel.INSTANCE.events().removeModelListener(var.getConfiguration().getProject(), this);
        }
        for (Control key: flawedControls.keySet()) {
            ControlDecoration decoration = flawedControls.get(key);
            decoration.hide();
            decoration.dispose();
        }
        flawedControls.clear();
        super.dispose();
    }
    
    /**
     * Called by {@link #createPartControl(Composite)}.
     * 
     * @param parent the parent composite to add elements to (here, a two-colum grid layout composite)
     */
    protected void createAdditionalControls(Composite parent) {
    }
    
    @Override
    public final void createPartControl(Composite parent) {
    
        ScrolledComposite scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        scroll.setExpandHorizontal(false);
        
        final Composite inner = new Composite(scroll, SWT.NONE);
        scroll.setContent(inner);
        super.createPartControl(inner);
        
        //GridLayout for the editor with two columns
        GridLayout layout = new GridLayout(2, false);
        
        //Set the margin thus the textfields wont fill completely
        layout.marginRight = 80;
        inner.setLayout(layout);
        
        if (null != var) { // may not be there, e.g., in case of the wrong model
            createEditor(var);
        }
        setPartName(input.getName());
        ImageDescriptor iDesc = input.getImageDescriptor();
        if (null != iDesc) {
            setTitleImage(iDesc.createImage());
        }

        collectTextFields(inner);
        applyGridData(inner);
        considerReasoningResults(inner);
        Point p = inner.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        p.x = Math.max(p.x, PREFERRED_WIDTH);
        inner.setSize(p);
        inner.layout();
        
//        inner.addKeyListener(new KeyAdapter() {
//            @Override
//            public void keyPressed( KeyEvent exc ) {
//         
//                if (exc.keyCode == 'a'
//                        && ( exc.stateMask & SWT.MODIFIER_MASK ) == SWT.CTRL ) {
//                    
//                    collectTextFields(inner);
//                    applyGridData(inner);
//                    considerReasoningResults(inner);
//                }<commit_msg>bringing the upload button back (for testing)<commit_after>
package de.uni_hildesheim.sse.qmApp.editors;

import java.util.HashMap;

import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
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.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolTip;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;

import de.uni_hildesheim.sse.easy_producer.instantiator.Bundle;
import de.uni_hildesheim.sse.model.confModel.Configuration;
import de.uni_hildesheim.sse.model.confModel.IDecisionVariable;
import de.uni_hildesheim.sse.model.management.VarModel;
import de.uni_hildesheim.sse.model.varModel.Project;
import de.uni_hildesheim.sse.qmApp.images.IconManager;
import de.uni_hildesheim.sse.qmApp.model.Reasoning;
import de.uni_hildesheim.sse.utils.logger.EASyLoggerFactory;
import de.uni_hildesheim.sse.utils.modelManagement.IModelListener;

/**
 * This class is responsible for providing Editors for given elements which are shown in the 
 * {@link de.uni_hildesheim.sse.qmApp.treeView.ConfigurableElementsView}.
 * Requires {@link DecisionVariableEditorInput} as input.
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class VariableEditor extends AbstractVarModelEditor implements IModelListener<Project> {

    public static final String ID = "de.uni_hildesheim.sse.qmApp.VariableEditor";
    
    private static HashMap<Control, ControlDecoration> flawedControls = new HashMap<Control, ControlDecoration>();
    
    private static final String COMPOSITE_STRING = "class org.eclipse.swt.widgets.Composite";
    private static final int PREFERRED_WIDTH = 400;
    
    private DecisionVariableEditorInput input;
    private IDecisionVariable var;
    
    
    @Override
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        super.init(site, input);
        if (input instanceof DecisionVariableEditorInput) {
            this.input = (DecisionVariableEditorInput) input;
            var = this.input.getVariable();
            if (null != var) {
                VarModel.INSTANCE.events().addModelListener(var.getConfiguration().getProject(), this);
                setConfiguration(var.getConfiguration());
            }
        } else {
            throw new PartInitException("wrong editor input");
        }
    }
    
    @Override
    public void dispose() {
        if (null != var) {
            VarModel.INSTANCE.events().removeModelListener(var.getConfiguration().getProject(), this);
        }
        for (Control key: flawedControls.keySet()) {
            ControlDecoration decoration = flawedControls.get(key);
            decoration.hide();
            decoration.dispose();
        }
        flawedControls.clear();
        super.dispose();
    }
    
    /**
     * Called by {@link #createPartControl(Composite)}.
     * 
     * @param parent the parent composite to add elements to (here, a two-colum grid layout composite)
     */
    protected void createAdditionalControls(Composite parent) {
    }
    
    @Override
    public final void createPartControl(Composite parent) {
    
        ScrolledComposite scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        scroll.setExpandHorizontal(false);
        
        final Composite inner = new Composite(scroll, SWT.NONE);
        scroll.setContent(inner);
        super.createPartControl(inner);
        
        //GridLayout for the editor with two columns
        GridLayout layout = new GridLayout(2, false);
        
        //Set the margin thus the textfields wont fill completely
        layout.marginRight = 80;
        inner.setLayout(layout);
        
        if (null != var) { // may not be there, e.g., in case of the wrong model
            createEditor(var);
        }
        setPartName(input.getName());
        ImageDescriptor iDesc = input.getImageDescriptor();
        if (null != iDesc) {
            setTitleImage(iDesc.createImage());
        }

        collectTextFields(inner);
        applyGridData(inner);
        considerReasoningResults(inner);
        Point p = inner.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        p.x = Math.max(p.x, PREFERRED_WIDTH);
        inner.setSize(p);
        inner.layout();
        
        createAdditionalControls(inner);
        
//        inner.addKeyListener(new KeyAdapter() {
//            @Override
//            public void keyPressed( KeyEvent exc ) {
//         
//                if (exc.keyCode == 'a'
//                        && ( exc.stateMask & SWT.MODIFIER_MASK ) == SWT.CTRL ) {
//                    
//                    collectTextFields(inner);
//                    applyGridData(inner);
//                    considerReasoningResults(inner);
//                }
{'fraction_non_alphanumeric': 0.10260524825372852, 'fraction_numerical': 0.0011327166320558807, 'mean_word_length': 2.7664415215072875, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6349609', 'n_tokens_mistral': 3116, 'n_tokens_neox': 3024, 'n_words': 611}