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;
|
|
|
15 |
|
73 |
ilm |
16 |
import static org.openconcerto.task.TM.getTM;
|
142 |
ilm |
17 |
|
|
|
18 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRowListRSH;
|
17 |
ilm |
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.sql.users.UserManager;
|
|
|
26 |
import org.openconcerto.sql.users.UserTableCellRenderer;
|
|
|
27 |
import org.openconcerto.task.ui.UserComboBox;
|
|
|
28 |
import org.openconcerto.task.ui.UserTableCellEditor;
|
|
|
29 |
import org.openconcerto.ui.JMultiLineToolTip;
|
|
|
30 |
import org.openconcerto.ui.LightEventJTable;
|
|
|
31 |
import org.openconcerto.ui.ReloadPanel;
|
|
|
32 |
import org.openconcerto.ui.TitledSeparator;
|
|
|
33 |
import org.openconcerto.ui.table.AlternateTableCellRenderer;
|
|
|
34 |
import org.openconcerto.ui.table.IconTableCellRenderer;
|
|
|
35 |
import org.openconcerto.ui.table.JCheckBoxTableCellRender;
|
21 |
ilm |
36 |
import org.openconcerto.ui.table.TablePopupMouseListener;
|
17 |
ilm |
37 |
import org.openconcerto.ui.table.TimestampTableCellEditor;
|
|
|
38 |
import org.openconcerto.ui.table.TimestampTableCellRenderer;
|
67 |
ilm |
39 |
import org.openconcerto.utils.ExceptionHandler;
|
17 |
ilm |
40 |
import org.openconcerto.utils.TableSorter;
|
21 |
ilm |
41 |
import org.openconcerto.utils.cc.ITransformer;
|
17 |
ilm |
42 |
|
|
|
43 |
import java.awt.Color;
|
|
|
44 |
import java.awt.Component;
|
|
|
45 |
import java.awt.Graphics;
|
|
|
46 |
import java.awt.GridBagConstraints;
|
|
|
47 |
import java.awt.GridBagLayout;
|
|
|
48 |
import java.awt.Insets;
|
|
|
49 |
import java.awt.Point;
|
|
|
50 |
import java.awt.event.ActionEvent;
|
|
|
51 |
import java.awt.event.ActionListener;
|
80 |
ilm |
52 |
import java.awt.event.ItemEvent;
|
|
|
53 |
import java.awt.event.ItemListener;
|
17 |
ilm |
54 |
import java.awt.event.MouseEvent;
|
|
|
55 |
import java.awt.event.MouseListener;
|
|
|
56 |
import java.net.URL;
|
|
|
57 |
import java.util.ArrayList;
|
|
|
58 |
import java.util.Calendar;
|
|
|
59 |
import java.util.Date;
|
|
|
60 |
import java.util.List;
|
|
|
61 |
import java.util.Vector;
|
|
|
62 |
|
|
|
63 |
import javax.swing.AbstractAction;
|
|
|
64 |
import javax.swing.Action;
|
80 |
ilm |
65 |
import javax.swing.BorderFactory;
|
17 |
ilm |
66 |
import javax.swing.DefaultCellEditor;
|
|
|
67 |
import javax.swing.Icon;
|
|
|
68 |
import javax.swing.ImageIcon;
|
|
|
69 |
import javax.swing.JButton;
|
|
|
70 |
import javax.swing.JCheckBox;
|
|
|
71 |
import javax.swing.JCheckBoxMenuItem;
|
|
|
72 |
import javax.swing.JFrame;
|
|
|
73 |
import javax.swing.JLabel;
|
|
|
74 |
import javax.swing.JMenu;
|
|
|
75 |
import javax.swing.JMenuBar;
|
|
|
76 |
import javax.swing.JPanel;
|
21 |
ilm |
77 |
import javax.swing.JPopupMenu;
|
17 |
ilm |
78 |
import javax.swing.JScrollPane;
|
|
|
79 |
import javax.swing.JTable;
|
|
|
80 |
import javax.swing.JTextField;
|
|
|
81 |
import javax.swing.JToolTip;
|
|
|
82 |
import javax.swing.SwingConstants;
|
|
|
83 |
import javax.swing.SwingUtilities;
|
144 |
ilm |
84 |
import javax.swing.SwingWorker;
|
17 |
ilm |
85 |
import javax.swing.event.AncestorEvent;
|
|
|
86 |
import javax.swing.event.AncestorListener;
|
|
|
87 |
import javax.swing.event.ChangeEvent;
|
|
|
88 |
import javax.swing.event.ListSelectionEvent;
|
|
|
89 |
import javax.swing.event.ListSelectionListener;
|
21 |
ilm |
90 |
import javax.swing.table.DefaultTableCellRenderer;
|
17 |
ilm |
91 |
import javax.swing.table.JTableHeader;
|
|
|
92 |
import javax.swing.table.TableCellRenderer;
|
|
|
93 |
import javax.swing.table.TableColumn;
|
|
|
94 |
import javax.swing.table.TableColumnModel;
|
|
|
95 |
|
|
|
96 |
public class TodoListPanel extends JPanel implements ModelStateListener {
|
|
|
97 |
|
144 |
ilm |
98 |
private final UserManager uMngr;
|
17 |
ilm |
99 |
// Actions
|
|
|
100 |
private final JCheckBox detailCheckBox;
|
|
|
101 |
private final JCheckBox hideOldCheckBox;
|
|
|
102 |
private JMenu comboUser;
|
|
|
103 |
private final JButton addButton, removeButton;
|
|
|
104 |
|
|
|
105 |
// Table
|
|
|
106 |
private final LightEventJTable t;
|
|
|
107 |
private final TodoListModel model;
|
|
|
108 |
private final TimestampTableCellRenderer timestampTableCellRendererCreated;
|
|
|
109 |
private final TimestampTableCellRenderer timestampTableCellRendererDone;
|
|
|
110 |
private final TimestampTableCellRenderer timestampTableCellRendererDeadLine;
|
|
|
111 |
private final IconTableCellRenderer iconEditor, iconRenderer;
|
|
|
112 |
private final UserTableCellRenderer userTableCellRenderer;
|
|
|
113 |
private final JCheckBoxTableCellRender a = new JCheckBoxTableCellRender();
|
|
|
114 |
private final ImageIcon iconTache, iconPriorite;
|
|
|
115 |
private TimestampTableCellEditor timestampTableCellEditorDeadLine;
|
|
|
116 |
private TimestampTableCellEditor timestampTableCellEditorCreated;
|
|
|
117 |
private TimestampTableCellEditor timestampTableCellEditorDone;
|
|
|
118 |
private final Vector<User> users = new Vector<User>();
|
|
|
119 |
final ReloadPanel reloadPanel = new ReloadPanel();
|
|
|
120 |
TableSorter sorter;
|
|
|
121 |
|
144 |
ilm |
122 |
public TodoListPanel(final UserManager uMngr) {
|
|
|
123 |
this.uMngr = uMngr;
|
17 |
ilm |
124 |
this.setOpaque(false);
|
80 |
ilm |
125 |
this.iconTache = new ImageIcon(TodoListPanel.class.getResource("tache.png"));
|
|
|
126 |
this.iconPriorite = new ImageIcon(TodoListPanel.class.getResource("priorite.png"));
|
144 |
ilm |
127 |
this.userTableCellRenderer = new UserTableCellRenderer(uMngr);
|
17 |
ilm |
128 |
this.timestampTableCellRendererCreated = new TimestampTableCellRenderer();
|
|
|
129 |
this.timestampTableCellRendererDone = new TimestampTableCellRenderer();
|
|
|
130 |
this.timestampTableCellRendererDeadLine = new TimestampTableCellRenderer(true);
|
|
|
131 |
this.timestampTableCellEditorCreated = new TimestampTableCellEditor();
|
|
|
132 |
this.timestampTableCellEditorDone = new TimestampTableCellEditor();
|
|
|
133 |
this.timestampTableCellEditorDeadLine = new TimestampTableCellEditor();
|
|
|
134 |
// Icon renderer
|
|
|
135 |
List<URL> l = new Vector<URL>();
|
80 |
ilm |
136 |
l.add(TodoListPanel.class.getResource("empty.png"));
|
|
|
137 |
l.add(TodoListPanel.class.getResource("high.png"));
|
|
|
138 |
l.add(TodoListPanel.class.getResource("normal.png"));
|
|
|
139 |
l.add(TodoListPanel.class.getResource("low.png"));
|
17 |
ilm |
140 |
this.iconEditor = new IconTableCellRenderer(l);
|
|
|
141 |
this.iconRenderer = new IconTableCellRenderer(l);
|
|
|
142 |
|
144 |
ilm |
143 |
final User currentUser = uMngr.getCurrentUser();
|
|
|
144 |
this.model = new TodoListModel(uMngr);
|
17 |
ilm |
145 |
this.sorter = new TableSorter(this.model);
|
|
|
146 |
this.t = new LightEventJTable(this.sorter) {
|
|
|
147 |
public JToolTip createToolTip() {
|
|
|
148 |
return new JMultiLineToolTip();
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
@Override
|
|
|
152 |
public String getToolTipText(MouseEvent event) {
|
|
|
153 |
String r = null;
|
|
|
154 |
TodoListElement task = getTaskAt(event.getPoint());
|
|
|
155 |
|
|
|
156 |
if (task != null && task.getCreatorId() > 1) {
|
|
|
157 |
final String comment = task.getComment();
|
|
|
158 |
if (comment != null) {
|
|
|
159 |
r = comment;
|
|
|
160 |
r += "\n\n";
|
|
|
161 |
} else {
|
|
|
162 |
r = "";
|
|
|
163 |
}
|
144 |
ilm |
164 |
r += getTM().trM("assignedBy", "user", uMngr.getUser(task.getCreatorId()).getFullName(), "date", task.getDate());
|
17 |
ilm |
165 |
}
|
|
|
166 |
|
|
|
167 |
return r;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
};
|
|
|
171 |
this.sorter.setTableHeader(this.t.getTableHeader());
|
|
|
172 |
|
|
|
173 |
this.model.setTable(this.t);
|
|
|
174 |
|
73 |
ilm |
175 |
this.comboUser = new JMenu(TM.tr("showTaskAssignedTo"));
|
67 |
ilm |
176 |
initViewableUsers(currentUser);
|
17 |
ilm |
177 |
|
|
|
178 |
// L'utilisateur courant doit voir ses taches + toutes les taches dont il a les droits
|
|
|
179 |
this.model.addIdListenerSilently(Integer.valueOf(currentUser.getId()));
|
|
|
180 |
|
73 |
ilm |
181 |
final int size = this.users.size();
|
|
|
182 |
for (int i = 0; i < size; i++) {
|
17 |
ilm |
183 |
Integer id = Integer.valueOf((this.users.get(i)).getId());
|
|
|
184 |
if (this.model.listenToId(id)) {
|
|
|
185 |
((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true);
|
|
|
186 |
} else {
|
|
|
187 |
((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(false);
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
73 |
ilm |
191 |
this.addButton = new JButton(TM.tr("addTask"));
|
|
|
192 |
this.removeButton = new JButton();
|
25 |
ilm |
193 |
this.removeButton.setOpaque(false);
|
73 |
ilm |
194 |
updateDeleteBtn();
|
17 |
ilm |
195 |
this.setLayout(new GridBagLayout());
|
|
|
196 |
GridBagConstraints c = new GridBagConstraints();
|
|
|
197 |
c.insets = new Insets(2, 2, 1, 2);
|
|
|
198 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
199 |
c.gridx = 0;
|
|
|
200 |
c.gridy = 0;
|
|
|
201 |
c.weightx = 1;
|
|
|
202 |
c.weighty = 0;
|
|
|
203 |
c.gridwidth = 6;
|
|
|
204 |
// SEP
|
73 |
ilm |
205 |
TitledSeparator sep = new TitledSeparator(currentUser.getFirstName() + " " + currentUser.getName().toUpperCase());
|
17 |
ilm |
206 |
this.add(sep, c);
|
|
|
207 |
|
|
|
208 |
c.gridwidth = 1;
|
|
|
209 |
c.gridx = 0;
|
|
|
210 |
c.gridy++;
|
|
|
211 |
c.weightx = 0;
|
|
|
212 |
this.add(this.addButton, c);
|
|
|
213 |
c.gridx++;
|
|
|
214 |
this.add(this.removeButton, c);
|
|
|
215 |
|
|
|
216 |
c.anchor = GridBagConstraints.EAST;
|
|
|
217 |
c.gridx++;
|
73 |
ilm |
218 |
final JMenuBar b = new JMenuBar();
|
25 |
ilm |
219 |
b.setOpaque(false);
|
17 |
ilm |
220 |
b.setBorderPainted(false);
|
|
|
221 |
b.add(this.comboUser);
|
|
|
222 |
// Pour que le menu ne disparaisse pas quand on rapetisse trop la fenetre en bas
|
|
|
223 |
b.setMinimumSize(b.getPreferredSize());
|
|
|
224 |
this.add(b, c);
|
|
|
225 |
|
|
|
226 |
c.gridx++;
|
|
|
227 |
c.weightx = 1;
|
73 |
ilm |
228 |
this.detailCheckBox = new JCheckBox(TM.tr("showDetails"));
|
25 |
ilm |
229 |
this.detailCheckBox.setOpaque(false);
|
17 |
ilm |
230 |
this.detailCheckBox.setSelected(false);
|
|
|
231 |
this.add(this.detailCheckBox, c);
|
|
|
232 |
|
|
|
233 |
//
|
|
|
234 |
c.gridx++;
|
73 |
ilm |
235 |
this.hideOldCheckBox = new JCheckBox(TM.tr("hideHistory"));
|
25 |
ilm |
236 |
this.hideOldCheckBox.setOpaque(false);
|
17 |
ilm |
237 |
this.hideOldCheckBox.setSelected(true);
|
|
|
238 |
this.add(this.hideOldCheckBox, c);
|
|
|
239 |
|
|
|
240 |
c.gridx++;
|
|
|
241 |
|
|
|
242 |
c.weightx = 0;
|
|
|
243 |
c.anchor = GridBagConstraints.EAST;
|
25 |
ilm |
244 |
this.reloadPanel.setOpaque(false);
|
17 |
ilm |
245 |
this.add(this.reloadPanel, c);
|
|
|
246 |
|
|
|
247 |
// Table
|
|
|
248 |
c.gridwidth = 6;
|
|
|
249 |
c.gridx = 0;
|
|
|
250 |
c.gridy++;
|
|
|
251 |
c.fill = GridBagConstraints.BOTH;
|
|
|
252 |
c.weighty = 1;
|
|
|
253 |
c.weightx = 1;
|
|
|
254 |
initPopUp();
|
|
|
255 |
initTable(TodoListModel.SIMPLE_MODE);
|
|
|
256 |
this.add(new JScrollPane(this.t), c);
|
|
|
257 |
|
|
|
258 |
initListeners();
|
|
|
259 |
|
|
|
260 |
this.model.asynchronousFill();
|
|
|
261 |
}
|
|
|
262 |
|
144 |
ilm |
263 |
public final UserManager getUserManager() {
|
|
|
264 |
return this.uMngr;
|
|
|
265 |
}
|
|
|
266 |
|
67 |
ilm |
267 |
private void initViewableUsers(final User currentUser) {
|
144 |
ilm |
268 |
final SwingWorker<List<User>, Object> worker = new SwingWorker<List<User>, Object>() {
|
67 |
ilm |
269 |
|
|
|
270 |
@Override
|
142 |
ilm |
271 |
protected List<User> doInBackground() throws Exception {
|
67 |
ilm |
272 |
final List<Integer> canViewUsers = new ArrayList<Integer>();
|
|
|
273 |
for (final UserTaskRight right : UserTaskRight.getUserTaskRight(currentUser)) {
|
|
|
274 |
if (right.canRead())
|
|
|
275 |
canViewUsers.add(right.getIdToUser());
|
|
|
276 |
}
|
|
|
277 |
// final Vector users = new Vector();
|
144 |
ilm |
278 |
final SQLTable userT = getUserManager().getTable();
|
|
|
279 |
final SQLSelect select1 = new SQLSelect(false);
|
142 |
ilm |
280 |
select1.addSelectStar(userT);
|
67 |
ilm |
281 |
final Where meWhere = new Where(userT.getKey(), "=", currentUser.getId());
|
|
|
282 |
final Where canViewWhere = new Where(userT.getKey(), canViewUsers);
|
|
|
283 |
select1.setWhere(meWhere.or(canViewWhere));
|
|
|
284 |
|
142 |
ilm |
285 |
final List<User> result = new ArrayList<User>();
|
|
|
286 |
for (final SQLRow r : SQLRowListRSH.execute(select1)) {
|
|
|
287 |
result.add(new User(r));
|
|
|
288 |
}
|
67 |
ilm |
289 |
return result;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
@Override
|
|
|
293 |
protected void done() {
|
|
|
294 |
try {
|
142 |
ilm |
295 |
final List<User> tuples = get();
|
|
|
296 |
for (final User user : tuples) {
|
|
|
297 |
String displayName = user.getNickName();
|
|
|
298 |
if (displayName.length() == 0) {
|
|
|
299 |
displayName = user.getFirstName() + " " + user.getName().toUpperCase();
|
|
|
300 |
}
|
|
|
301 |
final JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(displayName);
|
67 |
ilm |
302 |
TodoListPanel.this.comboUser.add(checkBoxMenuItem);
|
|
|
303 |
|
142 |
ilm |
304 |
final int uId = user.getId();
|
67 |
ilm |
305 |
|
142 |
ilm |
306 |
TodoListPanel.this.users.add(user);
|
67 |
ilm |
307 |
checkBoxMenuItem.addActionListener(new ActionListener() {
|
|
|
308 |
|
|
|
309 |
public void actionPerformed(ActionEvent e) {
|
|
|
310 |
if (checkBoxMenuItem.isSelected())
|
|
|
311 |
addUserListenerId(uId);
|
|
|
312 |
else
|
|
|
313 |
removeUserListenerId(uId);
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
});
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
} catch (Exception e) {
|
|
|
320 |
ExceptionHandler.handle("Unable to get tasks users", e);
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
}
|
|
|
324 |
};
|
|
|
325 |
|
|
|
326 |
worker.execute();
|
|
|
327 |
|
|
|
328 |
}
|
|
|
329 |
|
17 |
ilm |
330 |
/**
|
|
|
331 |
* @param addButton
|
|
|
332 |
* @param removeButton
|
|
|
333 |
*/
|
|
|
334 |
private void initListeners() {
|
|
|
335 |
this.t.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
73 |
ilm |
336 |
@Override
|
17 |
ilm |
337 |
public void valueChanged(ListSelectionEvent e) {
|
73 |
ilm |
338 |
updateDeleteBtn();
|
17 |
ilm |
339 |
}
|
|
|
340 |
});
|
|
|
341 |
this.removeButton.addActionListener(new ActionListener() {
|
|
|
342 |
public void actionPerformed(ActionEvent e) {
|
|
|
343 |
removeSelectedTask();
|
|
|
344 |
}
|
|
|
345 |
});
|
|
|
346 |
this.addButton.addActionListener(new ActionListener() {
|
|
|
347 |
public void actionPerformed(ActionEvent e) {
|
|
|
348 |
addTask();
|
|
|
349 |
}
|
|
|
350 |
});
|
80 |
ilm |
351 |
this.detailCheckBox.addItemListener(new ItemListener() {
|
|
|
352 |
@Override
|
|
|
353 |
public void itemStateChanged(ItemEvent e) {
|
17 |
ilm |
354 |
// masque les colonnes "fait le" et "le"
|
|
|
355 |
detailCheckBoxClicked();
|
|
|
356 |
}
|
|
|
357 |
});
|
80 |
ilm |
358 |
this.hideOldCheckBox.addItemListener(new ItemListener() {
|
|
|
359 |
@Override
|
|
|
360 |
public void itemStateChanged(ItemEvent e) {
|
|
|
361 |
TodoListPanel.this.model.setHistoryVisible(e.getStateChange() == ItemEvent.DESELECTED);
|
17 |
ilm |
362 |
TodoListPanel.this.model.asynchronousFill();
|
|
|
363 |
}
|
|
|
364 |
});
|
|
|
365 |
try {
|
|
|
366 |
|
|
|
367 |
} catch (Exception e) {
|
|
|
368 |
throw new RuntimeException();
|
|
|
369 |
}
|
|
|
370 |
this.model.addModelStateListener(TodoListPanel.this);
|
|
|
371 |
this.addAncestorListener(new AncestorListener() {
|
|
|
372 |
|
|
|
373 |
public void ancestorAdded(AncestorEvent event) {
|
180 |
ilm |
374 |
if (!TodoListPanel.this.model.isAutoRefreshing()) {
|
|
|
375 |
TodoListPanel.this.model.addModelStateListener(TodoListPanel.this);
|
|
|
376 |
TodoListPanel.this.model.enableUpdate();
|
|
|
377 |
}
|
17 |
ilm |
378 |
}
|
|
|
379 |
|
|
|
380 |
public void ancestorMoved(AncestorEvent event) {
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
public void ancestorRemoved(AncestorEvent event) {
|
|
|
384 |
TodoListPanel.this.model.removeModelStateListener(TodoListPanel.this);
|
|
|
385 |
TodoListPanel.this.model.stopUpdate();
|
|
|
386 |
}
|
|
|
387 |
});
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
protected void removeSelectedTask() {
|
|
|
391 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
392 |
public void run() {
|
|
|
393 |
TodoListPanel.this.t.editingCanceled(null);
|
|
|
394 |
int index = TodoListPanel.this.t.getSelectedRow();
|
|
|
395 |
while (index >= 0) {
|
|
|
396 |
|
|
|
397 |
if (!TodoListPanel.this.model.deleteTaskAtIndex(TodoListPanel.this.sorter.modelIndex(index))) {
|
|
|
398 |
break;
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
index = TodoListPanel.this.t.getSelectedRow();
|
|
|
402 |
}
|
|
|
403 |
TodoListPanel.this.model.asynchronousFill();
|
|
|
404 |
}
|
|
|
405 |
});
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
protected void detailCheckBoxClicked() {
|
|
|
409 |
if (this.detailCheckBox.isSelected()) {
|
|
|
410 |
initTable(TodoListModel.EXTENDED_MODE);
|
|
|
411 |
} else {
|
|
|
412 |
initTable(TodoListModel.SIMPLE_MODE);
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
private void initTable(int mode) {
|
|
|
417 |
this.t.setBlockRepaint(true);
|
|
|
418 |
|
|
|
419 |
this.t.setBlockEventOnColumn(true);
|
|
|
420 |
this.model.setMode(mode);
|
|
|
421 |
|
|
|
422 |
this.t.getColumnModel().getColumn(0).setCellRenderer(this.a);
|
|
|
423 |
this.t.getColumnModel().getColumn(0).setCellEditor(this.a);
|
|
|
424 |
this.t.setBlockEventOnColumn(true);
|
|
|
425 |
setIconForColumn(0, this.iconTache);
|
|
|
426 |
setIconForColumn(1, this.iconPriorite);
|
|
|
427 |
this.t.setBlockEventOnColumn(true);
|
|
|
428 |
|
|
|
429 |
this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor);
|
|
|
430 |
final JTextField textField = new JTextField() {
|
|
|
431 |
@Override
|
|
|
432 |
public void paint(Graphics g) {
|
|
|
433 |
super.paint(g);
|
|
|
434 |
g.setColor(TodoListPanel.this.t.getGridColor());
|
|
|
435 |
g.fillRect(getWidth() - 19, 0, 1, getHeight());
|
|
|
436 |
g.setColor(new Color(250, 250, 250));
|
|
|
437 |
g.fillRect(getWidth() - 18, 0, 18, getHeight());
|
|
|
438 |
g.setColor(Color.BLACK);
|
|
|
439 |
for (int i = 0; i < 3; i++) {
|
|
|
440 |
int x = getWidth() - 14 + i * 4;
|
|
|
441 |
int y = getHeight() - 5;
|
|
|
442 |
g.fillRect(x, y, 1, 2);
|
|
|
443 |
}
|
|
|
444 |
}
|
|
|
445 |
};
|
80 |
ilm |
446 |
textField.setBorder(BorderFactory.createEmptyBorder());
|
17 |
ilm |
447 |
final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField);
|
|
|
448 |
textField.addMouseListener(new MouseListener() {
|
|
|
449 |
|
|
|
450 |
public void mouseClicked(MouseEvent e) {
|
|
|
451 |
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
public void mouseEntered(MouseEvent e) {
|
|
|
455 |
// TODO Auto-generated method stub
|
|
|
456 |
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
public void mouseExited(MouseEvent e) {
|
|
|
460 |
// TODO Auto-generated method stub
|
|
|
461 |
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
public void mousePressed(MouseEvent e) {
|
|
|
465 |
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
public void mouseReleased(MouseEvent e) {
|
|
|
469 |
if (e.getX() > textField.getWidth() - 19) {
|
|
|
470 |
TodoListElement l = getTaskAt(SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t));
|
|
|
471 |
TodoListPanel.this.t.editingCanceled(new ChangeEvent(this));
|
73 |
ilm |
472 |
JFrame f = new JFrame(TM.tr("details"));
|
17 |
ilm |
473 |
f.setContentPane(new TodoListElementEditorPanel(l));
|
|
|
474 |
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
475 |
f.setSize(500, 200);
|
|
|
476 |
f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight());
|
|
|
477 |
f.setVisible(true);
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
}
|
|
|
481 |
});
|
|
|
482 |
this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);
|
|
|
483 |
this.t.getColumnModel().getColumn(3).setMaxWidth(300);
|
|
|
484 |
this.t.getColumnModel().getColumn(3).setMinWidth(100);
|
|
|
485 |
|
|
|
486 |
this.timestampTableCellEditorCreated.stopCellEditing();
|
|
|
487 |
this.timestampTableCellEditorDone.stopCellEditing();
|
|
|
488 |
this.timestampTableCellEditorDeadLine.stopCellEditing();
|
|
|
489 |
|
|
|
490 |
if (this.model.getMode() == TodoListModel.EXTENDED_MODE) {
|
|
|
491 |
this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated);
|
|
|
492 |
this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated);
|
|
|
493 |
|
|
|
494 |
this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone);
|
|
|
495 |
this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone);
|
|
|
496 |
|
|
|
497 |
this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine);
|
|
|
498 |
this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine);
|
|
|
499 |
} else {
|
|
|
500 |
this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine);
|
|
|
501 |
this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine);
|
|
|
502 |
}
|
|
|
503 |
|
67 |
ilm |
504 |
final TableColumn userColumn = this.t.getColumnModel().getColumn(this.t.getColumnModel().getColumnCount() - 1);
|
|
|
505 |
userColumn.setCellRenderer(this.userTableCellRenderer);
|
|
|
506 |
userColumn.setMaxWidth(150);
|
|
|
507 |
userColumn.setMinWidth(100);
|
|
|
508 |
t.setEnabled(false);
|
|
|
509 |
initUserCellEditor(userColumn);
|
|
|
510 |
|
17 |
ilm |
511 |
this.t.setBlockEventOnColumn(false);
|
|
|
512 |
this.t.setBlockRepaint(false);
|
|
|
513 |
this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer);
|
25 |
ilm |
514 |
// Better look
|
|
|
515 |
this.t.setShowHorizontalLines(false);
|
|
|
516 |
this.t.setGridColor(new Color(230, 230, 230));
|
73 |
ilm |
517 |
this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4);
|
19 |
ilm |
518 |
AlternateTableCellRenderer.UTILS.setAllColumns(this.t);
|
17 |
ilm |
519 |
this.t.repaint();
|
|
|
520 |
|
|
|
521 |
}
|
|
|
522 |
|
67 |
ilm |
523 |
private void initUserCellEditor(final TableColumn userColumn) {
|
144 |
ilm |
524 |
new SwingWorker<List<UserTaskRight>, Object>() {
|
67 |
ilm |
525 |
@Override
|
|
|
526 |
protected List<UserTaskRight> doInBackground() throws Exception {
|
144 |
ilm |
527 |
return UserTaskRight.getUserTaskRight(getUserManager().getCurrentUser());
|
67 |
ilm |
528 |
}
|
|
|
529 |
|
|
|
530 |
@Override
|
|
|
531 |
protected void done() {
|
|
|
532 |
// only display allowed recipients
|
|
|
533 |
try {
|
|
|
534 |
final List<UserTaskRight> rights = get();
|
|
|
535 |
final List<User> canAddUsers = new ArrayList<User>();
|
|
|
536 |
for (final UserTaskRight right : rights) {
|
144 |
ilm |
537 |
assert right.getIdUser() == getUserManager().getCurrentUser().getId();
|
67 |
ilm |
538 |
if (right.canAdd()) {
|
144 |
ilm |
539 |
canAddUsers.add(getUserManager().getUser(right.getIdToUser()));
|
67 |
ilm |
540 |
}
|
|
|
541 |
}
|
144 |
ilm |
542 |
userColumn.setCellEditor(new UserTableCellEditor(getUserManager(), new UserComboBox(canAddUsers)));
|
67 |
ilm |
543 |
t.setEnabled(true);
|
|
|
544 |
} catch (Exception e) {
|
|
|
545 |
ExceptionHandler.handle("Unable to get user task rights", e);
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
super.done();
|
|
|
549 |
}
|
144 |
ilm |
550 |
}.execute();
|
67 |
ilm |
551 |
}
|
|
|
552 |
|
17 |
ilm |
553 |
void initPopUp() {
|
21 |
ilm |
554 |
TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() {
|
17 |
ilm |
555 |
|
21 |
ilm |
556 |
@Override
|
|
|
557 |
public JPopupMenu transformChecked(MouseEvent evt) {
|
|
|
558 |
final JTable table = (JTable) evt.getSource();
|
|
|
559 |
final int modelIndex = TodoListPanel.this.sorter.modelIndex(table.getSelectedRow());
|
|
|
560 |
final JPopupMenu res = new JPopupMenu();
|
17 |
ilm |
561 |
|
|
|
562 |
// Avancer d'un jour
|
|
|
563 |
Action act = new AbstractAction() {
|
|
|
564 |
public void actionPerformed(ActionEvent e) {
|
21 |
ilm |
565 |
final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
|
17 |
ilm |
566 |
if (element != null) {
|
|
|
567 |
final Date ts = element.getExpectedDate();
|
|
|
568 |
final Calendar cal = Calendar.getInstance();
|
|
|
569 |
cal.setTimeInMillis(ts.getTime());
|
|
|
570 |
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
571 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
572 |
public void run() {
|
|
|
573 |
ts.setTime(cal.getTimeInMillis());
|
|
|
574 |
element.setExpectedDate(ts);
|
|
|
575 |
element.commitChangesAndWait();
|
|
|
576 |
table.repaint();
|
|
|
577 |
}
|
|
|
578 |
});
|
|
|
579 |
}
|
|
|
580 |
}
|
|
|
581 |
};
|
73 |
ilm |
582 |
act.putValue(Action.NAME, TM.tr("moveOneDay"));
|
21 |
ilm |
583 |
res.add(act);
|
17 |
ilm |
584 |
|
|
|
585 |
// Marquer comme réalisé
|
|
|
586 |
act = new AbstractAction() {
|
|
|
587 |
public void actionPerformed(ActionEvent e) {
|
21 |
ilm |
588 |
TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
|
17 |
ilm |
589 |
if (element != null) {
|
|
|
590 |
element.setDone(true);
|
|
|
591 |
element.commitChangesAndWait();
|
|
|
592 |
table.repaint();
|
|
|
593 |
}
|
|
|
594 |
}
|
|
|
595 |
};
|
73 |
ilm |
596 |
act.putValue(Action.NAME, TM.tr("markDone"));
|
21 |
ilm |
597 |
res.add(act);
|
17 |
ilm |
598 |
|
|
|
599 |
// Suppression
|
|
|
600 |
act = new AbstractAction() {
|
|
|
601 |
public void actionPerformed(ActionEvent e) {
|
21 |
ilm |
602 |
TodoListPanel.this.model.deleteTaskAtIndex(modelIndex);
|
17 |
ilm |
603 |
table.repaint();
|
|
|
604 |
}
|
|
|
605 |
};
|
73 |
ilm |
606 |
act.putValue(Action.NAME, TM.tr("delete"));
|
21 |
ilm |
607 |
res.add(act);
|
17 |
ilm |
608 |
|
21 |
ilm |
609 |
final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
|
17 |
ilm |
610 |
SQLRowValues rowTache = element.getRowValues();
|
|
|
611 |
|
|
|
612 |
List<AbstractAction> actions = TacheActionManager.getInstance().getActionsForTaskRow(rowTache);
|
|
|
613 |
|
|
|
614 |
for (AbstractAction abstractAction : actions) {
|
21 |
ilm |
615 |
res.add(abstractAction);
|
17 |
ilm |
616 |
}
|
|
|
617 |
|
21 |
ilm |
618 |
return res;
|
17 |
ilm |
619 |
}
|
|
|
620 |
});
|
|
|
621 |
}
|
|
|
622 |
|
|
|
623 |
private void setIconForColumn(int i, ImageIcon icon) {
|
|
|
624 |
|
|
|
625 |
TableCellRenderer renderer = new JComponentTableCellRenderer(icon);
|
|
|
626 |
TableColumnModel columnModel = this.t.getColumnModel();
|
|
|
627 |
TableColumn column = columnModel.getColumn(i);
|
|
|
628 |
column.setHeaderRenderer(renderer);
|
|
|
629 |
column.setMaxWidth(icon.getIconWidth() + 16);
|
|
|
630 |
column.setMinWidth(icon.getIconWidth() + 8);
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
private void addTask() {
|
|
|
634 |
this.model.addNewTask();
|
|
|
635 |
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
public void addUserListenerId(int id) {
|
|
|
639 |
// Selection de l'utilisateur dans la combo
|
|
|
640 |
for (int i = 0; i < this.users.size(); i++) {
|
|
|
641 |
Integer idUser = Integer.valueOf((this.users.get(i)).getId());
|
|
|
642 |
if (idUser.intValue() == id) {
|
|
|
643 |
((JCheckBoxMenuItem) this.comboUser.getMenuComponent(i)).setState(true);
|
|
|
644 |
}
|
|
|
645 |
}
|
|
|
646 |
this.model.addIdListener(Integer.valueOf(id));
|
|
|
647 |
}
|
|
|
648 |
|
|
|
649 |
private void removeUserListenerId(int id) {
|
|
|
650 |
this.t.editingCanceled(new ChangeEvent(this));
|
|
|
651 |
this.model.removeIdListener(Integer.valueOf(id));
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
public void stopUpdate() {
|
|
|
655 |
this.model.stopUpdate();
|
|
|
656 |
}
|
|
|
657 |
|
|
|
658 |
public void stateChanged(int state) {
|
|
|
659 |
if (state == ModelStateListener.STATE_OK) {
|
65 |
ilm |
660 |
this.reloadPanel.setMode(ReloadPanel.MODE_EMPTY);
|
17 |
ilm |
661 |
}
|
|
|
662 |
if (state == ModelStateListener.STATE_DEAD) {
|
|
|
663 |
this.reloadPanel.setMode(ReloadPanel.MODE_BLINK);
|
|
|
664 |
}
|
|
|
665 |
if (state == ModelStateListener.STATE_RELOADING) {
|
|
|
666 |
this.reloadPanel.setMode(ReloadPanel.MODE_ROTATE);
|
|
|
667 |
}
|
|
|
668 |
}
|
|
|
669 |
|
|
|
670 |
public void addModelStateListener(ModelStateListener l) {
|
|
|
671 |
this.model.addModelStateListener(l);
|
|
|
672 |
}
|
|
|
673 |
|
|
|
674 |
/**
|
|
|
675 |
* @param event
|
|
|
676 |
* @return
|
|
|
677 |
*/
|
|
|
678 |
private TodoListElement getTaskAt(Point p) {
|
|
|
679 |
int row = this.t.rowAtPoint(p);
|
|
|
680 |
TodoListElement task = this.model.getTaskAtRow(TodoListPanel.this.sorter.modelIndex(row));
|
|
|
681 |
return task;
|
|
|
682 |
}
|
73 |
ilm |
683 |
|
|
|
684 |
protected void updateDeleteBtn() {
|
|
|
685 |
final int nbRows = this.t.getSelectedRows().length;
|
|
|
686 |
this.removeButton.setEnabled(nbRows > 0);
|
|
|
687 |
this.removeButton.setText(getTM().trM("deleteSelectedTasks", "count", nbRows));
|
|
|
688 |
}
|
17 |
ilm |
689 |
}
|
|
|
690 |
|
19 |
ilm |
691 |
class JComponentTableCellRenderer extends DefaultTableCellRenderer {
|
17 |
ilm |
692 |
Icon icon;
|
|
|
693 |
TableCellRenderer renderer;
|
|
|
694 |
|
|
|
695 |
public JComponentTableCellRenderer(Icon icon) {
|
|
|
696 |
super();
|
|
|
697 |
this.icon = icon;
|
|
|
698 |
this.renderer = new JTableHeader().getDefaultRenderer();
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
702 |
JLabel label = (JLabel) this.renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
703 |
label.setIcon(this.icon);
|
80 |
ilm |
704 |
label.setBorder(BorderFactory.createEmptyBorder());
|
17 |
ilm |
705 |
label.setIconTextGap(0);
|
|
|
706 |
label.setHorizontalTextPosition(0);
|
|
|
707 |
label.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
708 |
return label;
|
|
|
709 |
}
|
|
|
710 |
}
|