1 | |
package br.mia.test.view.tabelas; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
|
5 | |
import javax.swing.JTable; |
6 | |
import javax.swing.table.AbstractTableModel; |
7 | |
|
8 | |
import br.mia.test.controler.ControladorErro; |
9 | |
import br.mia.test.seguranca.Vulnerabilidade; |
10 | |
import br.mia.test.seguranca.VulnerabilidadeValor; |
11 | |
|
12 | 0 | public class TabelaModeloValoresVulnerabilidade extends AbstractTableModel { |
13 | |
|
14 | |
private JTable tipos; |
15 | |
|
16 | |
private ArrayList<Vulnerabilidade> tiposVulnerabilidade; |
17 | |
|
18 | |
private static final long serialVersionUID = -4369190215976405393L; |
19 | |
|
20 | |
public String getColumnName(int arg0) { |
21 | |
|
22 | 0 | String[] nomes = { "Valor", "Observacao" }; |
23 | |
|
24 | 0 | return nomes[arg0]; |
25 | |
} |
26 | |
|
27 | |
public int getColumnCount() { |
28 | 0 | return 2; |
29 | |
} |
30 | |
|
31 | |
public int getRowCount() { |
32 | |
|
33 | |
try { |
34 | 0 | int selected = tipos.getSelectedRow(); |
35 | 0 | if (selected == -1) { |
36 | 0 | return 0; |
37 | |
} else { |
38 | 0 | if (this.tiposVulnerabilidade.size() > 0) { |
39 | 0 | Vulnerabilidade vulnerabilidade = (Vulnerabilidade) tiposVulnerabilidade |
40 | 0 | .get(selected); |
41 | 0 | return vulnerabilidade.getValues().size(); |
42 | |
} else { |
43 | 0 | return 0; |
44 | |
} |
45 | |
} |
46 | 0 | } catch (Exception e) { |
47 | 0 | return 1; |
48 | |
} |
49 | |
} |
50 | |
|
51 | |
public Object getValueAt(int arg0, int arg1) { |
52 | |
try { |
53 | 0 | int selected = tipos.getSelectedRow(); |
54 | |
|
55 | 0 | Vulnerabilidade vulnerabilidade = (Vulnerabilidade) this.tiposVulnerabilidade |
56 | 0 | .get(selected); |
57 | |
|
58 | 0 | VulnerabilidadeValor vulnerabilidadeValor = (VulnerabilidadeValor) vulnerabilidade |
59 | 0 | .getValues().get(arg0); |
60 | |
|
61 | 0 | if (arg1 == 0) { |
62 | |
|
63 | 0 | return vulnerabilidadeValor.getValor().toString(); |
64 | |
} |
65 | 0 | if (arg1 == 1) { |
66 | |
|
67 | 0 | return vulnerabilidadeValor.getObservacao(); |
68 | |
} |
69 | 0 | } catch (Exception e) { |
70 | 0 | ControladorErro.trata(e, this); |
71 | |
} |
72 | |
|
73 | 0 | return null; |
74 | |
} |
75 | |
|
76 | |
@SuppressWarnings("unchecked") |
77 | |
public Class getColumnClass(int c) { |
78 | |
try { |
79 | 0 | return getValueAt(0, c).getClass(); |
80 | 0 | } catch (Exception e) { |
81 | 0 | return "Deletado".getClass(); |
82 | |
} |
83 | |
} |
84 | |
|
85 | |
public boolean isCellEditable(int arg0, int arg1) { |
86 | |
|
87 | 0 | return true; |
88 | |
} |
89 | |
|
90 | |
public static long getSerialVersionUID() { |
91 | 0 | return serialVersionUID; |
92 | |
} |
93 | |
|
94 | |
public JTable getTipos() { |
95 | 0 | return tipos; |
96 | |
} |
97 | |
|
98 | |
public void setTipos(JTable datas) { |
99 | 0 | this.tipos = datas; |
100 | 0 | } |
101 | |
|
102 | |
public ArrayList<Vulnerabilidade> getTiposVulnerabilidade() { |
103 | 0 | return tiposVulnerabilidade; |
104 | |
} |
105 | |
|
106 | |
public void setTiposVulnerabilidade( |
107 | |
ArrayList<Vulnerabilidade> tiposVulnerabilidade) { |
108 | 0 | this.tiposVulnerabilidade = tiposVulnerabilidade; |
109 | 0 | } |
110 | |
|
111 | |
} |