| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package org.homeunix.thecave.buddi.view.panels; |
| 7 | |
|
| 8 | |
import java.awt.BorderLayout; |
| 9 | |
import java.awt.Dimension; |
| 10 | |
import java.awt.GridBagConstraints; |
| 11 | |
import java.awt.GridBagLayout; |
| 12 | |
import java.awt.Toolkit; |
| 13 | |
import java.awt.event.ActionEvent; |
| 14 | |
import java.awt.event.ActionListener; |
| 15 | |
import java.awt.event.FocusAdapter; |
| 16 | |
import java.awt.event.FocusEvent; |
| 17 | |
import java.awt.event.ItemEvent; |
| 18 | |
import java.awt.event.ItemListener; |
| 19 | |
import java.awt.event.KeyAdapter; |
| 20 | |
import java.awt.event.KeyEvent; |
| 21 | |
import java.text.ParseException; |
| 22 | |
import java.text.SimpleDateFormat; |
| 23 | |
import java.util.Date; |
| 24 | |
import java.util.List; |
| 25 | |
import java.util.Vector; |
| 26 | |
import java.util.logging.Level; |
| 27 | |
import java.util.logging.Logger; |
| 28 | |
|
| 29 | |
import javax.swing.BorderFactory; |
| 30 | |
import javax.swing.Box; |
| 31 | |
import javax.swing.BoxLayout; |
| 32 | |
import javax.swing.JButton; |
| 33 | |
import javax.swing.JCheckBox; |
| 34 | |
import javax.swing.JComponent; |
| 35 | |
import javax.swing.JFormattedTextField; |
| 36 | |
import javax.swing.JLabel; |
| 37 | |
import javax.swing.JPanel; |
| 38 | |
import javax.swing.JScrollPane; |
| 39 | |
import javax.swing.JTextField; |
| 40 | |
import javax.swing.ScrollPaneConstants; |
| 41 | |
import javax.swing.text.JTextComponent; |
| 42 | |
|
| 43 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 44 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 45 | |
import org.homeunix.thecave.buddi.model.Document; |
| 46 | |
import org.homeunix.thecave.buddi.model.Source; |
| 47 | |
import org.homeunix.thecave.buddi.model.Split; |
| 48 | |
import org.homeunix.thecave.buddi.model.Transaction; |
| 49 | |
import org.homeunix.thecave.buddi.model.TransactionSplit; |
| 50 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
| 51 | |
import org.homeunix.thecave.buddi.model.impl.SplitImpl; |
| 52 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 53 | |
import org.homeunix.thecave.buddi.model.swing.AutoCompleteEntryModel; |
| 54 | |
import org.homeunix.thecave.buddi.model.swing.DescriptionList; |
| 55 | |
import org.homeunix.thecave.buddi.model.swing.SourceComboBoxModel; |
| 56 | |
import org.homeunix.thecave.buddi.model.swing.AutoCompleteEntryModel.AutoCompleteEntry; |
| 57 | |
import org.homeunix.thecave.buddi.plugin.api.exception.InvalidValueException; |
| 58 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
| 59 | |
import org.homeunix.thecave.buddi.view.TransactionFrame; |
| 60 | |
import org.homeunix.thecave.buddi.view.dialogs.SplitTransactionDialog; |
| 61 | |
import org.homeunix.thecave.buddi.view.swing.MaxLengthListCellRenderer; |
| 62 | |
import org.homeunix.thecave.buddi.view.swing.SourceListCellRenderer; |
| 63 | |
import org.jdesktop.swingx.JXDatePicker; |
| 64 | |
|
| 65 | |
import ca.digitalcave.moss.common.DateUtil; |
| 66 | |
import ca.digitalcave.moss.common.OperatingSystemUtil; |
| 67 | |
import ca.digitalcave.moss.swing.MossDecimalField; |
| 68 | |
import ca.digitalcave.moss.swing.MossHintComboBox; |
| 69 | |
import ca.digitalcave.moss.swing.MossHintTextArea; |
| 70 | |
import ca.digitalcave.moss.swing.MossHintTextField; |
| 71 | |
import ca.digitalcave.moss.swing.MossPanel; |
| 72 | |
import ca.digitalcave.moss.swing.MossScrollingComboBox; |
| 73 | |
import ca.digitalcave.moss.swing.exception.WindowOpenException; |
| 74 | |
import ca.digitalcave.moss.swing.model.AutoCompleteMossHintComboBoxModel; |
| 75 | |
import ca.digitalcave.moss.swing.model.BackedComboBoxModel; |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 469 | public class TransactionEditorPanel extends MossPanel { |
| 85 | |
public static final long serialVersionUID = 0; |
| 86 | |
|
| 87 | |
private final Vector<JComponent> components; |
| 88 | |
|
| 89 | |
private Transaction transaction; |
| 90 | |
|
| 91 | |
private final TransactionFrame frame; |
| 92 | |
|
| 93 | |
private final JXDatePicker date; |
| 94 | |
private final MossHintComboBox description; |
| 95 | |
private final MossHintTextField number; |
| 96 | |
private final MossDecimalField amount; |
| 97 | |
private final MossScrollingComboBox from; |
| 98 | |
private final MossScrollingComboBox to; |
| 99 | |
private final JButton fromSplit; |
| 100 | |
private final JButton toSplit; |
| 101 | |
private final JCheckBox cleared; |
| 102 | |
private final JCheckBox reconciled; |
| 103 | |
private final MossHintTextArea memo; |
| 104 | |
|
| 105 | 1165 | private List<TransactionSplit> fromSplits = null; |
| 106 | 1165 | private List<TransactionSplit> toSplits = null; |
| 107 | |
|
| 108 | |
|
| 109 | |
private final Document model; |
| 110 | |
private final Source associatedSource; |
| 111 | |
|
| 112 | |
private final AutoCompleteEntryModel autoCompleteEntries; |
| 113 | |
|
| 114 | |
private boolean changed; |
| 115 | |
|
| 116 | |
public TransactionEditorPanel(TransactionFrame frame, Document model, Source associatedSource, boolean scheduledTransactionPane){ |
| 117 | 1165 | super(true); |
| 118 | 1165 | this.model = model; |
| 119 | 1165 | this.associatedSource = associatedSource; |
| 120 | 1165 | this.frame = frame; |
| 121 | |
|
| 122 | 1165 | autoCompleteEntries = new AutoCompleteEntryModel(model); |
| 123 | |
|
| 124 | 1165 | date = new JXDatePicker(); |
| 125 | 1165 | amount = new MossDecimalField(); |
| 126 | 1165 | from = new MossScrollingComboBox(); |
| 127 | 1165 | to = new MossScrollingComboBox(); |
| 128 | 1165 | fromSplit = new JButton(TextFormatter.getTranslation(BuddiKeys.SPLIT_BUTTON)); |
| 129 | 1165 | toSplit = new JButton(TextFormatter.getTranslation(BuddiKeys.SPLIT_BUTTON)); |
| 130 | 1165 | number = new MossHintTextField(PrefsModel.getInstance().getTranslator().get(BuddiKeys.HINT_NUMBER)); |
| 131 | 1165 | description = new MossHintComboBox(PrefsModel.getInstance().getTranslator().get(BuddiKeys.HINT_DESCRIPTION)); |
| 132 | 1165 | description.setMaximumRowCount(5); |
| 133 | |
|
| 134 | 1165 | if (PrefsModel.getInstance().isShowAutoComplete()) |
| 135 | 1165 | description.setModel(new AutoCompleteMossHintComboBoxModel<String>(description, new DescriptionList(this.model))); |
| 136 | |
else |
| 137 | 0 | description.setModel(new BackedComboBoxModel<String>(new DescriptionList(this.model))); |
| 138 | 1165 | memo = new MossHintTextArea(PrefsModel.getInstance().getTranslator().get(BuddiKeys.HINT_MEMO)); |
| 139 | 1165 | cleared = new JCheckBox(PrefsModel.getInstance().getTranslator().get(BuddiKeys.SHORT_CLEARED)); |
| 140 | 1165 | reconciled = new JCheckBox(PrefsModel.getInstance().getTranslator().get(BuddiKeys.SHORT_RECONCILED)); |
| 141 | |
|
| 142 | 1165 | components = new Vector<JComponent>(); |
| 143 | |
|
| 144 | 1165 | date.setVisible(!scheduledTransactionPane); |
| 145 | 1165 | cleared.setVisible(!scheduledTransactionPane && associatedSource != null); |
| 146 | 1165 | reconciled.setVisible(!scheduledTransactionPane && associatedSource != null); |
| 147 | |
|
| 148 | 1165 | open(); |
| 149 | 1165 | } |
| 150 | |
|
| 151 | |
@Override |
| 152 | |
public void init() { |
| 153 | 1165 | super.init(); |
| 154 | |
|
| 155 | 1165 | description.setText(""); |
| 156 | |
|
| 157 | 1165 | from.setModel(new SourceComboBoxModel(this.model, true, true, null)); |
| 158 | 1165 | to.setModel(new SourceComboBoxModel(this.model, false, true, null)); |
| 159 | |
|
| 160 | 1165 | from.setRenderer(new SourceListCellRenderer(TextFormatter.getTranslation(BuddiKeys.HINT_FROM), from)); |
| 161 | 1165 | to.setRenderer(new SourceListCellRenderer(TextFormatter.getTranslation(BuddiKeys.HINT_TO), to)); |
| 162 | |
|
| 163 | 1165 | from.setSelectedItem(null); |
| 164 | 1165 | to.setSelectedItem(null); |
| 165 | |
|
| 166 | 1165 | fromSplit.setVisible(false); |
| 167 | 1165 | toSplit.setVisible(false); |
| 168 | |
|
| 169 | 1165 | fromSplit.addActionListener(new ActionListener(){ |
| 170 | |
public void actionPerformed(ActionEvent e) { |
| 171 | |
try { |
| 172 | |
List<TransactionSplit> splits; |
| 173 | 102 | if (getTransaction() == null) |
| 174 | 102 | splits = null; |
| 175 | |
else |
| 176 | 0 | splits = fromSplits; |
| 177 | 102 | SplitTransactionDialog splitTransactionDialog = new SplitTransactionDialog(frame, model, splits, associatedSource, amount.getValue(), true); |
| 178 | 102 | splitTransactionDialog.openWindow(); |
| 179 | 37 | fromSplits = splitTransactionDialog.getSplits(); |
| 180 | |
} |
| 181 | 0 | catch (WindowOpenException woe){ |
| 182 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error opening to split window", woe); |
| 183 | 37 | } |
| 184 | 37 | } |
| 185 | |
}); |
| 186 | |
|
| 187 | 1165 | toSplit.addActionListener(new ActionListener(){ |
| 188 | |
public void actionPerformed(ActionEvent e) { |
| 189 | |
try { |
| 190 | |
List<TransactionSplit> splits; |
| 191 | 0 | if (getTransaction() == null) |
| 192 | 0 | splits = null; |
| 193 | |
else |
| 194 | 0 | splits = toSplits; |
| 195 | 0 | SplitTransactionDialog splitTransactionDialog = new SplitTransactionDialog(frame, model, splits, associatedSource, amount.getValue(), false); |
| 196 | 0 | splitTransactionDialog.openWindow(); |
| 197 | 0 | toSplits = splitTransactionDialog.getSplits(); |
| 198 | |
} |
| 199 | 0 | catch (WindowOpenException woe){ |
| 200 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error opening to split window", woe); |
| 201 | 0 | } |
| 202 | 0 | } |
| 203 | |
}); |
| 204 | |
|
| 205 | 1165 | date.setEditor(new JFormattedTextField(new SimpleDateFormat(PrefsModel.getInstance().getDateFormat()))); |
| 206 | 1165 | date.setDate(new Date()); |
| 207 | |
|
| 208 | |
|
| 209 | 1165 | addTooltips(); |
| 210 | |
|
| 211 | 1165 | JScrollPane memoScroller = new JScrollPane(memo); |
| 212 | 1165 | memo.setWrapStyleWord(true); |
| 213 | 1165 | memo.setLineWrap(true); |
| 214 | 1165 | memoScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
| 215 | 1165 | memoScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
| 216 | |
|
| 217 | 1165 | components.add(date); |
| 218 | 1165 | components.add(amount); |
| 219 | 1165 | components.add(from); |
| 220 | 1165 | components.add(to); |
| 221 | |
|
| 222 | 1165 | components.add(number); |
| 223 | 1165 | components.add(description); |
| 224 | 1165 | components.add(memo); |
| 225 | 1165 | components.add(memoScroller); |
| 226 | |
|
| 227 | 1165 | memoScroller.setPreferredSize(new Dimension(130, memo.getPreferredSize().height)); |
| 228 | |
|
| 229 | |
|
| 230 | 1165 | JPanel topPanel = new JPanel(new GridBagLayout()); |
| 231 | 1165 | JPanel bottomPanel = new JPanel(new GridBagLayout()); |
| 232 | 1165 | GridBagConstraints cTop = new GridBagConstraints(); |
| 233 | 1165 | GridBagConstraints cBottom = new GridBagConstraints(); |
| 234 | |
|
| 235 | 1165 | cTop.weighty = 0; |
| 236 | 1165 | cTop.gridy = 0; |
| 237 | 1165 | cTop.fill = GridBagConstraints.HORIZONTAL; |
| 238 | |
|
| 239 | 1165 | cTop.weightx = 0.2; |
| 240 | 1165 | cTop.gridx = 0; |
| 241 | 1165 | topPanel.add(date, cTop); |
| 242 | |
|
| 243 | 1165 | if (!OperatingSystemUtil.isMac()){ |
| 244 | 1165 | cTop.weightx = 0.0; |
| 245 | 1165 | cTop.ipadx = 5; |
| 246 | 1165 | cTop.gridx = 1; |
| 247 | 1165 | topPanel.add(new JLabel(), cTop); |
| 248 | |
} |
| 249 | |
|
| 250 | 1165 | cTop.weightx = 0.5; |
| 251 | 1165 | cTop.gridx = 2; |
| 252 | 1165 | topPanel.add(description, cTop); |
| 253 | |
|
| 254 | 1165 | if (!OperatingSystemUtil.isMac()){ |
| 255 | 1165 | cTop.weightx = 0.0; |
| 256 | 1165 | cTop.ipadx = 5; |
| 257 | 1165 | cTop.gridx = 3; |
| 258 | 1165 | topPanel.add(new JLabel(), cTop); |
| 259 | |
} |
| 260 | |
|
| 261 | 1165 | cTop.weightx = 0.4; |
| 262 | 1165 | cTop.gridx = 4; |
| 263 | 1165 | topPanel.add(number, cTop); |
| 264 | |
|
| 265 | 1165 | if (PrefsModel.getInstance().isShowCleared()){ |
| 266 | 0 | cTop.weightx = 0.0; |
| 267 | 0 | cTop.gridx = 5; |
| 268 | 0 | topPanel.add(cleared, cTop); |
| 269 | |
} |
| 270 | 1165 | if (PrefsModel.getInstance().isShowReconciled()){ |
| 271 | 0 | cTop.weightx = 0.0; |
| 272 | 0 | cTop.gridx = 6; |
| 273 | 0 | topPanel.add(reconciled, cTop); |
| 274 | |
} |
| 275 | |
|
| 276 | 1165 | cBottom.weighty = 0; |
| 277 | 1165 | cBottom.gridy = 0; |
| 278 | 1165 | cBottom.fill = GridBagConstraints.HORIZONTAL; |
| 279 | |
|
| 280 | 1165 | cBottom.weightx = 0.2; |
| 281 | 1165 | cBottom.ipadx = 100; |
| 282 | 1165 | cBottom.gridx = 0; |
| 283 | 1165 | bottomPanel.add(amount, cBottom); |
| 284 | |
|
| 285 | 1165 | if (!OperatingSystemUtil.isMac()){ |
| 286 | 1165 | cBottom.weightx = 0.0; |
| 287 | 1165 | cBottom.ipadx = 5; |
| 288 | 1165 | cBottom.gridx = 1; |
| 289 | 1165 | bottomPanel.add(new JLabel(), cBottom); |
| 290 | |
} |
| 291 | |
|
| 292 | 1165 | cBottom.weightx = 0.5; |
| 293 | 1165 | cBottom.ipadx = 0; |
| 294 | 1165 | cBottom.gridx = 2; |
| 295 | 1165 | bottomPanel.add(from, cBottom); |
| 296 | |
|
| 297 | 1165 | cBottom.weightx = 0.0; |
| 298 | 1165 | cBottom.ipadx = 0; |
| 299 | 1165 | cBottom.gridx = 3; |
| 300 | 1165 | bottomPanel.add(fromSplit, cBottom); |
| 301 | |
|
| 302 | 1165 | cBottom.weightx = 0.0; |
| 303 | 1165 | cBottom.ipadx = 0; |
| 304 | 1165 | cBottom.gridx = 4; |
| 305 | 1165 | bottomPanel.add(new JLabel(TextFormatter.getTranslation(BuddiKeys.TO)), cBottom); |
| 306 | |
|
| 307 | 1165 | cBottom.weightx = 0.5; |
| 308 | 1165 | cBottom.ipadx = 0; |
| 309 | 1165 | cBottom.gridx = 5; |
| 310 | 1165 | bottomPanel.add(to, cBottom); |
| 311 | |
|
| 312 | 1165 | cBottom.weightx = 0.0; |
| 313 | 1165 | cBottom.ipadx = 0; |
| 314 | 1165 | cBottom.gridx = 6; |
| 315 | 1165 | bottomPanel.add(toSplit, cBottom); |
| 316 | |
|
| 317 | 1165 | JPanel centerPanel = new JPanel(); |
| 318 | 1165 | centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); |
| 319 | 1165 | centerPanel.add(topPanel); |
| 320 | 1165 | if (!OperatingSystemUtil.isMac()) centerPanel.add(Box.createVerticalStrut(3)); |
| 321 | 1165 | centerPanel.add(bottomPanel); |
| 322 | |
|
| 323 | 1165 | this.setLayout(new BorderLayout()); |
| 324 | 1165 | this.add(centerPanel, BorderLayout.CENTER); |
| 325 | 1165 | this.add(memoScroller, BorderLayout.EAST); |
| 326 | 1165 | if (OperatingSystemUtil.isMac()) |
| 327 | 0 | this.setBorder(BorderFactory.createTitledBorder((String) null)); |
| 328 | |
|
| 329 | 1165 | for (JComponent component : components) { |
| 330 | 9320 | component.addKeyListener(new KeyAdapter(){ |
| 331 | |
public void keyTyped(KeyEvent arg0) { |
| 332 | 0 | if (arg0.getKeyChar() != '\n') { |
| 333 | 0 | TransactionEditorPanel.this.setChanged(true); |
| 334 | |
} |
| 335 | 0 | super.keyTyped(arg0); |
| 336 | 0 | } |
| 337 | |
}); |
| 338 | |
|
| 339 | 9320 | component.addFocusListener(new FocusAdapter(){ |
| 340 | |
public void focusGained(FocusEvent arg0) { |
| 341 | 0 | if (arg0.getSource() instanceof JTextField |
| 342 | |
|| arg0.getSource() instanceof JFormattedTextField){ |
| 343 | 0 | JTextField text = (JTextField) arg0.getSource(); |
| 344 | 0 | text.selectAll(); |
| 345 | |
} |
| 346 | 0 | } |
| 347 | |
}); |
| 348 | |
} |
| 349 | |
|
| 350 | 1165 | date.getEditor().addFocusListener(new FocusAdapter(){ |
| 351 | |
@Override |
| 352 | |
public void focusLost(FocusEvent e) { |
| 353 | 0 | super.focusLost(e); |
| 354 | |
|
| 355 | 0 | if (date.getDate().before(DateUtil.getDate(1900)) || date.getDate().after(DateUtil.getDate(3000))){ |
| 356 | 0 | Toolkit.getDefaultToolkit().beep(); |
| 357 | 0 | date.requestFocusInWindow(); |
| 358 | |
} |
| 359 | 0 | } |
| 360 | |
}); |
| 361 | |
|
| 362 | 1165 | description.addItemListener(new ItemListener(){ |
| 363 | |
public void itemStateChanged(ItemEvent arg0) { |
| 364 | 0 | fillInOtherFields(); |
| 365 | 0 | } |
| 366 | |
}); |
| 367 | |
|
| 368 | |
|
| 369 | 1165 | ((JTextComponent) description.getEditor().getEditorComponent()).addFocusListener(new FocusAdapter(){ |
| 370 | |
@Override |
| 371 | |
public void focusLost(FocusEvent arg0) { |
| 372 | 0 | fillInOtherFields(); |
| 373 | 0 | } |
| 374 | |
}); |
| 375 | |
|
| 376 | 1165 | ((JTextComponent) description.getEditor().getEditorComponent()).addKeyListener(new KeyAdapter(){ |
| 377 | |
|
| 378 | |
@Override |
| 379 | |
public void keyReleased(KeyEvent e) { |
| 380 | 0 | super.keyReleased(e); |
| 381 | 0 | fillInOtherFields(); |
| 382 | 0 | } |
| 383 | |
}); |
| 384 | |
|
| 385 | |
|
| 386 | 1165 | from.addActionListener(new ActionListener(){ |
| 387 | |
public void actionPerformed(ActionEvent arg0) { |
| 388 | 2 | fromSplit.setVisible(BuddiKeys.SPLITS.toString().equals(from.getSelectedItem())); |
| 389 | |
|
| 390 | 2 | if (BuddiKeys.SPLITS.toString().equals(from.getSelectedItem())){ |
| 391 | |
|
| 392 | |
} |
| 393 | 2 | else if (from.getSelectedItem() instanceof Source) { |
| 394 | 0 | if (associatedSource != null){ |
| 395 | 0 | if (!associatedSource.equals(from.getSelectedItem())){ |
| 396 | 0 | to.setSelectedItem(associatedSource); |
| 397 | |
} |
| 398 | |
|
| 399 | 0 | if (associatedSource.equals(from.getSelectedItem()) |
| 400 | |
&& associatedSource.equals(to.getSelectedItem())){ |
| 401 | 0 | to.setSelectedItem(null); |
| 402 | |
} |
| 403 | |
} |
| 404 | |
else { |
| 405 | 0 | if (from.getSelectedItem() instanceof BudgetCategory){ |
| 406 | 0 | if (to.getSelectedItem() instanceof BudgetCategory){ |
| 407 | 0 | to.setSelectedItem(null); |
| 408 | |
} |
| 409 | |
} |
| 410 | 0 | else if (from.getSelectedItem() != null |
| 411 | |
&& to.getSelectedItem() != null |
| 412 | |
&& from.getSelectedItem().equals(to.getSelectedItem())){ |
| 413 | 0 | to.setSelectedItem(null); |
| 414 | |
} |
| 415 | |
} |
| 416 | |
} |
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | 2 | else if (!BuddiKeys.SPLITS.toString().equals(from.getSelectedItem())){ |
| 434 | 2 | from.setSelectedItem(null); |
| 435 | |
} |
| 436 | 2 | } |
| 437 | |
}); |
| 438 | |
|
| 439 | |
|
| 440 | 1165 | to.addActionListener(new ActionListener(){ |
| 441 | |
public void actionPerformed(ActionEvent arg0) { |
| 442 | 2 | toSplit.setVisible(BuddiKeys.SPLITS.toString().equals(to.getSelectedItem())); |
| 443 | |
|
| 444 | 2 | if (BuddiKeys.SPLITS.toString().equals(to.getSelectedItem())){ |
| 445 | |
|
| 446 | |
} |
| 447 | 2 | else if (to.getSelectedItem() instanceof Source) { |
| 448 | 0 | if (associatedSource != null){ |
| 449 | 0 | if (!associatedSource.equals(to.getSelectedItem())){ |
| 450 | 0 | from.setSelectedItem(associatedSource); |
| 451 | |
} |
| 452 | |
|
| 453 | 0 | if (associatedSource.equals(from.getSelectedItem()) |
| 454 | |
&& associatedSource.equals(to.getSelectedItem())){ |
| 455 | 0 | from.setSelectedItem(null); |
| 456 | |
} |
| 457 | |
} |
| 458 | |
else { |
| 459 | 0 | if (to.getSelectedItem() instanceof BudgetCategory){ |
| 460 | 0 | if (from.getSelectedItem() instanceof BudgetCategory){ |
| 461 | 0 | from.setSelectedItem(null); |
| 462 | |
} |
| 463 | |
} |
| 464 | 0 | else if (from.getSelectedItem() != null |
| 465 | |
&& to.getSelectedItem() != null |
| 466 | |
&& from.getSelectedItem().equals(to.getSelectedItem())){ |
| 467 | 0 | from.setSelectedItem(null); |
| 468 | |
} |
| 469 | |
} |
| 470 | |
} |
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | 2 | else if (!BuddiKeys.SPLITS.toString().equals(to.getSelectedItem())){ |
| 490 | 2 | to.setSelectedItem(null); |
| 491 | |
} |
| 492 | 2 | } |
| 493 | |
}); |
| 494 | |
|
| 495 | 1165 | reconciled.addActionListener(new ActionListener(){ |
| 496 | |
public void actionPerformed(ActionEvent e) { |
| 497 | |
|
| 498 | 0 | if (transaction != null){ |
| 499 | |
try{ |
| 500 | 0 | TransactionEditorPanel.this.getTransactionUpdated(); |
| 501 | |
} |
| 502 | 0 | catch (InvalidValueException ive){ |
| 503 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Invalid value while reconciling transaction: ", ive); |
| 504 | 0 | } |
| 505 | |
} |
| 506 | 0 | } |
| 507 | |
}); |
| 508 | |
|
| 509 | 1165 | cleared.addActionListener(new ActionListener(){ |
| 510 | |
public void actionPerformed(ActionEvent e) { |
| 511 | |
|
| 512 | 0 | if (transaction != null){ |
| 513 | |
try{ |
| 514 | 0 | TransactionEditorPanel.this.getTransactionUpdated(); |
| 515 | |
} |
| 516 | 0 | catch (InvalidValueException ive){ |
| 517 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Invalid value while clearing transaction: ", ive); |
| 518 | 0 | } |
| 519 | |
} |
| 520 | 0 | } |
| 521 | |
}); |
| 522 | |
|
| 523 | 1165 | final MaxLengthListCellRenderer renderer = new MaxLengthListCellRenderer(description); |
| 524 | 1165 | description.setRenderer(renderer); |
| 525 | 1165 | } |
| 526 | |
|
| 527 | |
private void addTooltips(){ |
| 528 | 1165 | if (PrefsModel.getInstance().isShowTooltips()){ |
| 529 | 1165 | date.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DATE)); |
| 530 | 1165 | amount.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_AMOUNT)); |
| 531 | 1165 | from.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_FROM)); |
| 532 | 1165 | to.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_TO)); |
| 533 | 1165 | number.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_NUMBER)); |
| 534 | 1165 | description.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DESC)); |
| 535 | 1165 | memo.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_MEMO)); |
| 536 | 1165 | cleared.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_CLEARED)); |
| 537 | 1165 | reconciled.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_RECONCILED)); |
| 538 | |
} |
| 539 | |
else { |
| 540 | 0 | date.setToolTipText(null); |
| 541 | 0 | amount.setToolTipText(null); |
| 542 | 0 | from.setToolTipText(null); |
| 543 | 0 | to.setToolTipText(null); |
| 544 | 0 | number.setToolTipText(null); |
| 545 | 0 | description.setToolTipText(null); |
| 546 | 0 | memo.setToolTipText(null); |
| 547 | 0 | cleared.setToolTipText(null); |
| 548 | 0 | reconciled.setToolTipText(null); |
| 549 | |
} |
| 550 | 1165 | } |
| 551 | |
|
| 552 | |
public void setTransaction(Transaction transaction, boolean force, JButton saveButton){ |
| 553 | |
|
| 554 | 0 | date.setEnabled(true); |
| 555 | 0 | description.setEnabled(true); |
| 556 | 0 | number.setEnabled(true); |
| 557 | 0 | from.setEnabled(true); |
| 558 | 0 | to.setEnabled(true); |
| 559 | 0 | amount.setEnabled(true); |
| 560 | 0 | fromSplit.setEnabled(true); |
| 561 | 0 | toSplit.setEnabled(true); |
| 562 | 0 | memo.setEnabled(true); |
| 563 | 0 | saveButton.setEnabled(true); |
| 564 | 0 | addTooltips(); |
| 565 | |
|
| 566 | |
|
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
|
| 574 | 0 | if (!force && this.transaction == null && transaction == null){ |
| 575 | 0 | resetToFromComboBoxModels(); |
| 576 | 0 | return; |
| 577 | |
} |
| 578 | 0 | if (!force && this.transaction != null && this.transaction.equals(transaction)){ |
| 579 | 0 | resetToFromComboBoxModels(); |
| 580 | 0 | return; |
| 581 | |
} |
| 582 | 0 | if (transaction != null){ |
| 583 | 0 | resetToFromComboBoxModels(); |
| 584 | |
|
| 585 | |
|
| 586 | |
|
| 587 | 0 | if (transaction.getFrom() instanceof Split || transaction.getTo() instanceof Split){ |
| 588 | 0 | if (!transaction.getFrom().equals(associatedSource) && !transaction.getTo().equals(associatedSource)){ |
| 589 | 0 | date.setEnabled(false); |
| 590 | 0 | description.setEnabled(false); |
| 591 | 0 | number.setEnabled(false); |
| 592 | 0 | from.setEnabled(false); |
| 593 | 0 | to.setEnabled(false); |
| 594 | 0 | amount.setEnabled(false); |
| 595 | 0 | fromSplit.setEnabled(false); |
| 596 | 0 | toSplit.setEnabled(false); |
| 597 | 0 | memo.setEnabled(false); |
| 598 | 0 | saveButton.setEnabled(false); |
| 599 | |
|
| 600 | 0 | date.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 601 | 0 | description.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 602 | 0 | number.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 603 | 0 | from.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 604 | 0 | to.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 605 | 0 | amount.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 606 | 0 | fromSplit.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 607 | 0 | toSplit.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 608 | 0 | memo.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 609 | 0 | saveButton.setToolTipText(PrefsModel.getInstance().getTranslator().get(BuddiKeys.TOOLTIP_DISABLED_FOR_SPLIT)); |
| 610 | |
} |
| 611 | |
} |
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | 0 | date.setDate(transaction.getDate() == null ? new Date() : transaction.getDate()); |
| 619 | 0 | number.setText(transaction.getNumber()); |
| 620 | 0 | description.setText(transaction.getDescription()); |
| 621 | 0 | memo.setText(transaction.getMemo()); |
| 622 | 0 | amount.setValue(transaction.getAmount()); |
| 623 | 0 | if (!((SourceComboBoxModel) from.getModel()).contains(transaction.getFrom())){ |
| 624 | 0 | ((SourceComboBoxModel) from.getModel()).updateComboBoxModel(transaction.getFrom()); |
| 625 | 0 | from.invalidate(); |
| 626 | |
} |
| 627 | 0 | if (transaction.getFrom() instanceof SplitImpl){ |
| 628 | 0 | from.setSelectedItem(BuddiKeys.SPLITS.toString()); |
| 629 | |
} |
| 630 | |
else { |
| 631 | 0 | from.setSelectedItem(transaction.getFrom()); |
| 632 | |
} |
| 633 | 0 | if (!((SourceComboBoxModel) to.getModel()).contains(transaction.getTo())){ |
| 634 | 0 | ((SourceComboBoxModel) to.getModel()).updateComboBoxModel(transaction.getTo()); |
| 635 | 0 | to.invalidate(); |
| 636 | |
} |
| 637 | 0 | if (transaction.getTo() instanceof SplitImpl){ |
| 638 | 0 | to.setSelectedItem(BuddiKeys.SPLITS.toString()); |
| 639 | |
} |
| 640 | |
else { |
| 641 | 0 | to.setSelectedItem(transaction.getTo()); |
| 642 | |
} |
| 643 | 0 | if (associatedSource != null){ |
| 644 | 0 | if (associatedSource.equals(from.getSelectedItem())){ |
| 645 | 0 | cleared.setSelected(transaction.isClearedFrom()); |
| 646 | 0 | reconciled.setSelected(transaction.isReconciledFrom()); |
| 647 | |
} |
| 648 | 0 | else if (associatedSource.equals(to.getSelectedItem())){ |
| 649 | 0 | cleared.setSelected(transaction.isClearedTo()); |
| 650 | 0 | reconciled.setSelected(transaction.isReconciledTo()); |
| 651 | |
} |
| 652 | |
} |
| 653 | 0 | fromSplits = transaction.getFromSplits(); |
| 654 | 0 | toSplits = transaction.getToSplits(); |
| 655 | |
} |
| 656 | |
else{ |
| 657 | 0 | if (date.getDate() == null) |
| 658 | 0 | date.setDate(new Date()); |
| 659 | 0 | number.setText(""); |
| 660 | 0 | description.setText(""); |
| 661 | 0 | amount.setValue(0); |
| 662 | 0 | to.setSelectedItem(null); |
| 663 | 0 | from.setSelectedItem(null); |
| 664 | 0 | memo.setText(""); |
| 665 | 0 | cleared.setSelected(false); |
| 666 | 0 | reconciled.setSelected(false); |
| 667 | 0 | fromSplits = null; |
| 668 | 0 | toSplits = null; |
| 669 | |
|
| 670 | 0 | resetSelection(); |
| 671 | |
} |
| 672 | |
|
| 673 | 0 | setChanged(false); |
| 674 | |
|
| 675 | 0 | this.transaction = transaction; |
| 676 | 0 | } |
| 677 | |
|
| 678 | |
private void resetToFromComboBoxModels(){ |
| 679 | |
|
| 680 | 0 | ((SourceComboBoxModel) from.getModel()).updateComboBoxModel(null); |
| 681 | 0 | ((SourceComboBoxModel) to.getModel()).updateComboBoxModel(null); |
| 682 | 0 | from.invalidate(); |
| 683 | 0 | to.invalidate(); |
| 684 | 0 | } |
| 685 | |
|
| 686 | |
public boolean isChanged(){ |
| 687 | 0 | return changed; |
| 688 | |
} |
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
public boolean isDangerouslyChanged() { |
| 695 | 0 | if (transaction == null) |
| 696 | 0 | return false; |
| 697 | 0 | boolean changedDesc = !(description.getText().equals(transaction.getDescription())); |
| 698 | 0 | boolean changedAmt = !(amount.getValue() == transaction.getAmount()); |
| 699 | 0 | boolean changedDate = !(date.getDate().equals(transaction.getDate())); |
| 700 | 0 | return changedDesc && changedAmt && changedDate; |
| 701 | |
} |
| 702 | |
|
| 703 | |
public void setChanged(boolean changed){ |
| 704 | 0 | this.changed = changed; |
| 705 | 0 | } |
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
|
| 711 | |
public Transaction getTransactionUpdated() throws InvalidValueException { |
| 712 | 0 | if (transaction == null) |
| 713 | 0 | throw new InvalidValueException("This transaction is not already created; call getTransactionNew() to get it."); |
| 714 | |
|
| 715 | |
try { |
| 716 | 0 | date.commitEdit(); |
| 717 | 0 | } catch (ParseException e) { |
| 718 | 0 | throw new InvalidValueException("Cannot parse updated transaction date", e); |
| 719 | 0 | } |
| 720 | |
|
| 721 | 0 | transaction.setDate(date.getDate()); |
| 722 | 0 | transaction.setDescription(description.getText()); |
| 723 | 0 | transaction.setAmount(amount.getValue()); |
| 724 | |
|
| 725 | 0 | if (from.getSelectedItem() instanceof Source){ |
| 726 | 0 | transaction.setFrom((Source) from.getSelectedItem()); |
| 727 | |
} |
| 728 | 0 | else if (fromSplits != null) { |
| 729 | 0 | transaction.setFromSplits(fromSplits); |
| 730 | |
} |
| 731 | |
|
| 732 | 0 | if (to.getSelectedItem() instanceof Source){ |
| 733 | 0 | transaction.setTo((Source) to.getSelectedItem()); |
| 734 | |
} |
| 735 | 0 | else if (toSplits != null) { |
| 736 | 0 | transaction.setToSplits(toSplits); |
| 737 | |
} |
| 738 | |
|
| 739 | 0 | transaction.setNumber(number.getText().toString()); |
| 740 | 0 | transaction.setMemo(memo.getText().toString()); |
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | 0 | if (associatedSource != null){ |
| 745 | 0 | if (associatedSource.equals(from.getSelectedItem())){ |
| 746 | 0 | transaction.setClearedFrom(cleared.isSelected()); |
| 747 | 0 | transaction.setReconciledFrom(reconciled.isSelected()); |
| 748 | |
} |
| 749 | 0 | else if (associatedSource.equals(to.getSelectedItem())){ |
| 750 | 0 | transaction.setClearedTo(cleared.isSelected()); |
| 751 | 0 | transaction.setReconciledTo(reconciled.isSelected()); |
| 752 | |
} |
| 753 | |
} |
| 754 | 0 | return transaction; |
| 755 | |
} |
| 756 | |
|
| 757 | |
public void toggleCleared(){ |
| 758 | 0 | cleared.doClick(); |
| 759 | 0 | } |
| 760 | |
|
| 761 | |
public void toggleReconciled(){ |
| 762 | 0 | reconciled.doClick(); |
| 763 | 0 | } |
| 764 | |
|
| 765 | |
public Transaction getTransaction(){ |
| 766 | 102 | return transaction; |
| 767 | |
} |
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
public Transaction getTransactionNew() throws InvalidValueException { |
| 776 | 44 | if (!isTransactionValid()) |
| 777 | 44 | throw new InvalidValueException("New transaction is not completely filled in"); |
| 778 | |
|
| 779 | |
try { |
| 780 | 0 | date.commitEdit(); |
| 781 | 0 | } catch (ParseException e) { |
| 782 | 0 | throw new InvalidValueException("Cannot parse new transaction date", e); |
| 783 | 0 | } |
| 784 | |
|
| 785 | 0 | Source fromSource = (Source) (from.getSelectedItem() instanceof Source ? from.getSelectedItem() : null); |
| 786 | 0 | Source toSource = (Source) (to.getSelectedItem() instanceof Source ? to.getSelectedItem() : null); |
| 787 | 0 | Transaction t = ModelFactory.createTransaction(date.getDate(), description.getText(), amount.getValue(), fromSource, toSource); |
| 788 | 0 | t.setNumber(number.getText()); |
| 789 | 0 | t.setMemo(memo.getText()); |
| 790 | |
|
| 791 | |
|
| 792 | 0 | if (from.getSelectedItem() instanceof Source){ |
| 793 | 0 | t.setFrom((Source) from.getSelectedItem()); |
| 794 | |
} |
| 795 | 0 | else if (fromSplits != null) { |
| 796 | 0 | t.setFromSplits(fromSplits); |
| 797 | |
} |
| 798 | |
|
| 799 | 0 | if (to.getSelectedItem() instanceof Source){ |
| 800 | 0 | t.setTo((Source) to.getSelectedItem()); |
| 801 | |
} |
| 802 | 0 | else if (toSplits != null) { |
| 803 | 0 | t.setToSplits(toSplits); |
| 804 | |
} |
| 805 | |
|
| 806 | 0 | if (associatedSource != null){ |
| 807 | 0 | if (associatedSource.equals(from.getSelectedItem())){ |
| 808 | 0 | t.setClearedFrom(cleared.isSelected()); |
| 809 | 0 | t.setReconciledFrom(reconciled.isSelected()); |
| 810 | |
} |
| 811 | 0 | else if (associatedSource.equals(to.getSelectedItem())){ |
| 812 | 0 | t.setClearedTo(cleared.isSelected()); |
| 813 | 0 | t.setReconciledTo(reconciled.isSelected()); |
| 814 | |
} |
| 815 | |
} |
| 816 | 0 | return t; |
| 817 | |
} |
| 818 | |
|
| 819 | |
|
| 820 | |
|
| 821 | |
|
| 822 | |
|
| 823 | |
|
| 824 | |
|
| 825 | |
|
| 826 | |
|
| 827 | |
|
| 828 | |
|
| 829 | |
|
| 830 | |
|
| 831 | |
|
| 832 | |
|
| 833 | |
|
| 834 | |
|
| 835 | |
|
| 836 | |
|
| 837 | |
|
| 838 | |
|
| 839 | |
|
| 840 | |
|
| 841 | |
public boolean isTransactionValid(){ |
| 842 | 44 | return this.isTransactionValid(null); |
| 843 | |
} |
| 844 | |
|
| 845 | |
public boolean isTransactionValid(Source thisSource){ |
| 846 | |
|
| 847 | 44 | if (description.getText().length() == 0) |
| 848 | 43 | return false; |
| 849 | 1 | if (date.getDate() == null) |
| 850 | 0 | return false; |
| 851 | 1 | if (to.getSelectedItem() == null) |
| 852 | 1 | return false; |
| 853 | 0 | if (from.getSelectedItem() == null) |
| 854 | 0 | return false; |
| 855 | |
|
| 856 | |
|
| 857 | 0 | if (BuddiKeys.SPLITS.toString().equals(from.getSelectedItem()) && BuddiKeys.SPLITS.toString().equals(to.getSelectedItem())) |
| 858 | 0 | return false; |
| 859 | |
|
| 860 | |
|
| 861 | |
|
| 862 | 0 | if (thisSource != null){ |
| 863 | 0 | if (!from.getSelectedItem().equals(thisSource) && !to.getSelectedItem().equals(thisSource)) |
| 864 | 0 | return false; |
| 865 | |
} |
| 866 | |
|
| 867 | 0 | return true; |
| 868 | |
} |
| 869 | |
|
| 870 | |
public void updateContent(){ |
| 871 | 1165 | super.updateContent(); |
| 872 | |
|
| 873 | |
|
| 874 | 1165 | setEnabled(true); |
| 875 | |
|
| 876 | |
|
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
|
| 885 | |
|
| 886 | |
|
| 887 | |
|
| 888 | |
|
| 889 | |
|
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | |
|
| 894 | |
|
| 895 | |
|
| 896 | |
|
| 897 | |
|
| 898 | |
|
| 899 | |
|
| 900 | 1165 | } |
| 901 | |
|
| 902 | |
@Override |
| 903 | |
public void setEnabled(boolean arg0) { |
| 904 | 1165 | for (JComponent c : components) { |
| 905 | 9320 | c.setEnabled(arg0); |
| 906 | |
} |
| 907 | 1165 | } |
| 908 | |
|
| 909 | |
public void resetSelection(){ |
| 910 | 0 | date.requestFocusInWindow(); |
| 911 | 0 | } |
| 912 | |
|
| 913 | |
|
| 914 | |
|
| 915 | |
|
| 916 | |
|
| 917 | |
|
| 918 | |
public void updateClearedAndReconciled(){ |
| 919 | 0 | if (associatedSource.equals(from.getSelectedItem())){ |
| 920 | 0 | cleared.setSelected(transaction.isClearedFrom()); |
| 921 | 0 | reconciled.setSelected(transaction.isReconciledFrom()); |
| 922 | |
} |
| 923 | 0 | else if (associatedSource.equals(to.getSelectedItem())){ |
| 924 | 0 | cleared.setSelected(transaction.isClearedTo()); |
| 925 | 0 | reconciled.setSelected(transaction.isReconciledTo()); |
| 926 | |
} |
| 927 | 0 | } |
| 928 | |
|
| 929 | |
private void fillInOtherFields(){ |
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
|
| 934 | |
|
| 935 | |
|
| 936 | 0 | if (PrefsModel.getInstance().isShowAutoComplete() && transaction == null){ |
| 937 | 0 | if (description != null |
| 938 | |
&& description.getText() != null |
| 939 | |
&& description.getText().length() > 0){ |
| 940 | 0 | AutoCompleteEntry ace = autoCompleteEntries.getEntry(description.getText()); |
| 941 | 0 | if (ace != null){ |
| 942 | |
|
| 943 | |
|
| 944 | |
|
| 945 | 0 | if (amount.getValue() == 0) |
| 946 | 0 | amount.setValue(ace.getAmount()); |
| 947 | |
|
| 948 | |
|
| 949 | |
|
| 950 | |
|
| 951 | |
|
| 952 | |
|
| 953 | |
|
| 954 | |
|
| 955 | 0 | if (ace.getFrom() instanceof Split) |
| 956 | 0 | from.setSelectedItem(BuddiKeys.SPLITS.toString()); |
| 957 | 0 | else if (ace.getFrom() != null && from.getSelectedItem() == null){ |
| 958 | 0 | for (int i = 0; i < from.getModel().getSize(); i++){ |
| 959 | 0 | if (from.getModel().getElementAt(i) != null |
| 960 | |
&& from.getModel().getElementAt(i).equals(ace.getFrom())){ |
| 961 | 0 | from.setSelectedIndex(i); |
| 962 | 0 | break; |
| 963 | |
} |
| 964 | |
} |
| 965 | |
} |
| 966 | |
|
| 967 | 0 | if (ace.getTo() instanceof Split) |
| 968 | 0 | to.setSelectedItem(BuddiKeys.SPLITS.toString()); |
| 969 | 0 | else if (ace.getTo() != null && to.getSelectedItem() == null){ |
| 970 | 0 | for (int i = 0; i < to.getModel().getSize(); i++){ |
| 971 | 0 | if (to.getModel().getElementAt(i) != null |
| 972 | |
&& to.getModel().getElementAt(i).equals(ace.getTo())){ |
| 973 | 0 | to.setSelectedIndex(i); |
| 974 | 0 | break; |
| 975 | |
} |
| 976 | |
} |
| 977 | |
} |
| 978 | |
} |
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
|
| 985 | |
|
| 986 | |
|
| 987 | |
|
| 988 | |
} |
| 989 | |
} |
| 990 | 0 | } |
| 991 | |
} |