Search in sources :

Example 6 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class MassCollectionImporterDialog method initGUI.

private void initGUI() throws SQLException {
    getContentPane().setLayout(new BorderLayout(0, 0));
    deck = new MagicDeck();
    JPanel panelCollectionInput = new JPanel();
    getContentPane().add(panelCollectionInput, BorderLayout.NORTH);
    JLabel lblImport = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("IMPORT") + " ");
    panelCollectionInput.add(lblImport);
    List<MagicEdition> list = new ArrayList<>();
    try {
        list = MTGControler.getInstance().getEnabledProviders().loadEditions();
    } catch (IOException e2) {
        MTGLogger.printStackTrace(e2);
    }
    final JComboBox cboEditions = new JComboBox(list.toArray());
    cboEditions.setRenderer(new MagicEditionListRenderer());
    panelCollectionInput.add(cboEditions);
    List<MagicCollection> lc = MTGControler.getInstance().getEnabledDAO().getCollections();
    JLabel lblNewLabel = new JLabel(MTGControler.getInstance().getLangService().getCapitalize("BY"));
    panelCollectionInput.add(lblNewLabel);
    final JComboBox<String> cboByType = new JComboBox<>();
    cboByType.setModel(new DefaultComboBoxModel<String>(new String[] { "number", "name" }));
    panelCollectionInput.add(cboByType);
    JLabel lblIn = new JLabel("in");
    panelCollectionInput.add(lblIn);
    final JComboBox cboCollections = new JComboBox(lc.toArray());
    panelCollectionInput.add(cboCollections);
    JPanel panneauBas = new JPanel();
    getContentPane().add(panneauBas, BorderLayout.SOUTH);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    final JCheckBox checkNewOne = new JCheckBox(MTGControler.getInstance().getLangService().getCapitalize("IMPORT_OTHER_SERIE"));
    JButton btnInverse = new JButton("Inverse");
    btnInverse.addActionListener(e -> {
        MagicEdition ed = (MagicEdition) cboEditions.getSelectedItem();
        int max = ed.getCardCount();
        List<String> elements = Arrays.asList(txtNumbersInput.getText().replaceAll("\n", " ").replaceAll("  ", " ").trim().split(" "));
        List<String> edList = new ArrayList<>();
        for (int i = 1; i <= max; i++) edList.add(String.valueOf(i));
        edList.removeAll(elements);
        StringBuilder temp = new StringBuilder();
        for (String s : edList) temp.append(s).append(" ");
        txtNumbersInput.setText(temp.toString());
    });
    panneauBas.add(btnInverse);
    panneauBas.add(checkNewOne);
    JButton btnImport = new JButton(MTGControler.getInstance().getLangService().getCapitalize("IMPORT"));
    btnImport.addActionListener(e -> {
        final MagicEdition ed = (MagicEdition) cboEditions.getSelectedItem();
        final MagicCollection col = (MagicCollection) cboCollections.getSelectedItem();
        if (cboByType.getSelectedItem().equals("number"))
            ids = txtNumbersInput.getText().replaceAll("\n", " ").replaceAll("  ", " ").trim().split(" ");
        else
            ids = txtNumbersInput.getText().split("\n");
        progressBar.setMaximum(ids.length);
        ThreadManager.getInstance().execute(() -> {
            int i = 1;
            for (String id : ids) {
                try {
                    MagicCard mc = null;
                    if (cboByType.getSelectedItem().toString().equalsIgnoreCase("number"))
                        mc = MTGControler.getInstance().getEnabledProviders().getCardByNumber(id, ed);
                    else
                        mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", id.replaceAll("\n", " ").replaceAll("  ", " ").trim(), (MagicEdition) cboEditions.getSelectedItem(), true).get(0);
                    deck.add(mc);
                    MTGControler.getInstance().getEnabledDAO().saveCard(mc, col);
                    progressBar.setValue(i++);
                } catch (Exception e1) {
                    MTGLogger.printStackTrace(e1);
                }
            }
            JOptionPane.showMessageDialog(null, MTGControler.getInstance().getLangService().getCapitalize("X_ITEMS_IMPORTED", ids.length), MTGControler.getInstance().getLangService().getCapitalize("FINISHED"), JOptionPane.INFORMATION_MESSAGE);
            if (!checkNewOne.isSelected()) {
                setVisible(false);
                progressBar.setValue(0);
            }
        }, "btnImport importCards");
    });
    panneauBas.add(btnImport);
    panneauBas.add(progressBar);
    txtNumbersInput = new JTextPane();
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    scrollPane.setViewportView(txtNumbersInput);
    setModal(true);
    setLocationRelativeTo(null);
}
Also used : JPanel(javax.swing.JPanel) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) JButton(javax.swing.JButton) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) MagicCollection(org.magic.api.beans.MagicCollection) MagicDeck(org.magic.api.beans.MagicDeck) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JCheckBox(javax.swing.JCheckBox) MagicCard(org.magic.api.beans.MagicCard) MagicEditionListRenderer(org.magic.gui.renderer.MagicEditionListRenderer)

Example 7 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class HsqlDAO method getCollection.

@Override
public MagicCollection getCollection(String name) throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
        pst.setString(1, name);
        try (ResultSet rs = pst.executeQuery()) {
            if (rs.next()) {
                MagicCollection mc = new MagicCollection();
                mc.setName(rs.getString("name"));
                return mc;
            }
            return null;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 8 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class HsqlDAO method listCollectionFromCards.

@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
    if (mc.getEditions().isEmpty())
        throw new SQLException("No edition defined");
    try (PreparedStatement pst = con.prepareStatement("SELECT COLLECTION FROM CARDS WHERE name=? and edition=?")) {
        pst.setString(1, mc.getName());
        pst.setString(2, mc.getEditions().get(0).getId());
        logger.trace("SELECT COLLECTION FROM CARDS WHERE name='" + mc.getName() + "' and edition='" + mc.getEditions().get(0).getId() + "'");
        try (ResultSet rs = pst.executeQuery()) {
            List<MagicCollection> cols = new ArrayList<>();
            while (rs.next()) {
                MagicCollection col = new MagicCollection();
                col.setName(rs.getString("COLLECTION"));
                cols.add(col);
            }
            return cols;
        }
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 9 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class HsqlDAO method getCollections.

@Override
public List<MagicCollection> getCollections() throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from collections")) {
        try (ResultSet rs = pst.executeQuery()) {
            List<MagicCollection> colls = new ArrayList<>();
            while (rs.next()) {
                MagicCollection mc = new MagicCollection();
                mc.setName(rs.getString(1));
                colls.add(mc);
            }
            return colls;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 10 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class MongoDbDAO method listStocks.

@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
    ArrayList<MagicCardStock> ret = new ArrayList<>();
    BasicDBObject filter = new BasicDBObject(dbCardIDField, IDGenerator.generate(mc));
    filter.put("stockItem.magicCollection.name", col.getName());
    logger.debug(filter);
    db.getCollection(colStocks, BasicDBObject.class).find(filter).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get(dbStockField).toString(), MagicCardStock.class)));
    return ret;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Document(org.bson.Document) Arrays(java.util.Arrays) MagicCollection(org.magic.api.beans.MagicCollection) MongoCollection(com.mongodb.client.MongoCollection) MagicCardAlert(org.magic.api.beans.MagicCardAlert) Aggregates(com.mongodb.client.model.Aggregates) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) MongoDatabase(com.mongodb.client.MongoDatabase) MagicCardStock(org.magic.api.beans.MagicCardStock) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) STATUT(org.magic.api.interfaces.MTGCardsProvider.STATUT) Filters(com.mongodb.client.model.Filters) SQLException(java.sql.SQLException) MongoClientOptions(com.mongodb.MongoClientOptions) UpdateResult(com.mongodb.client.result.UpdateResult) Gson(com.google.gson.Gson) Map(java.util.Map) AbstractMagicDAO(org.magic.api.interfaces.abstracts.AbstractMagicDAO) CodecRegistries.fromRegistries(org.bson.codecs.configuration.CodecRegistries.fromRegistries) ServerAddress(com.mongodb.ServerAddress) PojoCodecProvider(org.bson.codecs.pojo.PojoCodecProvider) Accumulators(com.mongodb.client.model.Accumulators) MagicNews(org.magic.api.beans.MagicNews) CodecRegistries.fromProviders(org.bson.codecs.configuration.CodecRegistries.fromProviders) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) TreeMap(java.util.TreeMap) IDGenerator(org.magic.tools.IDGenerator) MongoClient(com.mongodb.MongoClient) MagicCard(org.magic.api.beans.MagicCard) DeleteResult(com.mongodb.client.result.DeleteResult) BasicDBObject(com.mongodb.BasicDBObject) ArrayList(java.util.ArrayList) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicCollection (org.magic.api.beans.MagicCollection)32 ArrayList (java.util.ArrayList)20 MagicCard (org.magic.api.beans.MagicCard)15 SQLException (java.sql.SQLException)14 MagicEdition (org.magic.api.beans.MagicEdition)13 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 IOException (java.io.IOException)9 MagicCardStock (org.magic.api.beans.MagicCardStock)8 File (java.io.File)7 List (java.util.List)6 BorderLayout (java.awt.BorderLayout)4 Map (java.util.Map)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 BasicDBObject (com.mongodb.BasicDBObject)3 DeleteResult (com.mongodb.client.result.DeleteResult)3 Point (java.awt.Point)3