Skip to content

Commit eaece3a

Browse files
author
Tom Gottfried
committed
Let table models know the type of their rows
Leverages compile time checks to avoid arbitrary objects in rows.
1 parent c1cf74a commit eaece3a

65 files changed

Lines changed: 299 additions & 442 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/de/bielefeld/umweltamt/aui/mappings/DatabaseAtlQuery.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ public static Messstelle getKlaerschlammProbepunkt(
10121012
*/
10131013

10141014

1015-
public static Object[] findSielhaut(String search)
1015+
public static List<Object[]> findSielhaut(String search)
10161016
{
10171017

10181018
boolean bSearch = (search != null && search.length() > 0);
@@ -1026,9 +1026,8 @@ public static Object[] findSielhaut(String search)
10261026
query += "ORDER BY s.PSielhaut DESC, s.PFirmenprobe DESC, o.inaktiv ASC, s.bezeichnung ASC" ;
10271027

10281028

1029-
List sielhaut = HibernateSessionFactory.currentSession().createQuery(query).list();
1030-
1031-
return (Object[]) sielhaut.toArray();
1029+
return HibernateSessionFactory.currentSession()
1030+
.createQuery(query, Object[].class).list();
10321031
}
10331032

10341033

src/de/bielefeld/umweltamt/aui/module/AwsvKontrollenAuswertung.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public String getCategory() {
168168
}
169169
}
170170

171-
class WiedervorlageSVModel extends ListTableModel {
171+
class WiedervorlageSVModel extends ListTableModel<Kontrollen> {
172172
private static final long serialVersionUID = 8869570451383123968L;
173173

174174
public WiedervorlageSVModel() {
@@ -185,9 +185,8 @@ public WiedervorlageSVModel() {
185185
}
186186

187187
@Override
188-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
188+
public Object getColumnValue(Kontrollen vk, int columnIndex) {
189189
Object tmp;
190-
Kontrollen vk = (Kontrollen) objectAtRow;
191190

192191
switch (columnIndex) {
193192
case 0:

src/de/bielefeld/umweltamt/aui/module/AwsvVerwaltungsverfAuswertung.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public String getCategory() {
168168
}
169169
}
170170

171-
class WiedervorlageVVModel extends ListTableModel {
171+
class WiedervorlageVVModel extends ListTableModel<Verwaltungsverf> {
172172
private static final long serialVersionUID = -325284569406149762L;
173173

174174
public WiedervorlageVVModel() {
@@ -185,9 +185,8 @@ public WiedervorlageVVModel() {
185185
}
186186

187187
@Override
188-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
188+
public Object getColumnValue(Verwaltungsverf vf, int columnIndex) {
189189
Object tmp;
190-
Verwaltungsverf vf = (Verwaltungsverf) objectAtRow;
191190

192191
switch (columnIndex) {
193192
case 0:

src/de/bielefeld/umweltamt/aui/module/common/AdresseChooser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,31 @@ public AdresseChooser(Object initial, HauptFrame frame, String caller) {
8383
this.frame = frame;
8484
this.caller = caller;
8585

86-
List<Object> initialList = new ArrayList<Object>();
87-
initialList.add(initial);
88-
8986
if (initial instanceof Adresse && caller == "adresse") {
9087
setTitle("Adresse auswählen");
9188
this.adresse = (Adresse) initial;
9289
this.adresseModel = new BasisAdresseModel();
9390
if (this.adresse.getId() != null) {
91+
List<Adresse> initialList = new ArrayList<>();
92+
initialList.add(this.adresse);
9493
this.adresseModel.setList(initialList);
9594
}
9695
} else if (initial instanceof Inhaber && caller == "betreiber") {
9796
setTitle("Inhaber auswählen");
9897
this.inhaber = (Inhaber) initial;
9998
this.inhaberModel = new BasisInhaberModel();
10099
if (this.inhaber.getId() != null) {
100+
List<Inhaber> initialList = new ArrayList<>();
101+
initialList.add(this.inhaber);
101102
this.inhaberModel.setList(initialList);
102103
}
103104
} else if (initial instanceof Standort && caller == "standort") {
104105
setTitle("Standort auswählen");
105106
this.standort = (Standort) initial;
106107
this.standortModel = new BasisStandortModel();
107108
if (this.standort.getId() != null) {
109+
List<Standort> initialList = new ArrayList<>();
110+
initialList.add(this.standort);
108111
this.standortModel.setList(initialList);
109112
}
110113
} else {

src/de/bielefeld/umweltamt/aui/module/common/editors/AwsvEditor.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ private JPanel getVerwGebuehrenTab() {
19391939
* Ein editierbares TableModel für die Vaws-Anlagenchronologie.
19401940
* @author David Klotz
19411941
*/
1942-
class VawsAnlagenChronoModel extends EditableListTableModel {
1942+
class VawsAnlagenChronoModel extends EditableListTableModel<Anlagenchrono> {
19431943
private static final long serialVersionUID = -2520120636324926275L;
19441944
private List<Anlagenchrono> geloeschte;
19451945
private Fachdaten fachdaten;
@@ -1966,8 +1966,9 @@ public void setFachdaten(Fachdaten fachdaten) {
19661966
}
19671967

19681968
@Override
1969-
public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
1970-
Anlagenchrono chrono = (Anlagenchrono) objectAtRow;
1969+
public void editObject(
1970+
Anlagenchrono chrono, int columnIndex, Object newValue
1971+
) {
19711972
String tmp = "";
19721973
if (newValue instanceof String) {
19731974
tmp = (String) newValue;
@@ -2016,16 +2017,15 @@ public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
20162017
}
20172018

20182019
@Override
2019-
public Object newObject() {
2020+
public Anlagenchrono newObject() {
20202021
Anlagenchrono chr = new Anlagenchrono();
20212022
chr.setFachdaten(fachdaten);
20222023
chr.setDatum(new Date());
20232024
return chr;
20242025
}
20252026

20262027
@Override
2027-
public boolean objectRemoved(Object objectAtRow) {
2028-
Anlagenchrono chrono = (Anlagenchrono) objectAtRow;
2028+
public boolean objectRemoved(Anlagenchrono chrono) {
20292029
if (chrono.getId() != null) {
20302030
geloeschte.add(chrono);
20312031
}
@@ -2043,8 +2043,7 @@ public List<Anlagenchrono> getGeloeschte() {
20432043
* (java.lang.Object, int)
20442044
*/
20452045
@Override
2046-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
2047-
Anlagenchrono ac = (Anlagenchrono) objectAtRow;
2046+
public Object getColumnValue(Anlagenchrono ac, int columnIndex) {
20482047
Object tmp;
20492048

20502049
switch (columnIndex) {
@@ -2106,7 +2105,7 @@ public void updateList() {
21062105
* (Sachverständigenprüfung).
21072106
* @author David Klotz
21082107
*/
2109-
class VawsKontrollenModel extends EditableListTableModel {
2108+
class VawsKontrollenModel extends EditableListTableModel<Kontrollen> {
21102109
private static final long serialVersionUID = 1747805482011126348L;
21112110
private List<Kontrollen> geloeschte;
21122111
private Fachdaten fachdaten;
@@ -2134,8 +2133,7 @@ public void setFachdaten(Fachdaten fachdaten) {
21342133
}
21352134

21362135
@Override
2137-
public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
2138-
Kontrollen ktrl = (Kontrollen) objectAtRow;
2136+
public void editObject(Kontrollen ktrl, int columnIndex, Object newValue) {
21392137
String tmp = "";
21402138
if (newValue instanceof String) {
21412139
tmp = (String) newValue;
@@ -2183,7 +2181,7 @@ public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
21832181
}
21842182

21852183
@Override
2186-
public Object newObject() {
2184+
public Kontrollen newObject() {
21872185
Kontrollen ktr = new Kontrollen();
21882186
ktr.setFachdaten(fachdaten);
21892187
ktr.setPruefdatum(new Date());
@@ -2192,8 +2190,7 @@ public Object newObject() {
21922190
}
21932191

21942192
@Override
2195-
public boolean objectRemoved(Object objectAtRow) {
2196-
Kontrollen ktr = (Kontrollen) objectAtRow;
2193+
public boolean objectRemoved(Kontrollen ktr) {
21972194
if (ktr.getId() != null) {
21982195
geloeschte.add(ktr);
21992196
}
@@ -2211,8 +2208,7 @@ public List<Kontrollen> getGeloeschte() {
22112208
* (java.lang.Object, int)
22122209
*/
22132210
@Override
2214-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
2215-
Kontrollen ac = (Kontrollen) objectAtRow;
2211+
public Object getColumnValue(Kontrollen ac, int columnIndex) {
22162212
Object tmp;
22172213

22182214
switch (columnIndex) {
@@ -2277,7 +2273,7 @@ public void updateList() {
22772273
* Ein editierbares TableModel für die VawsVerwaltungsverfahren.
22782274
* @author David Klotz
22792275
*/
2280-
class VerwVerfahrenModel extends EditableListTableModel {
2276+
class VerwVerfahrenModel extends EditableListTableModel<Verwaltungsverf> {
22812277
private static final long serialVersionUID = -7932308301889587228L;
22822278
private List<Verwaltungsverf> geloeschte;
22832279
private Fachdaten fachdaten;
@@ -2304,8 +2300,9 @@ public void setFachdaten(Fachdaten fachdaten) {
23042300
}
23052301

23062302
@Override
2307-
public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
2308-
Verwaltungsverf verf = (Verwaltungsverf) objectAtRow;
2303+
public void editObject(
2304+
Verwaltungsverf verf, int columnIndex, Object newValue
2305+
) {
23092306
String tmp = "";
23102307
if (newValue instanceof String) {
23112308
tmp = (String) newValue;
@@ -2350,7 +2347,7 @@ public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
23502347
}
23512348

23522349
@Override
2353-
public Object newObject() {
2350+
public Verwaltungsverf newObject() {
23542351
Verwaltungsverf verf = new Verwaltungsverf();
23552352
verf.setFachdaten(fachdaten);
23562353
verf.setWvverwverf(false);
@@ -2359,8 +2356,7 @@ public Object newObject() {
23592356
}
23602357

23612358
@Override
2362-
public boolean objectRemoved(Object objectAtRow) {
2363-
Verwaltungsverf verf = (Verwaltungsverf) objectAtRow;
2359+
public boolean objectRemoved(Verwaltungsverf verf) {
23642360
if (verf.getId() != null) {
23652361
geloeschte.add(verf);
23662362
}
@@ -2378,8 +2374,7 @@ public List<Verwaltungsverf> getGeloeschte() {
23782374
* (java.lang.Object, int)
23792375
*/
23802376
@Override
2381-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
2382-
Verwaltungsverf verf = (Verwaltungsverf) objectAtRow;
2377+
public Object getColumnValue(Verwaltungsverf verf, int columnIndex) {
23832378
Object tmp;
23842379

23852380
switch (columnIndex) {
@@ -2440,7 +2435,7 @@ public void updateList() {
24402435
* Ein editierbares TableModel für die VawsVerwaltungsverfahren.
24412436
* @author David Klotz
24422437
*/
2443-
class VerwGebuehrenModel extends EditableListTableModel {
2438+
class VerwGebuehrenModel extends EditableListTableModel<Verwaltungsgebuehren> {
24442439
private static final long serialVersionUID = 8662150283828728780L;
24452440
private List<Verwaltungsgebuehren> geloeschte;
24462441
private Fachdaten fachdaten;
@@ -2467,8 +2462,9 @@ public void setFachdaten(Fachdaten fachdaten) {
24672462
}
24682463

24692464
@Override
2470-
public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
2471-
Verwaltungsgebuehren gebuehr = (Verwaltungsgebuehren) objectAtRow;
2465+
public void editObject(
2466+
Verwaltungsgebuehren gebuehr, int columnIndex, Object newValue
2467+
) {
24722468
String tmp = "";
24732469
if (newValue instanceof String) {
24742470
tmp = (String) newValue;
@@ -2511,7 +2507,7 @@ public void editObject(Object objectAtRow, int columnIndex, Object newValue) {
25112507
}
25122508

25132509
@Override
2514-
public Object newObject() {
2510+
public Verwaltungsgebuehren newObject() {
25152511
Verwaltungsgebuehren gebuehr = new Verwaltungsgebuehren();
25162512
gebuehr.setBetrag(new Float(0.0));
25172513
gebuehr.setAbschnitt("360.12 LW");
@@ -2521,8 +2517,7 @@ public Object newObject() {
25212517
}
25222518

25232519
@Override
2524-
public boolean objectRemoved(Object objectAtRow) {
2525-
Verwaltungsgebuehren gebuehr = (Verwaltungsgebuehren) objectAtRow;
2520+
public boolean objectRemoved(Verwaltungsgebuehren gebuehr) {
25262521
if (gebuehr.getId() != null) {
25272522
geloeschte.add(gebuehr);
25282523
}
@@ -2540,8 +2535,9 @@ public List<Verwaltungsgebuehren> getGeloeschte() {
25402535
* (java.lang.Object, int)
25412536
*/
25422537
@Override
2543-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
2544-
Verwaltungsgebuehren gebuehr = (Verwaltungsgebuehren) objectAtRow;
2538+
public Object getColumnValue(
2539+
Verwaltungsgebuehren gebuehr, int columnIndex
2540+
) {
25452541
Object tmp;
25462542

25472543
switch (columnIndex) {

src/de/bielefeld/umweltamt/aui/module/common/editors/EinstellungenEditor.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public class EinstellungenEditor extends AbstractApplyEditor {
8787
private JTable einstellungenTabelle;
8888
private JLabel titel;
8989
private EinstellungenModel einstModel;
90-
private List settinglist;
90+
private List<String[]> settinglist;
9191

92-
private class EinstellungenModel extends EditableListTableModel {
92+
private class EinstellungenModel extends EditableListTableModel<String[]> {
9393
private static final long serialVersionUID = 6042681141925302970L;
9494

9595
public EinstellungenModel(SettingsManager instance) {
@@ -102,15 +102,13 @@ public EinstellungenModel(SettingsManager instance) {
102102

103103
@Override
104104
public void updateList() {
105-
106105
setList(settinglist);
107106
fireTableDataChanged();
108107
}
109108

110109
@Override
111-
public Object getColumnValue(Object objectAtRow, int columnIndex) {
110+
public Object getColumnValue(String[] row, int columnIndex) {
112111
Object value;
113-
Object[] row = (Object[]) objectAtRow;
114112
switch (columnIndex) {
115113
// Parameter
116114
case 0:
@@ -123,41 +121,33 @@ public Object getColumnValue(Object objectAtRow, int columnIndex) {
123121
default:
124122
value = null;
125123
}
126-
127124
return value;
128125
}
129126

130127
@Override
131-
public void editObject(Object objectAtRow, int columnIndex,
132-
Object newValue) {
133-
Object[] row = (Object[]) objectAtRow;
134-
128+
public void editObject(String[] row, int columnIndex, Object newValue) {
135129
switch (columnIndex) {
136130
case 0:
137131
String tmpPara = (String) newValue;
138132
row[0] = tmpPara;
139133
break;
140-
141134
case 1:
142135
String tmpWert = (String) newValue;
143136
row[1] = tmpWert;
144137
_instance.setSetting((String)row[0], tmpWert, true);
145138
break;
146-
147139
default:
148140
break;
149141
}
150-
151142
}
152143

153144
@Override
154-
public Object newObject() {
155-
return _instance;
145+
public String[] newObject() {
146+
return new String[2];
156147
}
157148

158-
@Override
159-
public boolean objectRemoved(Object objectAtRow) {
160-
149+
@Override
150+
public boolean objectRemoved(String[] objectAtRow) {
161151
return true;
162152
}
163153
}
@@ -249,7 +239,6 @@ protected boolean doSave() {
249239
@Override
250240
protected void doApply() {
251241
// TODO Auto-generated method stub
252-
253242
}
254243

255244
private JTable getEinstellungenTabelle() {

0 commit comments

Comments
 (0)