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.system.pagemode;
20  
21  import java.util.Arrays;
22  
23  import org.springframework.security.access.annotation.Secured;
24  import org.springframework.stereotype.Component;
25  import org.springframework.web.context.request.RequestContextHolder;
26  
27  import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration;
28  import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration_;
29  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
30  import com.hack23.cia.service.api.DataContainer;
31  import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest;
32  import com.hack23.cia.web.impl.ui.application.action.ViewAction;
33  import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
34  import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentSize;
35  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
36  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
37  import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.UpdateApplicationConfigurationClickListener;
38  import com.vaadin.data.util.BeanItem;
39  import com.vaadin.data.util.BeanItemContainer;
40  import com.vaadin.ui.Button.ClickListener;
41  import com.vaadin.ui.FormLayout;
42  import com.vaadin.ui.HorizontalLayout;
43  import com.vaadin.ui.Layout;
44  import com.vaadin.ui.MenuBar;
45  import com.vaadin.ui.Panel;
46  import com.vaadin.ui.VerticalLayout;
47  
48  /**
49   * The Class AdminApplicationConfigurationPageModContentFactoryImpl.
50   */
51  @Component
52  public final class AdminApplicationConfigurationPageModContentFactoryImpl
53  		extends AbstractAdminSystemPageModContentFactoryImpl {
54  
55  	/** The Constant ADMIN_APPLICATION_CONFIGURATION. */
56  	private static final String ADMIN_APPLICATION_CONFIGURATION = "Admin Application Configuration";
57  
58  	/** The Constant NAME. */
59  	public static final String NAME = AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME;
60  
61  	/**
62  	 * Instantiates a new admin application configuration page mod content
63  	 * factory impl.
64  	 */
65  	public AdminApplicationConfigurationPageModContentFactoryImpl() {
66  		super();
67  	}
68  
69  	@Override
70  	public boolean matches(final String page, final String parameters) {
71  		return NAME.equals(page);
72  	}
73  
74  	@Secured({ "ROLE_ADMIN" })
75  	@Override
76  	public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
77  		final VerticalLayout content = createPanelContent();
78  
79  		final String pageId = getPageId(parameters);
80  		final int pageNr= getPageNr(parameters);
81  
82  
83  		getMenuItemFactory().createMainPageMenuBar(menuBar);
84  
85  		LabelFactory.createHeader2Label(content,ADMIN_APPLICATION_CONFIGURATION);
86  
87  		final DataContainer<ApplicationConfiguration, Long> dataContainer = getApplicationManager()
88  				.getDataContainer(ApplicationConfiguration.class);
89  
90  		final BeanItemContainer<ApplicationConfiguration> politicianDocumentDataSource = new BeanItemContainer<>(
91  				ApplicationConfiguration.class,
92  		dataContainer.getPageOrderBy(pageNr,DEFAULT_RESULTS_PER_PAGE, ApplicationConfiguration_.configurationGroup));
93  
94  		createPagingControls(content,NAME,pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
95  
96  		getGridFactory().createBasicBeanItemGrid(content,
97  				politicianDocumentDataSource,
98  				"ApplicationConfiguration",
99  				new String[] { "hjid", "configurationGroup", "component", "componentTitle", "configTitle", "configDescription",
100 						 "componentDescription", "propertyId", "propertyValue" }, new String[] { "hjid", "modelObjectId", "modelObjectVersion", "createdDate", "updatedDate","propertyId" ,"componentDescription", "componentTitle"},
101 				new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME, "hjid"), null, null);
102 
103 		if (pageId != null && !pageId.isEmpty()) {
104 
105 			final ApplicationConfiguration applicationConfiguration = dataContainer.load(Long.valueOf(pageId));
106 
107 			if (applicationConfiguration != null) {
108 
109 				final VerticalLayout leftLayout = new VerticalLayout();
110 				leftLayout.setSizeFull();
111 				final VerticalLayout rightLayout = new VerticalLayout();
112 				rightLayout.setSizeFull();
113 				final HorizontalLayout horizontalLayout = new HorizontalLayout();
114 				horizontalLayout.setWidth(ContentSize.FULL_SIZE);
115 				content.addComponent(horizontalLayout);
116 				horizontalLayout.addComponent(leftLayout);
117 				horizontalLayout.addComponent(rightLayout);
118 
119 
120 				getFormFactory().addFormPanelTextFields(leftLayout, new BeanItem<>(applicationConfiguration),
121 						ApplicationConfiguration.class,
122 						Arrays.asList(new String[] { "configurationGroup", "component","configTitle" ,"configDescription",
123 								"propertyValue", "createdDate",
124 								"updatedDate" }));
125 
126 				final UpdateApplicationConfigurationRequest request = new UpdateApplicationConfigurationRequest();
127 				request.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
128 				request.setApplicationConfigurationId(applicationConfiguration.getHjid());
129 
130 				request.setConfigTitle(applicationConfiguration.getConfigTitle());
131 				request.setConfigDescription(applicationConfiguration.getConfigDescription());
132 
133 				request.setComponentTitle(applicationConfiguration.getConfigTitle());
134 				request.setComponentDescription(applicationConfiguration.getComponentDescription());
135 
136 				request.setPropertyValue(applicationConfiguration.getPropertyValue());
137 
138 				final ClickListener buttonListener = new UpdateApplicationConfigurationClickListener(request);
139 
140 				final Panel updateFormPanel = new Panel();
141 				updateFormPanel.setSizeFull();
142 
143 				rightLayout.addComponent(updateFormPanel);
144 
145 				final FormLayout updateFormContent = new FormLayout();
146 				updateFormPanel.setContent(updateFormContent);
147 
148 				getFormFactory().addRequestInputFormFields(updateFormContent, new BeanItem<>(request),
149 						UpdateApplicationConfigurationRequest.class, Arrays.asList(new String[] { "configTitle",
150 								"configDescription", "componentTitle", "componentDescription", "propertyValue" }),
151 						"Update Configuration", buttonListener);
152 
153 			}
154 		}
155 
156 		getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_CONFIGURATION_VIEW,
157 				ApplicationEventGroup.ADMIN, NAME, null, pageId);
158 
159 		return content;
160 	}
161 
162 }