This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
/
UIApplication.java
145 lines (123 loc) · 4.9 KB
/
UIApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Copyright (C) 2009 eXo Platform SAS.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.exoplatform.webui.core;
import java.io.Writer;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.web.application.AbstractApplicationMessage;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.exception.MessageException;
/**
* This is abstract class for Root WebUI component of applications in GateIn. <br/>
* Act as container of WebUI components, it also provide method to show a Popup message
*/
@Serialized
public abstract class UIApplication extends UIContainer {
protected static Log log = ExoLogger.getLogger("portal:UIApplication");
private String owner;
private long lastAccessApplication_;
private UIPopupMessages uiPopupMessages_;
private static final String UIAPPLICATION = "uiapplication";
public UIApplication() {
}
// TODO this looks like not to be used anymore
public String getOwner() {
return owner;
}
// TODO this looks like not to be used anymore
public void setOwner(String s) {
owner = s;
}
/**
* Return the common UIPopupMessages
*
* @return UIPopupMessages
*/
public UIPopupMessages getUIPopupMessages() {
if (uiPopupMessages_ == null) {
try {
uiPopupMessages_ = createUIComponent(UIPopupMessages.class, null, null);
uiPopupMessages_.setId("_" + uiPopupMessages_.hashCode());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return uiPopupMessages_;
}
public void addMessage(AbstractApplicationMessage message) {
getUIPopupMessages().addMessage(message);
}
public void addMessage(ApplicationMessage message) {
addMessage((AbstractApplicationMessage) message);
}
public void clearMessages() {
getUIPopupMessages().clearMessages();
}
public long getLastAccessApplication() {
return lastAccessApplication_;
}
public void setLastAccessApplication(long time) {
lastAccessApplication_ = time;
}
public String getUIComponentName() {
return UIAPPLICATION;
}
@SuppressWarnings("unchecked")
public <T extends UIComponent> T findComponentById(String lookupId) {
if (getUIPopupMessages().getId().equals(lookupId))
return (T) getUIPopupMessages();
return (T) super.findComponentById(lookupId);
}
public void renderChildren() throws Exception {
super.renderChildren();
if (getUIPopupMessages() == null)
return;
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
getUIPopupMessages().processRender(context);
}
/**
* Wrap the action processing by a try catch, if there is exceptions, show a popup message
* if no exception the processAction will be delegate to the target of the action request
*/
public void processAction(WebuiRequestContext context) throws Exception {
try {
super.processAction(context);
} catch (MessageException ex) {
addMessage(ex.getDetailMessage());
} catch (Throwable t) {
ApplicationMessage msg = new ApplicationMessage("UIApplication.msg.unknown-error", null, ApplicationMessage.ERROR);
addMessage(msg);
log.error("Error during the processAction phase", t);
}
}
/**
* Triggered when there is Ajax request. <br/>
* This method add xml structure that help PortalHttpRequest.js parse the response
*/
public void renderBlockToUpdate(UIComponent uicomponent, WebuiRequestContext context, Writer w) throws Exception {
w.write("<div class=\"BlockToUpdate\">");
w.append("<div class=\"BlockToUpdateId\">").append(uicomponent.getId()).append("</div>");
w.write("<div class=\"BlockToUpdateData\">");
uicomponent.processRender(context);
w.write("</div>");
w.write("</div>");
}
}