1 | |
package br.mia.test.view.graph.observer; |
2 | |
|
3 | |
import java.awt.event.ComponentEvent; |
4 | |
import java.awt.event.ComponentListener; |
5 | |
import java.awt.event.KeyEvent; |
6 | |
import java.awt.event.KeyListener; |
7 | |
import java.util.ArrayList; |
8 | |
|
9 | |
import org.jgraph.JGraph; |
10 | |
import org.jgraph.event.GraphSelectionEvent; |
11 | |
import org.jgraph.event.GraphSelectionListener; |
12 | |
import org.jgraph.graph.DefaultEdge; |
13 | |
|
14 | |
import br.mia.test.controler.ControladorData; |
15 | |
import br.mia.test.controler.ControladorErro; |
16 | |
import br.mia.test.controler.ControladorStep; |
17 | |
import br.mia.test.controler.FlowController; |
18 | |
import br.mia.test.model.CasoUso; |
19 | |
import br.mia.test.model.Filtro; |
20 | |
import br.mia.test.model.Link; |
21 | |
import br.mia.test.model.Step; |
22 | |
import br.mia.test.model.dao.DAOFiltro; |
23 | |
import br.mia.test.testcase.DadosTeste; |
24 | |
import br.mia.test.view.graph.CodeGrafoPane; |
25 | |
import br.mia.test.view.graph.CondicionalCell; |
26 | |
import br.mia.test.view.graph.DataCell; |
27 | |
import br.mia.test.view.graph.LinkEdge; |
28 | |
import br.mia.test.view.graph.LinkPort; |
29 | |
import br.mia.test.view.graph.RuleCell; |
30 | |
import br.mia.test.view.graph.StepCell; |
31 | |
import br.mia.test.view.graph.Util; |
32 | |
import br.mia.test.view.observers.Observer; |
33 | |
|
34 | |
public class ObserverComponentCodigo extends Observer implements ComponentListener, |
35 | |
GraphSelectionListener, KeyListener { |
36 | |
|
37 | 0 | public ObserverComponentCodigo(CodeGrafoPane grafoPane) { |
38 | 0 | this.grafoPane = grafoPane; |
39 | |
|
40 | 0 | } |
41 | |
|
42 | |
private CodeGrafoPane grafoPane; |
43 | |
|
44 | |
public CodeGrafoPane getGrafoPane() { |
45 | 0 | return grafoPane; |
46 | |
} |
47 | |
|
48 | |
public void setGrafoPane(CodeGrafoPane grafoPane) { |
49 | 0 | this.grafoPane = grafoPane; |
50 | 0 | } |
51 | |
|
52 | |
public void componentResized(ComponentEvent e) { |
53 | |
|
54 | |
|
55 | 0 | } |
56 | |
|
57 | |
public void componentMoved(ComponentEvent e) { |
58 | |
|
59 | |
|
60 | 0 | } |
61 | |
|
62 | |
public void componentShown(ComponentEvent e) { |
63 | |
|
64 | |
|
65 | 0 | } |
66 | |
|
67 | |
public void componentHidden(ComponentEvent e) { |
68 | |
|
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
public void valueChanged(GraphSelectionEvent arg0) { |
73 | |
|
74 | 0 | } |
75 | |
|
76 | |
public void keyTyped(KeyEvent e) { |
77 | |
|
78 | |
|
79 | 0 | } |
80 | |
|
81 | |
public void keyPressed(KeyEvent e) { |
82 | |
|
83 | 0 | } |
84 | |
|
85 | |
public void keyReleased(KeyEvent e) { |
86 | |
try { |
87 | 0 | if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
88 | 0 | JGraph graph = this.getGraph().get(0); |
89 | 0 | Object[] celulas2 = graph.getSelectionCells(); |
90 | 0 | CasoUso useCase = (CasoUso) this.getObjetos().get(0); |
91 | |
|
92 | 0 | StepCell primeiro = null; |
93 | 0 | for (int i = 0; i <= celulas2.length - 1; i++) { |
94 | |
|
95 | 0 | Object celula = celulas2[i]; |
96 | |
|
97 | 0 | if (celula instanceof StepCell) { |
98 | |
|
99 | 0 | primeiro = (StepCell) celula; |
100 | |
|
101 | 0 | FlowController controlador = new FlowController(); |
102 | |
|
103 | 0 | String descricao = primeiro.toString(); |
104 | |
|
105 | 0 | controlador.renomearCodigo(primeiro.getStep(), primeiro |
106 | 0 | .getFlow(), descricao, primeiro.getUseCase()); |
107 | |
|
108 | |
} |
109 | 0 | if (celula instanceof LinkEdge) { |
110 | |
|
111 | 0 | LinkEdge edge = (LinkEdge) celula; |
112 | 0 | LinkPort porta = (LinkPort) edge.getSource(); |
113 | 0 | Step step = porta.getStep(); |
114 | 0 | double probabilidade = Double.parseDouble(edge |
115 | 0 | .toString()); |
116 | 0 | Link link = edge.getLink(); |
117 | 0 | link.setProbabilidade(probabilidade); |
118 | 0 | FlowController controlador = new FlowController(); |
119 | 0 | controlador.atualizaLink(link, step, link.getFlow(), |
120 | 0 | useCase); |
121 | |
|
122 | |
} |
123 | |
|
124 | |
|
125 | |
} |
126 | |
|
127 | |
} |
128 | 0 | if (e.getKeyCode() == KeyEvent.VK_DELETE) { |
129 | 0 | JGraph graph = this.getGraph().get(0); |
130 | 0 | Object[] celulas2 = graph.getSelectionCells(); |
131 | |
|
132 | 0 | CasoUso useCase = (CasoUso) this.getObjetos().get(0); |
133 | |
|
134 | 0 | StepCell primeiro = null; |
135 | 0 | ArrayList<Object> remocao = new ArrayList<Object>(); |
136 | |
|
137 | 0 | for (int i = 0; i <= celulas2.length - 1; i++) { |
138 | |
|
139 | 0 | Object celula = celulas2[i]; |
140 | |
|
141 | 0 | if (celula instanceof StepCell) { |
142 | |
|
143 | 0 | primeiro = (StepCell) celula; |
144 | |
|
145 | 0 | ControladorStep controlador = new ControladorStep(); |
146 | 0 | controlador.deletarStep(primeiro.getStep(), useCase, |
147 | 0 | primeiro.getFlow()); |
148 | |
|
149 | 0 | remocao.add(primeiro.getSetaAnterior()); |
150 | 0 | remocao.add(primeiro); |
151 | |
|
152 | |
} |
153 | 0 | if (celula instanceof LinkEdge) { |
154 | |
|
155 | 0 | LinkEdge link = (LinkEdge) celula; |
156 | |
|
157 | 0 | FlowController controlador = new FlowController(); |
158 | 0 | controlador.deletarLink(link.getLink()); |
159 | |
|
160 | 0 | link.getStep().getLinks().remove( |
161 | 0 | link.getLink()); |
162 | |
|
163 | 0 | remocao.add(link); |
164 | |
|
165 | |
} |
166 | 0 | if (celula instanceof RuleCell) { |
167 | |
|
168 | 0 | RuleCell rule = (RuleCell) celula; |
169 | |
|
170 | 0 | FlowController controlador = new FlowController(); |
171 | 0 | controlador |
172 | 0 | .deletarRegra(rule.getRule(), rule.getStep()); |
173 | |
|
174 | 0 | rule.getStep().getRegras().remove( |
175 | 0 | rule.getRule()); |
176 | |
|
177 | 0 | remocao.add(rule); |
178 | 0 | remocao.add(rule.getEdge()); |
179 | |
|
180 | |
} |
181 | 0 | if (celula instanceof DataCell) { |
182 | |
|
183 | 0 | DataCell dataCell = (DataCell) celula; |
184 | 0 | Step step = dataCell.getStep(); |
185 | |
|
186 | 0 | DadosTeste data = dataCell.getData(); |
187 | |
|
188 | 0 | if (step != null) { |
189 | 0 | ControladorData controlador = new ControladorData(); |
190 | 0 | controlador.deletarDado(data, step); |
191 | 0 | step.getDatas().remove(data); |
192 | |
} |
193 | |
|
194 | 0 | remocao.add(celula); |
195 | 0 | if (dataCell.getDadoEdge() != null) { |
196 | 0 | remocao.add(dataCell.getDadoEdge()); |
197 | |
} |
198 | |
|
199 | |
} |
200 | 0 | if (celula instanceof CondicionalCell) { |
201 | |
|
202 | 0 | CondicionalCell condicionalCell = (CondicionalCell) celula; |
203 | 0 | Step step = condicionalCell.getStep(); |
204 | |
|
205 | 0 | Filtro filtro = condicionalCell.getFiltro(); |
206 | |
|
207 | 0 | DAOFiltro daoFiltro = new DAOFiltro(); |
208 | 0 | daoFiltro.delete(step,filtro); |
209 | |
|
210 | 0 | |
211 | |
|
212 | 0 | remocao.add(celula); |
213 | 0 | remocao.add(condicionalCell.getFiltroEdge()); |
214 | |
|
215 | |
} |
216 | |
|
217 | |
} |
218 | |
|
219 | 0 | graph.getGraphLayoutCache().remove(remocao.toArray()); |
220 | 0 | grafoPane.getCelulas().removeAll(remocao); |
221 | |
|
222 | |
} |
223 | 0 | if (e.getKeyCode() == KeyEvent.VK_INSERT) { |
224 | 0 | JGraph graph = this.getGraph().get(0); |
225 | 0 | ArrayList<Object> adicao = new ArrayList<Object>(); |
226 | |
|
227 | 0 | Object[] celulas = graph.getSelectionCells(); |
228 | |
|
229 | 0 | StepCell primeiro = null; |
230 | 0 | for (int i = 1; i <= celulas.length - 1; i++) { |
231 | |
|
232 | 0 | Object celula = celulas[i]; |
233 | 0 | Object celulaAnterior = celulas[i - 1]; |
234 | |
|
235 | 0 | if ((celula instanceof StepCell) |
236 | 0 | && (celulaAnterior instanceof StepCell)) { |
237 | |
|
238 | 0 | primeiro = (StepCell) celulaAnterior; |
239 | 0 | StepCell segundo = (StepCell) celula; |
240 | |
|
241 | 0 | if (!(primeiro.getFlow().equals(segundo.getFlow()))) { |
242 | |
|
243 | 0 | DefaultEdge seta = Util.criaLink(primeiro, segundo, |
244 | 0 | new Link()); |
245 | 0 | adicao.add(seta); |
246 | |
|
247 | 0 | FlowController controlador = new FlowController(); |
248 | 0 | controlador.inserirLink(primeiro.getStep(), segundo |
249 | 0 | .getFlow(), segundo.getStepNumber(), |
250 | 0 | primeiro.getUseCase()); |
251 | |
|
252 | |
} |
253 | |
|
254 | |
} |
255 | |
|
256 | |
} |
257 | 0 | graph.getGraphLayoutCache().insert(adicao.toArray()); |
258 | 0 | grafoPane.getCelulas().addAll(adicao); |
259 | |
|
260 | |
} |
261 | 0 | } catch (Exception e1) { |
262 | 0 | ControladorErro.trata(e1,this); |
263 | |
} |
264 | |
|
265 | 0 | } |
266 | |
} |