Skip to content

Package: AddRouterViewLogic$3

AddRouterViewLogic$3

nameinstructionbranchcomplexitylinemethod
actionPerformed(ActionEvent)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: *
3: */
4: package gui;
5:
6: import gui.view.AddRouterView;
7:
8: import java.awt.event.ActionEvent;
9: import java.awt.event.ActionListener;
10:
11: import javax.swing.JFileChooser;
12:
13: import model.RouterSoftware;
14: import reader.ReaderException;
15:
16: /**
17: * @author Phil
18: *
19: */
20: public class AddRouterViewLogic {
21:         /**
22:          * the main view logic.
23:          */
24:         private final MainViewLogic mainViewLogic;
25:         /**
26:          * the view to set.
27:          */
28:         private final AddRouterView addRouterView;
29:         /**
30:          * The controller (mvc).
31:          */
32:         private final MainController controller;
33:
34:         /**
35:          * constructor. Creates the view and sets fields.
36:          *
37:          * @param mainViewLogic
38:          * The main view logic to set.
39:          * @param controller
40:          * the controller to set.
41:          */
42:         public AddRouterViewLogic(final MainController controller, final MainViewLogic mainViewLogic) {
43:                 this.controller = controller;
44:                 this.mainViewLogic = mainViewLogic;
45:                 this.addRouterView = new AddRouterView();
46:                 initLogic();
47:         }
48:
49:         /**
50:          * Initializes the logic.
51:          */
52:         private void initLogic() {
53:
54:                 final MainController tempController = this.controller;
55:                 final AddRouterView tempAddRouterView = this.addRouterView;
56:                 final MainViewLogic tempMainViewLogic = this.mainViewLogic;
57:                 this.getAddRouterView().getBtnSearchPath().addActionListener(new ActionListener() {
58:                         @Override
59:                         public void actionPerformed(final ActionEvent arg0) {
60:                                 final int returnValue =
61:                                                 getAddRouterView().getFileChooser().showOpenDialog(
62:                                                                 getMainViewLogic().getMainView().getjFrame());
63:                                 if (returnValue == JFileChooser.APPROVE_OPTION) {
64:                                         getAddRouterView().getTfSourcePath().setText(
65:                                                         getAddRouterView().getFileChooser().getSelectedFile().getPath());
66:                                 }
67:                         }
68:                 });
69:                 this.getAddRouterView().getOkButton().addActionListener(new ActionListener() {
70:
71:                         @Override
72:                         public void actionPerformed(final ActionEvent arg0) {
73:                                 try {
74:                                         tempMainViewLogic.addSofwareToTreeModel(new RouterSoftware(getAddRouterView()
75:                                                         .getTfSourcePath().getText()));
76:                                 } catch (final ReaderException redEx) {
77:                                         new ExceptionViewLogic(tempController, redEx);
78:                                 } catch (final Exception e) {
79:                                         new ExceptionViewLogic(tempController, e);
80:                                 }
81:                                 tempAddRouterView.setVisible(false);
82:                         }
83:                 });
84:                 this.getAddRouterView().getCancelButton().addActionListener(new ActionListener() {
85:
86:                         @Override
87:                         public void actionPerformed(final ActionEvent arg0) {
88:                                 tempAddRouterView.setVisible(false);
89:                         }
90:                 });
91:
92:         }
93:
94:         /**
95:          * returns this.addRouterView.
96:          *
97:          * @return this.addRouterView.
98:          */
99:         protected AddRouterView getAddRouterView() {
100:                 return this.addRouterView;
101:         }
102:
103:         /**
104:          * returns this.controller.
105:          *
106:          * @return this.controller.
107:          */
108:         protected MainController getController() {
109:                 return this.controller;
110:         }
111:
112:         /**
113:          * @return the mainViewLogic
114:          */
115:         public MainViewLogic getMainViewLogic() {
116:                 return this.mainViewLogic;
117:         }
118: }