112 |
ilm |
1 |
package org.openconcerto.modules.operation;
|
|
|
2 |
|
|
|
3 |
import java.util.Collections;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import javax.swing.JMenu;
|
|
|
7 |
import javax.swing.JPopupMenu;
|
|
|
8 |
|
|
|
9 |
import org.jopencalendar.model.Flag;
|
|
|
10 |
import org.jopencalendar.model.JCalendarItemPart;
|
|
|
11 |
import org.jopencalendar.ui.JPopupMenuProvider;
|
|
|
12 |
import org.openconcerto.modules.operation.action.AssignToUserAction;
|
|
|
13 |
import org.openconcerto.modules.operation.action.DeleteAction;
|
|
|
14 |
import org.openconcerto.modules.operation.action.DuplicateAction;
|
|
|
15 |
import org.openconcerto.modules.operation.action.LockAction;
|
|
|
16 |
import org.openconcerto.modules.operation.action.ModifyAction;
|
|
|
17 |
import org.openconcerto.modules.operation.action.RePlanAction;
|
|
|
18 |
import org.openconcerto.modules.operation.action.SetStatusAction;
|
|
|
19 |
import org.openconcerto.modules.operation.action.UnlockAction;
|
|
|
20 |
import org.openconcerto.sql.users.User;
|
|
|
21 |
import org.openconcerto.sql.users.UserManager;
|
|
|
22 |
|
|
|
23 |
public class OperationMenuProvider implements JPopupMenuProvider {
|
|
|
24 |
public OperationMenuProvider() {
|
147 |
ilm |
25 |
//
|
112 |
ilm |
26 |
}
|
|
|
27 |
|
|
|
28 |
@Override
|
|
|
29 |
public JPopupMenu getPopup(List<JCalendarItemPart> selectedItems, List<JCalendarItemPart> currentColumnParts) {
|
|
|
30 |
boolean oneIsLocked = false;
|
|
|
31 |
for (JCalendarItemPart jCalendarItemPart : selectedItems) {
|
|
|
32 |
if (jCalendarItemPart.getItem().hasFlag(Flag.getFlag("locked"))) {
|
|
|
33 |
oneIsLocked = true;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
// Menu
|
|
|
38 |
JPopupMenu menu = new JPopupMenu();
|
|
|
39 |
if (!oneIsLocked && !selectedItems.isEmpty()) {
|
|
|
40 |
menu.add(new ModifyAction(selectedItems));
|
|
|
41 |
}
|
|
|
42 |
if (!selectedItems.isEmpty()) {
|
|
|
43 |
final JMenu menuAssign = new JMenu("Assigner à");
|
147 |
ilm |
44 |
final List<User> users = UserManager.getInstance().getAllActiveUsers();
|
112 |
ilm |
45 |
// Sort by full name
|
|
|
46 |
Collections.sort(users, new UserComparator());
|
|
|
47 |
for (User user : users) {
|
|
|
48 |
menuAssign.add(new AssignToUserAction(user, selectedItems));
|
|
|
49 |
}
|
|
|
50 |
menu.add(menuAssign);
|
|
|
51 |
|
|
|
52 |
final JMenu menuState = new JMenu("Marquer comme");
|
|
|
53 |
final List<String> status = OperationStateListModel.getStatus();
|
|
|
54 |
for (String s : status) {
|
|
|
55 |
menuState.add(new SetStatusAction(s, selectedItems));
|
|
|
56 |
}
|
|
|
57 |
menu.add(menuState);
|
|
|
58 |
if (oneIsLocked) {
|
|
|
59 |
menuAssign.setEnabled(false);
|
|
|
60 |
menuState.setEnabled(false);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if (selectedItems.size() == 1 && !oneIsLocked) {
|
|
|
64 |
menu.addSeparator();
|
|
|
65 |
menu.add(new RePlanAction(selectedItems));
|
|
|
66 |
}
|
|
|
67 |
menu.addSeparator();
|
|
|
68 |
if (!oneIsLocked) {
|
|
|
69 |
menu.add(new LockAction("Verrouiller", selectedItems));
|
|
|
70 |
} else {
|
|
|
71 |
menu.add(new UnlockAction("Déverrouiller", selectedItems));
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
if (selectedItems.isEmpty() && !currentColumnParts.isEmpty()) {
|
|
|
75 |
menu.add(new LockAction("Verrouiller la journée", currentColumnParts));
|
|
|
76 |
}
|
|
|
77 |
if (!selectedItems.isEmpty()) {
|
|
|
78 |
final DuplicateAction dup = new DuplicateAction(selectedItems);
|
|
|
79 |
if (selectedItems.size() > 1) {
|
|
|
80 |
dup.setEnabled(false);
|
|
|
81 |
}
|
|
|
82 |
menu.add(dup);
|
|
|
83 |
}
|
|
|
84 |
|
147 |
ilm |
85 |
if (!selectedItems.isEmpty() && !oneIsLocked) {
|
|
|
86 |
menu.addSeparator();
|
|
|
87 |
menu.add(new DeleteAction(selectedItems));
|
112 |
ilm |
88 |
}
|
|
|
89 |
return menu;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|