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  import org.springframework.beans.factory.annotation.Autowired;
24  
25  import com.hack23.cia.model.internal.application.data.impl.DataAgentOperation;
26  import com.hack23.cia.model.internal.application.data.impl.DataAgentTarget;
27  import com.hack23.cia.model.internal.application.data.impl.DataAgentWorkOrder;
28  import com.hack23.cia.service.api.AgentContainer;
29  import com.vaadin.ui.Button.ClickEvent;
30  import com.vaadin.ui.Button.ClickListener;
31  import com.vaadin.ui.ComboBox;
32  
33  /**
34   * The Class StartAgentClickListener.
35   */
36  public final class StartAgentClickListener implements ClickListener {
37  
38  	/** The Constant serialVersionUID. */
39  	private static final long serialVersionUID = 1L;
40  
41  	/** The Constant LOG_MSG_EXECUTE_WORKORDER. */
42  	private static final String LOG_MSG_EXECUTE_WORKORDER = "Execute workorder:{}";
43  
44  	/** The Constant LOGGER. */
45  	private static final Logger LOGGER = LoggerFactory.getLogger(StartAgentClickListener.class);
46  
47  	/** The target select. */
48  	private final ComboBox targetSelect;
49  
50  	/** The operation select. */
51  	private final ComboBox operationSelect;
52  
53  	/** The agent container. */
54  	@Autowired
55  	private final transient AgentContainer agentContainer;
56  
57  	/**
58  	 * Instantiates a new start agent click listener.
59  	 *
60  	 * @param targetSelect
61  	 *            the target select
62  	 * @param operationSelect
63  	 *            the operation select
64  	 * @param agentContainer
65  	 *            the agent container
66  	 */
67  	public StartAgentClickListener(final ComboBox targetSelect, final ComboBox operationSelect, final AgentContainer agentContainer) {
68  		super();
69  		this.targetSelect = targetSelect;
70  		this.operationSelect = operationSelect;
71  		this.agentContainer = agentContainer;
72  	}
73  
74  	@Override
75  	public void buttonClick(final ClickEvent event) {
76  		if (targetSelect.getValue() != null && operationSelect.getValue() != null) {
77  			final DataAgentWorkOrder dataAgentWorkOrder = new DataAgentWorkOrder();
78  			final DataAgentTarget target = DataAgentTarget.valueOf(targetSelect.getValue().toString());
79  			dataAgentWorkOrder.setTarget(target);
80  			dataAgentWorkOrder.setOperation(DataAgentOperation.valueOf(operationSelect.getValue().toString()));
81  			LOGGER.info(LOG_MSG_EXECUTE_WORKORDER, dataAgentWorkOrder);
82  			agentContainer.execute(dataAgentWorkOrder);
83  		}
84  	}
85  
86  
87  }