KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > WaitWrapper


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import org.aopalliance.intercept.ConstructorInvocation;
22 import org.aopalliance.intercept.MethodInvocation;
23 import org.apache.log4j.Logger;
24 import org.objectweb.jac.core.AspectComponent;
25 import org.objectweb.jac.core.Display;
26 import org.objectweb.jac.core.Interaction;
27 import org.objectweb.jac.core.Wrapper;
28
29 /**
30  * This wrapper displays a "Please wait message" for slow operations.
31  * @see org.objectweb.jac.aspects.gui.GuiAC#setSlowOperation(AbstractMethodItem,boolean)
32  */

33 public class WaitWrapper extends Wrapper {
34     static Logger logger = Logger.getLogger("gui.wait");
35
36     public WaitWrapper(AspectComponent ac) {
37         super(ac);
38     }
39
40     public Object JavaDoc pleaseWait(Interaction interaction) {
41         DialogView page = null;
42         CustomizedDisplay display = null;
43         Object JavaDoc result = null;
44         try {
45             if (GuiAC.isSlowOperation(interaction.method)) {
46                 logger.debug("pleaseWait "+interaction);
47                 DisplayContext context =
48                     (DisplayContext)attr(GuiAC.DISPLAY_CONTEXT);
49                 if (context!=null) {
50                     display = context.getDisplay();
51                     page =
52                         (DialogView)display.showRefreshMessage(
53                             "Please wait",
54                             "Please wait: "+interaction.method.getName()+" is running...");
55                 } else {
56                     logger.error("pleaseWait: no display context available for "+
57                                  interaction.method);
58                 }
59             }
60             result = interaction.proceed();
61         } finally {
62             if (page!=null)
63                 page.waitForClose();
64         }
65         return result;
66     }
67
68     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
69         return pleaseWait((Interaction)invocation);
70     }
71
72     public Object JavaDoc construct(ConstructorInvocation invocation) throws Throwable JavaDoc {
73         return pleaseWait((Interaction)invocation);
74     }
75 }
76
Popular Tags