<commit_before>/**
 * Copyright 2015 <NAME>, <NAME>, <NAME>
 * 
 * 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 com.salsaw.msalsa;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.server.Page;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.Upload.SucceededEvent;
import com.vaadin.ui.Upload.SucceededListener;

public class HomePageView extends CustomComponent implements IHomePageView {

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	@AutoGenerated
	private GridLayout mainLayout;
	@AutoGenerated
	private Upload uploadInput;
	@AutoGenerated
	private Label titile;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public HomePageView() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here		
		
		// Implement both receiver that saves upload in a file and
		// listener for successful upload
		class AligmentUploader implements Receiver, SucceededListener {
		    public File file;
		    
		    public OutputStream receiveUpload(String filename,
		                                      String mimeType) {
		        // Create upload stream
		        FileOutputStream fos = null; // Stream to write to
		        try {
		            // Open the file for writing.
		            file = new File(filename);
		            fos = new FileOutputStream(file);
		        } catch (final java.io.FileNotFoundException e) {
		            new Notification("Could not open file<br/>",
		                             e.getMessage(),
		                             Notification.Type.ERROR_MESSAGE)
		                .show(Page.getCurrent());
		            return null;
		        }
		        return fos; // Return the output stream to write to
		    }

		    public void uploadSucceeded(SucceededEvent event) {
		        // TODO - start with align
		    	
		    	for (IHomePageListener listener: listeners){
		            listener.buttonClick(file);
		    	}
		    }
		};
		
		AligmentUploader receiver = new AligmentUploader();
		
		uploadInput.setReceiver(receiver);
		uploadInput.addSucceededListener(receiver);

	}

	/* Only the presenter registers one listener... */
    List<IHomePageListener> listeners =
            new ArrayList<IHomePageListener>();

    @Override
    public void addListener(IHomePageListener listener) {
        listeners.add(listener);
    }

	@AutoGenerated
	private GridLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new GridLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		mainLayout.setRows(2);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// titile
		titile = new Label();
		titile.setImmediate(false);
		titile.setWidth("-1px");
		titile.setHeight("-1px");
		titile.setValue("M-SALSA");
		mainLayout.addComponent(titile, 0, 0);
		mainLayout.setComponentAlignment(titile, new Alignment(48));
		
		// uploadInput
		uploadInput = new Upload();
		uploadInput.setCaption("Upload align input");
		uploadInput.setImmediate(false);
		uploadInput.setWidth("-1px");
		uploadInput.setHeight("-1px");
		mainLayout.addComponent(uploadInput, 0, 1);
		mainLayout.setComponentAlignment(uploadInput, new Alignment(48));
		
		return mainLayout;
	}<commit_msg>[ENH] Add to home the Salsa parameters toogle form<commit_after>/**
 * Copyright 2015 <NAME>, <NAME>, <NAME>
 * 
 * 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 com.salsaw.msalsa;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import com.salsaw.msalsa.cli.SalsaParameters;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.util.BeanItem;
import com.vaadin.server.Page;
import com.vaadin.ui.Accordion;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.Upload.SucceededEvent;
import com.vaadin.ui.Upload.SucceededListener;

public class HomePageView extends CustomComponent implements IHomePageView {

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@AutoGenerated
	private GridLayout mainLayout;	
	@AutoGenerated
	private Upload uploadInput;
	@AutoGenerated
	private Label titile;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public HomePageView() {
		buildMainLayout();
		
		// Create form with salsa parameters
		SalsaParameters salsaParameters = new SalsaParameters();
		BeanItem<SalsaParameters> salsaParametersBeanItem = new BeanItem<SalsaParameters>(salsaParameters);		
		SalsaParametersForm salsaParametersForm = new SalsaParametersForm(salsaParametersBeanItem);		
		
		Button toogleSalsaParametersButton = new Button("Show/Hide M-SALSA Parameters");
		toogleSalsaParametersButton.addClickListener(new Button.ClickListener() {
		    /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public void buttonClick(ClickEvent event) {
				salsaParametersForm.setVisible(!salsaParametersForm.isVisible());
		    }
		});
		
		toogleSalsaParametersButton.setWidth("-1px");
		toogleSalsaParametersButton.setHeight("-1px");			
		mainLayout.addComponent(toogleSalsaParametersButton);
		mainLayout.setComponentAlignment(toogleSalsaParametersButton, new Alignment(48));
		
		salsaParametersForm.setWidth("-1px");
		salsaParametersForm.setHeight("-1px");
		mainLayout.addComponent(salsaParametersForm);
		mainLayout.setComponentAlignment(salsaParametersForm, new Alignment(48));
		
		setCompositionRoot(mainLayout);

		// TODO add user code here		
		
		// Implement both receiver that saves upload in a file and
		// listener for successful upload
		class AligmentUploader implements Receiver, SucceededListener {
		    /**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			
			public File file;
		    
		    public OutputStream receiveUpload(String filename,
		                                      String mimeType) {
		        // Create upload stream
		        FileOutputStream fos = null; // Stream to write to
		        try {
		            // Open the file for writing.
		            file = new File(filename);
		            fos = new FileOutputStream(file);
		        } catch (final java.io.FileNotFoundException e) {
		            new Notification("Could not open file<br/>",
		                             e.getMessage(),
		                             Notification.Type.ERROR_MESSAGE)
		                .show(Page.getCurrent());
		            return null;
		        }
		        return fos; // Return the output stream to write to
		    }

		    public void uploadSucceeded(SucceededEvent event) {
		        // TODO - start with align
		    	
		    	for (IHomePageListener listener: listeners){
		            listener.buttonClick(file);
		    	}
		    }
		};
		
		AligmentUploader receiver = new AligmentUploader();
		
		uploadInput.setReceiver(receiver);
		uploadInput.addSucceededListener(receiver);

	}

	/* Only the presenter registers one listener... */
    List<IHomePageListener> listeners =
            new ArrayList<IHomePageListener>();

    @Override
    public void addListener(IHomePageListener listener) {
        listeners.add(listener);
    }

	@AutoGenerated
	private GridLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new GridLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		mainLayout.setRows(4);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// titile
		titile = new Label();
		titile.setImmediate(false);
		titile.setWidth("-1px");
		titile.setHeight("-1px");
		titile.setValue("M-SALSA");
		mainLayout.addComponent(titile, 0, 0);
		mainLayout.setComponentAlignment(titile, new Alignment(48));
		
		// uploadInput
		uploadInput = new Upload();
		uploadInput.setCaption("Upload align input");
		uploadInput.setImmediate(false);
		uploadInput.setWidth("-1px");
		uploadInput.setHeight("-1px");
		mainLayout.addComponent(uploadInput, 0, 1);
		mainLayout.setComponentAlignment(uploadInput, new Alignment(48));
				
		return mainLayout;
	}
{'fraction_non_alphanumeric': 0.09996125532739249, 'fraction_numerical': 0.008620689655172414, 'mean_word_length': 3.3364132717345654, 'pattern_counts': {'":': 12, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7658147', 'n_tokens_mistral': 3273, 'n_tokens_neox': 2844, 'n_words': 752}