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.admin.agentoperations.pagemode;
20  
21  import java.util.Arrays;
22  
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.security.access.annotation.Secured;
25  import org.springframework.stereotype.Component;
26  
27  import com.hack23.cia.model.internal.application.data.impl.DataAgentOperation;
28  import com.hack23.cia.model.internal.application.data.impl.DataAgentTarget;
29  import com.hack23.cia.service.api.AgentContainer;
30  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
31  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
32  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
33  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
34  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.StartAgentClickListener;
35  import com.vaadin.server.FontAwesome;
36  import com.vaadin.server.Sizeable.Unit;
37  import com.vaadin.ui.Button;
38  import com.vaadin.ui.ComboBox;
39  import com.vaadin.ui.Layout;
40  import com.vaadin.ui.MenuBar;
41  import com.vaadin.ui.Panel;
42  import com.vaadin.ui.VerticalLayout;
43  
44  /**
45   * The Class AgentOperationsOverviewPageModContentFactoryImpl.
46   */
47  @Component
48  public final class AgentOperationsOverviewPageModContentFactoryImpl
49  		extends AbstractAgentOperationsPageModContentFactoryImpl {
50  
51  	/** The Constant NAME. */
52  	public static final String NAME = AdminViews.ADMIN_AGENT_OPERATIONVIEW_NAME;
53  
54  	/** The Constant OPERATION2. */
55  	private static final String OPERATION2 = "/Operation";
56  
57  	/** The Constant TARGET2. */
58  	private static final String TARGET2 = "/Target";
59  
60  	/** The Constant START. */
61  	private static final String START = "Start";
62  
63  	/** The Constant OPERATION. */
64  	private static final String OPERATION = "Operation";
65  
66  	/** The Constant TARGET. */
67  	private static final String TARGET = "Target";
68  
69  	/** The Constant ADMIN_AGENT_OPERATION. */
70  	private static final String ADMIN_AGENT_OPERATION = "Admin Agent Operation";
71  
72  	/** The agent container. */
73  	@Autowired
74  	private AgentContainer agentContainer;
75  
76  	/**
77  	 * Instantiates a new agent operations overview page mod content factory
78  	 * impl.
79  	 */
80  	public AgentOperationsOverviewPageModContentFactoryImpl() {
81  		super();
82  	}
83  
84  	@Override
85  	public boolean matches(final String page, final String parameters) {
86  		return NAME.equals(page);
87  	}
88  
89  	@Secured({ "ROLE_ADMIN" })
90  	@Override
91  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
92  		final VerticalLayout content = createPanelContent();
93  
94  		getMenuItemFactory().createMainPageMenuBar(menuBar);
95  
96  		LabelFactory.createHeader2Label(content,ADMIN_AGENT_OPERATION);
97  
98  		final ComboBox targetSelect = new ComboBox(TARGET, Arrays.asList(DataAgentTarget.values()));
99  		targetSelect.setId(ViewAction.START_AGENT_BUTTON + TARGET2);
100 		content.addComponent(targetSelect);
101 		content.setExpandRatio(targetSelect, ContentRatio.SMALL2);
102 
103 		final ComboBox operationSelect = new ComboBox(OPERATION, Arrays.asList(DataAgentOperation.values()));
104 		operationSelect.setId(ViewAction.START_AGENT_BUTTON + OPERATION2);
105 		content.addComponent(operationSelect);
106 		content.setExpandRatio(operationSelect, ContentRatio.SMALL2);
107 
108 		final Button startAgentButton = new Button(START,
109 				new StartAgentClickListener(targetSelect, operationSelect, agentContainer));
110 		startAgentButton.setId(ViewAction.START_AGENT_BUTTON.name());
111 		startAgentButton.setIcon(FontAwesome.CROSSHAIRS);
112 		content.addComponent(startAgentButton);
113 		content.setExpandRatio(startAgentButton, ContentRatio.SMALL3);
114 
115 		content.setSizeFull();
116 		content.setMargin(false);
117 		content.setSpacing(true);
118 
119 		content.setWidth(100, Unit.PERCENTAGE);
120 		content.setHeight(100, Unit.PERCENTAGE);
121 
122 		return content;
123 	}
124 
125 }