| 1 | |
package org.jtheque.films.view.impl.panels.config; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.beans.IBeansManager; |
| 21 | |
import org.jtheque.core.managers.error.JThequeError; |
| 22 | |
import org.jtheque.core.managers.language.ILanguageManager; |
| 23 | |
import org.jtheque.core.managers.view.impl.components.config.ConfigTabComponent; |
| 24 | |
import org.jtheque.core.utils.ui.Borders; |
| 25 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 26 | |
import org.jtheque.core.utils.ui.ValidationUtils; |
| 27 | |
import org.jtheque.films.IFilmsModule; |
| 28 | |
import org.jtheque.films.services.impl.utils.config.Configuration; |
| 29 | |
import org.jtheque.films.view.impl.actions.config.AcCheckLendings; |
| 30 | |
import org.jtheque.films.view.impl.actions.config.AcCheckMail; |
| 31 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 32 | |
|
| 33 | |
import javax.annotation.PostConstruct; |
| 34 | |
import javax.swing.JCheckBox; |
| 35 | |
import javax.swing.JComponent; |
| 36 | |
import javax.swing.JPanel; |
| 37 | |
import javax.swing.JTextArea; |
| 38 | |
import javax.swing.JTextField; |
| 39 | |
import java.awt.Color; |
| 40 | |
import java.util.Collection; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | 0 | public final class JPanelConfigLendings extends JPanel implements ConfigTabComponent { |
| 48 | |
private JCheckBox boxControlLendings; |
| 49 | |
private JCheckBox boxSendMail; |
| 50 | |
private JTextField fieldDays; |
| 51 | |
private JTextArea fieldMessage; |
| 52 | |
private JCheckBox boxAvertWithDialog; |
| 53 | |
private JCheckBox boxAvertWithMail; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
@PostConstruct |
| 59 | |
private void init() { |
| 60 | 0 | build(); |
| 61 | 0 | fillAllFields(); |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
@Override |
| 65 | |
public String getTitle() { |
| 66 | 0 | return Managers.getManager(ILanguageManager.class).getMessage("config.view.tab.lendings"); |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
private void build() { |
| 73 | 0 | PanelBuilder builder = new PanelBuilder(this); |
| 74 | |
|
| 75 | 0 | boxControlLendings = builder.addI18nCheckBox("config.lendings.check", builder.gbcSet(0, 0)); |
| 76 | 0 | boxControlLendings.addActionListener(new AcCheckLendings()); |
| 77 | |
|
| 78 | 0 | PanelBuilder mailBuilder = builder.addPanel(builder.gbcSet(0, 1)); |
| 79 | 0 | mailBuilder.getPanel().setBackground(Color.white); |
| 80 | 0 | mailBuilder.getPanel().setBorder(Borders.createTitledBorder("config.lendings.mail")); |
| 81 | |
|
| 82 | 0 | boxSendMail = mailBuilder.addI18nCheckBox("config.lendings.send", mailBuilder.gbcSet(0, 0)); |
| 83 | 0 | boxSendMail.addActionListener(new AcCheckMail()); |
| 84 | |
|
| 85 | 0 | mailBuilder.addI18nLabel("config.lendings.days", mailBuilder.gbcSet(0, 1)); |
| 86 | |
|
| 87 | 0 | fieldDays = mailBuilder.add(new JTextField(), mailBuilder.gbcSet(1, 1)); |
| 88 | |
|
| 89 | 0 | mailBuilder.addI18nLabel("config.lendings.message", mailBuilder.gbcSet(0, 2)); |
| 90 | |
|
| 91 | 0 | fieldMessage = new JTextArea(); |
| 92 | 0 | fieldMessage.setLineWrap(true); |
| 93 | |
|
| 94 | 0 | mailBuilder.addScrolled(fieldMessage, mailBuilder.gbcSet(0, 3, GridBagUtils.BOTH, 2, 1)); |
| 95 | |
|
| 96 | 0 | PanelBuilder notificationsBuilder = builder.addPanel(builder.gbcSet(0, 2)); |
| 97 | 0 | notificationsBuilder.getPanel().setBackground(Color.white); |
| 98 | 0 | notificationsBuilder.getPanel().setBorder(Borders.createTitledBorder("config.lendings.notifications")); |
| 99 | |
|
| 100 | 0 | boxAvertWithDialog = notificationsBuilder.addI18nCheckBox("config.lendings.avert.dialog", notificationsBuilder.gbcSet(0, 0)); |
| 101 | 0 | boxAvertWithMail = notificationsBuilder.addI18nCheckBox("config.lendings.avert.mail", notificationsBuilder.gbcSet(0, 1)); |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
private void fillAllFields() { |
| 108 | 0 | boxControlLendings.setSelected(getConfig().mustControlLendingsOnStartup()); |
| 109 | 0 | boxSendMail.setSelected(getConfig().areMailSendAutomatically()); |
| 110 | 0 | fieldDays.setText(Integer.toString(getConfig().getTimeBeforeAutomaticSend())); |
| 111 | 0 | fieldMessage.setText(getConfig().getAutomaticMail()); |
| 112 | 0 | boxAvertWithDialog.setSelected(getConfig().alertWithDialog()); |
| 113 | 0 | boxAvertWithMail.setSelected(getConfig().alertWithMail()); |
| 114 | 0 | } |
| 115 | |
|
| 116 | |
@Override |
| 117 | |
public void apply() { |
| 118 | 0 | getConfig().setMustControlLendingsOnStartup(boxControlLendings.isSelected()); |
| 119 | 0 | getConfig().setMailSendAutomatically(boxSendMail.isSelected()); |
| 120 | 0 | getConfig().setTimeBeforeAutomaticSend(Integer.parseInt(fieldDays.getText())); |
| 121 | 0 | getConfig().setAutomaticMail(fieldMessage.getText()); |
| 122 | 0 | getConfig().setAlertWithDialog(boxAvertWithDialog.isSelected()); |
| 123 | 0 | getConfig().setAlertWithMail(boxAvertWithMail.isSelected()); |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
@Override |
| 127 | |
public void cancel() { |
| 128 | 0 | fillAllFields(); |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public JCheckBox getBoxControlLendings() { |
| 137 | 0 | return boxControlLendings; |
| 138 | |
} |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
public JCheckBox getBoxSendMail() { |
| 146 | 0 | return boxSendMail; |
| 147 | |
} |
| 148 | |
|
| 149 | |
@Override |
| 150 | |
public void validate(Collection<JThequeError> errors) { |
| 151 | 0 | ValidationUtils.rejectIfNotNumerical(fieldDays.getText(), "config.lendings.days", errors); |
| 152 | 0 | ValidationUtils.rejectIfEmpty(fieldMessage.getText(), "config.lendings.message", errors); |
| 153 | 0 | } |
| 154 | |
|
| 155 | |
@Override |
| 156 | |
public JComponent getComponent() { |
| 157 | 0 | return this; |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public void setLendingsConfigurationEnabled(boolean selected) { |
| 166 | 0 | boxAvertWithDialog.setEnabled(selected); |
| 167 | 0 | boxAvertWithMail.setEnabled(selected); |
| 168 | 0 | boxSendMail.setEnabled(selected); |
| 169 | 0 | fieldDays.setEnabled(selected); |
| 170 | 0 | fieldMessage.setEnabled(selected); |
| 171 | 0 | } |
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
public void setMailEnabled(boolean selected) { |
| 179 | 0 | fieldDays.setEnabled(selected); |
| 180 | 0 | fieldMessage.setEnabled(selected); |
| 181 | 0 | } |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
private static Configuration getConfig() { |
| 189 | 0 | return Managers.getManager(IBeansManager.class).<IFilmsModule>getBean("filmsModule").getConfiguration(); |
| 190 | |
} |
| 191 | |
} |