1 | |
package org.jtheque.films.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.components.model.SimpleListModel; |
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.films.services.impl.utils.web.FilmResult; |
25 | |
import org.jtheque.films.utils.Constants.Properties.Film; |
26 | |
import org.jtheque.films.utils.Constants.Site; |
27 | |
import org.jtheque.films.view.able.IAutoAddView; |
28 | |
import org.jtheque.films.view.impl.actions.DisplayBeanViewAction; |
29 | |
import org.jtheque.films.view.impl.actions.auto.add.AcChooseSite; |
30 | |
import org.jtheque.films.view.impl.actions.auto.add.AcCloseAutoAddView; |
31 | |
import org.jtheque.films.view.impl.actions.auto.add.AcValidateAutoAddView; |
32 | |
import org.jtheque.films.view.impl.models.able.IAutoAddModel; |
33 | |
import org.jtheque.utils.ui.GridBagUtils; |
34 | |
import org.jtheque.utils.ui.SwingUtils; |
35 | |
|
36 | |
import javax.annotation.PostConstruct; |
37 | |
import javax.swing.Action; |
38 | |
import javax.swing.DefaultListModel; |
39 | |
import javax.swing.JList; |
40 | |
import javax.swing.JTextField; |
41 | |
import javax.swing.ListSelectionModel; |
42 | |
import java.awt.Container; |
43 | |
import java.awt.Frame; |
44 | |
import java.util.Collection; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public final class AutoAddView extends SwingDialogView implements IAutoAddView { |
52 | |
private static final long serialVersionUID = 4633039680922071605L; |
53 | |
|
54 | |
private JTextField fieldTitle; |
55 | |
private JList listSites; |
56 | |
private JList listFilms; |
57 | |
|
58 | |
private DefaultListModel modelListFilms; |
59 | |
|
60 | 0 | private int phase = PHASE_1; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public AutoAddView(Frame parent) { |
68 | 0 | super(parent); |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@PostConstruct |
75 | |
private void build() { |
76 | 0 | setTitleKey("auto.add.view.title"); |
77 | 0 | setContentPane(buildContentPane()); |
78 | 0 | pack(); |
79 | |
|
80 | 0 | setLocationRelativeTo(getOwner()); |
81 | 0 | } |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
private Container buildContentPane() { |
89 | 0 | PanelBuilder builder = new PanelBuilder(); |
90 | |
|
91 | 0 | builder.addI18nLabel(Film.TITLE, builder.gbcSet(0, 0)); |
92 | |
|
93 | 0 | Action chooseSiteAction = new AcChooseSite(); |
94 | |
|
95 | 0 | fieldTitle = builder.add(new JTextField(), builder.gbcSet(1, 0)); |
96 | 0 | SwingUtils.addFieldValidateAction(fieldTitle, chooseSiteAction); |
97 | |
|
98 | 0 | addListsPanel(builder, chooseSiteAction); |
99 | |
|
100 | 0 | builder.addButtonBar(builder.gbcSet(0, 2, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1), |
101 | |
new DisplayBeanViewAction("auto.add.view.actions.infos", "sitesView"), |
102 | |
new AcValidateAutoAddView(), |
103 | |
new AcCloseAutoAddView()); |
104 | |
|
105 | 0 | return builder.getPanel(); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
private void addListsPanel(PanelBuilder parent, Action chooseSiteAction) { |
115 | 0 | PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 1, GridBagUtils.BOTH, GridBagUtils.BASELINE_LEADING, 2, 1)); |
116 | |
|
117 | 0 | listSites = new JList(new SimpleListModel<Site>(Site.values())); |
118 | 0 | listSites.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
119 | |
|
120 | 0 | builder.addScrolled(listSites, builder.gbcSet(0, 0, GridBagUtils.BOTH)); |
121 | |
|
122 | 0 | builder.addButton(chooseSiteAction, builder.gbcSet(1, 0)); |
123 | |
|
124 | 0 | modelListFilms = new DefaultListModel(); |
125 | |
|
126 | 0 | listFilms = new JList(modelListFilms); |
127 | 0 | listFilms.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
128 | |
|
129 | 0 | builder.addScrolled(listFilms, builder.gbcSet(2, 0, GridBagUtils.BOTH)); |
130 | 0 | } |
131 | |
|
132 | |
@Override |
133 | |
public void sendMessage(String message, Object value) { |
134 | 0 | if ("title".equals(message)) { |
135 | 0 | fieldTitle.setText((String) value); |
136 | |
} |
137 | 0 | } |
138 | |
|
139 | |
@Override |
140 | |
public JTextField getFieldTitle() { |
141 | 0 | return fieldTitle; |
142 | |
} |
143 | |
|
144 | |
@Override |
145 | |
public DefaultListModel getModelListFilms() { |
146 | 0 | return modelListFilms; |
147 | |
} |
148 | |
|
149 | |
@Override |
150 | |
public Site getSelectedSite() { |
151 | 0 | return (Site) listSites.getSelectedValue(); |
152 | |
} |
153 | |
|
154 | |
@Override |
155 | |
public FilmResult getSelectedFilm() { |
156 | 0 | return (FilmResult) listFilms.getSelectedValue(); |
157 | |
} |
158 | |
|
159 | |
@Override |
160 | |
public IAutoAddModel getModel() { |
161 | 0 | return (IAutoAddModel) super.getModel(); |
162 | |
} |
163 | |
|
164 | |
@Override |
165 | |
public boolean validateContent(int phase) { |
166 | 0 | this.phase = phase; |
167 | |
|
168 | 0 | return validateContent(); |
169 | |
} |
170 | |
|
171 | |
@Override |
172 | |
protected void validate(Collection<JThequeError> errors) { |
173 | 0 | if (PHASE_1 == phase) { |
174 | 0 | ValidationUtils.rejectIfEmpty(fieldTitle.getText(), "auto.view.title.film", errors); |
175 | 0 | ValidationUtils.rejectIfNothingSelected(listSites, "auto.view.site", errors); |
176 | 0 | } else if (PHASE_2 == phase) { |
177 | 0 | ValidationUtils.rejectIfNothingSelected(listFilms, "auto.add.view.title.film", errors); |
178 | |
} |
179 | 0 | } |
180 | |
} |