| 1 | |
package org.jtheque.films.view.impl.frames; |
| 2 | |
|
| 3 | |
import org.jtheque.core.managers.error.JThequeError; |
| 4 | |
import org.jtheque.core.managers.view.impl.components.JThequeCheckBox; |
| 5 | |
import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView; |
| 6 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 7 | |
import org.jtheque.core.utils.ui.constraints.ConstraintManager; |
| 8 | |
import org.jtheque.films.services.impl.utils.file.FTPConnectionInfos; |
| 9 | |
import org.jtheque.films.utils.Constants.Properties.Publication; |
| 10 | |
import org.jtheque.films.view.able.IPublicationView; |
| 11 | |
import org.jtheque.films.view.impl.actions.CloseViewAction; |
| 12 | |
import org.jtheque.films.view.impl.actions.publication.AcValidatePublicationView; |
| 13 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 14 | |
import org.jtheque.utils.ui.SwingUtils; |
| 15 | |
|
| 16 | |
import javax.swing.Action; |
| 17 | |
import javax.swing.JPasswordField; |
| 18 | |
import javax.swing.JTextField; |
| 19 | |
import java.awt.Color; |
| 20 | |
import java.awt.Container; |
| 21 | |
import java.awt.Frame; |
| 22 | |
import java.util.Collection; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public final class PublicationView extends SwingDialogView implements IPublicationView { |
| 46 | |
private JTextField fieldHost; |
| 47 | |
private JTextField fieldPath; |
| 48 | |
private JTextField fieldUser; |
| 49 | |
private JPasswordField fieldPassword; |
| 50 | |
private JTextField fieldPort; |
| 51 | |
private JThequeCheckBox passiveBox; |
| 52 | |
|
| 53 | |
private static final int FIELD_COLUMNS = 15; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public PublicationView(Frame parent) { |
| 61 | 0 | super(parent); |
| 62 | |
|
| 63 | 0 | setTitleKey("publication.view.title"); |
| 64 | 0 | setContentPane(buildContentPane()); |
| 65 | 0 | pack(); |
| 66 | |
|
| 67 | 0 | setLocationRelativeTo(getOwner()); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
private Container buildContentPane() { |
| 76 | 0 | PanelBuilder builder = new PanelBuilder(); |
| 77 | |
|
| 78 | 0 | Action validateAction = new AcValidatePublicationView(); |
| 79 | |
|
| 80 | 0 | addPathFields(builder, validateAction); |
| 81 | 0 | addAuthenticationFields(builder, validateAction); |
| 82 | 0 | addPortField(builder, validateAction); |
| 83 | 0 | addPassiveField(builder); |
| 84 | |
|
| 85 | 0 | builder.addButtonBar(builder.gbcSet(0, 6, GridBagUtils.HORIZONTAL, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 0, 1.0, 1.0), |
| 86 | |
validateAction, new CloseViewAction("generic.view.actions.cancel", this)); |
| 87 | |
|
| 88 | 0 | return builder.getPanel(); |
| 89 | |
} |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
private void addPathFields(PanelBuilder builder, Action validateAction) { |
| 98 | 0 | builder.addI18nLabel(Publication.HOST, builder.gbcSet(0, 0)); |
| 99 | |
|
| 100 | 0 | fieldHost = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 0, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 101 | 0 | SwingUtils.addFieldValidateAction(fieldHost, validateAction); |
| 102 | 0 | ConstraintManager.configure(fieldHost, Publication.HOST); |
| 103 | |
|
| 104 | 0 | builder.addI18nLabel(Publication.PATH, builder.gbcSet(0, 1)); |
| 105 | |
|
| 106 | 0 | fieldPath = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 107 | 0 | SwingUtils.addFieldValidateAction(fieldPath, validateAction); |
| 108 | 0 | ConstraintManager.configure(fieldPath, Publication.PATH); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
private void addAuthenticationFields(PanelBuilder builder, Action validateAction) { |
| 118 | 0 | builder.addI18nLabel(Publication.USER, builder.gbcSet(0, 2)); |
| 119 | |
|
| 120 | 0 | fieldUser = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 2, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 121 | 0 | SwingUtils.addFieldValidateAction(fieldUser, validateAction); |
| 122 | 0 | ConstraintManager.configure(fieldUser, Publication.USER); |
| 123 | |
|
| 124 | 0 | builder.addI18nLabel(Publication.PASSWORD, builder.gbcSet(0, 3)); |
| 125 | |
|
| 126 | 0 | fieldPassword = builder.add(new JPasswordField(FIELD_COLUMNS), builder.gbcSet(1, 3, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 127 | 0 | SwingUtils.addFieldValidateAction(fieldPassword, validateAction); |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
private void addPortField(PanelBuilder builder, Action validateAction) { |
| 137 | 0 | builder.addI18nLabel(Publication.PORT, builder.gbcSet(0, 4)); |
| 138 | |
|
| 139 | 0 | fieldPort = builder.add(new JTextField(FIELD_COLUMNS), builder.gbcSet(1, 4, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 140 | 0 | SwingUtils.addFieldValidateAction(fieldPort, validateAction); |
| 141 | 0 | ConstraintManager.configure(fieldPort, Publication.PORT); |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
private void addPassiveField(PanelBuilder builder) { |
| 150 | 0 | passiveBox = new JThequeCheckBox("publication.passive"); |
| 151 | 0 | passiveBox.setBackground(Color.white); |
| 152 | |
|
| 153 | 0 | builder.add(passiveBox, builder.gbcSet(0, 5, GridBagUtils.HORIZONTAL, GridBagUtils.ABOVE_BASELINE_LEADING, 0, 1, 1.0, 0.0)); |
| 154 | 0 | } |
| 155 | |
|
| 156 | |
@Override |
| 157 | |
protected void validate(Collection<JThequeError> errors) { |
| 158 | 0 | ConstraintManager.validate(Publication.HOST, fieldHost.getText(), errors); |
| 159 | 0 | ConstraintManager.validate(Publication.USER, fieldUser.getText(), errors); |
| 160 | 0 | ConstraintManager.validate(Publication.PASSWORD, new String(fieldPassword.getPassword()), errors); |
| 161 | 0 | ConstraintManager.validate(Publication.PORT, fieldPort.getText(), errors); |
| 162 | 0 | ConstraintManager.validate(Publication.PATH, fieldPath.getText(), errors); |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
@Override |
| 166 | |
public FTPConnectionInfos getConnectionInfos() { |
| 167 | 0 | FTPConnectionInfos infos = new FTPConnectionInfos(); |
| 168 | |
|
| 169 | 0 | infos.setHost(fieldHost.getText()); |
| 170 | 0 | infos.setPath(fieldPath.getText()); |
| 171 | 0 | infos.setUser(fieldUser.getText()); |
| 172 | 0 | infos.setPassword(new String(fieldPassword.getPassword())); |
| 173 | 0 | infos.setPassive(passiveBox.isSelected()); |
| 174 | 0 | infos.setPort(Integer.parseInt(fieldPort.getText())); |
| 175 | |
|
| 176 | 0 | return infos; |
| 177 | |
} |
| 178 | |
} |