74 |
ilm |
1 |
package org.openconcerto.modules.extensionbuilder;
|
|
|
2 |
|
|
|
3 |
import java.awt.Component;
|
|
|
4 |
import java.awt.Window;
|
|
|
5 |
|
|
|
6 |
import javax.swing.DefaultListCellRenderer;
|
|
|
7 |
import javax.swing.ImageIcon;
|
|
|
8 |
import javax.swing.JLabel;
|
|
|
9 |
import javax.swing.JList;
|
|
|
10 |
import javax.swing.JOptionPane;
|
|
|
11 |
import javax.swing.JPanel;
|
|
|
12 |
import javax.swing.SwingUtilities;
|
|
|
13 |
|
|
|
14 |
import org.openconcerto.modules.extensionbuilder.list.EditableListPanel;
|
|
|
15 |
|
|
|
16 |
public class ExtensionMainListPanel extends EditableListPanel {
|
|
|
17 |
|
|
|
18 |
private ExtensionListPanel moduleListPanel;
|
|
|
19 |
|
|
|
20 |
ExtensionMainListPanel(final ExtensionListPanel moduleListPanel) {
|
|
|
21 |
super(new ExtensionListModel(moduleListPanel), "Vos extensions", "Créer une extension");
|
|
|
22 |
this.moduleListPanel = moduleListPanel;
|
|
|
23 |
this.list.setFixedCellHeight(new JLabel("A").getPreferredSize().height + 8);
|
|
|
24 |
this.list.setCellRenderer(new DefaultListCellRenderer() {
|
|
|
25 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
|
|
26 |
final JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, ((Extension) value).getName(), index, isSelected, cellHasFocus);
|
|
|
27 |
Extension e = (Extension) value;
|
|
|
28 |
if (e.isStarted()) {
|
|
|
29 |
listCellRendererComponent.setIcon(new ImageIcon(ExtensionMainListPanel.this.getClass().getResource("started.png")));
|
|
|
30 |
}
|
|
|
31 |
return listCellRendererComponent;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
});
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public void fill() {
|
|
|
38 |
((ExtensionListModel) dataModel).fill(this);
|
|
|
39 |
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
@Override
|
|
|
43 |
public void addNewItem() {
|
|
|
44 |
((ExtensionListModel) dataModel).addNewModule();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
@Override
|
|
|
48 |
public void renameItem(Object item) {
|
|
|
49 |
final Extension e = (Extension) item;
|
|
|
50 |
final Window w = SwingUtilities.windowForComponent(this);
|
|
|
51 |
final String s = (String) JOptionPane.showInputDialog(w, "Nouveau nom", "Renommer l'extension", JOptionPane.PLAIN_MESSAGE, null, null, e.getName());
|
|
|
52 |
if ((s != null) && (s.length() > 0)) {
|
|
|
53 |
e.setName(s);
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public void removeItem(Object item) {
|
|
|
59 |
((ExtensionListModel) dataModel).removeElement(item);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public void itemSelected(Object item) {
|
|
|
64 |
if (item != null) {
|
|
|
65 |
final ExtensionInfoPanel p = new ExtensionInfoPanel((Extension) item, moduleListPanel);
|
|
|
66 |
moduleListPanel.setRightPanel(p);
|
|
|
67 |
} else {
|
|
|
68 |
moduleListPanel.setRightPanel(new JPanel());
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public void modelChanged() {
|
|
|
74 |
list.invalidate();
|
|
|
75 |
list.repaint();
|
|
|
76 |
}
|
|
|
77 |
}
|