| 1 | |
package de.glossmaker.gui.bibtex.model; |
| 2 | |
|
| 3 | |
import javax.swing.table.AbstractTableModel; |
| 4 | |
|
| 5 | |
import org.bushe.swing.event.EventBus; |
| 6 | |
|
| 7 | |
import de.glossmaker.bib.datastructure.ABibItem; |
| 8 | |
import de.glossmaker.bib.datastructure.BibItems; |
| 9 | |
import de.glossmaker.bib.datastructure.Misc; |
| 10 | |
import de.glossmaker.gloss.language.Translation; |
| 11 | |
import de.glossmaker.gui.bibtex.BibItemEvent; |
| 12 | |
import de.glossmaker.gui.bibtex.BibItemEvents; |
| 13 | |
import de.glossmaker.gui.bibtex.EEventCommands; |
| 14 | |
import de.glossmaker.gui.bibtex.EUserInteration; |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
public abstract class AItemTableModel extends AbstractTableModel { |
| 22 | |
private static final long serialVersionUID = 1L; |
| 23 | 16 | private String[] mColumnNames = null; |
| 24 | 16 | private Translation mTranslation = null; |
| 25 | 16 | private BibItems mBibItems = null; |
| 26 | 16 | private ABibItem mItem = null; |
| 27 | |
|
| 28 | 16 | public AItemTableModel(BibItems items, ABibItem item) { |
| 29 | 16 | mBibItems = items; |
| 30 | 16 | mItem = item; |
| 31 | 16 | mTranslation = Translation.getInstance(); |
| 32 | 16 | mColumnNames = new String[2]; |
| 33 | 16 | mColumnNames[0] = mTranslation.getValue("bibtex.table.bibitem.description.text"); |
| 34 | 16 | mColumnNames[1] = mTranslation.getValue("bibtex.table.bibitem.value.text"); |
| 35 | 16 | } |
| 36 | |
|
| 37 | |
public String getColumnName(int col) { |
| 38 | 6 | return mColumnNames[col]; |
| 39 | |
} |
| 40 | |
|
| 41 | |
@Override |
| 42 | |
public int getColumnCount() { |
| 43 | 3 | return mColumnNames.length; |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
@Override |
| 48 | |
public int getRowCount() { |
| 49 | 0 | return 0; |
| 50 | |
} |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
public Object getValueAt(int arg0, int arg1) { |
| 54 | 0 | return null; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public ABibItem getItem() { |
| 58 | 32 | return mItem; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public Translation getTranslation() { |
| 62 | 0 | return mTranslation; |
| 63 | |
} |
| 64 | |
|
| 65 | |
public BibItems getBibItems() { |
| 66 | 0 | return mBibItems; |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public boolean setKey(String key) { |
| 73 | 0 | boolean result = false; |
| 74 | 0 | if (key.length() > 0 && |
| 75 | |
key.contains(" ") == false && |
| 76 | |
getBibItems().existsKey(key) == false) { |
| 77 | 0 | getItem().setKey(key); |
| 78 | 0 | result = true; |
| 79 | |
} |
| 80 | 0 | return result; |
| 81 | |
} |
| 82 | |
|
| 83 | |
public int getRequiredRow() { |
| 84 | 0 | return 0; |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
public abstract int getOptionalRow(); |
| 89 | |
|
| 90 | |
@Override |
| 91 | |
public void setValueAt(Object obj, int row, int col) { |
| 92 | 0 | boolean fireUpdate = false; |
| 93 | 0 | boolean keySet = true; |
| 94 | 0 | Misc oldMisc = new Misc(getItem().getKey()); |
| 95 | 0 | oldMisc.setItemValues(getItem()); |
| 96 | 0 | switch(row) { |
| 97 | |
case 1: |
| 98 | 0 | String key = (String)obj; |
| 99 | 0 | fireUpdate = setKey(key); |
| 100 | 0 | if (key != null && key.equals("") == false) { |
| 101 | 0 | keySet = fireUpdate; |
| 102 | |
} |
| 103 | 0 | if (fireUpdate == true) { |
| 104 | 0 | EventBus.publish(EEventCommands.CHANGE.toString(), |
| 105 | |
new BibItemEvents(EEventCommands.CHANGE.toString(), |
| 106 | |
new BibItemEvent( |
| 107 | |
EEventCommands.CHANGE.toString(), |
| 108 | |
oldMisc, getItem()))); |
| 109 | |
} else { |
| 110 | |
|
| 111 | 0 | if (keySet == false) { |
| 112 | 0 | EventBus.publish(EUserInteration.NOT_VALID_INPUT.toString(), |
| 113 | |
Translation.getInstance().getValue("bibtex.user_interaction.key_exists.text", (String)obj)); |
| 114 | |
} |
| 115 | |
} |
| 116 | |
break; |
| 117 | |
} |
| 118 | 0 | } |
| 119 | |
} |