1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 package org.kuali.rice.krad.uif.view;
17
18 import org.kuali.rice.krad.uif.component.Component;
19 import org.kuali.rice.krad.uif.element.Message;
20 import org.kuali.rice.krad.uif.util.ComponentFactory;
21
22 import java.util.List;
23
24 /**
25 * View that presents a message to the user (for example an application error message)
26 *
27 * @author Kuali Rice Team (rice.collab@kuali.org)
28 */
29 public class MessageView extends FormView {
30 private static final long serialVersionUID = 5578210247236389466L;
31
32 private Message message;
33
34 public MessageView() {
35 super();
36
37 super.setSinglePageView(true);
38 }
39
40 /**
41 * The following initialization is performed:
42 *
43 * <ul>
44 * <li>Set the message text onto the message component and add to the page items</li>
45 * </ul>
46 *
47 * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(View, java.lang.Object)
48 */
49 public void performInitialization(View view, Object model) {
50 super.performInitialization(view, model);
51
52 List<Component> newItems = (List<Component>) getPage().getItems();
53 newItems.add(message);
54 getPage().setItems(newItems);
55 }
56
57 /**
58 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
59 */
60 @Override
61 public List<Component> getComponentsForLifecycle() {
62 List<Component> components = super.getComponentsForLifecycle();
63
64 components.add(message);
65
66 return components;
67 }
68
69 /**
70 * Message component that will be used to display the message (used for styling and so on)
71 *
72 * @return Message component instance
73 */
74 public Message getMessage() {
75 return message;
76 }
77
78 /**
79 * Setter for the message component
80 *
81 * @param message
82 */
83 public void setMessage(Message message) {
84 this.message = message;
85 }
86
87 /**
88 * Helper method for setting the message text
89 *
90 * @param messageText text to use for the message
91 */
92 public void setMessageText(String messageText) {
93 if (this.message == null) {
94 this.message = ComponentFactory.getMessage();
95 }
96
97 this.message.setMessageText(messageText);
98 }
99
100 /**
101 * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
102 */
103 @Override
104 protected <T> void copyProperties(T component) {
105 super.copyProperties(component);
106 MessageView messageViewCopy = (MessageView) component;
107
108 if(this.message != null) {
109 messageViewCopy.setMessage((Message)this.getMessage().copy());
110 }
111 }
112 }