<commit_before>package org.jcryptool.visual.rss.ui;

import java.io.FileNotFoundException;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.jcryptool.visual.rss.Activator;
import org.jcryptool.visual.rss.Descriptions;
import org.jcryptool.visual.rss.algorithm.RssAlgorithmController;
import org.jcryptool.visual.rss.persistence.InvalidSignatureException;
import org.jcryptool.visual.rss.persistence.MessageAndRedactable;
import org.jcryptool.visual.rss.persistence.XMLPersistence;
import org.jcryptool.visual.rss.ui.RssBodyComposite.ActiveRssBodyComposite;
import org.jcryptool.visual.rss.ui.RssVisualDataComposite.DataType;

/**
 * The composite with button, text fields etc. with the function to set the message parts to be encrypted.
 *  
 * @author <NAME>, <NAME>
 */
public class RssSetMessageComposite extends RssRightSideComposite {
    private static int DEFAULT_NUMBER_PARTS = 3;
    private static int MAX_NUMBER_PARTS = 5;
    private static int MIN_NUMBER_PARTS = 2;

    private final Composite inner;
    private final Composite addMessageComposite;
    private final List<Text> addMessageTextList;
    private final List<Label> addMessageLabelList;
    private final Button addMessagePartButton;
    private final Button removeMessagePartButton;
    private final Button confirmMessageButton;
  
    private final Button loadMessageButton;

    public RssSetMessageComposite(RssBodyComposite body, RssAlgorithmController rac, int numberMessageParts,
            List<String> oldMessages) {
        super(body, SWT.NONE);
        prepareGroupView(this, Descriptions.SetMessages);
        prepareAboutComposite();

        inner = new Composite(leftComposite, SWT.NONE);
        inner.setLayout(new GridLayout());

        addMessageComposite = new Composite(inner, SWT.NULL);
        addMessageComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        addMessageComposite.setLayout(new GridLayout(1, false));
        addMessageLabelList = new ArrayList<Label>();
        addMessageTextList = new ArrayList<Text>();
        for (int i = 0; i < numberMessageParts; i++) {
            Label desc = new Label(addMessageComposite, SWT.READ_ONLY);
            desc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            desc.setText(Descriptions.PasteYour + " " + (i + 1) + " " + Descriptions.PartHere);
            addMessageLabelList.add(desc);
            Text msg = new Text(addMessageComposite, SWT.MULTI | SWT.BORDER | SWT.WRAP);
            msg.setLayoutData(new GridData(300, 50));
            msg.setToolTipText(Descriptions.PasteYour + " " + (i + 1) + " " + Descriptions.PartHere);
            if (i < oldMessages.size()) {
                msg.setText(oldMessages.get(i));
            }
            msg.addModifyListener(getAllNotEmptyListener());
            addMessageTextList.add(msg);
        }

        addMessagePartButton = new Button(inner, SWT.PUSH);
        addMessagePartButton.setImage(Activator.getImageDescriptor("icons/outline_add_black_24dp.png").createImage(true));
        addMessagePartButton.setText(Descriptions.AddMessagePart);
        if (numberMessageParts >= MAX_NUMBER_PARTS) {
            addMessagePartButton.setEnabled(false);
        }
        
        addMessagePartButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    body.updateBodyComposite(
                            new RssSetMessageComposite(body, rac, numberMessageParts + 1, getMessages()));
                    body.setActiveRssComposite(ActiveRssBodyComposite.SET_MESSAGE);
                }
            }
        });
        
        removeMessagePartButton = new Button(inner, SWT.PUSH);
        removeMessagePartButton.setImage(Activator.getImageDescriptor("icons/outline_remove_black_24dp.png").createImage(true));
        removeMessagePartButton.setText(Descriptions.RemoveMessagePart);
        if (numberMessageParts <= MIN_NUMBER_PARTS) {
        	removeMessagePartButton.setEnabled(false);
        }
        
        removeMessagePartButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    body.updateBodyComposite(
                            new RssSetMessageComposite(body, rac, numberMessageParts - 1, getMessages()));
                    body.setActiveRssComposite(ActiveRssBodyComposite.SET_MESSAGE);
                }
            }
        });

        confirmMessageButton = new Button(inner, SWT.PUSH);
        confirmMessageButton.setEnabled(false);
        confirmMessageButton.setImage(Activator.getImageDescriptor("icons/outline_navigate_next_black_24dp.png").createImage(true));
        confirmMessageButton.setText(Descriptions.ConfirmMessages);
        
        confirmMessageButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    addMessagePartButton.setEnabled(false);
                    confirmMessageButton.setEnabled(false);
                    disableMessageEditing();
                    rac.newMessage(getMessages());
                    body.lightPath();
                    body.setActiveRssComposite(ActiveRssBodyComposite.SIGN_MESSAGE);
                }
            }<commit_msg>Fixed bug with confirm button of new message step<commit_after>package org.jcryptool.visual.rss.ui;

import java.io.FileNotFoundException;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.jcryptool.visual.rss.Activator;
import org.jcryptool.visual.rss.Descriptions;
import org.jcryptool.visual.rss.algorithm.RssAlgorithmController;
import org.jcryptool.visual.rss.persistence.InvalidSignatureException;
import org.jcryptool.visual.rss.persistence.MessageAndRedactable;
import org.jcryptool.visual.rss.persistence.XMLPersistence;
import org.jcryptool.visual.rss.ui.RssBodyComposite.ActiveRssBodyComposite;
import org.jcryptool.visual.rss.ui.RssVisualDataComposite.DataType;

/**
 * The composite with button, text fields etc. with the function to set the message parts to be encrypted.
 *  
 * @author <NAME>, <NAME>
 */
public class RssSetMessageComposite extends RssRightSideComposite {
    private static int DEFAULT_NUMBER_PARTS = 3;
    private static int MAX_NUMBER_PARTS = 5;
    private static int MIN_NUMBER_PARTS = 2;

    private final Composite inner;
    private final Composite addMessageComposite;
    private final List<Text> addMessageTextList;
    private final List<Label> addMessageLabelList;
    private final Button addMessagePartButton;
    private final Button removeMessagePartButton;
    private final Button confirmMessageButton;
  
    private final Button loadMessageButton;

    public RssSetMessageComposite(RssBodyComposite body, RssAlgorithmController rac, int numberMessageParts,
            List<String> oldMessages) {
        super(body, SWT.NONE);
        prepareGroupView(this, Descriptions.SetMessages);
        prepareAboutComposite();

        inner = new Composite(leftComposite, SWT.NONE);
        inner.setLayout(new GridLayout());

        addMessageComposite = new Composite(inner, SWT.NULL);
        addMessageComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        addMessageComposite.setLayout(new GridLayout(1, false));
        addMessageLabelList = new ArrayList<Label>();
        addMessageTextList = new ArrayList<Text>();
        for (int i = 0; i < numberMessageParts; i++) {
            Label desc = new Label(addMessageComposite, SWT.READ_ONLY);
            desc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            desc.setText(Descriptions.PasteYour + " " + (i + 1) + " " + Descriptions.PartHere);
            addMessageLabelList.add(desc);
            Text msg = new Text(addMessageComposite, SWT.MULTI | SWT.BORDER | SWT.WRAP);
            msg.setLayoutData(new GridData(300, 50));
            msg.setToolTipText(Descriptions.PasteYour + " " + (i + 1) + " " + Descriptions.PartHere);
            if (i < oldMessages.size()) {
                msg.setText(oldMessages.get(i));
            }
            msg.addModifyListener(getAllNotEmptyListener());
            addMessageTextList.add(msg);
        }

        addMessagePartButton = new Button(inner, SWT.PUSH);
        addMessagePartButton.setImage(Activator.getImageDescriptor("icons/outline_add_black_24dp.png").createImage(true));
        addMessagePartButton.setText(Descriptions.AddMessagePart);
        if (numberMessageParts >= MAX_NUMBER_PARTS) {
            addMessagePartButton.setEnabled(false);
        }
        
        addMessagePartButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    body.updateBodyComposite(
                            new RssSetMessageComposite(body, rac, numberMessageParts + 1, getMessages()));
                    body.setActiveRssComposite(ActiveRssBodyComposite.SET_MESSAGE);
                }
            }
        });
        
        removeMessagePartButton = new Button(inner, SWT.PUSH);
        removeMessagePartButton.setImage(Activator.getImageDescriptor("icons/outline_remove_black_24dp.png").createImage(true));
        removeMessagePartButton.setText(Descriptions.RemoveMessagePart);
        if (numberMessageParts <= MIN_NUMBER_PARTS) {
        	removeMessagePartButton.setEnabled(false);
        }
        
        removeMessagePartButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    body.updateBodyComposite(
                            new RssSetMessageComposite(body, rac, numberMessageParts - 1, getMessages()));
                    body.setActiveRssComposite(ActiveRssBodyComposite.SET_MESSAGE);
                }
            }
        });

        confirmMessageButton = new Button(inner, SWT.PUSH);
        confirmMessageButton.setEnabled(addMessageTextList.stream().allMatch(l -> !l.getText().isEmpty()));
        confirmMessageButton.setImage(Activator.getImageDescriptor("icons/outline_navigate_next_black_24dp.png").createImage(true));
        confirmMessageButton.setText(Descriptions.ConfirmMessages);
        
        confirmMessageButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                if (e.type == SWT.Selection) {
                    addMessagePartButton.setEnabled(false);
                    confirmMessageButton.setEnabled(false);
                    disableMessageEditing();
                    rac.newMessage(getMessages());
                    body.lightPath();
                    body.setActiveRssComposite(ActiveRssBodyComposite.SIGN_MESSAGE);
                }
            }
{'fraction_non_alphanumeric': 0.09533485045513654, 'fraction_numerical': 0.003250975292587776, 'mean_word_length': 3.0344262295081967, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, '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': '1894829', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3394, 'n_words': 587}