View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.pageclicklistener;
20  
21  import org.slf4j.Logger;
22  import org.slf4j.LoggerFactory;
23  
24  import com.vaadin.data.fieldgroup.BeanFieldGroup;
25  import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
26  import com.vaadin.ui.Button.ClickEvent;
27  import com.vaadin.ui.Button.ClickListener;
28  import com.vaadin.ui.Notification;
29  
30  /**
31   * The Class CommitFormWrapperClickListener.
32   */
33  public final class CommitFormWrapperClickListener implements ClickListener {
34  
35  	/** The Constant FORM_ERROR. */
36  	private static final String FORM_ERROR = "Form Error";
37  
38  	/** The Constant serialVersionUID. */
39  	private static final long serialVersionUID = 1L;
40  
41  	/** The Constant LOGGER. */
42  	private static final Logger LOGGER = LoggerFactory.getLogger(CommitFormWrapperClickListener.class);
43  
44  	/** The field group. */
45  	private final BeanFieldGroup<?> fieldGroup;
46  
47  	/** The button listener. */
48  	private final ClickListener buttonListener;
49  
50  	/**
51  	 * Instantiates a new commit form wrapper click listener.
52  	 *
53  	 * @param fieldGroup
54  	 *            the field group
55  	 * @param buttonListener
56  	 *            the button listener
57  	 */
58  	public CommitFormWrapperClickListener(final BeanFieldGroup<?> fieldGroup, final ClickListener buttonListener) {
59  		this.fieldGroup = fieldGroup;
60  		this.buttonListener = buttonListener;
61  	}
62  
63  	@Override
64  	public void buttonClick(final ClickEvent event) {
65  		try {
66  			fieldGroup.commit();
67  		} catch (final CommitException e) {
68  			Notification.show(FORM_ERROR,
69  	                  e.getMessage(),
70  	                  Notification.Type.WARNING_MESSAGE);
71  			LOGGER.warn(FORM_ERROR,e);
72  		}
73  		buttonListener.buttonClick(event);
74  	}
75  }