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.view.impl.frame.abstraction.SwingBuildedDialogView; |
21 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
22 | |
import org.jtheque.core.utils.ui.ValidationUtils; |
23 | |
import org.jtheque.primary.od.able.Data; |
24 | |
import org.jtheque.primary.od.able.Kind; |
25 | |
import org.jtheque.primary.view.able.IKindView; |
26 | |
import org.jtheque.primary.view.impl.actions.kind.AcValidateKindView; |
27 | |
import org.jtheque.primary.view.impl.models.KindModel; |
28 | |
import org.jtheque.primary.view.impl.models.able.IKindModel; |
29 | |
import org.jtheque.utils.ui.GridBagUtils; |
30 | |
import org.jtheque.utils.ui.SwingUtils; |
31 | |
|
32 | |
import javax.swing.Action; |
33 | |
import javax.swing.JTextField; |
34 | |
import java.util.Collection; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public final class KindView extends SwingBuildedDialogView<IKindModel> implements IKindView { |
42 | |
private JTextField fieldName; |
43 | |
|
44 | |
private static final int NAME_MAX_LENGTH = 150; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public KindView(){ |
50 | 0 | super(); |
51 | |
|
52 | 0 | build(); |
53 | 0 | } |
54 | |
|
55 | |
@Override |
56 | |
protected void initView(){ |
57 | 0 | setModel(new KindModel()); |
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
protected void buildView(PanelBuilder builder){ |
62 | 0 | builder.addI18nLabel("kind.view.name", builder.gbcSet(0, 0)); |
63 | |
|
64 | 0 | Action validateAction = new AcValidateKindView(); |
65 | |
|
66 | 0 | fieldName = builder.add(new JTextField(15), builder.gbcSet(1, 0, GridBagUtils.HORIZONTAL)); |
67 | 0 | SwingUtils.addFieldLengthLimit(fieldName, NAME_MAX_LENGTH); |
68 | 0 | SwingUtils.addFieldValidateAction(fieldName, validateAction); |
69 | |
|
70 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL), validateAction, getCloseAction("language.actions.cancel")); |
71 | |
|
72 | 0 | reload(); |
73 | 0 | } |
74 | |
|
75 | |
@Override |
76 | |
public void reload(){ |
77 | 0 | setTitleKey("kind.view.title"); |
78 | |
|
79 | 0 | getModel().setKind(null); |
80 | |
|
81 | 0 | fieldName.setText(""); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
@Override |
86 | |
public void reload(Data data){ |
87 | 0 | Kind kind = (Kind) data; |
88 | |
|
89 | 0 | getModel().setKind(kind); |
90 | |
|
91 | 0 | setTitle(getMessage("kind.view.title.modify") + kind.getDisplayableText()); |
92 | |
|
93 | 0 | fieldName.setText(kind.getName()); |
94 | 0 | } |
95 | |
|
96 | |
@Override |
97 | |
public JTextField getFieldName(){ |
98 | 0 | return fieldName; |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public void refreshText(){ |
103 | 0 | super.refreshText(); |
104 | |
|
105 | 0 | if (getModel().getKind() != null){ |
106 | 0 | setTitle(getMessage("kind.view.title.modify") + getModel().getKind().getDisplayableText()); |
107 | |
} |
108 | 0 | } |
109 | |
|
110 | |
@Override |
111 | |
protected void validate(Collection<JThequeError> errors){ |
112 | 0 | ValidationUtils.rejectIfEmpty(fieldName.getText(), "kind.view.name", errors); |
113 | 0 | ValidationUtils.rejectIfLongerThan(fieldName.getText(), "kind.view.name", NAME_MAX_LENGTH, errors); |
114 | 0 | } |
115 | |
} |