-
Notifications
You must be signed in to change notification settings - Fork 5
/
TagSwitcher.java
58 lines (48 loc) · 2.31 KB
/
TagSwitcher.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
package org.genericsystem.reactor.model;
import org.genericsystem.reactor.modelproperties.UserRoleDefaults;
import java.util.function.BiFunction;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.security.model.Role.Admin;
import org.genericsystem.security.model.UserRole;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
public interface TagSwitcher extends BiFunction<Context, Tag, ObservableValue<Boolean>> {
public static class NORMAL_MODE_ONLY implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Boolean> adminProperty = tag.getAdminModeProperty(context);
return Bindings.createBooleanBinding(() -> !Boolean.TRUE.equals(adminProperty.getValue()), adminProperty);
}
}
public static class ADMIN_MODE_ONLY implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
return tag.getAdminModeProperty(context);
}
}
public static class LOGGED_USER implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Generic> loggedUserProperty = ((UserRoleDefaults) tag).getLoggedUserProperty(context);
return Bindings.createBooleanBinding(() -> loggedUserProperty.getValue() != null, loggedUserProperty);
}
}
public static class NO_LOGGED_USER implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Generic> loggedUserProperty = ((UserRoleDefaults) tag).getLoggedUserProperty(context);
return Bindings.createBooleanBinding(() -> loggedUserProperty.getValue() == null, loggedUserProperty);
}
}
public static class LOGGED_USER_ADMIN implements TagSwitcher {
@Override
public ObservableValue<Boolean> apply(Context context, Tag tag) {
Property<Generic> loggedUserProperty = tag.getLoggedUserProperty(context);
ObservableValue<Generic> adminObservable = context.find(Admin.class).getObservableLink(context.find(UserRole.class), loggedUserProperty.getValue());
return Bindings.createBooleanBinding(() -> loggedUserProperty.getValue() != null && adminObservable.getValue() != null, loggedUserProperty, adminObservable);
}
}
}