BrightSide Workbench Full Report + Source Code
CommentLabel.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.contacts.zul.label;
19 
20 import org.turro.string.Strings;
21 import org.turro.contacts.Comment;
22 import org.turro.contacts.Contact;
23 import org.turro.elephant.context.Application;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Label;
26 
31 public class CommentLabel extends Label implements AfterCompose {
32 
33  private Contact contact;
34  private String key;
35 
36  public Contact getContact() {
37  return contact;
38  }
39 
40  public void setContact(Contact contact) {
41  this.contact = contact;
42  }
43 
44  public String getKey() {
45  return key;
46  }
47 
48  public void setKey(String key) {
49  this.key = key;
50  }
51 
52  @Override
53  public void afterCompose() {
54  String lang = key + "_" + Application.getUsedLocale().getLanguage();
55  if(contact != null) {
56  for(Comment c : contact.getComments()) {
57  if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
58  setValue(c.getComment().substring(lang.length()));
59  break;
60  }
61  }
62  }
63  if(Strings.isBlank(getValue())) {
64  lang = key + "#";
65  if(contact != null) {
66  for(Comment c : contact.getComments()) {
67  if(!Strings.isBlank(c.getComment()) && c.getComment().startsWith(lang)) {
68  setValue(c.getComment().substring(lang.length()));
69  break;
70  }
71  }
72  }
73  }
74  }
75 
76 }
Set< Comment > getComments()
Definition: Contact.java:415