BrightSide Workbench Full Report + Source Code
LongOperation.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.util;
20 
21 import org.turro.string.Strings;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.zkoss.zk.ui.Component;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.util.Clients;
29 
34 public class LongOperation {
35 
36  private static final String LONG_OPERATION_EVENT = "onLongOperation";
37 
38  public static void executeLongOperation(Component component, final Command command) {
39  executeLongOperation(component, null, command);
40  }
41 
42  public static void executeLongOperation(final Component component, final String busyMsg, final Command command) {
43  if(!Strings.isBlank(busyMsg)) {
44  Clients.showBusy(busyMsg);
45  }
46  component.addEventListener(LONG_OPERATION_EVENT, new EventListener<Event>() {
47  @Override
48  public void onEvent(Event event) throws Exception {
49  Context ctx = new Context();
50  command.execute(ctx);
51  if(!Strings.isBlank(busyMsg)) {
52  Clients.clearBusy();
53  }
54  component.removeEventListener(LONG_OPERATION_EVENT, this);
55  }
56  });
57  Events.echoEvent(LONG_OPERATION_EVENT, component, null);
58  }
59 
60 }
static void executeLongOperation(Component component, final Command command)
static void executeLongOperation(final Component component, final String busyMsg, final Command command)