
nz.co.senanque.bundle1.Layout Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c)2011 Prometheus Consulting
*
* 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 nz.co.senanque.bundle1;
import nz.co.senanque.perspectiveslibrary.Blackboard;
import nz.co.senanque.perspectiveslibrary.BlackboardListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
/**
* This is a sub-application that maintains user preferences for the current user.
* There is no database (this is demo code) so changes are not persisted anywhere
* but they do operate for the current session.
*
* @author Roger Parkinson
*
*/
public class Layout extends VerticalLayout {
private static Logger logger = LoggerFactory.getLogger(Layout.class);
private Blackboard m_blackboard;
private VerticalLayout mainLayout;
private TextField m_phone;
private TextField m_postcode;
private TextField m_address;
private TextField m_name;
private static final long serialVersionUID = -1L;
/**
* 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.
* @param messageSourceAccessor
*/
public Layout(MessageSourceAccessor messageSourceAccessor) {
buildMainLayout(messageSourceAccessor);
addComponent(mainLayout);
m_name.addTextChangeListener(new TextChangeListener(){
private static final long serialVersionUID = -1L;
public void textChange(TextChangeEvent event) {
m_blackboard.publish("userName", event.getText());
}});
}
private VerticalLayout buildMainLayout(MessageSourceAccessor messageSourceAccessor) {
// common part: create layout
mainLayout = new VerticalLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);
// top-level component properties
setWidth("100.0%");
setHeight("100.0%");
// m_name
m_name = new TextField();
m_name.setCaption(messageSourceAccessor.getMessage("name"));
m_name.setImmediate(false);
m_name.setWidth("-1px");
m_name.setHeight("-1px");
mainLayout.addComponent(m_name);
// m_address
m_address = new TextField();
m_address.setCaption(messageSourceAccessor.getMessage("address"));
m_address.setImmediate(false);
m_address.setWidth("-1px");
m_address.setHeight("-1px");
mainLayout.addComponent(m_address);
// m_postcode
m_postcode = new TextField();
m_postcode.setCaption(messageSourceAccessor.getMessage("postcode"));
m_postcode.setImmediate(false);
m_postcode.setWidth("-1px");
m_postcode.setHeight("-1px");
mainLayout.addComponent(m_postcode);
// m_phone
m_phone = new TextField();
m_phone.setCaption(messageSourceAccessor.getMessage("phone"));
m_phone.setImmediate(false);
m_phone.setWidth("-1px");
m_phone.setHeight("-1px");
mainLayout.addComponent(m_phone);
return mainLayout;
}
public void save() {
logger.debug("");
}
public void close() {
logger.debug("");
}
public Blackboard getBlackboard() {
return m_blackboard;
}
public void setBlackboard(Blackboard blackboard) {
m_blackboard = blackboard;
m_blackboard.add(new BlackboardListener(){
public void valueChanged(Object value) {
m_name.setValue(value.toString());
}
public String getName() {
return "userName";
}});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy