| 1 | |
package de.glossmaker.gui.gloss.importGloss; |
| 2 | |
|
| 3 | |
import java.awt.BorderLayout; |
| 4 | |
|
| 5 | |
import javax.swing.DefaultCellEditor; |
| 6 | |
import javax.swing.JComboBox; |
| 7 | |
import javax.swing.JPanel; |
| 8 | |
import javax.swing.JScrollPane; |
| 9 | |
import javax.swing.JTable; |
| 10 | |
|
| 11 | |
import de.glossmaker.gloss.datastructure.EOperation; |
| 12 | |
import de.glossmaker.gloss.datastructure.GlossItems; |
| 13 | |
import de.glossmaker.gloss.language.Translation; |
| 14 | |
import de.glossmaker.gloss.observer.GlossItemsChangePublisher; |
| 15 | |
import de.glossmaker.gui.gloss.help.HelpSystem; |
| 16 | |
|
| 17 | |
import javax.swing.JButton; |
| 18 | |
import java.awt.event.ActionListener; |
| 19 | |
import java.awt.event.ActionEvent; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | 0 | public class ImportGlossTablePanel extends JPanel { |
| 27 | |
private static final long serialVersionUID = -7716356035213972865L; |
| 28 | 0 | private JTable mTable = null; |
| 29 | 0 | private JScrollPane mScrollPane = null; |
| 30 | 0 | private GlossItems mGlossItems = null; |
| 31 | 0 | private GlossItems mImportItems = null; |
| 32 | |
private JButton mOk; |
| 33 | |
private JButton mCancel; |
| 34 | |
private JButton mHelp; |
| 35 | 0 | private Translation mTranslation = null; |
| 36 | |
|
| 37 | 0 | public ImportGlossTablePanel(GlossItems items, GlossItems importItems) { |
| 38 | 0 | mGlossItems = items; |
| 39 | 0 | mImportItems = importItems; |
| 40 | 0 | mTranslation = Translation.getInstance(); |
| 41 | 0 | initialize(); |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
private void initialize() { |
| 45 | 0 | this.setLayout(new BorderLayout()); |
| 46 | 0 | this.add(getScrollPane(), BorderLayout.CENTER); |
| 47 | |
|
| 48 | 0 | JPanel ButtonPanel = new JPanel(); |
| 49 | 0 | add(ButtonPanel, BorderLayout.SOUTH); |
| 50 | 0 | ButtonPanel.add(getMOk()); |
| 51 | 0 | ButtonPanel.add(getMCancel()); |
| 52 | 0 | ButtonPanel.add(getMHelp()); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
private JScrollPane getScrollPane() { |
| 56 | 0 | if (mScrollPane == null) { |
| 57 | 0 | mScrollPane = new JScrollPane(); |
| 58 | 0 | mScrollPane.setViewportView(getTable()); |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | return mScrollPane; |
| 62 | |
} |
| 63 | |
|
| 64 | |
private JComboBox getOperationComboBox() { |
| 65 | 0 | JComboBox result = new JComboBox(); |
| 66 | 0 | for (EOperation operation : EOperation.values()) { |
| 67 | 0 | result.addItem(operation); |
| 68 | |
} |
| 69 | 0 | return result; |
| 70 | |
} |
| 71 | |
|
| 72 | |
|
| 73 | |
private JTable getTable() { |
| 74 | 0 | if (mTable == null) { |
| 75 | 0 | mTable = new JTable(new ImportGlossTableModel(mGlossItems, mImportItems)); |
| 76 | 0 | mTable.setRowHeight(20); |
| 77 | 0 | mTable.setAutoCreateRowSorter(true); |
| 78 | 0 | mTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(getOperationComboBox())); |
| 79 | 0 | for(int i = 0; i < mTable.getColumnCount(); i++) { |
| 80 | 0 | mTable.getColumnModel().getColumn(i).setCellRenderer(new ImportGlossCellRenderer(false)); |
| 81 | |
} |
| 82 | |
} |
| 83 | 0 | return mTable; |
| 84 | |
} |
| 85 | |
private JButton getMOk() { |
| 86 | 0 | if (mOk == null) { |
| 87 | 0 | mOk = new JButton(mTranslation.getValue("importgloss.button.ok.text")); |
| 88 | 0 | mOk.addActionListener(new ActionListener() { |
| 89 | |
public void actionPerformed(ActionEvent event) { |
| 90 | 0 | GlossItemsChangePublisher.getInstance(mGlossItems).importGlossItems(mImportItems); |
| 91 | 0 | } |
| 92 | |
}); |
| 93 | 0 | mOk.setToolTipText(mTranslation.getValue("importgloss.button.ok.tooltip")); |
| 94 | |
} |
| 95 | 0 | return mOk; |
| 96 | |
} |
| 97 | |
private JButton getMCancel() { |
| 98 | 0 | if (mCancel == null) { |
| 99 | 0 | mCancel = new JButton(mTranslation.getValue("importgloss.button.cancel.text")); |
| 100 | 0 | mCancel.addActionListener(new ActionListener() { |
| 101 | |
public void actionPerformed(ActionEvent arg0) { |
| 102 | 0 | GlossItemsChangePublisher.getInstance(mGlossItems).closeImportFileDialog(); |
| 103 | 0 | } |
| 104 | |
}); |
| 105 | 0 | mCancel.setToolTipText(mTranslation.getValue("importgloss.button.cancel.tooltip")); |
| 106 | |
} |
| 107 | 0 | return mCancel; |
| 108 | |
} |
| 109 | |
private JButton getMHelp() { |
| 110 | 0 | if (mHelp == null) { |
| 111 | 0 | mHelp = new JButton(mTranslation.getValue("importgloss.button.help.text")); |
| 112 | 0 | HelpSystem.getInstance().enableHelpOnButton(mHelp, "section.import.glossary_file", null); |
| 113 | 0 | mHelp.setToolTipText(mTranslation.getValue("importgloss.button.help.tooltip")); |
| 114 | |
} |
| 115 | 0 | return mHelp; |
| 116 | |
} |
| 117 | |
} |