Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PoolChangeCommand |
|
| 1.0;1 |
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.command; | |
11 | ||
12 | import org.openpermis.editor.policy.presenter.PolicyPartPool; | |
13 | import org.openpermis.policy.bean.PartBean; | |
14 | import org.openpermis.policy.bean.PolicyBean; | |
15 | ||
16 | ||
17 | /** | |
18 | * Command to edit a part. | |
19 | * @param <P> the current beantype | |
20 | * @since 0.1.0 | |
21 | */ | |
22 | public abstract class PoolChangeCommand<P extends PartBean> extends AbstractCommand | |
23 | { | |
24 | ||
25 | //---- State | |
26 | ||
27 | /** | |
28 | * Pool to change. | |
29 | * @since 0.1.0 | |
30 | */ | |
31 | private PolicyPartPool<P> pool; | |
32 | ||
33 | /** | |
34 | * The bean to operate on. | |
35 | * @since 0.1.0 | |
36 | */ | |
37 | private P elementBean; | |
38 | ||
39 | ||
40 | //---- Constructors | |
41 | ||
42 | /** | |
43 | * Creates a new command. * | |
44 | * @param pool pool to be changed | |
45 | * @param elementBean bean to operate on | |
46 | * @since 0.1.0 | |
47 | */ | |
48 | public PoolChangeCommand (PolicyPartPool<P> pool, P elementBean) { | |
49 | 0 | super("PoolChangeCommand"); |
50 | 0 | this.pool = pool; |
51 | 0 | this.elementBean = elementBean; |
52 | 0 | } |
53 | ||
54 | //---- Methods | |
55 | ||
56 | /** | |
57 | * @return the pool. | |
58 | * @since 0.1.0 | |
59 | */ | |
60 | public PolicyPartPool<P> getPool () { | |
61 | 0 | return this.pool; |
62 | } | |
63 | ||
64 | /** | |
65 | * @return the elementBean. | |
66 | * @since 0.1.0 | |
67 | */ | |
68 | public P getElementBean () { | |
69 | 0 | return this.elementBean; |
70 | } | |
71 | ||
72 | /** | |
73 | * @param doExec wether to "exec" or to "undo" | |
74 | * @since 0.1.0 | |
75 | */ | |
76 | abstract void operateElement (boolean doExec); | |
77 | ||
78 | /** | |
79 | * @since 0.1.0 | |
80 | */ | |
81 | private void changeCollection (boolean doExec) { | |
82 | 0 | operateElement(doExec); |
83 | 0 | } |
84 | ||
85 | //---- Command | |
86 | ||
87 | /** | |
88 | * @since 0.1.0 | |
89 | */ | |
90 | @Override | |
91 | public void execute (PolicyBean policyBean) { | |
92 | 0 | changeCollection(true); |
93 | 0 | } |
94 | ||
95 | /** | |
96 | * @since 0.1.0 | |
97 | */ | |
98 | @Override | |
99 | public void undo (PolicyBean policyBean) { | |
100 | 0 | changeCollection(false); |
101 | 0 | } |
102 | ||
103 | } |