1 | |
package org.jtheque.primary.view.impl.frames; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.error.JThequeError; |
20 | |
import org.jtheque.core.managers.persistence.able.DataContainerProvider; |
21 | |
import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView; |
22 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
23 | |
import org.jtheque.core.utils.ui.ValidationUtils; |
24 | |
import org.jtheque.primary.od.able.Data; |
25 | |
import org.jtheque.primary.utils.DataTypeManager; |
26 | |
import org.jtheque.primary.view.able.IChoiceView; |
27 | |
import org.jtheque.primary.view.impl.actions.choice.AcValidateChoiceView; |
28 | |
import org.jtheque.primary.view.impl.models.DataContainerCachedComboBoxModel; |
29 | |
import org.jtheque.utils.ui.SwingUtils; |
30 | |
|
31 | |
import javax.swing.Action; |
32 | |
import javax.swing.JComponent; |
33 | |
import java.awt.Container; |
34 | |
import java.util.Collection; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public final class ChoiceView extends SwingDialogView implements IChoiceView { |
42 | |
private DataContainerCachedComboBoxModel<?> model; |
43 | |
|
44 | |
private String content; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public ChoiceView(){ |
50 | 0 | super(); |
51 | |
|
52 | 0 | setLocationRelativeTo(getParent()); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private void reload(String content){ |
61 | 0 | this.content = content; |
62 | |
|
63 | 0 | setTitle(DataTypeManager.getTextForDataType(content)); |
64 | 0 | setContentPane(buildContentPane()); |
65 | 0 | pack(); |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private Container buildContentPane(){ |
74 | 0 | PanelBuilder builder = new PanelBuilder(); |
75 | |
|
76 | 0 | model = new DataContainerCachedComboBoxModel(DataContainerProvider.getInstance().getContainerForDataType(content)); |
77 | |
|
78 | 0 | Action validateAction = new AcValidateChoiceView(); |
79 | |
|
80 | 0 | JComponent comboElements = builder.addComboBox(model, builder.gbcSet(0, 0)); |
81 | 0 | SwingUtils.addFieldValidateAction(comboElements, validateAction); |
82 | |
|
83 | 0 | builder.addButtonBar(builder.gbcSet(1, 0), validateAction, getCloseAction("choice.actions.cancel")); |
84 | |
|
85 | 0 | return builder.getPanel(); |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public Data getSelectedItem(){ |
90 | 0 | return model.getSelectedData(); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public void display(String content){ |
95 | 0 | reload(content); |
96 | |
|
97 | 0 | display(); |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
public void refreshText(){ |
102 | 0 | if (content != null){ |
103 | 0 | setTitle(DataTypeManager.getTextForDataType(content)); |
104 | |
} |
105 | 0 | } |
106 | |
|
107 | |
@Override |
108 | |
protected void validate(Collection<JThequeError> errors){ |
109 | 0 | ValidationUtils.rejectIfNothingSelected(model, "choice.view.title", errors); |
110 | 0 | } |
111 | |
} |