| 1 | |
package de.glossmaker.gui.gloss.importGloss; |
| 2 | |
|
| 3 | |
import javax.swing.table.AbstractTableModel; |
| 4 | |
|
| 5 | |
import de.glossmaker.gloss.datastructure.EOperation; |
| 6 | |
import de.glossmaker.gloss.datastructure.GlossItem; |
| 7 | |
import de.glossmaker.gloss.datastructure.GlossItems; |
| 8 | |
import de.glossmaker.gloss.language.Translation; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
public class ImportGlossTableModel extends AbstractTableModel { |
| 15 | |
private static final long serialVersionUID = -6295608157221049420L; |
| 16 | |
|
| 17 | 0 | private String[] mColumnNames = null; |
| 18 | 0 | private GlossItems mGlossItems = null; |
| 19 | 0 | private GlossItems mImportItems = null; |
| 20 | 0 | private Translation mTranslation = null; |
| 21 | |
|
| 22 | 0 | public ImportGlossTableModel(GlossItems items, GlossItems importItems) { |
| 23 | 0 | mGlossItems = items; |
| 24 | 0 | mImportItems = importItems; |
| 25 | 0 | mTranslation = Translation.getInstance(); |
| 26 | 0 | for(int i = 0; i < mImportItems.size(); i++) { |
| 27 | 0 | GlossItem item = mImportItems.get(i); |
| 28 | 0 | if (mGlossItems.existsKey(item.getKey())) { |
| 29 | 0 | item.setOperation(EOperation.KEEP); |
| 30 | |
} else { |
| 31 | 0 | item.setOperation(EOperation.IMPORT); |
| 32 | |
} |
| 33 | |
} |
| 34 | 0 | mColumnNames = new String[5]; |
| 35 | 0 | mColumnNames[0] = mTranslation.getValue("importgloss.table.column.operation.text"); |
| 36 | 0 | mColumnNames[1] = mTranslation.getValue("importgloss.table.column.heading.text"); |
| 37 | 0 | mColumnNames[2] = mTranslation.getValue("importgloss.table.column.key.text"); |
| 38 | 0 | mColumnNames[3] = mTranslation.getValue("importgloss.table.column.word.text"); |
| 39 | 0 | mColumnNames[4] = mTranslation.getValue("importgloss.table.column.definition.text"); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
public String getColumnName(int col) { |
| 43 | 0 | return mColumnNames[col]; |
| 44 | |
} |
| 45 | |
|
| 46 | |
@Override |
| 47 | |
public int getColumnCount() { |
| 48 | 0 | return mColumnNames.length; |
| 49 | |
} |
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public int getRowCount() { |
| 53 | 0 | if (mImportItems != null) { |
| 54 | 0 | return mImportItems.size(); |
| 55 | |
} else { |
| 56 | 0 | return 0; |
| 57 | |
} |
| 58 | |
} |
| 59 | |
|
| 60 | |
@Override |
| 61 | |
public Object getValueAt(int row, int col) { |
| 62 | 0 | Object result = ""; |
| 63 | 0 | switch(col) { |
| 64 | |
case 0: |
| 65 | 0 | result = mImportItems.get(row).getOperation(); |
| 66 | 0 | break; |
| 67 | |
case 1: |
| 68 | 0 | result = mImportItems.get(row).getHeading(); |
| 69 | 0 | break; |
| 70 | |
case 2: |
| 71 | 0 | result = mImportItems.get(row).getKey(); |
| 72 | 0 | break; |
| 73 | |
case 3: |
| 74 | 0 | result = mImportItems.get(row).getWord(); |
| 75 | 0 | break; |
| 76 | |
case 4: |
| 77 | 0 | result = mImportItems.get(row).getDefinition(); |
| 78 | |
} |
| 79 | 0 | return result; |
| 80 | |
} |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
@Override |
| 85 | |
public void setValueAt(Object obj, int row, int col) { |
| 86 | 0 | if (col == 0 && obj instanceof EOperation) { |
| 87 | 0 | EOperation operation = (EOperation)obj; |
| 88 | 0 | if (operation != getValueAt(row, col)) { |
| 89 | 0 | mImportItems.get(row).setOperation(operation); |
| 90 | 0 | fireTableRowsUpdated(row, row); |
| 91 | |
} |
| 92 | |
} |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
public boolean isCellEditable(int row, int col) { |
| 96 | 0 | return col == 0 || col == 1; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public boolean existsItem(int row) { |
| 100 | 0 | GlossItem item = mImportItems.get(row); |
| 101 | 0 | return mGlossItems.existsKey(item.getKey()); |
| 102 | |
} |
| 103 | |
|
| 104 | |
public EOperation getOperation(int row) { |
| 105 | 0 | return mImportItems.get(row).getOperation(); |
| 106 | |
} |
| 107 | |
} |