Coverage Report - br.mia.test.view.observers.ObserverEditFlow
 
Classes in this File Line Coverage Branch Coverage Complexity
ObserverEditFlow
0%
0/408
0%
0/136
0
 
 1  
 package br.mia.test.view.observers;
 2  
 
 3  
 import java.awt.BorderLayout;
 4  
 import java.awt.FileDialog;
 5  
 import java.awt.event.ActionEvent;
 6  
 import java.awt.event.ActionListener;
 7  
 import java.awt.event.KeyEvent;
 8  
 import java.awt.event.KeyListener;
 9  
 import java.awt.event.MouseEvent;
 10  
 import java.awt.event.MouseListener;
 11  
 import java.io.File;
 12  
 import java.util.ArrayList;
 13  
 
 14  
 import javax.swing.ImageIcon;
 15  
 import javax.swing.JComboBox;
 16  
 import javax.swing.JFrame;
 17  
 import javax.swing.JLabel;
 18  
 import javax.swing.JOptionPane;
 19  
 import javax.swing.JTable;
 20  
 import javax.swing.JTextArea;
 21  
 import javax.swing.JTextField;
 22  
 
 23  
 import org.apache.log4j.Logger;
 24  
 
 25  
 import br.mia.test.controler.ControladorData;
 26  
 import br.mia.test.controler.ControladorErro;
 27  
 import br.mia.test.controler.ControladorStep;
 28  
 import br.mia.test.controler.FlowController;
 29  
 import br.mia.test.model.CasoUso;
 30  
 import br.mia.test.model.Fluxo;
 31  
 import br.mia.test.model.Link;
 32  
 import br.mia.test.model.RegraNegocio;
 33  
 import br.mia.test.model.Step;
 34  
 import br.mia.test.model.dao.DAOStep;
 35  
 import br.mia.test.testcase.DadosTeste;
 36  
 import br.mia.test.util.Util;
 37  
 import br.mia.test.view.Global;
 38  
 import br.mia.test.view.ScriptRunner;
 39  
 
 40  
 public class ObserverEditFlow extends Observer implements ActionListener,
 41  
         MouseListener, KeyListener
 42  
 {
 43  
 
 44  0
     private CasoUso useCase;
 45  0
 
 46  0
     public ObserverEditFlow(CasoUso useCase) {
 47  0
         this.useCase = useCase;
 48  0
     }
 49  
 
 50  
     private int selectedFlow;
 51  0
 
 52  0
     public int getSelectedFlow() {
 53  0
         return selectedFlow;
 54  
     }
 55  0
 
 56  0
     public void setSelectedFlow(int selectedFlow) {
 57  0
         this.selectedFlow = selectedFlow;
 58  0
     }
 59  
 
 60  0
     public void actionPerformed(ActionEvent e) {
 61  0
 
 62  0
         JTable steps = (JTable) this.getTables().get(0);
 63  0
         JTable regras = (JTable) this.getTables().get(1);
 64  0
         JTable datas = (JTable) this.getTables().get(2);
 65  0
         JTable links = (JTable) this.getTables().get(3);
 66  0
         JComboBox comboBox = (JComboBox) this.getCombos().get(0);
 67  0
         JComboBox comboRegras = (JComboBox) this.getCombos().get(1);
 68  0
         JComboBox comboData = (JComboBox) this.getCombos().get(2);
 69  0
         JTextField descricao = (JTextField) this.getTextFields().get(0);
 70  0
         JTextField stepLink = (JTextField) this.getTextFields().get(1);
 71  0
         JTextArea duvidas = (JTextArea) this.getTextAreas().get(0);
 72  0
         JTextArea ambiente = (JTextArea) this.getTextAreas().get(1);
 73  
 
 74  0
         try {
 75  0
 
 76  0
             if (e.getActionCommand().equals("DeletarRegra")) {
 77  0
 
 78  0
                 int selectStep = steps.getSelectedRow();
 79  0
                 int selectRegra = regras.getSelectedRow();
 80  0
 
 81  0
                 Step step = (Step) ((Fluxo) useCase.getFlows().get(
 82  0
                         this.selectedFlow)).getSteps().get(selectStep);
 83  0
 
 84  0
                 RegraNegocio regra = (RegraNegocio) step.getRegras().get(
 85  0
                         selectRegra);
 86  0
 
 87  0
                 step.getRegras().remove(regra);
 88  0
 
 89  0
                 ((Fluxo) useCase.getFlows().get(this.selectedFlow)).getSteps()
 90  0
                         .set(selectStep, step);
 91  0
 
 92  0
                 FlowController controlador = new FlowController();
 93  0
                 controlador.deletarRegra(regra, step);
 94  0
 
 95  0
                 steps.revalidate();
 96  0
                 datas.revalidate();
 97  0
                 regras.revalidate();
 98  
 
 99  0
             }
 100  0
 
 101  0
             if (e.getActionCommand().equals("Rename")) {
 102  0
 
 103  0
                 int selectedFlowCombo = comboBox.getSelectedIndex();
 104  0
 
 105  0
                 Fluxo flow = ((Fluxo) useCase.getFlows().get(selectedFlowCombo));
 106  0
 
 107  0
                 int selectStep = steps.getSelectedRow();
 108  0
 
 109  0
                 Step step = (Step) ((Fluxo) useCase.getFlows().get(
 110  0
                         this.selectedFlow)).getSteps().get(selectStep);
 111  0
 
 112  0
                 step.setDescricao(descricao.getText());
 113  0
 
 114  0
                 FlowController controlador = new FlowController();
 115  0
                 controlador.renomear(step, flow, descricao.getText(), useCase);
 116  0
 
 117  0
                 steps.revalidate();
 118  
 
 119  0
             }
 120  0
 
 121  0
             if (e.getActionCommand().equals("InserirDado")) {
 122  0
                 int selectStep = steps.getSelectedRow();
 123  0
                 Step step = (Step) ((Fluxo) useCase.getFlows().get(
 124  0
                         this.selectedFlow)).getSteps().get(selectStep);
 125  0
 
 126  0
                 DadosTeste data = Util.getDataCombo(comboData, useCase);
 127  0
 
 128  0
                 if (data.getId() != 0) {
 129  0
 
 130  0
                     ControladorStep controlador = new ControladorStep();
 131  0
                     controlador.inserirData(data, step);
 132  0
                     this.atualiza();
 133  0
                 } else {
 134  0
                     JOptionPane.showMessageDialog(null,
 135  0
                             "Grave o projeto antes de realizar a opera��o");
 136  0
                 }
 137  
             }
 138  0
 
 139  0
             if (e.getActionCommand().equals("DescerLinha")) {
 140  0
 
 141  0
                 int selectStep = steps.getSelectedRow();
 142  0
 
 143  0
                 Step step = (Step) ((Fluxo) useCase.getFlows().get(
 144  0
                         this.selectedFlow)).getSteps().get(selectStep);
 145  0
 
 146  0
                 Step stepAnterior = (Step) ((Fluxo) useCase.getFlows().get(
 147  0
                         this.selectedFlow)).getSteps().get(selectStep + 1);
 148  0
 
 149  0
                 int indice1 = step.getOrdem();
 150  0
                 int indice2 = stepAnterior.getOrdem();
 151  0
 
 152  0
                 step.setOrdem(indice2);
 153  0
                 stepAnterior.setOrdem(indice1);
 154  0
 
 155  0
                 Fluxo flow = (Fluxo) useCase.getFlows().get(this.selectedFlow);
 156  0
 
 157  0
                 ((Fluxo) useCase.getFlows().get(this.selectedFlow)).getSteps()
 158  0
                         .set(selectStep, stepAnterior);
 159  0
 
 160  0
                 ((Fluxo) useCase.getFlows().get(this.selectedFlow)).getSteps()
 161  0
                         .set(selectStep + 1, step);
 162  0
 
 163  0
                 DAOStep daoStep = new DAOStep();
 164  0
 
 165  0
                 try {
 166  0
 
 167  0
                     daoStep.update(step, flow, useCase);
 168  0
                     daoStep.update(stepAnterior, flow, useCase);
 169  0
 
 170  0
                 } catch (Exception e1) {
 171  0
                     ControladorErro.trata(e1, this);
 172  0
                 }
 173  0
 
 174  0
                 steps.setVisible(false);
 175  0
                 steps.revalidate();
 176  0
                 steps.setVisible(true);
 177  0
 
 178  0
                 steps.changeSelection(selectStep + 1, 1, false, false);
 179  0
 
 180  0
             }
 181  0
 
 182  0
             if (e.getActionCommand().equals("SubirLinha")) {
 183  0
 
 184  0
                 int selectStep = steps.getSelectedRow();
 185  0
 
 186  0
                 Step step = (Step) ((Fluxo) useCase.getFlows().get(
 187  0
                         this.selectedFlow)).getSteps().get(selectStep);
 188  0
 
 189  0
                 Step stepAnterior = (Step) ((Fluxo) useCase.getFlows().get(
 190  0
                         this.selectedFlow)).getSteps().get(selectStep - 1);
 191  0
 
 192  0
                 int indice1 = step.getOrdem();
 193  0
                 int indice2 = stepAnterior.getOrdem();
 194  0
 
 195  0
                 if (indice1 == indice2) {
 196  0
                     indice1 = indice2 + 1;
 197  0
                 }
 198  0
 
 199  0
                 step.setOrdem(indice2);
 200  0
                 stepAnterior.setOrdem(indice1);
 201  0
 
 202  0
                 Fluxo flow = (Fluxo) useCase.getFlows().get(this.selectedFlow);
 203  0
 
 204  0
                 ((Fluxo) useCase.getFlows().get(this.selectedFlow)).getSteps()
 205  0
                         .set(selectStep, stepAnterior);
 206  0
 
 207  0
                 ((Fluxo) useCase.getFlows().get(this.selectedFlow)).getSteps()
 208  0
                         .set(selectStep - 1, step);
 209  0
 
 210  0
                 this.atualiza();
 211  0
 
 212  0
                 steps.changeSelection(selectStep - 1, 1, false, false);
 213  0
 
 214  0
                 DAOStep daoStep = new DAOStep();
 215  
 
 216  0
                 try {
 217  0
 
 218  0
                     daoStep.update(step, flow, useCase);
 219  0
                     daoStep.update(stepAnterior, flow, useCase);
 220  0
 
 221  0
                 } catch (Exception e1) {
 222  0
                     ControladorErro.trata(e1, this);
 223  0
                 }
 224  
 
 225  0
             }
 226  0
 
 227  0
             if (e.getActionCommand().equals("InserirPasso")) {
 228  0
                 Step step = new Step();
 229  0
                 step.setDescricao(descricao.getText());
 230  0
                 Fluxo flow = (Fluxo) useCase.getFlows().get(this.selectedFlow);
 231  0
 
 232  0
                 ControladorStep controlador = new ControladorStep();
 233  0
                 controlador.inserirPasso(step, flow);
 234  0
 
 235  0
                 this.atualiza();
 236  0
 
 237  0
             }
 238  0
 
 239  0
             if (e.getActionCommand().equals("DeletarPasso")) {
 240  0
                 if (Global.confirma("Passo") == 0) {
 241  0
                     Step step = (Step) ((Fluxo) useCase.getFlows().get(
 242  0
                             this.selectedFlow)).getSteps().get(
 243  0
                             steps.getSelectedRow());
 244  0
                     Fluxo flow = (Fluxo) useCase.getFlows().get(
 245  0
                             this.selectedFlow);
 246  0
 
 247  0
                     if (step.getId() != 0) {
 248  0
 
 249  0
                         ControladorStep controlador = new ControladorStep();
 250  0
                         controlador.deletarStep(step, useCase, flow);
 251  0
                     }
 252  0
 
 253  0
                     this.atualiza();
 254  0
                 }
 255  
 
 256  
             }
 257  0
 
 258  0
             if (e.getActionCommand().equals("Executa")) {
 259  0
                 Step step = (Step) ((Fluxo) this.useCase.getFlows().get(
 260  0
                         this.selectedFlow)).getSteps().get(
 261  0
                         steps.getSelectedRow());
 262  0
                 ScriptRunner script = new ScriptRunner();
 263  0
                 script.run(step.getTipoObjeto(), step.getPalavraChave(), "");
 264  0
 
 265  0
             }
 266  0
             if (e.getActionCommand().equals("Colar")) {
 267  0
 
 268  0
                 String conteudo = Util.getClipboardContents();
 269  0
 
 270  0
                 String[] linhas = conteudo.split("\n");
 271  0
 
 272  0
                 for (int i = 0; i <= linhas.length - 1; i++) {
 273  0
 
 274  0
                     String descricaoAux = linhas[i].toString();
 275  0
                     if (descricaoAux.replaceAll(" ", "").length() > 0) {
 276  0
 
 277  0
                         Step step = new Step();
 278  0
                         step.setDescricao(linhas[i]);
 279  0
                         Fluxo flow = (Fluxo) useCase.getFlows().get(
 280  0
                                 this.selectedFlow);
 281  0
                         DAOStep dao = new DAOStep();
 282  0
                         try {
 283  0
                             step = dao.insert(step, flow);
 284  0
                             ((Fluxo) useCase.getFlows().get(this.selectedFlow))
 285  0
                                     .getSteps().add(step);
 286  0
                         } catch (Exception e1) {
 287  0
                             ControladorErro.trata(e1, this);
 288  0
                         }
 289  0
 
 290  0
                         this.atualiza();
 291  0
                     }
 292  
 
 293  
                 }
 294  0
 
 295  0
             }
 296  0
             if (e.getActionCommand().equals("Imagem")) {
 297  0
 
 298  0
                 int selectedFlowCombo = comboBox.getSelectedIndex();
 299  0
 
 300  0
                 Fluxo flow = ((Fluxo) useCase.getFlows().get(selectedFlowCombo));
 301  0
                 FileDialog dialog = new FileDialog(Global.getMidpane());
 302  0
                 dialog.setVisible(true);
 303  0
                 Step step = (Step) flow.getSteps().get(steps.getSelectedRow());
 304  0
                 File is = new File(dialog.getDirectory() + dialog.getFile());
 305  0
 
 306  0
                 step.setImagem(is);
 307  0
 
 308  0
                 DAOStep dao = new DAOStep();
 309  0
                 dao.updateImagem(step, flow, useCase);
 310  0
 
 311  0
             }
 312  0
             if (e.getActionCommand().equals("VisualizarImagem")) {
 313  0
                 Step step = (Step) ((Fluxo) this.useCase.getFlows().get(
 314  0
                         this.selectedFlow)).getSteps().get(
 315  0
                         steps.getSelectedRow());
 316  0
                 DAOStep dao = new DAOStep();
 317  0
                 try {
 318  0
                     ImageIcon image = dao.selectImage(step);
 319  0
                     JFrame frame = new JFrame();
 320  0
                     JLabel label = new JLabel(image);
 321  0
                     frame.getContentPane().add(label, BorderLayout.CENTER);
 322  0
                     frame.pack();
 323  0
                     frame.setVisible(true);
 324  0
                 } catch (Exception e1) {
 325  0
                     ControladorErro.trata(e1, this);
 326  0
                 }
 327  0
 
 328  0
             }
 329  0
 
 330  0
             if (e.getActionCommand().equals("DeletarDado")) {
 331  0
                 Logger logger = Util.getLogger();
 332  0
 
 333  0
                 int selectedFlowCombo = comboBox.getSelectedIndex();
 334  0
                 int selectStep = steps.getSelectedRow();
 335  0
                 int selectData = datas.getSelectedRow();
 336  0
 
 337  0
                 Step step = (Step) ((Fluxo) this.useCase.getFlows().get(
 338  0
                         this.selectedFlow)).getSteps().get(selectStep);
 339  0
 
 340  0
                 Fluxo flow = ((Fluxo) this.useCase.getFlows().get(
 341  0
                         selectedFlowCombo));
 342  
 
 343  0
                 DadosTeste data = (DadosTeste) step.getDatas().get(selectData);
 344  0
 
 345  0
                 logger.info("Deletando dado " + data.getName());
 346  0
 
 347  0
                 step.getDatas().remove(data);
 348  0
 
 349  0
                 flow.getSteps().set(selectStep, step);
 350  0
 
 351  0
                 ControladorData controlador = new ControladorData();
 352  0
                 controlador.deletarDado(data, step);
 353  0
 
 354  0
                 this.atualiza();
 355  
             }
 356  0
 
 357  0
             if (e.getActionCommand().equals("AtualizarFlow")) {
 358  0
                 Logger logger = Util.getLogger();
 359  0
 
 360  0
                 Fluxo flow = ((Fluxo) this.useCase.getFlows().get(
 361  0
                         this.selectedFlow));
 362  0
                 flow.setDuvidas(duvidas.getText());
 363  0
                 flow.setAmbiente(ambiente.getText());
 364  0
 
 365  0
                 logger.info("Atualizando fluxo " + flow.getName());
 366  
 
 367  0
                 if ((flow.getIdFlow() != 0)) {
 368  0
                     FlowController controlador = new FlowController();
 369  0
                     controlador.atualiza(flow, this.useCase);
 370  
 
 371  
                 }
 372  0
 
 373  0
                 this.useCase.getFlows().set(this.selectedFlow, flow);
 374  0
 
 375  0
                 this.atualiza();
 376  0
             }
 377  0
 
 378  0
             if (e.getActionCommand().equals("InserirRegra")) {
 379  0
 
 380  0
                 int selectedFlowCombo = comboBox.getSelectedIndex();
 381  
 
 382  0
                 int selectStep = steps.getSelectedRow();
 383  0
                 int selectRegra = comboRegras.getSelectedIndex();
 384  
 
 385  0
                 Step step = (Step) ((Fluxo) this.useCase.getFlows().get(
 386  0
                         this.selectedFlow)).getSteps().get(selectStep);
 387  
 
 388  0
                 Fluxo flow = ((Fluxo) this.useCase.getFlows().get(
 389  0
                         selectedFlowCombo));
 390  0
 
 391  0
                 ArrayList<RegraNegocio> arrayRegras = new ArrayList<RegraNegocio>(
 392  0
                         useCase.getRegras());
 393  
 
 394  0
                 RegraNegocio data = (RegraNegocio) arrayRegras.get(selectRegra);
 395  0
 
 396  0
                 if (data.getId() != 0) {
 397  0
 
 398  0
                     ((Fluxo) this.useCase.getFlows().get(this.selectedFlow))
 399  0
                             .getSteps().set(selectStep, step);
 400  0
 
 401  0
                     ControladorStep controlador = new ControladorStep();
 402  0
                     controlador.inserirRegra(data, step, flow);
 403  0
 
 404  0
                     this.atualiza();
 405  
                 } else {
 406  0
                     JOptionPane.showMessageDialog(null,
 407  0
                             "Grave o projeto antes de realizar a opera��o");
 408  0
                 }
 409  0
             }
 410  0
 
 411  0
             if (e.getActionCommand().equals("DeletarLink")) {
 412  0
                 int selectLink = links.getSelectedRow();
 413  0
                 Link link = (Link) ((Step) ((Fluxo) this.useCase.getFlows()
 414  0
                         .get(this.selectedFlow)).getSteps().get(
 415  0
                         steps.getSelectedRow())).getLinks().get(selectLink);
 416  0
 
 417  0
                 FlowController controlador = new FlowController();
 418  0
                 controlador.deletarLink(link);
 419  
 
 420  0
                 ((Step) ((Fluxo) this.useCase.getFlows().get(this.selectedFlow))
 421  0
                         .getSteps().get(steps.getSelectedRow())).getLinks()
 422  0
                         .remove(link);
 423  0
 
 424  0
                 this.atualiza();
 425  0
 
 426  0
             }
 427  0
 
 428  0
             if (e.getActionCommand().equals("InserirLink")) {
 429  0
                 int selectedFlowCombo = comboBox.getSelectedIndex();
 430  0
                 int selectStep = steps.getSelectedRow();
 431  0
                 int numeroStep = Integer.parseInt(stepLink.getText()) - 1;
 432  0
 
 433  0
                 Step step = (Step) ((Fluxo) this.useCase.getFlows().get(
 434  0
                         this.selectedFlow)).getSteps().get(selectStep);
 435  0
 
 436  0
                 Fluxo flow = ((Fluxo) this.useCase.getFlows().get(
 437  0
                         selectedFlowCombo));
 438  0
 
 439  0
                 ((Fluxo) this.useCase.getFlows().get(this.selectedFlow))
 440  0
                         .getSteps().set(selectStep, step);
 441  0
 
 442  0
                 FlowController controlador = new FlowController();
 443  0
                 controlador.inserirLink(step, flow, numeroStep, useCase);
 444  0
 
 445  0
                 this.atualiza();
 446  0
             }
 447  0
         } catch (Exception e1) {
 448  0
             ControladorErro.trata(e1, this);
 449  
         }
 450  0
 
 451  0
     }
 452  0
 
 453  0
     public void mouseClicked(MouseEvent e) {
 454  0
         JTable steps = (JTable) this.getTables().get(0);
 455  0
         JTable regras = (JTable) this.getTables().get(1);
 456  0
         JTable datas = (JTable) this.getTables().get(2);
 457  0
         JTable links = (JTable) this.getTables().get(3);
 458  0
         JTextField descricao = (JTextField) this.getTextFields().get(0);
 459  0
         Fluxo flow = (Fluxo) useCase.getFlows().get(selectedFlow);
 460  0
         Step step = (Step) flow.getSteps().get(steps.getSelectedRow());
 461  0
         links.revalidate();
 462  0
         datas.revalidate();
 463  0
         regras.revalidate();
 464  0
 
 465  0
         descricao.setText(step.getDescricao());
 466  0
 
 467  0
     }
 468  0
 
 469  
     public void keyTyped(KeyEvent e) {
 470  0
         // TODO Auto-generated method stub
 471  
 
 472  0
     }
 473  0
 
 474  
     public void keyPressed(KeyEvent e) {
 475  0
         // TODO Auto-generated method stub
 476  
 
 477  0
     }
 478  0
 
 479  
     public void keyReleased(KeyEvent e) {
 480  0
         // TODO Auto-generated method stub
 481  
 
 482  0
     }
 483  
 
 484  
 }