17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.task.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.sql.Configuration;
|
|
|
17 |
import org.openconcerto.sql.model.SQLBase;
|
|
|
18 |
import org.openconcerto.sql.model.SQLDataSource;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
21 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
22 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
23 |
import org.openconcerto.sql.model.Where;
|
|
|
24 |
import org.openconcerto.sql.users.User;
|
|
|
25 |
import org.openconcerto.task.UserTaskRight;
|
|
|
26 |
|
|
|
27 |
import java.awt.Font;
|
|
|
28 |
import java.awt.GridBagConstraints;
|
|
|
29 |
import java.awt.GridBagLayout;
|
|
|
30 |
import java.awt.Insets;
|
|
|
31 |
import java.awt.event.MouseAdapter;
|
|
|
32 |
import java.awt.event.MouseEvent;
|
|
|
33 |
import java.sql.SQLException;
|
|
|
34 |
import java.util.List;
|
|
|
35 |
import java.util.Map;
|
|
|
36 |
|
|
|
37 |
import javax.swing.ImageIcon;
|
|
|
38 |
import javax.swing.JLabel;
|
|
|
39 |
import javax.swing.JList;
|
|
|
40 |
import javax.swing.JPanel;
|
|
|
41 |
import javax.swing.JScrollPane;
|
|
|
42 |
import javax.swing.JSeparator;
|
|
|
43 |
import javax.swing.ListModel;
|
|
|
44 |
|
|
|
45 |
public class UserRightPanelDetail extends JPanel {
|
|
|
46 |
|
|
|
47 |
JLabel labelDocumentation1 = new JLabel("");
|
|
|
48 |
JLabel labelDocumentation2 = new JLabel("");
|
|
|
49 |
UserTaskRightListModel model = new UserTaskRightListModel();
|
|
|
50 |
UserTaskRightListCellRenderer cellRenderer1 = new UserTaskRightListCellRenderer(UserTaskRightListCellRenderer.READ);
|
|
|
51 |
UserTaskRightListCellRenderer cellRenderer2 = new UserTaskRightListCellRenderer(UserTaskRightListCellRenderer.MODIFY);
|
|
|
52 |
UserTaskRightListCellRenderer cellRenderer3 = new UserTaskRightListCellRenderer(UserTaskRightListCellRenderer.ADD);
|
|
|
53 |
UserTaskRightListCellRenderer cellRenderer4 = new UserTaskRightListCellRenderer(UserTaskRightListCellRenderer.VALIDATE);
|
|
|
54 |
private User selectedUser;
|
|
|
55 |
private JList list1;
|
|
|
56 |
private JList list2;
|
|
|
57 |
private JList list3;
|
|
|
58 |
private JList list4;
|
|
|
59 |
|
|
|
60 |
UserRightPanelDetail() {
|
|
|
61 |
this.setLayout(new GridBagLayout());
|
|
|
62 |
GridBagConstraints c = new GridBagConstraints();
|
|
|
63 |
c.insets = new Insets(4, 10, 2, 2);
|
|
|
64 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
65 |
c.gridx = 0;
|
|
|
66 |
c.gridy = 0;
|
|
|
67 |
c.gridwidth = 4;
|
|
|
68 |
labelDocumentation1.setFont(labelDocumentation1.getFont().deriveFont(Font.BOLD));
|
|
|
69 |
this.add(labelDocumentation1, c);
|
|
|
70 |
c.gridy++;
|
|
|
71 |
c.insets = new Insets(0, 10, 10, 2);
|
|
|
72 |
this.add(labelDocumentation2, c);
|
|
|
73 |
c.gridy++;
|
|
|
74 |
c.insets = new Insets(0, 0, 0, 0);
|
|
|
75 |
this.add(new JSeparator(JSeparator.HORIZONTAL), c);
|
|
|
76 |
|
|
|
77 |
c.fill = GridBagConstraints.BOTH;
|
|
|
78 |
c.insets = new Insets(2, 10, 2, 10);
|
|
|
79 |
//
|
|
|
80 |
c.gridwidth = 1;
|
|
|
81 |
c.weightx = 1;
|
|
|
82 |
int YTOP = c.gridy + 1;
|
|
|
83 |
|
|
|
84 |
c.gridy = YTOP;
|
|
|
85 |
c.weighty = 0;
|
|
|
86 |
JLabel label1 = new JLabel("Voir les tâches assignées à:");
|
|
|
87 |
this.add(label1, c);
|
|
|
88 |
c.gridy++;
|
|
|
89 |
list1 = new JList(model);
|
|
|
90 |
list1.addMouseListener(new MouseAdapter() {
|
|
|
91 |
public void mouseClicked(MouseEvent e) {
|
|
|
92 |
swapOnDoubleClick(list1, e, "READ");
|
|
|
93 |
}
|
|
|
94 |
});
|
|
|
95 |
list1.setCellRenderer(cellRenderer1);
|
|
|
96 |
c.weighty = 1;
|
|
|
97 |
this.add(new JScrollPane(list1), c);
|
|
|
98 |
//
|
|
|
99 |
c.gridx++;
|
|
|
100 |
c.gridy = YTOP;
|
|
|
101 |
c.weighty = 0;
|
|
|
102 |
JLabel label2 = new JLabel("Modifier les tâches créées par:");
|
|
|
103 |
|
|
|
104 |
this.add(label2, c);
|
|
|
105 |
c.gridy++;
|
|
|
106 |
list2 = new JList(model);
|
|
|
107 |
list2.addMouseListener(new MouseAdapter() {
|
|
|
108 |
public void mouseClicked(MouseEvent e) {
|
|
|
109 |
swapOnDoubleClick(list2, e, "MODIFY");
|
|
|
110 |
}
|
|
|
111 |
});
|
|
|
112 |
list2.setCellRenderer(cellRenderer2);
|
|
|
113 |
c.weighty = 1;
|
|
|
114 |
this.add(new JScrollPane(list2), c);
|
|
|
115 |
//
|
|
|
116 |
c.gridx++;
|
|
|
117 |
c.gridy = YTOP;
|
|
|
118 |
c.weighty = 0;
|
|
|
119 |
JLabel label3 = new JLabel("Assigner des tâches à:");
|
|
|
120 |
this.add(label3, c);
|
|
|
121 |
c.gridy++;
|
|
|
122 |
list3 = new JList(model);
|
|
|
123 |
list3.addMouseListener(new MouseAdapter() {
|
|
|
124 |
public void mouseClicked(MouseEvent e) {
|
|
|
125 |
swapOnDoubleClick(list3, e, "ADD");
|
|
|
126 |
}
|
|
|
127 |
});
|
|
|
128 |
list3.setCellRenderer(cellRenderer3);
|
|
|
129 |
c.weighty = 1;
|
|
|
130 |
this.add(new JScrollPane(list3), c);
|
|
|
131 |
//
|
|
|
132 |
c.gridx++;
|
|
|
133 |
c.gridy = YTOP;
|
|
|
134 |
c.weighty = 0;
|
|
|
135 |
JLabel label4 = new JLabel("Valider les tâches de:");
|
|
|
136 |
this.add(label4, c);
|
|
|
137 |
c.gridy++;
|
|
|
138 |
list4 = new JList(model);
|
|
|
139 |
list4.addMouseListener(new MouseAdapter() {
|
|
|
140 |
public void mouseClicked(MouseEvent e) {
|
|
|
141 |
swapOnDoubleClick(list4, e, "VALIDATE");
|
|
|
142 |
}
|
|
|
143 |
});
|
|
|
144 |
list4.setCellRenderer(cellRenderer4);
|
|
|
145 |
c.weighty = 1;
|
|
|
146 |
this.add(new JScrollPane(list4), c);
|
|
|
147 |
|
|
|
148 |
c.weighty = 0;
|
|
|
149 |
c.gridy++;
|
|
|
150 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
151 |
c.gridx = 0;
|
|
|
152 |
c.gridwidth = 4;
|
|
|
153 |
JLabel labelHelp = new JLabel("Une autorisation désactivée apparait en gris clair");
|
|
|
154 |
labelHelp.setIcon(new ImageIcon(this.getClass().getResource("toc_open.gif")));
|
|
|
155 |
this.add(labelHelp, c);
|
|
|
156 |
|
|
|
157 |
setUser(null);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* @param list
|
|
|
162 |
* @param e
|
|
|
163 |
*/
|
|
|
164 |
private void swapOnDoubleClick(final JList list, MouseEvent e, String field) {
|
|
|
165 |
if (e.getClickCount() == 2) {
|
|
|
166 |
int index = list.locationToIndex(e.getPoint());
|
|
|
167 |
ListModel dlm = list.getModel();
|
|
|
168 |
Object item = dlm.getElementAt(index);
|
|
|
169 |
list.ensureIndexIsVisible(index);
|
|
|
170 |
User toUser = (User) item;
|
|
|
171 |
swapState(selectedUser, toUser, field);
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
protected void swapState(User user, User toUser, String field) {
|
|
|
177 |
System.out.println("Double clicked on " + toUser);
|
|
|
178 |
|
|
|
179 |
final SQLBase defaultBase = Configuration.getInstance().getBase();
|
|
|
180 |
final SQLTable tableTacheRights = defaultBase.getTable("TACHE_RIGHTS");
|
|
|
181 |
|
|
|
182 |
SQLRowValues rowV = new SQLRowValues(tableTacheRights);
|
|
|
183 |
rowV.put("ID_USER_COMMON", user.getId());
|
|
|
184 |
rowV.put("ID_USER_COMMON_TO", toUser.getId());
|
|
|
185 |
rowV.put(field, Boolean.TRUE);
|
|
|
186 |
SQLSelect sel = new SQLSelect(defaultBase);
|
65 |
ilm |
187 |
sel.addSelectStar(tableTacheRights);
|
17 |
ilm |
188 |
Where where = new Where(tableTacheRights.getField("ID_USER_COMMON"), "=", user.getId());
|
|
|
189 |
where = where.and(new Where(tableTacheRights.getField("ID_USER_COMMON_TO"), "=", toUser.getId()));
|
|
|
190 |
sel.setWhere(where);
|
|
|
191 |
|
|
|
192 |
SQLDataSource dataSource = defaultBase.getDataSource();
|
|
|
193 |
final Map valuesMap = dataSource.execute1(sel.asString());
|
|
|
194 |
if (valuesMap != null) {
|
|
|
195 |
SQLRow row = new SQLRow(tableTacheRights, valuesMap);
|
|
|
196 |
rowV.loadAbsolutelyAll(row);
|
|
|
197 |
if (rowV.getObject(field).equals(Boolean.TRUE)) {
|
|
|
198 |
rowV.put(field, Boolean.FALSE);
|
|
|
199 |
} else {
|
|
|
200 |
rowV.put(field, Boolean.TRUE);
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
try {
|
|
|
205 |
rowV.commit();
|
|
|
206 |
} catch (SQLException e1) {
|
|
|
207 |
// TODO Auto-generated catch block
|
|
|
208 |
e1.printStackTrace();
|
|
|
209 |
}
|
|
|
210 |
model.clearAndReload();
|
|
|
211 |
setUser(this.selectedUser);
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public void setUser(User selectedUser) {
|
|
|
215 |
// TODO Auto-generated method stub
|
|
|
216 |
if (selectedUser == null) {
|
|
|
217 |
labelDocumentation1.setText(" Veuillez sélectionner un utilisateur");
|
|
|
218 |
labelDocumentation2.setText(" Pour cela, cliquez sur un nom de la liste de gauche");
|
|
|
219 |
list1.setEnabled(false);
|
|
|
220 |
list2.setEnabled(false);
|
|
|
221 |
list3.setEnabled(false);
|
|
|
222 |
list4.setEnabled(false);
|
|
|
223 |
return;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
this.selectedUser = selectedUser;
|
|
|
227 |
|
63 |
ilm |
228 |
labelDocumentation1.setText(" Autorisations de l'utilisateur " + selectedUser.getFirstName() + " " + selectedUser.getName());
|
17 |
ilm |
229 |
labelDocumentation2.setText(" Double cliquez sur un nom d'une des colonnes suivantes pour activer/désactiver le droit correspondant.");
|
|
|
230 |
List<UserTaskRight> l = UserTaskRight.getUserTaskRight(selectedUser);
|
|
|
231 |
cellRenderer1.setUserTaskRight(l);
|
|
|
232 |
cellRenderer2.setUserTaskRight(l);
|
|
|
233 |
cellRenderer3.setUserTaskRight(l);
|
|
|
234 |
cellRenderer4.setUserTaskRight(l);
|
|
|
235 |
model.clearAndReload();
|
|
|
236 |
list1.setEnabled(true);
|
|
|
237 |
list2.setEnabled(true);
|
|
|
238 |
list3.setEnabled(true);
|
|
|
239 |
list4.setEnabled(true);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
}
|