All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.itcb.common.web.vaadin.component.impl.ContextAnalyserPanel Maven / Gradle / Ivy

Go to download

This module is the common portlet module. It defines the base on which the developements can be done by extending view, edit or help mode.

The newest version!
package net.sf.itcb.common.web.vaadin.component.impl;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;

import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import net.sf.itcb.common.web.vaadin.page.config.ContextHolder;

import org.springframework.oxm.jaxb.Jaxb2Marshaller;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.TextArea;

public class ContextAnalyserPanel extends CssLayout {

	private static final long serialVersionUID = 1L;

	protected TextArea textArea;
	protected Button modifyButton;
	
	public ContextAnalyserPanel(final Jaxb2Marshaller marshaller, final ContextHolder contextHolder) {

		this(marshaller, contextHolder, null, null);
	}
	
	public ContextAnalyserPanel(final Jaxb2Marshaller marshaller, final ContextHolder contextHolder, final Component specificComponentToAdd, final Button.ClickListener specificClickListener) {
		this.setSizeFull();
		StringWriter writer = new StringWriter();
		StreamResult stringResult = new StreamResult(writer);
		
		marshaller.marshal(contextHolder.getNavigationContext(), stringResult);
		textArea= new TextArea("Flow content", writer.toString());
		textArea.setSizeFull();
		textArea.addStyleName("ContextAnalyserPanelTextArea");
		addComponent(textArea);
		
		if(specificComponentToAdd != null) {
			addComponent(specificComponentToAdd);
		}
		
		modifyButton = new Button("Modify context", new Button.ClickListener() {
			
			private static final long serialVersionUID = 1L;

			@Override
			public void buttonClick(ClickEvent event) {
				contextHolder.setNavigationContext(marshaller.unmarshal(new StreamSource(new ByteArrayInputStream(textArea.getValue().toString().getBytes()) )));
				if(specificClickListener != null) {
					specificClickListener.buttonClick(event);
				}
			}
		});
		modifyButton.addStyleName("ContextAnalyserPanelModifyButton");
		addComponent(modifyButton);
	}
	
	public Button getModifyButton() {
		return modifyButton;
	}
	
	public TextArea getTextArea() {
		return textArea;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy