BrightSide Workbench Full Report + Source Code
DuplicatesVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.contacts.duplicates;
20 
21 import java.util.function.Consumer;
22 import org.turro.contacts.Contact;
23 import org.turro.elephant.util.Components;
24 import org.zkoss.bind.annotation.BindingParam;
25 import org.zkoss.bind.annotation.Command;
26 import org.zkoss.bind.annotation.ExecutionArgParam;
27 import org.zkoss.bind.annotation.Init;
28 import org.zkoss.zk.ui.Component;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.Window;
32 
37 public class DuplicatesVM {
38 
39  private Contact contact;
40  private DuplicatesModel dupmodel;
41  private Consumer<Contact> onSave;
42 
43  @Init
44  public void init(@ExecutionArgParam("contact") Contact contact,
45  @ExecutionArgParam("dupmodel") DuplicatesModel dupmodel,
46  @ExecutionArgParam("onSave") Consumer<Contact> onSave) {
47  this.contact = contact;
48  this.dupmodel = dupmodel;
49  this.onSave = onSave;
50  }
51 
52  @Command
53  public void onSave(@BindingParam("component") Component component) {
54  onSave.accept(contact);
55  Events.postEvent(new Event(Events.ON_CLOSE, Components.from(component).parent(Window.class), null));
56  }
57 
58  @Command
59  public void onCancel(@BindingParam("component") Component component) {
60  Events.postEvent(new Event(Events.ON_CLOSE, Components.from(component).parent(Window.class), null));
61  }
62 
63  public boolean canSave() {
64  return !dupmodel.hasStoppers();
65  }
66 
68  return dupmodel;
69  }
70 
71 }
void onCancel(@BindingParam("component") Component component)
void onSave(@BindingParam("component") Component component)
void init(@ExecutionArgParam("contact") Contact contact, @ExecutionArgParam("dupmodel") DuplicatesModel dupmodel, @ExecutionArgParam("onSave") Consumer< Contact > onSave)
static Components from(Object component)
Definition: Components.java:46