001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.romaframework.module.admin.view.domain.activesession;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.romaframework.aspect.core.annotation.AnnotationConstants;
022: import org.romaframework.aspect.core.annotation.CoreClass;
023: import org.romaframework.aspect.session.SessionAspect;
024: import org.romaframework.aspect.view.ViewCallback;
025: import org.romaframework.aspect.view.annotation.ViewField;
026: import org.romaframework.aspect.view.form.SelectableInstance;
027: import org.romaframework.core.domain.message.Message;
028: import org.romaframework.core.domain.message.MessageOk;
029: import org.romaframework.core.domain.message.MessageResponseListener;
030: import org.romaframework.core.domain.message.MessageTextEdit;
031: import org.romaframework.core.domain.message.MessageYesNo;
032: import org.romaframework.core.flow.ObjectContext;
033:
034: @CoreClass(orderFields="info sessions",orderActions="view refresh sendMessage shutdown selectAll deselectAll")
035: public abstract class ActiveSessionMain extends SelectableInstance
036: implements MessageResponseListener, ViewCallback {
037:
038: @ViewField(render="label")
039: protected String info;
040:
041: @ViewField(render="table",layout="block",selectionField="selection",enabled=AnnotationConstants.FALSE)
042: protected List<ActiveSessionListable> sessions;
043:
044: public ActiveSessionMain() {
045: sessions = new ArrayList<ActiveSessionListable>();
046: fillSessions();
047: }
048:
049: protected abstract void fillSessions();
050:
051: public void onShow() {
052: refresh();
053: }
054:
055: public void onDispose() {
056: }
057:
058: public List<ActiveSessionListable> getSessions() {
059: return sessions;
060: }
061:
062: public void view() {
063: Object[] sel = getSelection();
064: if (sel == null || sel.length == 0)
065: return;
066:
067: ObjectContext.getInstance().show(
068: new ActiveSessionInstance(
069: ((ActiveSessionListable) sel[0]).getEntity(),
070: this ));
071: }
072:
073: public void refresh() {
074: fillSessions();
075: }
076:
077: public void shutdown() {
078: if (getSelection() == null || getSelection().length == 0)
079: return;
080:
081: MessageYesNo msg = new MessageYesNo("delete", "Warning", this );
082: msg.setMessage("Are you sure you want to shutdown the "
083: + getSelection().length + " selected session(s) ?");
084: msg.setIcon("question.png");
085: ObjectContext.getInstance().show(msg);
086: }
087:
088: public void sendMessage() {
089: if (getSelection() == null || getSelection().length == 0)
090: return;
091:
092: MessageTextEdit msg = new MessageTextEdit("message", "Message",
093: this );
094: msg.setIcon("question.png");
095: ObjectContext.getInstance().show(msg);
096: }
097:
098: public String getInfo() {
099: return info;
100: }
101:
102: public void setInfo(String info) {
103: this .info = info;
104: }
105:
106: public void selectAll() {
107: Object[] sel = new Object[sessions.size()];
108: sessions.toArray(sel);
109: setSelection(sel);
110: ObjectContext.getInstance().refresh(this , "sessions");
111: }
112:
113: public void deselectAll() {
114: setSelection(null);
115: ObjectContext.getInstance().refresh(this , "sessions");
116: }
117:
118: public void responseMessage(Message iMessage, Object iResponse) {
119: ActiveSessionListable s;
120:
121: if (iMessage instanceof MessageYesNo) {
122: if (!(Boolean) iResponse)
123: return;
124:
125: // FORCE SHUTDOWN OF ALL SELECTED SESSIONS
126: for (Object sel : getSelection()) {
127: s = (ActiveSessionListable) sel;
128: ObjectContext.getInstance().getComponent(
129: SessionAspect.class).shutdown(
130: s.getEntity().getSystemSession());
131: }
132:
133: refresh();
134: } else if (iMessage instanceof MessageTextEdit) {
135:
136: MessageOk formattedMsg = new MessageOk("system message",
137: "System message");
138: formattedMsg.setMessage(((MessageTextEdit) iMessage)
139: .getDetail());
140:
141: for (Object sel : getSelection()) {
142: s = (ActiveSessionListable) sel;
143: ObjectContext.getInstance().show(formattedMsg, "popup",
144: null, s.getEntity());
145: }
146: }
147: }
148: }
|