| 1 | |
package de.glossmaker.gui.bibtex.model; |
| 2 | |
|
| 3 | |
import org.bushe.swing.event.EventBus; |
| 4 | |
|
| 5 | |
import de.glossmaker.bib.datastructure.BibItems; |
| 6 | |
import de.glossmaker.bib.datastructure.EBookType; |
| 7 | |
import de.glossmaker.bib.datastructure.InBook; |
| 8 | |
import de.glossmaker.bib.datastructure.Manual; |
| 9 | |
import de.glossmaker.gui.bibtex.BibItemEvent; |
| 10 | |
import de.glossmaker.gui.bibtex.BibItemEvents; |
| 11 | |
import de.glossmaker.gui.bibtex.EEventCommands; |
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
public class ManualTableModel extends AItemTableModel { |
| 19 | |
private static final long serialVersionUID = -4291127506450224270L; |
| 20 | |
|
| 21 | |
public ManualTableModel(BibItems items, Manual manual) { |
| 22 | 0 | super(items, manual); |
| 23 | 0 | } |
| 24 | |
|
| 25 | |
@Override |
| 26 | |
public int getOptionalRow() { |
| 27 | 0 | return 4; |
| 28 | |
} |
| 29 | |
|
| 30 | |
@Override |
| 31 | |
public int getRowCount() { |
| 32 | 0 | return 12; |
| 33 | |
} |
| 34 | |
|
| 35 | |
@Override |
| 36 | |
public Object getValueAt(int row, int col) { |
| 37 | 0 | Object result = null; |
| 38 | 0 | if (col == 0) { |
| 39 | 0 | switch(row) { |
| 40 | |
case 0: |
| 41 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.required_items.text"); |
| 42 | 0 | break; |
| 43 | |
case 1: |
| 44 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.key.text"); |
| 45 | 0 | break; |
| 46 | |
case 2: |
| 47 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.title.text"); |
| 48 | 0 | break; |
| 49 | |
case 4: |
| 50 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.optional_items.text"); |
| 51 | 0 | break; |
| 52 | |
case 5: |
| 53 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.author.text"); |
| 54 | 0 | break; |
| 55 | |
case 6: |
| 56 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.organization.text"); |
| 57 | 0 | break; |
| 58 | |
case 7: |
| 59 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.address.text"); |
| 60 | 0 | break; |
| 61 | |
case 8: |
| 62 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.edition.text"); |
| 63 | 0 | break; |
| 64 | |
case 9: |
| 65 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.month.text"); |
| 66 | 0 | break; |
| 67 | |
case 10: |
| 68 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.year.text"); |
| 69 | 0 | break; |
| 70 | |
case 11: |
| 71 | 0 | result = getTranslation().getValue("bibtex.table.bibitem.note.text"); |
| 72 | 0 | break; |
| 73 | |
} |
| 74 | |
} else { |
| 75 | 0 | switch(row) { |
| 76 | |
case 1: |
| 77 | 0 | result = getItem().getKey(); |
| 78 | 0 | break; |
| 79 | |
case 2: |
| 80 | 0 | result = getItem().getTitle(); |
| 81 | 0 | break; |
| 82 | |
case 5: |
| 83 | 0 | result = getItem().getAuthor(); |
| 84 | 0 | break; |
| 85 | |
case 6: |
| 86 | 0 | result = getItem().getOrganization(); |
| 87 | 0 | break; |
| 88 | |
case 7: |
| 89 | 0 | result = getItem().getAddress(); |
| 90 | 0 | break; |
| 91 | |
case 8: |
| 92 | 0 | result = getItem().getEdition(); |
| 93 | 0 | break; |
| 94 | |
case 9: |
| 95 | 0 | result = getItem().getMonth(); |
| 96 | 0 | break; |
| 97 | |
case 10: |
| 98 | 0 | result = getItem().getYear(); |
| 99 | 0 | break; |
| 100 | |
case 11: |
| 101 | 0 | result = getItem().getNote(); |
| 102 | |
} |
| 103 | |
|
| 104 | |
} |
| 105 | |
|
| 106 | 0 | return result; |
| 107 | |
} |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
public boolean isCellEditable(int row, int col) { |
| 111 | 0 | boolean result = false; |
| 112 | 0 | if (col == 1 && ((row > 0 && row < 3) || (row > 4))) { |
| 113 | 0 | result = true; |
| 114 | |
} |
| 115 | 0 | return result; |
| 116 | |
} |
| 117 | |
|
| 118 | |
@Override |
| 119 | |
public void setValueAt(Object obj, int row, int col) { |
| 120 | 0 | boolean fireUpdate = false; |
| 121 | 0 | InBook oldManual = new InBook(getItem().getKey(), EBookType.AUTHOR, getItem().getTitle(), |
| 122 | |
getItem().getAuthor(), getItem().getChapter(), getItem().getPublisher(), |
| 123 | |
getItem().getPages(), getItem().getYear()); |
| 124 | 0 | oldManual.setItemValues(getItem()); |
| 125 | 0 | switch(row) { |
| 126 | |
case 1: |
| 127 | 0 | super.setValueAt(obj, row, col); |
| 128 | 0 | break; |
| 129 | |
case 2: |
| 130 | 0 | fireUpdate = getItem().setTitle((String)obj, true); |
| 131 | 0 | break; |
| 132 | |
case 5: |
| 133 | 0 | fireUpdate = getItem().setAuthor((String) obj, false); |
| 134 | 0 | break; |
| 135 | |
case 6: |
| 136 | 0 | fireUpdate = getItem().setOrganization((String)obj); |
| 137 | 0 | break; |
| 138 | |
case 7: |
| 139 | 0 | fireUpdate = getItem().setAddress((String)obj); |
| 140 | 0 | break; |
| 141 | |
case 8: |
| 142 | 0 | fireUpdate = getItem().setEdition((String)obj); |
| 143 | 0 | break; |
| 144 | |
case 9: |
| 145 | 0 | fireUpdate = getItem().setMonth((String)obj); |
| 146 | 0 | break; |
| 147 | |
case 10: |
| 148 | 0 | fireUpdate = getItem().setYear((String) obj, false); |
| 149 | 0 | break; |
| 150 | |
case 11: |
| 151 | 0 | fireUpdate = getItem().setNote((String) obj, false); |
| 152 | |
} |
| 153 | |
|
| 154 | 0 | if (fireUpdate == true) { |
| 155 | 0 | EventBus.publish(EEventCommands.CHANGE.toString(), |
| 156 | |
new BibItemEvents(EEventCommands.CHANGE.toString(), |
| 157 | |
new BibItemEvent( |
| 158 | |
EEventCommands.CHANGE.toString(), |
| 159 | |
oldManual, getItem()))); |
| 160 | |
} |
| 161 | 0 | } |
| 162 | |
} |