Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ObligationPresenter |
|
| 1.25;1.25 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.presenter; | |
11 | ||
12 | import org.slf4j.Logger; | |
13 | import org.slf4j.LoggerFactory; | |
14 | ||
15 | import org.openpermis.editor.policy.beans.PropertyChange; | |
16 | import org.openpermis.policy.bean.ObligationBean; | |
17 | ||
18 | /** | |
19 | * Presenter for a single {@link ObligationBean}. | |
20 | * @since 0.3.0 | |
21 | */ | |
22 | public class ObligationPresenter extends PartPresenter<ObligationBean> { | |
23 | ||
24 | //---- Static | |
25 | ||
26 | /** | |
27 | * The logger object of this class. | |
28 | * @since 0.3.0 | |
29 | */ | |
30 | 0 | private static final Logger LOGGER = |
31 | LoggerFactory.getLogger(ObligationPresenter.class); | |
32 | ||
33 | //---- State | |
34 | ||
35 | /** | |
36 | * @since 0.3.0 | |
37 | */ | |
38 | private String text; | |
39 | ||
40 | //---- Constructors | |
41 | ||
42 | /** | |
43 | * Creates a new {@link ObligationPresenter}. | |
44 | * @param model the obligation to work on. | |
45 | * @param context policy context that provides additional information. | |
46 | * @since 0.3.0 | |
47 | */ | |
48 | public ObligationPresenter (ObligationBean model, PolicyContext context) { | |
49 | 0 | super(model, context); |
50 | ||
51 | 0 | LOGGER.debug("Presenter for [{}].", model); |
52 | 0 | updateText(); |
53 | 0 | } |
54 | ||
55 | //---- Methods | |
56 | ||
57 | /** | |
58 | * Gets the text. | |
59 | * @return the text. | |
60 | * @since 0.3.0 | |
61 | */ | |
62 | public String getText () { | |
63 | 0 | return this.text; |
64 | } | |
65 | ||
66 | /** | |
67 | * Sets the text of the model. | |
68 | * @param text the new text to set. | |
69 | * @since 0.3.0 | |
70 | */ | |
71 | public void setText (String text) { | |
72 | try { | |
73 | // update presenter | |
74 | 0 | this.text = text; |
75 | ||
76 | // trigger model | |
77 | 0 | change("text", this.text); |
78 | 0 | } catch (final Exception e) { |
79 | 0 | LOGGER.warn("Cannot set obligation text [" + text + "].", e); |
80 | 0 | } |
81 | 0 | } |
82 | ||
83 | //---- PropertyChange | |
84 | ||
85 | /** | |
86 | * Handles property changes of text. | |
87 | * @since 0.3.0 | |
88 | */ | |
89 | @PropertyChange(bean = ObligationBean.class, property = "text") | |
90 | public void updateText () { | |
91 | 0 | final String oldText = this.text; |
92 | 0 | this.text = getModel().getText(); |
93 | 0 | firePropertyChange("text", oldText, this.text); |
94 | 0 | } |
95 | ||
96 | } |