1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.vaadin.util;
|
11
|
|
12
|
import java.util.Iterator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import com.vaadin.ui.Component;
|
16
|
import com.vaadin.ui.HasComponents;
|
17
|
import com.vaadin.ui.UI;
|
18
|
|
19
|
import eu.etaxonomy.cdm.vaadin.component.CdmProgressComponent;
|
20
|
|
21
|
/**
|
22
|
* @author cmathew
|
23
|
* @date 7 Apr 2015
|
24
|
*
|
25
|
*/
|
26
|
public class CdmVaadinUtilities {
|
27
|
|
28
|
/**
|
29
|
* Thread safe method to asynchronously perform an update.
|
30
|
*
|
31
|
* @param update
|
32
|
*/
|
33
|
public static void asyncExec(Runnable update) {
|
34
|
UI currentUI = UI.getCurrent();
|
35
|
Thread t = new Thread(update);
|
36
|
if(currentUI != null) {
|
37
|
synchronized(currentUI) {
|
38
|
t.start();
|
39
|
}
|
40
|
} else {
|
41
|
throw new UnsupportedOperationException("Cannot execute update on a UI which is null");
|
42
|
}
|
43
|
}
|
44
|
|
45
|
public static void exec(CdmVaadinOperation op) {
|
46
|
if(op.isAsync()) {
|
47
|
asyncExec(op);
|
48
|
} else {
|
49
|
op.run();
|
50
|
}
|
51
|
}
|
52
|
|
53
|
|
54
|
public static void setEnabled(Component root, boolean isEnabled, List<? extends Component> exceptions) {
|
55
|
if(exceptions != null && exceptions.contains(root)) {
|
56
|
return;
|
57
|
}
|
58
|
if(root instanceof HasComponents) {
|
59
|
HasComponents hc = (HasComponents) root;
|
60
|
Iterator<Component> iterator = hc.iterator();
|
61
|
while(iterator.hasNext()) {
|
62
|
setEnabled(iterator.next(), isEnabled, exceptions);
|
63
|
}
|
64
|
} else {
|
65
|
root.setEnabled(isEnabled);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
public static void enableOnlyProgressBar(Component component) {
|
70
|
if(component instanceof CdmProgressComponent) {
|
71
|
component.setEnabled(true);
|
72
|
return;
|
73
|
}
|
74
|
if(component instanceof HasComponents) {
|
75
|
HasComponents hc = (HasComponents) component;
|
76
|
Iterator<Component> iterator = hc.iterator();
|
77
|
while(iterator.hasNext()) {
|
78
|
enableOnlyProgressBar(iterator.next());
|
79
|
}
|
80
|
} else {
|
81
|
component.setEnabled(false);
|
82
|
}
|
83
|
}
|
84
|
|
85
|
|
86
|
}
|