List of usage examples for javax.swing SwingWorker SwingWorker
public SwingWorker()
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectReload() { UIThreadsUtil.mustBeSwingThread();/*from w w w. j a v a2 s.c o m*/ if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); final ProjectProperties props = Core.getProject().getProjectProperties(); new SwingWorker<Object, Void>() { int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber(); protected Object doInBackground() throws Exception { IMainWindow mainWindow = Core.getMainWindow(); Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); Cursor oldCursor = mainWindow.getCursor(); mainWindow.setCursor(hourglassCursor); Core.executeExclusively(true, () -> { Core.getProject().saveProject(true); ProjectFactory.closeProject(); ProjectFactory.loadProject(props, true); }); mainWindow.setCursor(oldCursor); return null; } protected void done() { try { get(); SwingUtilities.invokeLater(() -> { // activate entry later - after project will be loaded Core.getEditor().gotoEntry(previousCurEntryNum); Core.getEditor().requestFocus(); }); } catch (Exception ex) { processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } } }.execute(); }
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectSave() { UIThreadsUtil.mustBeSwingThread();/*from ww w .j a v a 2 s. c om*/ if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); new SwingWorker<Object, Void>() { protected Object doInBackground() throws Exception { IMainWindow mainWindow = Core.getMainWindow(); Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); Cursor oldCursor = mainWindow.getCursor(); mainWindow.setCursor(hourglassCursor); mainWindow.showStatusMessageRB("MW_STATUS_SAVING"); Core.executeExclusively(true, () -> Core.getProject().saveProject(true)); mainWindow.showStatusMessageRB("MW_STATUS_SAVED"); mainWindow.setCursor(oldCursor); return null; } protected void done() { try { get(); } catch (Exception ex) { processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } } }.execute(); }
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectClose() { UIThreadsUtil.mustBeSwingThread();/*from w w w. j a v a2 s . c o m*/ if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); new SwingWorker<Object, Void>() { protected Object doInBackground() throws Exception { Core.getMainWindow().showStatusMessageRB("MW_STATUS_SAVING"); IMainWindow mainWindow = Core.getMainWindow(); Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); Cursor oldCursor = mainWindow.getCursor(); mainWindow.setCursor(hourglassCursor); Preferences.save(); Core.executeExclusively(true, () -> { Core.getProject().saveProject(true); ProjectFactory.closeProject(); }); Core.getMainWindow().showStatusMessageRB("MW_STATUS_SAVED"); mainWindow.setCursor(oldCursor); // fix - reset progress bar to defaults Core.getMainWindow().showLengthMessage(OStrings.getString("MW_SEGMENT_LENGTH_DEFAULT")); Core.getMainWindow() .showProgressMessage(Preferences.getPreferenceEnumDefault(Preferences.SB_PROGRESS_MODE, MainWindowUI.STATUS_BAR_MODE.DEFAULT) == MainWindowUI.STATUS_BAR_MODE.DEFAULT ? OStrings.getString("MW_PROGRESS_DEFAULT") : OStrings.getProgressBarDefaultPrecentageText()); return null; } protected void done() { try { get(); } catch (Exception ex) { processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } // Restore global prefs in case project had project-specific ones Core.setFilterMaster(new FilterMaster(Preferences.getFilters())); Core.setSegmenter(new Segmenter(Preferences.getSRX())); } }.execute(); }
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectEditProperties() { UIThreadsUtil.mustBeSwingThread();//www.j a v a 2s .c o m if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); // displaying the dialog to change paths and other properties ProjectPropertiesDialog prj = new ProjectPropertiesDialog(Core.getMainWindow().getApplicationFrame(), Core.getProject().getProjectProperties(), Core.getProject().getProjectProperties().getProjectName(), ProjectPropertiesDialog.Mode.EDIT_PROJECT); prj.setVisible(true); final ProjectProperties newProps = prj.getResult(); prj.dispose(); if (newProps == null) { return; } int res = JOptionPane.showConfirmDialog(Core.getMainWindow().getApplicationFrame(), OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { return; } new SwingWorker<Object, Void>() { int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber(); protected Object doInBackground() throws Exception { Core.executeExclusively(true, () -> { Core.getProject().saveProject(true); ProjectFactory.closeProject(); ProjectFactory.loadProject(newProps, true); }); return null; } protected void done() { try { get(); // Make sure to update Editor title SwingUtilities.invokeLater(() -> { // activate entry later - after project will be loaded Core.getEditor().gotoEntry(previousCurEntryNum); Core.getEditor().requestFocus(); }); } catch (Exception ex) { processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } } }.execute(); }
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectCompile() { UIThreadsUtil.mustBeSwingThread();//from ww w .ja v a 2s . com if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); new SwingWorker<Object, Void>() { protected Object doInBackground() throws Exception { Core.executeExclusively(true, () -> { Core.getProject().saveProject(true); try { Core.getProject().compileProject(".*"); } catch (Exception ex) { throw new RuntimeException(ex); } }); return null; } protected void done() { try { get(); } catch (Exception ex) { processSwingWorkerException(ex, "TF_COMPILE_ERROR"); } } }.execute(); }
From source file:org.omegat.gui.main.ProjectUICommands.java
public static void projectSingleCompile(final String sourcePattern) { UIThreadsUtil.mustBeSwingThread();//from w w w .j a v a 2 s . co m if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); new SwingWorker<Object, Void>() { @Override protected Object doInBackground() throws Exception { Core.executeExclusively(true, () -> { Core.getProject().saveProject(false); try { Core.getProject().compileProject(sourcePattern); } catch (Exception ex) { throw new RuntimeException(ex); } }); return null; } @Override protected void done() { try { get(); } catch (Exception ex) { processSwingWorkerException(ex, "TF_COMPILE_ERROR"); } } }.execute(); }
From source file:org.openconcerto.erp.core.finance.accounting.model.EtatChargeModel.java
private void fill() { new SwingWorker<String, Object>() { @Override//from ww w .j a v a2 s . co m protected String doInBackground() throws Exception { if (listRubCaisse == null) { fillMapCaisse(); } // this.vectCot = new Vector(); EtatChargeModel.this.mapCot = new HashMap(); EtatChargeModel.this.cotSal = 0.0F; EtatChargeModel.this.cotPat = 0.0F; // Requete SQLSelect selElt = new SQLSelect(base); selElt.addSelect(tableFichePayeElt.getField("SOURCE")); selElt.addSelect(tableFichePayeElt.getField("IDSOURCE")); selElt.addSelect(tableFichePayeElt.getField("NOM")); selElt.addSelect(tableFichePayeElt.getField("NB_BASE")); selElt.addSelect(tableFichePayeElt.getField("TAUX_SAL")); selElt.addSelect(tableFichePayeElt.getField("MONTANT_SAL_AJ")); selElt.addSelect(tableFichePayeElt.getField("MONTANT_SAL_DED")); selElt.addSelect(tableFichePayeElt.getField("TAUX_PAT")); selElt.addSelect(tableFichePayeElt.getField("MONTANT_PAT")); Where w = new Where(tableFichePaye.getField("VALIDE"), "=", Boolean.TRUE); Where w2 = new Where(tableFichePaye.getField("ANNEE"), "=", EtatChargeModel.this.annee); Where w3 = new Where(tableFichePaye.getField("ID_MOIS"), new Integer(EtatChargeModel.this.moisDe), new Integer(EtatChargeModel.this.moisAu)); Where w4 = new Where(tableFichePayeElt.getField("ID_FICHE_PAYE"), "=", tableFichePaye.getField("ID")); Where w5 = new Where(tableFichePayeElt.getField("SOURCE"), "=", tableRubCot.getName()); // FIXME prefixer tous les champs par le nom du schema --> voir avec Sylvain // Where w6 = new Where(tableFichePayeElt.getField("IDSOURCE"), "=", // "`GestionCommon`." + // tableRubCot.getField("ID").getFullName()); // Where w7 = new Where(tableRubCot.getField("ID_CAISSE_COTISATION"), "=", // this.idCaisse); selElt.setWhere(w.and(w2).and(w3).and(w4).and(w5));// .and(w6).and(w7)); String req = selElt.asString(); // StringBuffer req = new StringBuffer("SELECT \"" + base.getName() + "\"." + // tableFichePayeElt.getField("SOURCE").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("IDSOURCE").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("NOM").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("NB_BASE").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("TAUX_SAL").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("MONTANT_SAL_AJ").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("MONTANT_SAL_DED").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("TAUX_PAT").getFullName()); // req.append(", \"" + base.getName() + "\"." + // tableFichePayeElt.getField("MONTANT_PAT").getFullName()); // // req.append(" FROM \"" + base.getName() + "\"." + tableFichePaye.getName()); // req.append(", \"" + base.getName() + "\"." + tableFichePayeElt.getName()); // req.append(", \"" + tableRubCot.getBase().getName() + "\"." + // tableRubCot.getName()); // // req.append(" WHERE (\"" + base.getName() + "\"." + "FICHE_PAYE.ID!=1)"); // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE.ARCHIVE=0)"); // // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE_ELEMENT.ID!=1)"); // req.append(" AND (\"" + base.getName() + "\"." + // "FICHE_PAYE_ELEMENT.ARCHIVE=0)"); // // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE.VALIDE=1)"); // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE.ANNEE=" + this.annee // + ")"); // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE.ID_MOIS BETWEEN " + // this.moisDe + " AND " + this.moisAu + ")"); // // req.append(" AND (\"" + base.getName() + "\"." + // "FICHE_PAYE_ELEMENT.ID_FICHE_PAYE = \"" // + base.getName() + "\"." + "FICHE_PAYE.ID)"); // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE_ELEMENT.SOURCE='" + // tableRubCot.getName() + "')"); // req.append(" AND (\"" + base.getName() + "\"." + "FICHE_PAYE_ELEMENT.IDSOURCE=\"" // + // tableRubCot.getBase().getName() + "\"." + // tableRubCot.getField("ID").getFullName() + // ")"); // // req.append(" AND (\"" + tableRubCot.getBase().getName() + "\"." + // tableRubCot.getField("ID_CAISSE_COTISATION").getFullName() + "=" + this.idCaisse // + ")"); System.err.println(req); List listFicheElt = ((List) base.getDataSource().execute(req.toString(), new ArrayListHandler())); // Fill map for (Iterator i = listFicheElt.iterator(); i.hasNext();) { Object[] tmp = (Object[]) i.next(); SQLRowValues rowVals = null; if (EtatChargeModel.this.mapCot.get(new Integer(tmp[1].toString())) == null && EtatChargeModel.this.listRubCaisse.contains(tmp[1])) { rowVals = new SQLRowValues(tableFichePayeElt); rowVals.put("NOM", (tmp[2] == null) ? "" : tmp[2].toString()); rowVals.put("IDSOURCE", (tmp[1] == null) ? 0 : Integer.parseInt(tmp[1].toString())); rowVals.put("TAUX_SAL", (tmp[4] == null) ? new Float(0) : new Float(tmp[4].toString())); rowVals.put("TAUX_PAT", (tmp[7] == null) ? new Float(0) : new Float(tmp[7].toString())); EtatChargeModel.this.mapCot.put(new Integer(tmp[1].toString()), rowVals); } else { rowVals = (SQLRowValues) EtatChargeModel.this.mapCot.get(new Integer(tmp[1].toString())); } if (rowVals != null) { // Cumul des valeurs float base = (rowVals.getObject("NB_BASE") == null) ? 0.0F : ((Float) rowVals.getObject("NB_BASE")).floatValue(); base += (tmp[3] == null) ? 0.0F : ((Float) tmp[3]).floatValue(); rowVals.put("NB_BASE", new Float(base)); float montantSal = (rowVals.getObject("MONTANT_SAL_AJ") == null) ? 0.0F : ((Float) rowVals.getObject("MONTANT_SAL_AJ")).floatValue(); montantSal += (tmp[5] == null) ? 0.0F : ((Float) tmp[5]).floatValue(); rowVals.put("MONTANT_SAL_AJ", new Float(montantSal)); float montantSalDed = (rowVals.getObject("MONTANT_SAL_DED") == null) ? 0.0F : ((Float) rowVals.getObject("MONTANT_SAL_DED")).floatValue(); montantSalDed += (tmp[6] == null) ? 0.0F : ((Float) tmp[6]).floatValue(); rowVals.put("MONTANT_SAL_DED", new Float(montantSalDed)); float montantPat = (rowVals.getObject("MONTANT_PAT") == null) ? 0.0F : ((Float) rowVals.getObject("MONTANT_PAT")).floatValue(); montantPat += (tmp[8] == null) ? 0.0F : ((Float) tmp[8]).floatValue(); rowVals.put("MONTANT_PAT", new Float(montantPat)); // Cumuls total des cotisations EtatChargeModel.this.cotPat += (tmp[8] == null) ? 0.0F : new Float(tmp[8].toString()).intValue(); EtatChargeModel.this.cotSal += (tmp[6] == null) ? 0.0F : new Float(tmp[6].toString()).intValue(); } } return null; } @Override protected void done() { EtatChargeModel.this.fireTableDataChanged(); } }.execute(); }
From source file:org.openconcerto.erp.core.finance.accounting.model.LettrageModel.java
public void updateTotauxCompte() { new SwingWorker<String, Object>() { @Override/*w ww.java 2s. c o m*/ protected String doInBackground() throws Exception { SQLSelect sel = new SQLSelect(base); sel.addSelect(tableEcr.getField("CREDIT"), "SUM"); sel.addSelect(tableEcr.getField("DEBIT"), "SUM"); Where w = new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", LettrageModel.this.idCpt); sel.setWhere(w.and(new Where(tableEcr.getField("LETTRAGE"), "!=", ""))); String reqLettree = sel.toString(); Object obLettree = base.getDataSource().execute(reqLettree, new ArrayListHandler()); List myListLettree = (List) obLettree; LettrageModel.this.creditLettre = 0; LettrageModel.this.debitLettre = 0; if (myListLettree.size() != 0) { for (int i = 0; i < myListLettree.size(); i++) { Object[] objTmp = (Object[]) myListLettree.get(i); if (objTmp[0] != null) { LettrageModel.this.creditLettre += ((Number) objTmp[0]).longValue(); } if (objTmp[1] != null) { LettrageModel.this.debitLettre += ((Number) objTmp[1]).longValue(); } } } sel.setWhere(w.and(new Where(tableEcr.getField("LETTRAGE"), "=", ""))); String reqNotLettree = sel.toString(); Object obNotLettree = base.getDataSource().execute(reqNotLettree, new ArrayListHandler()); List myListNotLettree = (List) obNotLettree; LettrageModel.this.creditNonLettre = 0; LettrageModel.this.debitNonLettre = 0; if (myListNotLettree.size() != 0) { for (int i = 0; i < myListNotLettree.size(); i++) { Object[] objTmp = (Object[]) myListNotLettree.get(i); if (objTmp[0] != null) { LettrageModel.this.creditNonLettre += ((Number) objTmp[0]).longValue(); } if (objTmp[1] != null) { LettrageModel.this.debitNonLettre += ((Number) objTmp[1]).longValue(); } } } return null; } @Override protected void done() { LettrageModel.this.fireTableDataChanged(); } }.execute(); }
From source file:org.openconcerto.erp.core.finance.accounting.model.PlanComptableGModel.java
private PlanComptableGModel(final ClasseCompte classeDuCompte, final int typePlan, final String table) { new SwingWorker<String, Object>() { @Override/*from w w w .ja va 2 s . co m*/ protected String doInBackground() throws Exception { // on recupere les comptes final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete(); final SQLTable compteTable = base.getTable(table); final SQLSelect selCompte = new SQLSelect(base); selCompte.addSelect(compteTable.getField("ID")); selCompte.addSelect(compteTable.getField("NUMERO")); selCompte.addSelect(compteTable.getField("NOM")); selCompte.addSelect(compteTable.getField("INFOS")); String function = "REGEXP"; String match = classeDuCompte.getTypeNumeroCompte(); if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) { function = "~"; } Where w1 = new Where(compteTable.getField("NUMERO"), function, match); final Where w2; if (typePlan == 1) { w2 = new Where(compteTable.getField("ID_TYPE_COMPTE_PCG_BASE"), "!=", 1); } else if (typePlan == 2) { w2 = new Where(compteTable.getField("ID_TYPE_COMPTE_PCG_AB"), "!=", 1); } else if (typePlan == 3 || typePlan == 0) { w2 = null; } else { throw new IllegalArgumentException("Type de PCG inconnu : " + typePlan); } if (w2 != null) { w1 = w1.and(w2); } selCompte.setWhere(w1); selCompte.addRawOrder("\"" + table + "\".\"NUMERO\""); // selCompte.setDistinct(true); String reqCompte = selCompte.asString(); Object obCompte = base.getDataSource().execute(reqCompte, new ArrayListHandler()); List myListCompte = (List) obCompte; if (myListCompte != null) { int size = myListCompte.size(); for (int i = 0; i < size; i++) { Object[] objTmp = (Object[]) myListCompte.get(i); final Integer numero = new Integer(Integer.parseInt(objTmp[0].toString())); PlanComptableGModel.this.mapCompte.put(numero, new Integer(PlanComptableGModel.this.comptes.size())); PlanComptableGModel.this.comptes.add(new Compte(numero, objTmp[1].toString(), objTmp[2].toString(), objTmp[3].toString())); } } return null; } @Override protected void done() { PlanComptableGModel.this.fireTableDataChanged(); } }.execute(); this.titres.add("Compte"); this.titres.add("Libell"); }
From source file:org.openconcerto.erp.core.finance.accounting.model.PointageModel.java
public void updateTotauxCompte() { new SwingWorker<String, Object>() { @Override/* w ww . j a v a 2 s . c o m*/ protected String doInBackground() throws Exception { SQLSelect sel = new SQLSelect(base); sel.addSelect(tableEcr.getField("CREDIT"), "SUM"); sel.addSelect(tableEcr.getField("DEBIT"), "SUM"); Where w = new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", PointageModel.this.idCpt); sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "!=", ""))); String reqPointee = sel.toString(); Object obPointee = base.getDataSource().execute(reqPointee, new ArrayListHandler()); List myListPointee = (List) obPointee; PointageModel.this.creditPointe = 0; PointageModel.this.debitPointe = 0; if (myListPointee.size() != 0) { for (int i = 0; i < myListPointee.size(); i++) { Object[] objTmp = (Object[]) myListPointee.get(i); if (objTmp[0] != null) { PointageModel.this.creditPointe += ((Number) objTmp[0]).longValue(); } if (objTmp[1] != null) { PointageModel.this.debitPointe += ((Number) objTmp[1]).longValue(); } } } sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "=", ""))); String reqNotPointee = sel.toString(); Object obNotPointee = base.getDataSource().execute(reqNotPointee, new ArrayListHandler()); List myListNotPointee = (List) obNotPointee; PointageModel.this.creditNonPointe = 0; PointageModel.this.debitNonPointe = 0; if (myListNotPointee.size() != 0) { for (int i = 0; i < myListNotPointee.size(); i++) { Object[] objTmp = (Object[]) myListNotPointee.get(i); if (objTmp[0] != null) { PointageModel.this.creditNonPointe += ((Number) objTmp[0]).longValue(); } if (objTmp[1] != null) { PointageModel.this.debitNonPointe += ((Number) objTmp[1]).longValue(); } } } return null; } @Override protected void done() { PointageModel.this.fireTableDataChanged(); } }.execute(); }