| 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.jdesktop.swingx.JXTable; |
| 20 | |
import org.jtheque.core.managers.Managers; |
| 21 | |
import org.jtheque.core.managers.beans.IBeansManager; |
| 22 | |
import org.jtheque.core.managers.error.JThequeError; |
| 23 | |
import org.jtheque.core.managers.persistence.able.DataContainer; |
| 24 | |
import org.jtheque.core.managers.view.impl.frame.abstraction.SwingDialogView; |
| 25 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 26 | |
import org.jtheque.films.view.able.ILendingsView; |
| 27 | |
import org.jtheque.films.view.impl.actions.CloseViewAction; |
| 28 | |
import org.jtheque.films.view.impl.actions.DisplayBeanViewAction; |
| 29 | |
import org.jtheque.films.view.impl.actions.lendings.AcReturnCurrentFilm; |
| 30 | |
import org.jtheque.films.view.impl.editors.DataCellEditor; |
| 31 | |
import org.jtheque.films.view.impl.menus.JMenuBarLendings; |
| 32 | |
import org.jtheque.films.view.impl.models.table.LendingsTableModel; |
| 33 | |
import org.jtheque.primary.od.able.Person; |
| 34 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 35 | |
|
| 36 | |
import javax.swing.JTable; |
| 37 | |
import javax.swing.ListSelectionModel; |
| 38 | |
import java.awt.Container; |
| 39 | |
import java.awt.Frame; |
| 40 | |
import java.util.ArrayList; |
| 41 | |
import java.util.Collection; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public final class LendingsView extends SwingDialogView implements ILendingsView { |
| 49 | |
private static final long serialVersionUID = 6554684772063503187L; |
| 50 | |
|
| 51 | |
private LendingsTableModel model; |
| 52 | |
private JXTable tableLendings; |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public LendingsView(Frame parent) { |
| 60 | 0 | super(parent); |
| 61 | |
|
| 62 | 0 | build(); |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
private void build() { |
| 69 | 0 | setJMenuBar(new JMenuBarLendings()); |
| 70 | 0 | setTitleKey("lendings.view.title"); |
| 71 | 0 | setContentPane(buildContentPane()); |
| 72 | |
|
| 73 | 0 | pack(); |
| 74 | |
|
| 75 | 0 | setLocationRelativeTo(getOwner()); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
private Container buildContentPane() { |
| 84 | 0 | PanelBuilder builder = new PanelBuilder(); |
| 85 | |
|
| 86 | 0 | model = new LendingsTableModel(); |
| 87 | 0 | setTableHeader(); |
| 88 | |
|
| 89 | 0 | tableLendings = new JXTable(model); |
| 90 | 0 | tableLendings.getColumn(1).setCellEditor(new DataCellEditor(Managers.getManager(IBeansManager.class).<DataContainer<Person>>getBean("filmsService"))); |
| 91 | 0 | tableLendings.getColumn(2).setCellEditor(new DataCellEditor(Managers.getManager(IBeansManager.class).<DataContainer<Person>>getBean("borrowersService"))); |
| 92 | 0 | tableLendings.getTableHeader().setReorderingAllowed(false); |
| 93 | 0 | tableLendings.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
| 94 | 0 | tableLendings.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
| 95 | 0 | tableLendings.setColumnControlVisible(true); |
| 96 | 0 | setIdColumnNotVisible(); |
| 97 | 0 | tableLendings.packAll(); |
| 98 | |
|
| 99 | 0 | builder.addScrolled(tableLendings, builder.gbcSet(0, 0, GridBagUtils.BOTH, GridBagUtils.BASELINE_LEADING, 0, -1, 1.0, 1.0)); |
| 100 | |
|
| 101 | 0 | builder.addButtonBar(builder.gbcSet(0, 1, GridBagUtils.HORIZONTAL, 0, 0), |
| 102 | |
new DisplayBeanViewAction("lendings.view.actions.lend", "lendFilmView"), new AcReturnCurrentFilm(), |
| 103 | |
new CloseViewAction("generic.view.actions.cancel", this)); |
| 104 | |
|
| 105 | 0 | return builder.getPanel(); |
| 106 | |
} |
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public Collection<Integer> getSelectedLendingsID() { |
| 110 | 0 | Collection<Integer> lendings = new ArrayList<Integer>(tableLendings.getSelectedRowCount()); |
| 111 | |
|
| 112 | 0 | int[] rows = tableLendings.getSelectedRows(); |
| 113 | |
|
| 114 | 0 | if (rows.length > 0) { |
| 115 | 0 | for (int row : rows) { |
| 116 | 0 | lendings.add((Integer) model.getValueAt(tableLendings.convertRowIndexToModel(row), 0)); |
| 117 | |
} |
| 118 | |
} |
| 119 | |
|
| 120 | 0 | return lendings; |
| 121 | |
} |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public void refreshText() { |
| 125 | 0 | super.refreshText(); |
| 126 | |
|
| 127 | 0 | setTableHeader(); |
| 128 | 0 | setIdColumnNotVisible(); |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
private void setTableHeader() { |
| 135 | 0 | model.setHeader(new String[]{ |
| 136 | |
getMessage("lendings.view.table.id"), |
| 137 | |
getMessage("lendings.view.table.film"), |
| 138 | |
getMessage("lendings.view.table.borrower"), |
| 139 | |
getMessage("lendings.view.table.date")}); |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
private void setIdColumnNotVisible() { |
| 146 | 0 | tableLendings.getColumnExt(getMessage("lendings.view.table.id")).setVisible(false); |
| 147 | 0 | } |
| 148 | |
|
| 149 | |
@Override |
| 150 | |
protected void validate(Collection<JThequeError> errors) { |
| 151 | 0 | } |
| 152 | |
} |