<commit_before>package com.thingtrack.konekti.view.web.form.field;

import java.io.Serializable;

import org.vaadin.addon.customfield.CustomField;

import com.thingtrack.konekti.view.addon.ui.UploadViewForm;
import com.vaadin.data.Property;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;

@SuppressWarnings("serial")
public class FileField extends CustomField {
	
	private VerticalLayout mainLayout;
	private Button btnAttach;
	
	private byte[] file;
	private String fileName;
	
	// navigator button listeners
	private AttachmentChangeListener listenerChangeAttachment = null;
		
	public FileField() {
		this(null);
		
	}
	
	@Override
    public void setIcon(Resource icon) {
		btnAttach.setIcon(new ThemeResource("../konekti/images/icons/paper-clip.png"));
		
        requestRepaint();
    }
    
	public FileField(byte[] file) {
		buildMainLayout();
		setCompositionRoot(mainLayout);
		
		// TODO add user code here
		this.file = file;
		
		btnAttach.addListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				final UploadViewForm uploadViewForm = new UploadViewForm(FileField.this.file);
				
				//uploadViewForm.setWidth("300px");
				uploadViewForm.setWidth("-1px");
				uploadViewForm.setHeight("-1px");
				uploadViewForm.setClosable(false);
				uploadViewForm.addListener(new CloseListener() {				
					@Override
					public void windowClose(CloseEvent event) {						
						FileField.this.file = uploadViewForm.getFile();
						fileName = uploadViewForm.getFileName();
							
						if (uploadViewForm.getFile() != null) 
							btnAttach.setIcon(new ThemeResource("../konekti/images/icons/servicedesigner-module/tick.png"));						
						else 							
							btnAttach.setIcon(null);																				
												
						if (listenerChangeAttachment != null)
							listenerChangeAttachment.attachmentChange(new AttachmentChangeEvent(event.getComponent(), FileField.this.file , fileName));
						
						//setValue(file);<commit_msg>correct icon filebutton bug<commit_after>package com.thingtrack.konekti.view.web.form.field;

import java.io.Serializable;

import org.vaadin.addon.customfield.CustomField;

import com.thingtrack.konekti.view.addon.ui.UploadViewForm;
import com.vaadin.data.Property;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;

@SuppressWarnings("serial")
public class FileField extends CustomField {
	
	private VerticalLayout mainLayout;
	private Button btnAttach;
	
	private byte[] file;
	private String fileName;
	
	// navigator button listeners
	private AttachmentChangeListener listenerChangeAttachment = null;
		
	public FileField() {
		this(null);
		
	}
	
	@Override
    public void setIcon(Resource icon) {
		btnAttach.setIcon(new ThemeResource("../konekti/images/icons/paper-clip.png"));
		
        requestRepaint();
    }
    
	public FileField(byte[] file) {
		buildMainLayout();
		setCompositionRoot(mainLayout);
		
		// TODO add user code here
		this.file = file;
		
		btnAttach.addListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				final UploadViewForm uploadViewForm = new UploadViewForm(FileField.this.file);
				
				//uploadViewForm.setWidth("300px");
				uploadViewForm.setWidth("-1px");
				uploadViewForm.setHeight("-1px");
				uploadViewForm.setClosable(false);
				uploadViewForm.addListener(new CloseListener() {				
					@Override
					public void windowClose(CloseEvent event) {						
						FileField.this.file = uploadViewForm.getFile();
						fileName = uploadViewForm.getFileName();
							
						if (uploadViewForm.getFile() != null) 
							btnAttach.setIcon(new ThemeResource("../konekti/images/icons/servicedesigner-module/tick.png"));						
						else 							
							//btnAttach.setIcon(null);
							btnAttach.setIcon(new ThemeResource("../konekti/images/icons/paper-clip.png"));
												
						if (listenerChangeAttachment != null)
							listenerChangeAttachment.attachmentChange(new AttachmentChangeEvent(event.getComponent(), FileField.this.file , fileName));
						
						//setValue(file);
{'fraction_non_alphanumeric': 0.10893433799784714, 'fraction_numerical': 0.002152852529601722, 'mean_word_length': 3.740816326530612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3962112', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1389, 'n_words': 240}