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.Type; |
25 | |
import org.jtheque.primary.view.able.ITypeView; |
26 | |
import org.jtheque.primary.view.impl.actions.type.AcValidateTypeView; |
27 | |
import org.jtheque.primary.view.impl.models.TypeModel; |
28 | |
import org.jtheque.primary.view.impl.models.able.ITypeModel; |
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.awt.Frame; |
35 | |
import java.util.Collection; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public final class TypeView extends SwingBuildedDialogView<ITypeModel> implements ITypeView { |
43 | |
private JTextField fieldName; |
44 | |
|
45 | |
private static final int NAME_MAX_LENGTH = 50; |
46 | |
private static final int FIELD_COLUMNS = 15; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public TypeView(Frame frame){ |
54 | 0 | super(frame); |
55 | 0 | } |
56 | |
|
57 | |
@Override |
58 | |
public void reload(){ |
59 | 0 | setTitleKey("type.view.title"); |
60 | |
|
61 | 0 | fieldName.setText(""); |
62 | |
|
63 | 0 | getModel().setType(null); |
64 | 0 | } |
65 | |
|
66 | |
@Override |
67 | |
public void reload(Data newType){ |
68 | 0 | Type type = (Type) newType; |
69 | |
|
70 | 0 | setTitle(getMessage("type.view.title.modify") + type.getName()); |
71 | |
|
72 | 0 | fieldName.setText(type.getName()); |
73 | |
|
74 | 0 | getModel().setType(type); |
75 | 0 | } |
76 | |
|
77 | |
@Override |
78 | |
protected void initView(){ |
79 | 0 | setModel(new TypeModel()); |
80 | 0 | } |
81 | |
|
82 | |
@Override |
83 | |
protected void buildView(PanelBuilder builder){ |
84 | 0 | builder.addI18nLabel("saga.view.name", builder.gbcSet(0, 0)); |
85 | |
|
86 | 0 | Action validateAction = new AcValidateTypeView(); |
87 | |
|
88 | 0 | fieldName = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 0, GridBagUtils.HORIZONTAL)); |
89 | 0 | SwingUtils.addFieldLengthLimit(fieldName, NAME_MAX_LENGTH); |
90 | 0 | SwingUtils.addFieldValidateAction(fieldName, validateAction); |
91 | |
|
92 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL), |
93 | |
validateAction, getCloseAction("type.actions.cancel")); |
94 | |
|
95 | 0 | reload(); |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
public JTextField getFieldName(){ |
100 | 0 | return fieldName; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public void refreshText(){ |
105 | 0 | super.refreshText(); |
106 | |
|
107 | 0 | if (getModel().getType() != null){ |
108 | 0 | setTitle(getMessage("type.view.title.modify") + getModel().getType().getName()); |
109 | |
} |
110 | 0 | } |
111 | |
|
112 | |
@Override |
113 | |
protected void validate(Collection<JThequeError> errors){ |
114 | 0 | ValidationUtils.rejectIfEmpty(fieldName.getText(), "type.view.name", errors); |
115 | 0 | ValidationUtils.rejectIfLongerThan(fieldName.getText(), "type.view.name", NAME_MAX_LENGTH, errors); |
116 | 0 | } |
117 | |
} |