List of usage examples for java.beans PropertyChangeListener propertyChange
void propertyChange(PropertyChangeEvent evt);
From source file:edu.ku.brc.af.tasks.subpane.formeditor.EditorPropPanelOld.java
/** * @param controlHash// w ww .j a va 2 s. c o m * @param subcontrolHash * @param fieldsNotUsedByLabels * @param addSaveBtn * @param pcl */ public EditorPropPanelOld(final Hashtable<String, Control> controlHash, final Hashtable<String, SubControl> subcontrolHash, final Vector<FormCellField> fieldsNotUsedByLabels, final boolean addSaveBtn, final PropertyChangeListener pcl) { setLayout(new BorderLayout()); this.controlHash = controlHash; this.subcontrolHash = subcontrolHash; this.fieldsNotUsedByLabels = fieldsNotUsedByLabels; if (addSaveBtn) { saveBtn = UIHelper.createButton(getResourceString("EditorPropPanelOld.ACCEPT")); //$NON-NLS-1$ saveBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (currentData instanceof FormCellField) { getDataFromUI((FormCellField) currentData); } else { getDataFromUI(currentData); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(EditorPropPanelOld.this, "accept", currentData, //$NON-NLS-1$ currentData)); } } }); } viewDefMultiView = new MultiView(null, null, AppContextMgr.getInstance().getView("SystemSetup", "ViewDefProps"), //$NON-NLS-1$ //$NON-NLS-2$ AltViewIFace.CreationMode.EDIT, MultiView.IS_EDITTING, null); viewDefMultiView.getCurrentView().getValidator().setEnabled(true); viewDefMultiView.getCurrentView().getValidator().addEnableItem(saveBtn, FormValidator.EnableType.ValidAndChangedItems); viewMultiView = new MultiView(null, null, AppContextMgr.getInstance().getView("SystemSetup", "ViewProps"), //$NON-NLS-1$ //$NON-NLS-2$ AltViewIFace.CreationMode.EDIT, MultiView.IS_EDITTING, null); viewMultiView.getCurrentView().getValidator().setEnabled(true); viewMultiView.getCurrentView().getValidator().addEnableItem(saveBtn, FormValidator.EnableType.ValidAndChangedItems); }
From source file:edu.ku.brc.specify.config.SpecifyGUIDGeneratorFactory.java
/** * @param pcl/*from ww w . j a v a 2 s . c o m*/ * @param classes */ public static void buildAllGUIDsAynch(final PropertyChangeListener pcl, final ArrayList<Class<?>> classes) { final String COUNT = "COUNT"; final GhostGlassPane glassPane = UIRegistry.writeGlassPaneMsg(getResourceString("SETTING_GUIDS"), UIRegistry.STD_FONT_SIZE); glassPane.setProgress(0); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (SubPaneMgr.getInstance().aboutToShutdown()) { Taskable task = TaskMgr.getTask("Startup"); if (task != null) { SubPaneIFace splash = edu.ku.brc.specify.tasks.StartUpTask .createFullImageSplashPanel(task.getTitle(), task); SubPaneMgr.getInstance().addPane(splash); SubPaneMgr.getInstance().showPane(splash); } final GUIDWorker worker = new GUIDWorker() { protected Integer doInBackground() throws Exception { if (getInstance() instanceof SpecifyGUIDGeneratorFactory) { SpecifyGUIDGeneratorFactory guidGen = (SpecifyGUIDGeneratorFactory) getInstance(); guidGen.buildGUIDs(this); } return null; } @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("COUNT")) { firePropertyChange("COUNT", 0, evt.getNewValue()); } } @Override protected void done() { glassPane.setProgress(100); UIRegistry.clearGlassPaneMsg(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(this, "complete", "true", "true")); } } }; worker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (COUNT.equals(evt.getPropertyName())) { glassPane.setProgress((int) (((Integer) evt.getNewValue() * 100.0) / (double) CATEGORY_TYPE.values().length)); } } }); worker.execute(); } } }); }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * Does the backup on a SwingWorker Thread. * @param isMonthly whether it is a monthly backup * @param doSendAppExit requests sending an application exit command when done * @return true if the prefs are set up and there were no errors before the SwingWorker thread was started *//* ww w . j ava2s . c om*/ private boolean doBackUp(final boolean isMonthly, final boolean doSendAppExit, final PropertyChangeListener propChgListener) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqldumpLoc = remotePrefs.get(MYSQLDUMP_LOC, getDefaultMySQLDumpLoc()); final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc()); if (!(new File(mysqldumpLoc)).exists()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_DUMP", mysqldumpLoc); if (propChgListener != null) { propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } return false; } File backupDir = new File(backupLoc); if (!backupDir.exists()) { if (!backupDir.mkdir()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile()); if (propChgListener != null) { propChgListener.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } return false; } } errorMsg = null; final String databaseName = DBConnection.getInstance().getDatabaseName(); getNumberofTables(); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected String fullPath = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileOutputStream backupOut = null; try { Thread.sleep(100); // Create output file SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_kk_mm_ss"); String fileName = sdf.format(Calendar.getInstance().getTime()) + (isMonthly ? "_monthly" : "") + ".sql"; fullPath = backupLoc + File.separator + fileName; File file = new File(fullPath); backupOut = new FileOutputStream(file); writeStats(getCollectionStats(getTableNames()), getStatsName(fullPath)); String userName = DBConnection.getInstance().getUserName(); String password = DBConnection.getInstance().getPassword(); if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) { Pair<String, String> up = UserAndMasterPasswordMgr.getInstance().getUserNamePasswordForDB(); if (up != null && up.first != null && up.second != null) { userName = up.first; password = up.second; } } String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); Vector<String> args = new Vector<String>(); args.add(mysqldumpLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); InputStream input = process.getInputStream(); byte[] bytes = new byte[8192 * 2]; double oneMeg = (1024.0 * 1024.0); long dspMegs = 0; long totalBytes = 0; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { long megs = (long) (totalBytes / oneMeg); if (megs != dspMegs) { dspMegs = megs; long megsWithTenths = (long) ((totalBytes * 10.0) / oneMeg); firePropertyChange(MEGS, 0, megsWithTenths); } backupOut.write(bytes, 0, numBytes); } else { break; } } while (true); StringBuilder sb = new StringBuilder(); String line; BufferedReader errIn = new BufferedReader(new InputStreamReader(process.getErrorStream())); while ((line = errIn.readLine()) != null) { //System.err.println(line); if (line.startsWith("ERR") || StringUtils.contains(line, "Got error")) { sb.append(line); sb.append("\n"); if (StringUtils.contains(line, "1044") && StringUtils.contains(line, "LOCK TABLES")) { sb.append("\n"); sb.append(UIRegistry.getResourceString("MySQLBackupService.LCK_TBL_ERR")); sb.append("\n"); } } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_BK"); } finally { if (backupOut != null) { try { backupOut.flush(); backupOut.close(); } catch (IOException ex) { ex.printStackTrace(); errorMsg = ex.toString(); } } } return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(STATUSBAR_NAME); UIRegistry.clearSimpleGlassPaneMsg(); if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (doSendAppExit) { CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit")); } if (propChgListener != null) { propChgListener .propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, null, fullPath)); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(STATUSBAR_NAME, true); UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.BACKINGUP", databaseName), 24); backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName())) { long value = (Long) evt.getNewValue(); double val = value / 10.0; statusBar.setText(UIRegistry.getLocalizedMessage("MySQLBackupService.BACKUP_MEGS", val)); } } }); backupWorker.execute(); return true; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java
@Override public void copyLocale(final LocalizableIOIFaceListener lclIOListener, final Locale srcLocale, final Locale dstLocale, final PropertyChangeListener pcl) { double cnt = 0.0; Vector<LocalizableJListItem> items = getContainerDisplayItems(); double inc = 100.0 / items.size(); for (LocalizableJListItem listItem : items) { LocalizableContainerIFace table = getContainer(listItem, lclIOListener); copyLocale(table, srcLocale, dstLocale); for (LocalizableItemIFace field : table.getContainerItems()) { copyLocale(field, srcLocale, dstLocale); }/* w w w . ja va 2 s . co m*/ if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(listItem, "count", -1, (int) cnt)); //System.out.println(cnt); } cnt += inc; } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(this, "count", -1, 100)); } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerDlg.java
@Override public void copyLocale(final LocalizableIOIFaceListener lcl, Locale srcLocale, Locale dstLocale, final PropertyChangeListener pcl) { UIRegistry.getStatusBar().setProgressRange(SCHEMALOCDLG, 0, getContainerDisplayItems().size()); DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession(); try {/*w w w. j a v a 2 s .c om*/ double step = 100.0 / (double) tableDisplayItems.size(); double total = 0.0; for (LocalizableJListItem listItem : tableDisplayItems) { //System.out.println(listItem.getName()); SpLocaleContainer container = (SpLocaleContainer) tableHash.get(listItem.getId()); if (container == null) { container = loadTable(session, listItem.getId()); tableHash.put(listItem.getId(), container); } if (container != null) { copyLocale(container, srcLocale, dstLocale); for (LocalizableItemIFace field : container.getItems()) { //System.out.println(" "+field.getName()); copyLocale(field, srcLocale, dstLocale); } containerChanged(container); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(this, "progress", total, (int) (total + step))); } } else { log.error("Couldn't find Container[" + listItem.getId() + "]"); } total += step; } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, ex); ex.printStackTrace(); } finally { session.close(); UIRegistry.getStatusBar().setProgressDone(SCHEMALOCDLG); } pcl.propertyChange(new PropertyChangeEvent(this, "progress", 99, 100)); }
From source file:edu.ku.brc.specify.web.HttpLargeFileTransfer.java
/** * @param infileName/*from w ww. j a v a 2s .c o m*/ * @param outFileName * @param changeListener * @return */ public boolean compressFile(final String infileName, final String outFileName, final PropertyChangeListener propChgListener) { final File file = new File(infileName); if (file.exists()) { long fileSize = file.length(); if (fileSize > 0) { SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected String errorMsg = null; protected FileInputStream fis = null; protected GZIPOutputStream fos = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { try { Thread.sleep(100); long totalSize = file.length(); long bytesCnt = 0; FileInputStream fis = new FileInputStream(infileName); GZIPOutputStream fos = new GZIPOutputStream(new FileOutputStream(outFileName)); byte[] bytes = new byte[BUFFER_SIZE * 10]; while (true) { int len = fis.read(bytes); if (len > 0) { fos.write(bytes, 0, len); bytesCnt += len; firePropertyChange("MEGS", 0, (int) (((double) bytesCnt / (double) totalSize) * 100.0)); } else { break; } } fis.close(); fos.close(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); } finally { try { if (fis != null) { fis.close(); } if (fos != null) { fos.close(); } } catch (IOException ex) { errorMsg = ex.toString(); } } firePropertyChange("MEGS", 0, 100); return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(HttpLargeFileTransfer.class.toString()); //UIRegistry.clearSimpleGlassPaneMsg(); if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (propChgListener != null) { propChgListener.propertyChange( new PropertyChangeEvent(HttpLargeFileTransfer.this, "Done", 0, 1)); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(HttpLargeFileTransfer.class.toString(), true); UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("Compressing Backup..."), 24); backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if ("MEGS".equals(evt.getPropertyName())) { Integer value = (Integer) evt.getNewValue(); double val = value / 10.0; statusBar .setText(UIRegistry.getLocalizedMessage("MySQLBackupService.BACKUP_MEGS", val)); } } }); backupWorker.execute(); } else { // file doesn't exist } } else { // file doesn't exist } return false; }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param databaseName//from w w w . j av a 2 s .c om * @param restoreFilePath * @param glassPane * @param completionMsgKey */ protected boolean doRestoreInBackground(final String databaseName, final String restoreFilePath, final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl, final boolean doSynchronously) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc()); getNumberofTables(); SynchronousWorker backupWorker = new SynchronousWorker() { long dspMegs = 0; long fileSize = 0; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileInputStream input = null; try { String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName(); String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword(); String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); String cmdLine = String.format("%s -u %s --password=%s --host=%s %s %s", mysqlLoc, userName, password, server, (port != null ? ("--port=" + port) : ""), databaseName); Vector<String> args = new Vector<String>(); args.add(mysqlLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); Thread.sleep(100); OutputStream out = process.getOutputStream(); // wait as long it takes till the other process has prompted. try { File inFile = new File(restoreFilePath); fileSize = inFile.length(); //System.out.println(fileSize); double oneMB = (1024.0 * 1024.0); double threshold = fileSize < (oneMB * 4) ? 8192 * 8 : oneMB; long totalBytes = 0; dspMegs = 0; input = new FileInputStream(inFile); try { byte[] bytes = new byte[8192 * 4]; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { out.write(bytes, 0, numBytes); long megs = (long) (totalBytes / threshold); if (megs != dspMegs) { dspMegs = megs; firePropertyChange(MEGS, dspMegs, (int) ((100.0 * totalBytes) / fileSize)); } } else { break; } } while (true); } finally { input.close(); } } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MySQLBackupService.class, ex); ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_RS"); } catch (Exception ex) { ex.printStackTrace(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } setProgress(100); out.flush(); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.err.println(line); } in = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { if (line.startsWith("ERR")) { sb.append(line); sb.append("\n"); } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } return null; } @Override protected void done() { super.done(); JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { statusBar.setProgressDone(STATUSBAR_NAME); } if (glassPane != null) { UIRegistry.clearSimpleGlassPaneMsg(); } if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (statusBar != null) { statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs)); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1)); } } }; if (glassPane != null) { glassPane.setProgress(0); } backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName()) && glassPane != null) { int value = (Integer) evt.getNewValue(); if (value < 100) { glassPane.setProgress((Integer) evt.getNewValue()); } else { glassPane.setProgress(100); } } } }); if (doSynchronously) { return backupWorker.doWork(); } backupWorker.execute(); return true; }
From source file:edu.ku.brc.specify.web.HttpLargeFileTransfer.java
/** * @param fileName// w w w . j a v a 2 s .c o m * @param urlStr * @param isSiteFile * @param propChgListener */ public void transferFile(final String fileName, final String urlStr, final boolean isSiteFile, final PropertyChangeListener propChgListener) { final String prgName = HttpLargeFileTransfer.class.toString(); final File file = new File(fileName); if (file.exists()) { final long fileSize = file.length(); if (fileSize > 0) { SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected String errorMsg = null; protected FileInputStream fis = null; protected OutputStream fos = null; protected int nChunks = 0; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { try { Thread.sleep(100); fis = new FileInputStream(file); nChunks = (int) (fileSize / MAX_CHUNK_SIZE); if (fileSize % MAX_CHUNK_SIZE > 0) { nChunks++; } byte[] buf = new byte[BUFFER_SIZE]; long bytesRemaining = fileSize; String clientID = String.valueOf((long) (Long.MIN_VALUE * Math.random())); URL url = new URL(urlStr); UIRegistry.getStatusBar().setProgressRange(prgName, 0, nChunks); for (int i = 0; i < nChunks; i++) { firePropertyChange(prgName, i - 1, i == nChunks - 1 ? Integer.MAX_VALUE : i); if (i == nChunks - 1) { Thread.sleep(500); int x = 0; x++; } HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); int chunkSize = (int) ((bytesRemaining > MAX_CHUNK_SIZE) ? MAX_CHUNK_SIZE : bytesRemaining); bytesRemaining -= chunkSize; conn.setRequestProperty("Content-Type", "application/octet-stream"); conn.setRequestProperty("Content-Length", String.valueOf(chunkSize)); conn.setRequestProperty(CLIENT_ID_HEADER, clientID); conn.setRequestProperty(FILE_NAME_HEADER, fileName); conn.setRequestProperty(FILE_CHUNK_COUNT_HEADER, String.valueOf(nChunks)); conn.setRequestProperty(FILE_CHUNK_HEADER, String.valueOf(i)); conn.setRequestProperty(SERVICE_NUMBER, "10"); conn.setRequestProperty(IS_SITE_FILE, Boolean.toString(isSiteFile)); fos = conn.getOutputStream(); //UIRegistry.getStatusBar().setProgressRange(prgName, 0, (int)((double)chunkSize / BUFFER_SIZE)); int cnt = 0; int bytesRead = 0; while (bytesRead < chunkSize) { int read = fis.read(buf); if (read == -1) { break; } else if (read > 0) { bytesRead += read; fos.write(buf, 0, read); } cnt++; //firePropertyChange(prgName, cnt-1, cnt); } fos.close(); if (conn.getResponseCode() != HttpServletResponse.SC_OK) { System.err.println( conn.getResponseMessage() + " " + conn.getResponseCode() + " "); BufferedReader in = new BufferedReader( new InputStreamReader(conn.getErrorStream())); String line = null; StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { sb.append(line); sb.append("\n"); } System.out.println(sb.toString()); in.close(); } else { System.err.println("OK"); } //UIRegistry.getStatusBar().setProgressRange(prgName, 0, nChunks); firePropertyChange(prgName, i - 1, i == nChunks - 1 ? Integer.MAX_VALUE : i); } } catch (IOException ex) { errorMsg = ex.toString(); } //firePropertyChange(prgName, 0, 100); return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(prgName); UIRegistry.clearSimpleGlassPaneMsg(); if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (propChgListener != null) { propChgListener.propertyChange( new PropertyChangeEvent(HttpLargeFileTransfer.this, "Done", 0, 1)); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(HttpLargeFileTransfer.class.toString(), true); UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("Transmitting..."), 24); backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { System.out.println(evt.getPropertyName() + " " + evt.getNewValue()); if (prgName.equals(evt.getPropertyName())) { Integer value = (Integer) evt.getNewValue(); if (value == Integer.MAX_VALUE) { statusBar.setIndeterminate(prgName, true); UIRegistry.writeSimpleGlassPaneMsg( getLocalizedMessage("Transfering data into the database."), 24); } else { statusBar.setValue(prgName, value); } } } }); backupWorker.execute(); } else { // file doesn't exist } } else { // file doesn't exist } }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
public boolean doRestoreBulkDataInBackground(final String databaseName, final String options, final String restoreZipFilePath, final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl, final boolean doSynchronously, final boolean doDropDatabase) { getNumberofTables();//from www . j a va2 s . co m SynchronousWorker backupWorker = new SynchronousWorker() { long dspMegs = 0; @Override protected Integer doInBackground() throws Exception { boolean skipTrackExceptions = BasicSQLUtils.isSkipTrackExceptions(); BasicSQLUtils.setSkipTrackExceptions(false); try { String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName(); String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword(); DBConnection currDBConn = DBConnection.getInstance(); String dbName = currDBConn.getDatabaseName(); DBMSUserMgr dbMgr = DBMSUserMgr.getInstance(); if (dbMgr != null) { boolean isConnected = dbMgr.connectToDBMS(userName, password, currDBConn.getServerName(), dbName, currDBConn.isEmbedded()); if (isConnected) { if (doDropDatabase) { if (dbMgr.doesDBExists(databaseName) && !dbMgr.dropDatabase(databaseName)) { log.error("Database[" + databaseName + "] could not be dropped before load."); UIRegistry.showLocalizedError("MySQLBackupService.ERR_DRP_DB", databaseName); return null; } if (!dbMgr.createDatabase(databaseName)) { log.error("Database[" + databaseName + "] could not be created before load."); UIRegistry.showLocalizedError("MySQLBackupService.CRE_DRP_DB", databaseName); return null; } } DatabaseDriverInfo driverInfo = DatabaseDriverInfo .getDriver(DBConnection.getInstance().getDriverName()); String connStr = DBConnection.getInstance().getConnectionStr(); DBConnection itDBConn = DBConnection.createInstance(driverInfo.getDriverClassName(), driverInfo.getDialectClassName(), databaseName, connStr, userName, password); Connection connection = itDBConn.createConnection(); connection.setCatalog(databaseName); List<File> unzippedFiles = ZipFileHelper.getInstance() .unzipToFiles(new File(restoreZipFilePath)); boolean dbCreated = false; for (File file : unzippedFiles) { //System.out.println(file.getName()); if (file.getName().equals("createdb.sql")) { long size = restoreFile(connection, file); log.debug("size: " + size); dbCreated = true; } } if (dbCreated) { for (File file : unzippedFiles) { if (file.getName().endsWith("infile")) { String fPath = file.getCanonicalPath(); if (UIHelper.isWindows()) { fPath = StringUtils.replace(fPath, "\\", "\\\\"); } String sql = "LOAD DATA LOCAL INFILE '" + fPath + "' INTO TABLE " + FilenameUtils.getBaseName(file.getName()); log.debug(sql); //System.err.println(sql); int rv = BasicSQLUtils.update(connection, sql); log.debug("done fPath[" + fPath + "] rv= " + rv); //System.err.println("done fPath["+fPath+"] rv= "+rv); } } } ZipFileHelper.getInstance().cleanUp(); /*if (!dbMgr.dropDatabase(databaseName)) { log.error("Database["+databaseName+"] could not be dropped after load."); UIRegistry.showLocalizedError("MySQLBackupService.ERR_DRP_DBAF", databaseName); }*/ setProgress(100); //errorMsg = sb.toString(); itDBConn.close(); } else { // error can't connect } } else { // error } } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } finally { BasicSQLUtils.setSkipTrackExceptions(skipTrackExceptions); } return null; } @Override protected void done() { super.done(); JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { statusBar.setProgressDone(STATUSBAR_NAME); } if (glassPane != null) { UIRegistry.clearSimpleGlassPaneMsg(); } if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (statusBar != null) { statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs)); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1)); } } }; if (glassPane != null) { glassPane.setProgress(0); } backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName()) && glassPane != null) { int value = (Integer) evt.getNewValue(); if (value < 100) { glassPane.setProgress((Integer) evt.getNewValue()); } else { glassPane.setProgress(100); } } } }); if (doSynchronously) { return backupWorker.doWork(); } backupWorker.execute(); return true; }
From source file:org.colombbus.tangara.FileUtils.java
private static void addDirectoryToJar(File directory, JarOutputStream output, String prefix, PropertyChangeListener listener) throws IOException { try {/*from w ww.j a v a2 s. com*/ File files[] = directory.listFiles(); JarEntry entry = null; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { if (prefix != null) { entry = new JarEntry(prefix + "/" + files[i].getName() + "/"); output.putNextEntry(entry); addDirectoryToJar(files[i], output, prefix + "/" + files[i].getName(), listener); } else { entry = new JarEntry(files[i].getName() + "/"); output.putNextEntry(entry); addDirectoryToJar(files[i], output, files[i].getName(), listener); } } else { addFileToJar(files[i], output, prefix); if (listener != null) { listener.propertyChange(new PropertyChangeEvent(directory, "fileAdded", null, null)); } } } } catch (IOException e) { LOG.error("Error while adding directory '" + directory.getAbsolutePath() + "'", e); throw e; } }