Search in sources :

Example 1 with TaasCollection

use of gen.taas.TaasCollection in project omegat by omegat-org.

the class BrowseTaasCollectionsController method show.

public static void show() {
    dialog = new BrowseTaasCollectionsUI(Core.getMainWindow().getApplicationFrame(), true);
    final Language sourceLang = Core.getProject().getProjectProperties().getSourceLanguage();
    final Language targetLang = Core.getProject().getProjectProperties().getTargetLanguage();
    List<TaasCollection> list = Collections.emptyList();
    CollectionsTable model = new CollectionsTable(list, sourceLang, targetLang);
    dialog.tableCollections.setModel(model);
    dialog.tableCollections.setColumnModel(createColumnModel());
    dialog.labelStatus.setText(OStrings.getString("TAAS_STATUS_LIST"));
    new SwingWorker<List<TaasCollection>, Void>() {

        @Override
        protected List<TaasCollection> doInBackground() throws Exception {
            return TaaSPlugin.getClient().getCollectionsList();
        }

        @Override
        protected void done() {
            try {
                List<TaasCollection> list = get();
                removeUnusedCollections(list);
                CollectionsTable model = new CollectionsTable(list, sourceLang, targetLang);
                dialog.tableCollections.setModel(model);
                TableRowSorter<CollectionsTable> sorter = new TableRowSorter<CollectionsTable>(model);
                dialog.tableCollections.setRowSorter(sorter);
                sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
                dialog.tableCollections.setColumnModel(createColumnModel());
                dialog.labelStatus.setText(" ");
            } catch (ExecutionException e) {
                Throwable ex = e.getCause();
                if (ex instanceof TaaSClient.FormatError) {
                    Log.logErrorRB(ex, "TAAS_FORMAT_ERROR", ex.getMessage());
                    dialog.labelStatus.setText(OStrings.getString("TAAS_FORMAT_ERROR"));
                } else if (ex instanceof TaaSClient.Unauthorized) {
                    Log.logErrorRB(ex, "TAAS_UNAUTHORIZED_ERROR");
                    dialog.labelStatus.setText(OStrings.getString("TAAS_UNAUTHORIZED_ERROR"));
                } else {
                    Log.logErrorRB(ex, "TAAS_GENERAL_ERROR", ex.getMessage());
                    dialog.labelStatus.setText(MessageFormat.format(OStrings.getString("TAAS_GENERAL_ERROR"), ex.getMessage()));
                }
            } catch (InterruptedException ex) {
            }
        }
    }.execute();
    dialog.btnDownload.addActionListener(DOWNLOAD_LISTENER);
    StaticUIUtils.setEscapeClosable(dialog);
    dialog.btnClose.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    dialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
    dialog.setVisible(true);
}
Also used : TaasCollection(gen.taas.TaasCollection) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) ActionEvent(java.awt.event.ActionEvent) ExecutionException(java.util.concurrent.ExecutionException) TaasLanguage(gen.taas.TaasLanguage) Language(org.omegat.util.Language) ActionListener(java.awt.event.ActionListener) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) TableRowSorter(javax.swing.table.TableRowSorter)

Example 2 with TaasCollection

use of gen.taas.TaasCollection in project omegat by omegat-org.

the class BrowseTaasCollectionsController method removeUnusedCollections.

/**
 * Removes collections with zero terms count.
 */
static void removeUnusedCollections(List<TaasCollection> list) {
    final Language sourceLang = Core.getProject().getProjectProperties().getSourceLanguage();
    final Language targetLang = Core.getProject().getProjectProperties().getTargetLanguage();
    for (int i = 0; i < list.size(); i++) {
        TaasCollection c = list.get(i);
        if (getCountForLanguage(c, sourceLang) == 0 || getCountForLanguage(c, targetLang) == 0) {
            list.remove(i);
            i--;
        }
    }
}
Also used : TaasCollection(gen.taas.TaasCollection) TaasLanguage(gen.taas.TaasLanguage) Language(org.omegat.util.Language)

Aggregations

TaasCollection (gen.taas.TaasCollection)2 TaasLanguage (gen.taas.TaasLanguage)2 Language (org.omegat.util.Language)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 RowSorter (javax.swing.RowSorter)1 TableRowSorter (javax.swing.table.TableRowSorter)1