| 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.view.impl.frame.abstraction.SwingBuildedDialogView; |
| 20 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 21 | |
import org.jtheque.primary.od.able.Country; |
| 22 | |
import org.jtheque.primary.od.able.Data; |
| 23 | |
import org.jtheque.primary.view.able.ICountryView; |
| 24 | |
import org.jtheque.primary.view.impl.actions.country.AcValidateCountryView; |
| 25 | |
import org.jtheque.primary.view.impl.models.CountryModel; |
| 26 | |
import org.jtheque.primary.view.impl.models.able.ICountryModel; |
| 27 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 28 | |
import org.jtheque.utils.ui.SwingUtils; |
| 29 | |
|
| 30 | |
import javax.swing.Action; |
| 31 | |
import javax.swing.JTextField; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public final class CountryView extends SwingBuildedDialogView<ICountryModel> implements ICountryView { |
| 39 | |
private JTextField fieldNom; |
| 40 | |
|
| 41 | |
private static final int NAME_LENGTH_LIMIT = 50; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public CountryView(){ |
| 47 | 0 | super(); |
| 48 | |
|
| 49 | 0 | build(); |
| 50 | 0 | } |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
protected void initView(){ |
| 54 | 0 | setModel(new CountryModel()); |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
protected void buildView(PanelBuilder builder){ |
| 59 | 0 | Action validateAction = new AcValidateCountryView(); |
| 60 | |
|
| 61 | 0 | builder.addI18nLabel("country.view.name", builder.gbcSet(0, 0)); |
| 62 | |
|
| 63 | 0 | fieldNom = builder.add(new JTextField(15), builder.gbcSet(1, 0)); |
| 64 | 0 | SwingUtils.addFieldValidateAction(fieldNom, validateAction); |
| 65 | 0 | SwingUtils.addFieldLengthLimit(fieldNom, NAME_LENGTH_LIMIT); |
| 66 | |
|
| 67 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1), |
| 68 | |
validateAction, getCloseAction("country.actions.cancel")); |
| 69 | |
|
| 70 | 0 | reload(); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
@Override |
| 74 | |
public void reload(){ |
| 75 | 0 | setTitleKey("country.view.title"); |
| 76 | |
|
| 77 | 0 | fieldNom.setText(""); |
| 78 | |
|
| 79 | 0 | getModel().setCountry(null); |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public void reload(Data data){ |
| 84 | 0 | Country pays = (Country) data; |
| 85 | |
|
| 86 | 0 | setTitle(getMessage("country.view.title.modify") + pays.getName()); |
| 87 | |
|
| 88 | 0 | fieldNom.setText(pays.getName()); |
| 89 | |
|
| 90 | 0 | getModel().setCountry(pays); |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
@Override |
| 94 | |
public JTextField getFieldNom(){ |
| 95 | 0 | return fieldNom; |
| 96 | |
} |
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public void refreshText(){ |
| 100 | 0 | if (getModel().getCountry() != null){ |
| 101 | 0 | setTitle(getMessage("borrower.view.title.edit") + getModel().getCountry().getName()); |
| 102 | |
} |
| 103 | 0 | } |
| 104 | |
} |