BrightSide Workbench Full Report + Source Code
AssistantDialog.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.assistant;
20 
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.function.BiConsumer;
25 import java.util.function.Consumer;
26 import org.turro.i18n.I_;
27 import org.turro.ws.WsServer;
28 import org.turro.ws.service.ServerAdapter;
29 import org.turro.ws.service.member.Servers;
30 import org.turro.zkoss.dialog.Dialogs;
31 
36 public class AssistantDialog {
37 
38 
39  public static void load(Consumer<AssistantSet> consumer) {
40  AssistantSet as = new AssistantSet();
41  Dialogs.title(I_.get("Assistants"))
42  .addComponent("/commons/assistants.zul", Map.of(
43  "as", as,
44  "servers", Collections.EMPTY_LIST))
45  .width("60%").height("80%")
46  .onOk((include) -> {
47  consumer.accept(as);
48  })
49  .emptyCancel()
50  .show();
51  }
52 
53  public static void loadWithServers(BiConsumer<AssistantSet, List<WsServer>> consumer) {
54  AssistantSet as = new AssistantSet();
55  List<ServerAdapter> servers = Servers.getServers().stream().map(s -> ServerAdapter.from(s)).toList();
56  Dialogs.title(I_.get("Assistants"))
57  .addComponent("/commons/assistants.zul", Map.of(
58  "as", as,
59  "servers", servers))
60  .width("60%").height("80%")
61  .onOk((include) -> {
62  consumer.accept(as, servers.stream().filter(sa -> sa.isSelected()).map(sa -> sa.getServer()).toList());
63  })
64  .emptyCancel()
65  .show();
66  }
67 
68 }
static void load(Consumer< AssistantSet > consumer)
static void loadWithServers(BiConsumer< AssistantSet, List< WsServer >> consumer)
static String get(String msg)
Definition: I_.java:41
Dialogs width(String width)
Definition: Dialogs.java:70
Dialogs height(String height)
Definition: Dialogs.java:75
Dialogs onOk(Consumer< Dialogs > onOk)
Definition: Dialogs.java:85
static Dialogs title(String title)
Definition: Dialogs.java:161
Dialogs addComponent(HtmlBasedComponent component)
Definition: Dialogs.java:115