BrightSide Workbench Full Report + Source Code
AcceptanceButton.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.zul.acceptance;
19 
20 import org.turro.acceptance.AcceptanceUtil;
21 import org.turro.action.AcceptanceStatus;
22 import org.turro.annotation.ElephantPlugin;
23 import org.turro.auth.Authentication;
24 import org.turro.command.Command;
25 import org.turro.command.Context;
26 import org.turro.contacts.zul.menu.ContactMenu;
27 import org.turro.entities.Entities;
28 import org.turro.i18n.I_;
29 import org.turro.plugin.acceptance.IAcceptanceCtrl;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.Toolbarbutton;
34 
40 public class AcceptanceButton extends Toolbarbutton implements IAcceptanceCtrl {
41 
42  private Object entity;
43  private String path;
44  private AcceptanceStatus status;
45 
46  @Override
47  public Object getEntity() {
48  return entity;
49  }
50 
51  @Override
52  public void setEntity(Object entity) {
53  this.entity = entity;
54  if(entity instanceof String) {
55  path = (String) entity;
56  } else {
57  path = Entities.getController(entity).getPath();
58  }
59  setStatus();
60  setTooltiptext(I_.get("Acceptance"));
61  addEventListener(Events.ON_CLICK, new EventListener() {
62  @Override
63  public void onEvent(Event event) throws Exception {
64  ContactMenu.showAcceptance(path, new Command() {
65  @Override
66  public Object execute(Context context) {
67  setStatus();
68  return null;
69  }
70  });
71  }
72  });
73  }
74 
75  private void setStatus() {
77  setImage(status.getImage());
78  }
79 
80  @Override
81  public boolean isAccepted() {
82  return AcceptanceUtil.isAccepted(path);
83  }
84 
85  @Override
86  public boolean isBlocked() {
87  return AcceptanceUtil.isBlocked(path);
88  }
89 
90 }
static boolean isBlocked(String path)
static boolean isAccepted(String path)
static AcceptanceStatus getStatusFor(String path, IContact contact)
static void showAcceptance(String path, final Command command)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String get(String msg)
Definition: I_.java:41