Search in sources :

Example 6 with StoredObject

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);
    }
}
Also used : StoredObject(jgnash.engine.StoredObject) Engine(jgnash.engine.Engine)

Example 7 with StoredObject

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);
    }
}
Also used : StoredObject(jgnash.engine.StoredObject) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with StoredObject

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;
}
Also used : ExchangeRate(jgnash.engine.ExchangeRate) StoredObject(jgnash.engine.StoredObject)

Example 9 with StoredObject

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();
}
Also used : Dimension(java.awt.Dimension) StoredObject(jgnash.engine.StoredObject) SwingWorker(javax.swing.SwingWorker) Budget(jgnash.engine.budget.Budget) Preferences(java.util.prefs.Preferences) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

StoredObject (jgnash.engine.StoredObject)9 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExchangeRate (jgnash.engine.ExchangeRate)3 Budget (jgnash.engine.budget.Budget)3 XStream (com.thoughtworks.xstream.XStream)2 PureJavaReflectionProvider (com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Logger (java.util.logging.Logger)2 CommodityNode (jgnash.engine.CommodityNode)2 Config (jgnash.engine.Config)2 RootAccount (jgnash.engine.RootAccount)2 StoredObjectComparator (jgnash.engine.StoredObjectComparator)2 Reminder (jgnash.engine.recurring.Reminder)2 BinaryStreamDriver (com.thoughtworks.xstream.io.binary.BinaryStreamDriver)1 KXml2Driver (com.thoughtworks.xstream.io.xml.KXml2Driver)1 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)1 Dimension (java.awt.Dimension)1 BufferedOutputStream (java.io.BufferedOutputStream)1