1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.user.national;
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 import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
27 import fr.ifremer.quadrige3.ui.swing.table.editor.ButtonCellEditor;
28 import fr.ifremer.quadrige3.ui.swing.table.renderer.ButtonCellRenderer;
29 import fr.ifremer.reefdb.dto.referential.PersonDTO;
30 import fr.ifremer.reefdb.service.StatusFilter;
31 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.menu.UserMenuUIModel;
32 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.privileges.PrivilegesDialogUI;
33 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.table.UserRowModel;
34 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.table.UserTableModel;
35 import fr.ifremer.reefdb.ui.swing.content.manage.referential.user.table.UserTableUIModel;
36 import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableModel;
37 import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbTableUIHandler;
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40 import org.jdesktop.swingx.table.TableColumnExt;
41
42 import java.awt.Dimension;
43 import java.util.List;
44
45 import static org.nuiton.i18n.I18n.t;
46
47
48
49
50 public class ManageUsersNationalUIHandler extends AbstractReefDbTableUIHandler<UserRowModel, UserTableUIModel, ManageUsersNationalUI> {
51
52
53
54
55 private static final Log LOG = LogFactory.getLog(ManageUsersNationalUIHandler.class);
56
57
58 @Override
59 public void beforeInit(ManageUsersNationalUI ui) {
60 super.beforeInit(ui);
61
62
63 UserTableUIModel model = new UserTableUIModel();
64 ui.setContextValue(model);
65
66 }
67
68
69 @Override
70 public void afterInit(ManageUsersNationalUI ui) {
71 initUI(ui);
72
73
74 ui.getUserMenuUI().getHandler().enableContextFilter(false);
75
76
77 ui.getUserMenuUI().getHandler().forceLocal(false);
78
79
80 ui.getUserMenuUI().getModel().addPropertyChangeListener(UserMenuUIModel.PROPERTY_RESULTS, evt -> getModel().setBeans((List<PersonDTO>) evt.getNewValue()));
81
82 initTable();
83
84 }
85
86 private void initTable() {
87
88
89 TableColumnExt lastnameCol = addColumn(UserTableModel.LASTNAME);
90 lastnameCol.setSortable(true);
91
92
93 TableColumnExt firstnameCol = addColumn(UserTableModel.FIRSTNAME);
94 firstnameCol.setSortable(true);
95
96
97
98 TableColumnExt depCol = addFilterableComboDataColumnToModel(
99 UserTableModel.DEPARTMENT,
100 getContext().getReferentialService().getDepartments(),
101 true);
102 depCol.setSortable(true);
103
104
105 TableColumnExt emailCol = addColumn(UserTableModel.EMAIL);
106 emailCol.setSortable(true);
107
108
109 TableColumnExt phoneCol = addColumn(UserTableModel.PHONE);
110 phoneCol.setSortable(true);
111
112
113 addCommentColumn(UserTableModel.COMMENT, false);
114 TableColumnExt creationDateCol = addDatePickerColumnToModel(UserTableModel.CREATION_DATE, getConfig().getDateTimeFormat(), false);
115 fixColumnWidth(creationDateCol, 120);
116 TableColumnExt updateDateCol = addDatePickerColumnToModel(UserTableModel.UPDATE_DATE, getConfig().getDateTimeFormat(), false);
117 fixColumnWidth(updateDateCol, 120);
118
119
120 TableColumnExt statusCol = addFilterableComboDataColumnToModel(
121 UserTableModel.STATUS,
122 getContext().getReferentialService().getStatus(StatusFilter.ALL),
123 false);
124 statusCol.setSortable(true);
125
126
127 TableColumnExt privilegesCol = addColumn(
128 new ButtonCellEditor() {
129 @Override
130 public void onButtonCellAction(int row, int column) {
131
132 PrivilegesDialogUI dialog = new PrivilegesDialogUI(getContext());
133 int rowModelIndex = getTable().convertRowIndexToModel(row);
134 UserRowModel rowModel = getTableModel().getEntry(rowModelIndex);
135 dialog.getModel().setUser(rowModel);
136 dialog.getModel().setEditable(false);
137 openDialog(dialog, new Dimension(600, 200));
138 }
139
140 },
141 new ButtonCellRenderer<Integer>(),
142 UserTableModel.PRIVILEGES);
143 privilegesCol.setMaxWidth(100);
144 privilegesCol.setWidth(100);
145 privilegesCol.setSortable(false);
146
147
148
149
150 TableColumnExt idCol = addColumn(UserTableModel.REG_CODE);
151 idCol.setSortable(true);
152 fixColumnWidth(idCol, 80);
153
154
155 TableColumnExt intranetLoginCol = addColumn(UserTableModel.INTRANET_LOGIN);
156 intranetLoginCol.setSortable(true);
157
158
159 TableColumnExt extranetLoginCol = addColumn(UserTableModel.EXTRANET_LOGIN);
160 extranetLoginCol.setSortable(true);
161
162
163 TableColumnExt addressCol = addColumn(UserTableModel.ADDRESS);
164 addressCol.setSortable(true);
165
166
167 TableColumnExt organismCol = addColumn(UserTableModel.ORGANISM);
168 organismCol.setSortable(true);
169
170
171 TableColumnExt adminCenterCol = addColumn(UserTableModel.ADMIN_CENTER);
172 adminCenterCol.setSortable(true);
173
174
175 TableColumnExt siteCol = addColumn(UserTableModel.SITE);
176 siteCol.setSortable(true);
177
178
179 UserTableModel tableModel = new UserTableModel(getTable().getColumnModel(), false);
180 getTable().setModel(tableModel);
181
182
183 addExportToCSVAction(t("reefdb.property.users.national"), UserTableModel.PRIVILEGES);
184
185
186 initTable(getTable(), true);
187
188
189 tableModel.setNoneEditableCols(
190 UserTableModel.REG_CODE,
191 UserTableModel.FIRSTNAME,
192 UserTableModel.LASTNAME,
193 UserTableModel.DEPARTMENT,
194 UserTableModel.EMAIL,
195 UserTableModel.PHONE,
196 UserTableModel.STATUS,
197 UserTableModel.ADDRESS,
198 UserTableModel.INTRANET_LOGIN,
199 UserTableModel.EXTRANET_LOGIN,
200 UserTableModel.ORGANISM,
201 UserTableModel.ADMIN_CENTER,
202 UserTableModel.SITE);
203
204
205 idCol.setVisible(false);
206 intranetLoginCol.setVisible(false);
207 extranetLoginCol.setVisible(false);
208 addressCol.setVisible(false);
209 organismCol.setVisible(false);
210 adminCenterCol.setVisible(false);
211 siteCol.setVisible(false);
212
213 creationDateCol.setVisible(false);
214 updateDateCol.setVisible(false);
215
216
217 getTable().setVisibleRowCount(5);
218 }
219
220
221 @Override
222 public AbstractReefDbTableModel<UserRowModel> getTableModel() {
223 return (UserTableModel) getTable().getModel();
224 }
225
226
227 @Override
228 public SwingTable getTable() {
229 return ui.getManageUsersNationalTable();
230 }
231
232 }