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.SimpleData; |
24 | |
import org.jtheque.primary.view.able.ISimpleDataView; |
25 | |
import org.jtheque.primary.view.impl.actions.simple.ValidateSimpleDataViewAction; |
26 | |
import org.jtheque.primary.view.impl.models.SimpleDataModel; |
27 | |
import org.jtheque.primary.view.impl.models.able.ISimpleDataModel; |
28 | |
import org.jtheque.utils.ui.GridBagUtils; |
29 | |
import org.jtheque.utils.ui.SwingUtils; |
30 | |
|
31 | |
import javax.swing.Action; |
32 | |
import javax.swing.JTextField; |
33 | |
import java.util.Collection; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public final class SimpleDataView extends SwingBuildedDialogView<ISimpleDataModel> implements ISimpleDataView { |
41 | |
private JTextField fieldName; |
42 | |
|
43 | |
private static final int NAME_LENGTH_LIMIT = 100; |
44 | |
private static final int FIELD_COLUMNS = 15; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public SimpleDataView(){ |
50 | 0 | super(); |
51 | |
|
52 | 0 | build(); |
53 | 0 | } |
54 | |
|
55 | |
@Override |
56 | |
protected void initView(){ |
57 | 0 | setModel(new SimpleDataModel()); |
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
protected void buildView(PanelBuilder builder){ |
62 | 0 | Action validateAction = new ValidateSimpleDataViewAction(); |
63 | |
|
64 | 0 | builder.addI18nLabel("data.view.name", builder.gbcSet(0, 0)); |
65 | |
|
66 | 0 | fieldName = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 0)); |
67 | 0 | SwingUtils.addFieldValidateAction(fieldName, validateAction); |
68 | 0 | SwingUtils.addFieldLengthLimit(fieldName, NAME_LENGTH_LIMIT); |
69 | |
|
70 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1), |
71 | |
validateAction, getCloseAction("data.view.actions.cancel")); |
72 | 0 | } |
73 | |
|
74 | |
@Override |
75 | |
public void reload(){ |
76 | 0 | SimpleData simpleData = getModel().getSimpleData(); |
77 | |
|
78 | 0 | if(simpleData.isSaved()){ |
79 | 0 | refreshText(); |
80 | |
} else { |
81 | 0 | setTitleKey("data.view.title"); |
82 | |
} |
83 | |
|
84 | 0 | fieldName.setText(simpleData.getName()); |
85 | 0 | } |
86 | |
|
87 | |
@Override |
88 | |
public String getDataName(){ |
89 | 0 | return fieldName.getText(); |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public void refreshText(){ |
94 | 0 | if (getModel().getSimpleData() != null){ |
95 | 0 | setTitle(getMessage("data.view.title.modify", getModel().getSimpleData().getName())); |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
@Override |
100 | |
protected void validate(Collection<JThequeError> errors){ |
101 | 0 | ValidationUtils.rejectIfEmpty(fieldName.getText(), "data.view.name", errors); |
102 | 0 | ValidationUtils.rejectIfLongerThan(fieldName.getText(), "data.view.name", NAME_LENGTH_LIMIT, errors); |
103 | 0 | } |
104 | |
} |