Search in sources :

Example 1 with XlsxRowNumberHandler

use of com.cubrid.common.ui.cubrid.table.control.XlsxRowNumberHandler in project cubrid-manager by CUBRID.

the class XLSXImportFileHandler method getSourceFileInfo.

/**
	 * Get the source file information
	 *
	 * @return ImportFileDescription
	 * @throws InvocationTargetException Exception in process
	 * @throws InterruptedException The exception
	 */
public ImportFileDescription getSourceFileInfo() throws InvocationTargetException, InterruptedException {
    // FIXME move this logic to core module
    synchronized (this) {
        if (importFileDescription == null) {
            final XlsxRowNumberHandler xlsxRowNumberHandler = new XlsxRowNumberHandler(fileName);
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(final IProgressMonitor monitor) {
                    monitor.beginTask("", IProgressMonitor.UNKNOWN);
                    Thread thread = new //$NON-NLS-1$
                    Thread(//$NON-NLS-1$
                    "Monitoring cancel") {

                        public void run() {
                            while (monitor != null && !monitor.isCanceled() && !xlsxRowNumberHandler.isEnd()) {
                                try {
                                    sleep(100);
                                } catch (InterruptedException e) {
                                    LOGGER.error(e.getMessage(), e);
                                }
                            }
                            if (monitor != null && monitor.isCanceled()) {
                                xlsxRowNumberHandler.setCancel(true);
                                monitor.done();
                            }
                        }
                    };
                    thread.start();
                    xlsxRowNumberHandler.process();
                    monitor.done();
                }
            };
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
            List<Integer> itemsNumberOfSheets = null;
            int totalRowCount = 0;
            List<String> colsLst = xlsxRowNumberHandler.getHeadInfo();
            if (xlsxRowNumberHandler.isCancel()) {
                throw new InterruptedException();
            } else {
                totalRowCount = xlsxRowNumberHandler.getNumberOfAllRow();
                itemsNumberOfSheets = xlsxRowNumberHandler.getItemsNumberOfSheets();
            }
            int sheetNum = 0;
            if (itemsNumberOfSheets != null) {
                sheetNum = itemsNumberOfSheets.size();
            }
            importFileDescription = new ImportFileDescription(totalRowCount, sheetNum, colsLst);
            importFileDescription.setItemsNumberOfSheets(itemsNumberOfSheets);
        }
        return importFileDescription;
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XlsxRowNumberHandler(com.cubrid.common.ui.cubrid.table.control.XlsxRowNumberHandler) ImportFileDescription(com.cubrid.common.ui.cubrid.table.importhandler.ImportFileDescription) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

XlsxRowNumberHandler (com.cubrid.common.ui.cubrid.table.control.XlsxRowNumberHandler)1 ImportFileDescription (com.cubrid.common.ui.cubrid.table.importhandler.ImportFileDescription)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1