View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.user.national;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
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   * Controlleur pour la gestion des Users au niveau national
49   */
50  public class ManageUsersNationalUIHandler extends AbstractReefDbTableUIHandler<UserRowModel, UserTableUIModel, ManageUsersNationalUI> {
51  
52      /**
53       * Logger.
54       */
55      private static final Log LOG = LogFactory.getLog(ManageUsersNationalUIHandler.class);
56  
57      /** {@inheritDoc} */
58      @Override
59      public void beforeInit(ManageUsersNationalUI ui) {
60          super.beforeInit(ui);
61          
62          // create model and register to the JAXX context
63          UserTableUIModel model = new UserTableUIModel();
64          ui.setContextValue(model);
65  
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public void afterInit(ManageUsersNationalUI ui) {
71          initUI(ui);
72  
73          // hide 'apply filter'
74          ui.getUserMenuUI().getHandler().enableContextFilter(false);
75  
76          // force national
77          ui.getUserMenuUI().getHandler().forceLocal(false);
78  
79          // listen to search results
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          // lastname
89          TableColumnExt lastnameCol = addColumn(UserTableModel.LASTNAME);
90          lastnameCol.setSortable(true);
91  
92          // firstname
93          TableColumnExt firstnameCol = addColumn(UserTableModel.FIRSTNAME);
94          firstnameCol.setSortable(true);
95  
96  
97          // department
98          TableColumnExt depCol = addFilterableComboDataColumnToModel(
99                  UserTableModel.DEPARTMENT,
100                 getContext().getReferentialService().getDepartments(),
101                 true);
102         depCol.setSortable(true);
103 
104         // email
105         TableColumnExt emailCol = addColumn(UserTableModel.EMAIL);
106         emailCol.setSortable(true);
107 
108         // phone
109         TableColumnExt phoneCol = addColumn(UserTableModel.PHONE);
110         phoneCol.setSortable(true);
111 
112         // Comment, creation and update dates
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         // status
120         TableColumnExt statusCol = addFilterableComboDataColumnToModel(
121                 UserTableModel.STATUS,
122                 getContext().getReferentialService().getStatus(StatusFilter.ALL),
123                 false);
124         statusCol.setSortable(true);
125 
126         // privileges
127         TableColumnExt privilegesCol = addColumn(
128                 new ButtonCellEditor() {
129                     @Override
130                     public void onButtonCellAction(int row, int column) {
131                         // show popup + set beans
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         /* non visible cols */
148 
149         // matricule
150         TableColumnExt idCol = addColumn(UserTableModel.REG_CODE);
151         idCol.setSortable(true);
152         fixColumnWidth(idCol, 80);
153 
154         // intranet login
155         TableColumnExt intranetLoginCol = addColumn(UserTableModel.INTRANET_LOGIN);
156         intranetLoginCol.setSortable(true);
157 
158         // extranet login
159         TableColumnExt extranetLoginCol = addColumn(UserTableModel.EXTRANET_LOGIN);
160         extranetLoginCol.setSortable(true);
161 
162         // address
163         TableColumnExt addressCol = addColumn(UserTableModel.ADDRESS);
164         addressCol.setSortable(true);
165 
166         // organism
167         TableColumnExt organismCol = addColumn(UserTableModel.ORGANISM);
168         organismCol.setSortable(true);
169 
170         // admin center
171         TableColumnExt adminCenterCol = addColumn(UserTableModel.ADMIN_CENTER);
172         adminCenterCol.setSortable(true);
173 
174         // site
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         // Add extraction action
183         addExportToCSVAction(t("reefdb.property.users.national"), UserTableModel.PRIVILEGES);
184 
185         // Initialisation du tableau
186         initTable(getTable(), true);
187 
188         // all columns cannot be edited
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         // optionnal columns are hidden
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     /** {@inheritDoc} */
221     @Override
222     public AbstractReefDbTableModel<UserRowModel> getTableModel() {
223         return (UserTableModel) getTable().getModel();
224     }
225 
226     /** {@inheritDoc} */
227     @Override
228     public SwingTable getTable() {
229         return ui.getManageUsersNationalTable();
230     }
231 
232 }