Skip to content

Package: RenameAction

RenameAction

nameinstructionbranchcomplexitylinemethod
RenameAction(String, ConfigurationGraph)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
actionPerformed(ActionEvent)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getCurrentName()
M: 42 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
getName()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setName(String)
M: 18 C: 33
65%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 5 C: 10
67%
M: 0 C: 1
100%

Coverage

1: package networkconfigurator.actions;
2:
3: import java.awt.event.ActionEvent;
4: import java.util.ListIterator;
5:
6: import javax.swing.JOptionPane;
7:
8: import model.assignment.VariableAssignment;
9: import model.type.TypeDoesNotExistException;
10: import model.type.TypeExceptions;
11: import model.type.ValueNotInRangeOfTypeException;
12: import networkconfigurator.ConfigurationGraph;
13: import networkconfigurator.DetailBarLabel;
14: import networkconfigurator.DetailInputBox;
15: import networkconfigurator.item.ConfigRouter;
16: import networkconfigurator.item.HardwareEdge;
17: import networkconfigurator.item.Host;
18: import networkconfigurator.item.Internet;
19: import networkconfigurator.item.Item;
20: import networkconfigurator.item.ItemVisitor;
21: import networkconfigurator.item.NetworkAdapter;
22: import networkconfigurator.item.NetworkCable;
23: import networkconfigurator.item.Router;
24: import networkconfigurator.item.Slot;
25: import networkconfigurator.item.Switch;
26:
27: /**
28: * Action for renaming all selected nodes.
29: */
30: public final class RenameAction extends AbstractConfigurationGraphAction {
31:         /**
32:          * the new name of the node.
33:          */
34:         private String name;
35:
36:         /**
37:          * Üblicher Getter für das Attribut name.
38:          *
39:          * @return liefert name.
40:          */
41:         public String getName() {
42:                 return name;
43:         }
44:
45:         /**
46:          * constructor.
47:          *
48:          * @param name
49:          * the name
50:          * @param graph
51:          * the graph
52:          */
53:         public RenameAction(final String name, final ConfigurationGraph graph) {
54:                 super(name, graph);
55:         }
56:
57:         @Override
58:         public void actionPerformed(final ActionEvent e) {
59:                 name = getCurrentName();
60:                 setName(name);
61:         }
62:
63:         /**
64:          * get the current name.
65:          *
66:          * @return the current name
67:          */
68:         private String getCurrentName() {
69:                 name = "";
70:                 try {
71:                         final ListIterator<Item> iter = this.getGraph().getItems().listIterator();
72:•                        while (iter.hasNext()) {
73:                                 final Item n = iter.next();
74:•                                if (n.getSelected()) {
75:                                         final ItemGetNameVisitorImpl visitor = new ItemGetNameVisitorImpl();
76:                                         final String newName =
77:                                                         n.getPropertyBar().get(1).getPropertyBarEntry().accept(visitor);
78:
79:                                         name = JOptionPane.showInputDialog("Neuen Namen eingeben", newName);
80:                                 }
81:                         }
82:                 } catch (final NullPointerException | IllegalArgumentException e1) {
83:                         // Bei Abbruch passiert nichts.
84:                 }
85:                 return name;
86:         }
87:
88:         /**
89:          * set the current name.
90:          *
91:          * @param name
92:          * the new name.
93:          */
94:         public void setName(final String name) {
95:                 try {
96:                         final ListIterator<Item> iter = this.getGraph().getItems().listIterator();
97:•                        while (iter.hasNext()) {
98:                                 final Item n = iter.next();
99:•                                if (n.getSelected()) {
100:
101:                                         this.name = name;
102:                                         n.getPropertyBar().get(1).getPropertyBarEntry()
103:                                                         .accept(new ItemSetNameVisitor() {
104:
105:                                                                 @Override
106:                                                                 public void visit(final DetailInputBox detailBarInputBox) {
107:                                                                         detailBarInputBox.setContentValue(name);
108:                                                                 }
109:
110:                                                                 @Override
111:                                                                 public void visit(final DetailBarLabel label) {
112:                                                                         label.setLabelVaule(name);
113:                                                                 }
114:
115:                                                                 @Override
116:                                                                 public void visit(final VariableAssignment va)
117:                                                                                 throws IllegalArgumentException,
118:                                                                                 ValueNotInRangeOfTypeException, TypeDoesNotExistException,
119:                                                                                 TypeExceptions {
120:                                                                         va.setValue(name);
121:                                                                 }
122:                                                         });
123:                                         n.accept(new VisitorForUpdateDetailView());
124:                                 }
125:                         }
126:                         this.getGraph().repaint();
127:                 } catch (final NullPointerException | IllegalArgumentException
128:                                 | ValueNotInRangeOfTypeException | TypeDoesNotExistException
129:                                 | TypeExceptions e1) {
130:                         // Bei Abbruch passiert nichts.
131:                 } catch (final IndexOutOfBoundsException e2) {
132:                         throw new IllegalArgumentException(
133:                                         "the new VariableAssignment has not yet been implemented.");
134:                 }
135:         }
136:
137:         /**
138:          * Visitor for updating the deatilview.
139:          *
140:          * @author Erik Ole Arand
141:          *
142:          */
143:         private final class VisitorForUpdateDetailView implements ItemVisitor {
144:                 @Override
145:                 public void sWitch(final Switch sWitch) {
146:                         sWitch.setName(name);
147:                         getGraph().getDetailView().refreshDetails(sWitch);
148:                 }
149:
150:                 @Override
151:                 public void router(final Router router) {
152:                         router.setName(name);
153:                         getGraph().getDetailView().refreshDetails(router);
154:                 }
155:
156:                 @Override
157:                 public void internet(final Internet internet) {
158:                 }
159:
160:                 @Override
161:                 public void host(final Host host) {
162:                         host.setName(name);
163:                         getGraph().getDetailView().refreshDetails(host);
164:                 }
165:
166:                 @Override
167:                 public void configRouter(final ConfigRouter router) {
168:                         router.setName(name);
169:                         getGraph().getDetailView().refreshDetails(router);
170:                 }
171:
172:                 @Override
173:                 public void adapter(final NetworkAdapter adapter) {
174:                         adapter.setName(name);
175:                         getGraph().getDetailView().refreshDetails(adapter);
176:                 }
177:
178:                 @Override
179:                 public void hardwareEdge(final HardwareEdge edge) {
180:                 }
181:
182:                 @Override
183:                 public void networkCable(final NetworkCable edge) {
184:                 }
185:
186:                 @Override
187:                 public void slot(final Slot slot) {
188:                 }
189:         }
190:
191: }