use of jgnash.engine.StoredObject in project jgnash by ccavanaugh.
the class Message method readObject.
/**
* Read a Message from an ObjectInputStream.
*
* @param s input stream
* @throws java.io.IOException io exception
* @throws ClassNotFoundException thrown is class is not found
* @serialData Read serializable fields, if any exist. Read the integer count of properties. Read the key and value
* of each property
*/
@SuppressWarnings({ "unchecked", "unused" })
private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
s.defaultReadObject();
properties = new EnumMap<>(MessageProperty.class);
final int size = s.readInt();
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (int i = 0; i < size; i++) {
MessageProperty key = (MessageProperty) s.readObject();
Class<? extends StoredObject> clazz = (Class<? extends StoredObject>) Class.forName(s.readUTF());
StoredObject value = engine.getStoredObjectByUuid(clazz, s.readUTF());
properties.put(key, value);
}
}
use of jgnash.engine.StoredObject in project jgnash by ccavanaugh.
the class JpaTrashDAO method remove.
@Override
public void remove(final TrashObject trashObject) {
try {
final Future<Void> future = executorService.submit(() -> {
emLock.lock();
try {
em.getTransaction().begin();
final StoredObject object = trashObject.getObject();
em.remove(object);
em.remove(trashObject);
em.getTransaction().commit();
logger.info("Removed TrashObject");
return null;
} finally {
emLock.unlock();
}
}, Priority.BACKGROUND);
// block
future.get();
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
use of jgnash.engine.StoredObject in project jgnash by ccavanaugh.
the class XStreamCommodityDAO method getExchangeRateByUuid.
@Override
public ExchangeRate getExchangeRateByUuid(final String uuid) {
ExchangeRate exchangeRate = null;
StoredObject o = container.get(uuid);
if (o != null && o instanceof ExchangeRate) {
exchangeRate = (ExchangeRate) o;
}
return exchangeRate;
}
use of jgnash.engine.StoredObject in project jgnash by ccavanaugh.
the class BudgetPanel method initBudgetCombo.
private void initBudgetCombo() {
budgetCombo = new BudgetComboBox();
SwingWorker<StoredObject, Void> worker = new SwingWorker<StoredObject, Void>() {
@Override
protected StoredObject doInBackground() throws Exception {
Preferences preferences = Preferences.userNodeForPackage(BudgetPanel.class);
String lastBudgetUUID = preferences.get(LAST_BUDGET, null);
StoredObject o = null;
if (lastBudgetUUID != null) {
o = engine.getBudgetByUuid(lastBudgetUUID);
}
return o;
}
@Override
protected void done() {
try {
StoredObject o = get();
if (o != null && o instanceof Budget) {
budgetCombo.setSelectedBudget((Budget) o);
activeBudget = (Budget) o;
}
if (activeBudget == null) {
List<Budget> budgets = engine.getBudgetList();
if (!budgets.isEmpty()) {
budgetCombo.setSelectedBudget(budgets.get(0));
activeBudget = budgets.get(0);
}
}
// the combo takes the full toolbar space unless limited
budgetCombo.setMaximumSize(new Dimension(COMBO_BOX_WIDTH, budgetCombo.getPreferredSize().height * 3));
budgetCombo.addActionListener(e -> {
if (activeBudget != budgetCombo.getSelectedBudget()) {
refreshDisplay();
}
});
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
};
worker.execute();
}
Aggregations