Blame view

BRIC/src/GUI/InsertEventGUI.java 13.4 KB
eeb5cac08   Madiel de Souza Conserva Filho   first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package GUI;
  
  import LOGIC.BoolType;
  import LOGIC.Channel;
  import LOGIC.Contract;
  import LOGIC.Datatype;
  import LOGIC.EventChannel;
  import LOGIC.Internacional;
  import LOGIC.IntervalType;
  import LOGIC.ObjectList;
  import LOGIC.Protocols;
  import java.awt.AWTException;
  import java.awt.Robot;
  import java.awt.event.ActionEvent;
  import java.awt.event.KeyEvent;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.JOptionPane;
  import javax.swing.table.DefaultTableModel;
  
  /**
   *
   * @author sarah
   */
  public class InsertEventGUI extends javax.swing.JFrame {
  
      /**
       * Creates new form InsertEventGUI
       */
      public InsertEventGUI(Internacional inter, Channel c, Contract contrato, ObjectList listas, String tipo) {
          this.c = c;
          this.inter = inter;
          tipos = new String[c.getType().size() + 1];
          nome = c.getName() + ".";
          for (int i = 0; i < c.getType().size(); i++) {
  
              if (i == c.getType().size() - 1) {
                  nome = nome + c.getType().get(i).getNome();
              } else {
                  nome = nome + c.getType().get(i).getNome() + ".";
              }
          }
  
          tipos[0] = c.getName();
          for (int i = 1; i < c.getType().size() + 1; i++) {
              tipos[i] = c.getType().get(i - 1).getNome();
             // System.out.println(c.getType().get(i - 1).getNome());
          }
          tTipo = new DefaultTableModel(null, tipos);
  
          if (c.getType().isEmpty()) {
          } else {
              String[] linha = new String[]{null};
              tTipo.addRow(linha);
              for (int j = -1; j < c.getType().size(); j++) {
                  //if (VerificaI(c.getType().get(j).getEvento())){
                  tTipo.addColumn(linha);
              }
              tTipo.setValueAt(c.getName(), 0, 0);
          }
          initComponents();
          tTipo.setColumnCount(tipos.length);
  
          channel.setText(nome);
          this.listas = listas;
          this.contrato = contrato;
          this.tipo = tipo;
          bundleButtons();
      }
      Channel c;
      String[] tipos;
      String nome = "";
      DefaultTableModel tTipo;
      ObjectList listas;
      Contract contrato;
      String tipo;
      Internacional inter;
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          finish = new javax.swing.JButton();
          cancel = new javax.swing.JButton();
          defina = new javax.swing.JLabel();
          channel = new javax.swing.JLabel();
          jScrollPane1 = new javax.swing.JScrollPane();
          tabela = new javax.swing.JTable();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setMinimumSize(new java.awt.Dimension(308, 160));
  
          finish.setText("Concluir");
          finish.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  finishActionPerformed(evt);
              }
          });
  
          cancel.setText("Cancelar");
          cancel.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  cancelActionPerformed(evt);
              }
          });
  
          defina.setText("Defina os valores para o canal:");
  
          channel.setText("canal");
  
          tabela.setModel(tTipo);
          tabela.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt) {
                  tabelaMouseClicked(evt);
              }
          });
          jScrollPane1.setViewportView(tabela);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(layout.createSequentialGroup()
                          .addGap(12, 12, 12)
                          .addComponent(channel)
                          .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                      .addGroup(layout.createSequentialGroup()
                          .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                  .addGap(0, 0, Short.MAX_VALUE)
                                  .addComponent(cancel)
                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                  .addComponent(finish))
                              .addGroup(layout.createSequentialGroup()
                                  .addComponent(defina)
                                  .addGap(0, 0, Short.MAX_VALUE)))
                          .addContainerGap())))
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(defina)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(channel)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(18, 18, 18)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(finish)
                      .addComponent(cancel))
                  .addContainerGap())
          );
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
          ContractGUI.aberto = false;
          this.dispose();        // TODO add your handling code here:
      }//GEN-LAST:event_cancelActionPerformed
  
      private void finishActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishActionPerformed
          
          
          
          tabela.selectAll();
  
          String aux = (String) tabela.getValueAt(0, 0);
          String aux2 = (String) tabela.getValueAt(0, 1);
          //if (aux2 == null) {
          //    JOptionPane.showMessageDialog(null, "coloque pelo menos um tipo para que seja um evento...");
  //        } else {
              if (aux.equals(c.getName())) {
                  if (checaTipos()) {
                      String evento;
                      evento = criaEvento();
                      System.out.println(evento);
                      EventChannel e = new EventChannel();
                      e.criaEvento(c, evento);
                      //System.out.println("olha o sufixo aquiiii .... "+evento);
                      contrato.getEvents().add(e);
                      //System.out.println("sufixoooooooo... "+e.getSufixo());
                      if (tipo.equals("in")) {
                          contrato.getIn().add(e);
                          if(verificaC()){
                              c.setFlag("in");
                              contrato.getChannel().add(c);
                          }
                      }
                      if (tipo.equals("out")) {
                          contrato.getOut().add(e);
                          if(verificaC()){
                              c.setFlag("out");
                              contrato.getChannel().add(c);
                          }
                      }
                      if (tipo.equals("cc")){
                          if(verificaP(c.getName()+evento)){
                              Protocols p = new Protocols();
                              p.setCanal(c);
                              p.setDualProtocol("");
                              p.setProtocol("");
                              p.setCc(c.getName()+evento);
                              contrato.getProtocolos().add(p);
                              if(verificaC()){
                                  c.setFlag("cc");
                                  contrato.getChannel().add(c);
                                  
                              }
                          }
                          else{
                              JOptionPane.showMessageDialog(null, "Esse canal de comunicação já existe");
                          }
                      }
                      this.dispose();
                  } else {
                  }
              } 
              else {
                  JOptionPane.showMessageDialog(null, "O canal não é mais o mesmo...");
              }
  //        }
          // TODO add your handling code here:
      }//GEN-LAST:event_finishActionPerformed
  
      private void tabelaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaMouseClicked
          // TODO add your handling code here:
      }//GEN-LAST:event_tabelaMouseClicked
  
      
      public boolean verificaP(String c){
          for(int i = 0; i<contrato.getProtocolos().size(); i++){
              if (contrato.getProtocolos().get(i).getCc().equals(c)){
                  return false;
              }
          }
          
          return true;
      }
      
      public boolean checaTipos() {
          for (int i = 1; i < tabela.getColumnCount(); i++) {
              String aux = (String) tabela.getValueAt(0, i);
             // System.out.println("string: " + aux);
              if (aux == null) {
              } else {
                  if (checaString(c.getType().get(i - 1), aux)) {
                  } else {
                      JOptionPane.showMessageDialog(null, "erro no tipo numero " + i + " (" + tipos[i] + ")");
                      return false;
                  }
              }
          }
          return true;
      }
  
      public boolean checaString(LOGIC.Type t, String s) {
        //  System.out.println(s);
          if (s.equals("")) {
              return true;
          }
          if (t instanceof Datatype) {
              Datatype data = null;
              data = (Datatype) t;
              for (int i = 0; i < data.getDatatype().size(); i++) {
                  if (s.equals(data.getDatatype().get(i).getName())) {
                     // System.out.println("data true " + s);
                      return true;
                  }
              }
          }
          if (t instanceof IntervalType) {
              IntervalType inter = null;
              inter = (IntervalType) t;
              if (Integer.parseInt(s) <= inter.getMax() && Integer.parseInt(s) >= inter.getMim()) {
                //  System.out.println("inter true " + s);
                  return true;
  
              } else {
                 // System.out.println("inter false " + s + " min: " + inter.getMim() + " max: " + inter.getMax());
              }
          }
          if (t instanceof BoolType) {
              if (s.equals("true") || s.equals("false")) {
                //  System.out.println("bool true " + s);
                  return true;
              } else {
                  System.out.println("bool false " + s);
              }
          }
          return false;
      }
  
      public String criaEvento() {
          String e;
          String aux2 = (String) tabela.getValueAt(0, 1);
          if (aux2 == null) {
              e = "";
          } else {
              e = ".";
          }
  
          for (int i = 1; i < tabela.getColumnCount(); i++) {
              String aux = (String) tabela.getValueAt(0, i);
              String aux1 = "uhu";
              if (i < tabela.getColumnCount() - 1) {
                  aux1 = (String) tabela.getValueAt(0, i + 1);
              }
              if (aux == null) {
                  break;
              }
              if (i == tabela.getColumnCount() - 1 || aux1 == null) {
                  e = e + aux;
              } else {
                  e = e + aux + ".";
              }
  
          }
          return e;
      }
      public boolean verificaC(){
          for(int i = 0; i<contrato.getChannel().size(); i++){
              if(c==contrato.getChannel().get(i)){
                  return false;
              }
          }
          return true;
      }
      
      public void bundleButtons(){
          defina.setText(inter.retornarMensagem("COD0045"));
          channel.setText(inter.retornarMensagem("COD0002"));
          cancel.setText(inter.retornarMensagem("COD0026"));
          finish.setText(inter.retornarMensagem("COD0025"));
      }
  
      /**
       * @param args the command line arguments
       */
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JButton cancel;
      private javax.swing.JLabel channel;
      private javax.swing.JLabel defina;
      private javax.swing.JButton finish;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JTable tabela;
      // End of variables declaration//GEN-END:variables
  }