Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EditPartCommand |
|
| 2.0;2 |
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.view; | |
11 | ||
12 | import org.openpermis.editor.policy.command.AbstractCommand; | |
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 <M> the part type. | |
20 | * @since 0.1.0 | |
21 | */ | |
22 | public class EditPartCommand<M extends PartBean> | |
23 | extends AbstractCommand | |
24 | { | |
25 | ||
26 | //---- State | |
27 | ||
28 | /** | |
29 | * The view context used to open the part. | |
30 | * @since 0.1.0 | |
31 | */ | |
32 | private final ViewContext viewContext; | |
33 | ||
34 | /** | |
35 | * The part to edit. | |
36 | * @since 0.1.0 | |
37 | */ | |
38 | private M part; | |
39 | ||
40 | /** | |
41 | * The editor created for undo. | |
42 | * @since 0.1.0 | |
43 | */ | |
44 | private Editor editor; | |
45 | ||
46 | //---- Constructors | |
47 | ||
48 | /** | |
49 | * Creates a new edit part command. | |
50 | * @param viewContext the view context to use. | |
51 | * @since 0.1.0 | |
52 | */ | |
53 | public EditPartCommand (ViewContext viewContext) { | |
54 | 0 | super("EditPart"); |
55 | 0 | this.viewContext = viewContext; |
56 | 0 | } |
57 | ||
58 | //---- Methods | |
59 | ||
60 | /** | |
61 | * Sets the part and its type to edit. | |
62 | * @param partInstance the part to edit. | |
63 | * @since 0.1.0 | |
64 | */ | |
65 | public void setPart (M partInstance) { | |
66 | 0 | this.part = partInstance; |
67 | 0 | } |
68 | ||
69 | //---- Command | |
70 | ||
71 | /** | |
72 | * @since 0.1.0 | |
73 | */ | |
74 | @Override | |
75 | public void execute (PolicyBean policy) { | |
76 | 0 | if (this.part != null && this.viewContext != null) { |
77 | 0 | this.editor = this.viewContext.editPart(this.part); |
78 | } | |
79 | 0 | } |
80 | ||
81 | /** | |
82 | * @since 0.1.0 | |
83 | */ | |
84 | @Override | |
85 | public void undo (PolicyBean policy) { | |
86 | 0 | if (this.viewContext != null && this.editor != null) { |
87 | 0 | this.viewContext.closeView(this.editor, true); |
88 | 0 | this.editor = null; |
89 | } | |
90 | 0 | } |
91 | ||
92 | } |