Search in sources :

Example 1 with AbstractUITask

use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method showTopButtons.

private void showTopButtons() {
    final Composite buttonsComposite = new Composite(topSash, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(5, false));
    buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    if (compareRealDatabase) {
        showTopButtonsForRealDatabase(buttonsComposite);
    }
    final Button viewComparisonBtn = new Button(buttonsComposite, SWT.NONE);
    viewComparisonBtn.setText(Messages.viewEntireSchemaComparison);
    viewComparisonBtn.setToolTipText(Messages.aboutViewEntireSchemaComparison);
    viewComparisonBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            final List<String> sourceDBSchema = new ArrayList<String>();
            final List<String> targetDBSchema = new ArrayList<String>();
            viewComparisonBtn.setEnabled(false);
            ITask reportBugTask = new AbstractUITask() {

                public void cancel() {
                }

                public void finish() {
                }

                public boolean isCancel() {
                    return false;
                }

                public boolean isSuccess() {
                    return true;
                }

                public void execute(IProgressMonitor monitor) {
                    Map<String, SchemaInfo> source = compareModel.getSourceSchemas();
                    Map<String, SchemaInfo> target = compareModel.getTargetSchemas();
                    List<SchemaInfo> commonTables = new LinkedList<SchemaInfo>();
                    for (SchemaInfo sourceTable : source.values()) {
                        if (target.containsKey(sourceTable.getClassname())) {
                            commonTables.add(sourceTable);
                        }
                    }
                    Collections.sort(commonTables);
                    String s_schema = getDBSchema(sourceDB, source, commonTables);
                    sourceDBSchema.add(s_schema);
                    String t_schema = getDBSchema(targetDB, target, commonTables);
                    targetDBSchema.add(t_schema);
                }
            };
            TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
            taskExecutor.addTask(reportBugTask);
            new ExecTaskWithProgress(taskExecutor).exec();
            if (taskExecutor.isSuccess()) {
                String targetDbName = "";
                if (targetDB.isVirtual()) {
                    targetDbName = Messages.targetDatabase;
                    if (StringUtil.isNotEmpty(targetDB.getName())) {
                        targetDbName += " : " + targetDB.getName();
                    }
                } else {
                    targetDbName = Messages.targetDatabase + ": " + targetDB.getDatabaseInfo().getBrokerIP() + "@" + targetDB.getName();
                }
                String sourceBrokerIp = sourceDB.getDatabaseInfo().getBrokerIP();
                String sourceDbName = sourceDB.getName();
                showEntireSchemaCompareEditor(Messages.sourceDatabase + ": " + sourceBrokerIp + "@" + sourceDbName, Messages.targetDatabase + ": " + targetDbName, sourceDBSchema.get(0), targetDBSchema.get(0));
            }
            viewComparisonBtn.setEnabled(true);
        }
    });
    Button copyAlterFromSourceBtn = new Button(buttonsComposite, SWT.NONE);
    copyAlterFromSourceBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromSourceToTargetLabel + "]");
    copyAlterFromSourceBtn.setToolTipText(Messages.aboutCopyAlterSource);
    copyAlterFromSourceBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            copyTableAlterDDL(sourceDB, targetDB, true);
        }
    });
    Button copyAlterFromTargetBtn = new Button(buttonsComposite, SWT.NONE);
    copyAlterFromTargetBtn.setText(Messages.copyWholeSchemaAlter + "[" + Messages.fromTargetToSourceLabel + "]");
    copyAlterFromTargetBtn.setToolTipText(Messages.aboutCopyAlterTarget);
    copyAlterFromTargetBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            copyTableAlterDDL(targetDB, sourceDB, false);
        }
    });
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 2 with AbstractUITask

use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.

the class ImportERwinAction method createCompareModel.

/**
	 *
	 * @param tableSchema
	 * @param schemaInfos
	 */
private void createCompareModel(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, ERWinSchemaInfo> schemaInfos) {
    final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
    ITask reportBugTask = new AbstractUITask() {

        private boolean success = false;

        public void cancel() {
        }

        public void finish() {
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return success;
        }

        public void execute(IProgressMonitor monitor) {
            List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
            final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
            virtualDb.setVirtual(true);
            DatabaseInfo info = database.getDatabaseInfo();
            virtualDb.setDatabaseInfo(info);
            WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
            Map<String, SchemaInfo> dbSchemaInfos = new HashMap<String, SchemaInfo>();
            Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
            for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
                SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
                dbSchemaInfos.put(schemaInfo.getClassname(), schemaInfo);
            }
            wrappedDatabaseInfo.addSchemaInfos(dbSchemaInfos);
            wrappedDatabaseInfo.addTableSchemas(tableSchema);
            ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
            TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
            TableSchemaModel rightModel = new TableSchemaModel();
            rightModel.getTableSchemaMap().putAll(tableSchema);
            TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
            TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
            model.setSourceDB(database);
            model.setTargetDB(virtualDb);
            // TODO rename class to ErwinCompareModelInput
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
    taskExecutor.addTask(reportBugTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
        } catch (Exception e) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 3 with AbstractUITask

use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.

the class BLOBCellPopupDialog method exportData.

/**
	 *
	 * Export data to file
	 *
	 * @param isOpenProgram boolean
	 * @param filePath String
	 */
private boolean exportData(final String filePath, final boolean isOpenProgram) {
    final String charsetName = fileCharsetCombo.getText();
    if (currValue instanceof String) {
        try {
            "".getBytes(charsetName);
        } catch (UnsupportedEncodingException e) {
            CommonUITool.openErrorBox(Messages.errCharset);
            return false;
        }
    }
    AbstractUITask task = new AbstractUITask() {

        boolean isSuccess = false;

        public void execute(final IProgressMonitor monitor) {
            BufferedWriter writer = null;
            FileOutputStream out = null;
            InputStream in = null;
            try {
                if (currValue instanceof String) {
                    String content = (String) currValue;
                    if (DBAttrTypeFormatter.isBinaryString(content)) {
                        content = DBAttrTypeFormatter.getInnerString(content);
                        byte[] bytes = DBAttrTypeFormatter.getBytes(content, 2);
                        content = new String(bytes, charsetName);
                    } else if (DBAttrTypeFormatter.isHexString(content)) {
                        content = DBAttrTypeFormatter.getInnerString(content);
                        byte[] bytes = DBAttrTypeFormatter.getBytes(content, 16);
                        content = new String(bytes, charsetName);
                    }
                    writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), charsetName));
                    writer.write(content);
                    writer.flush();
                } else if (currValue instanceof File) {
                    out = new FileOutputStream(filePath);
                    in = new FileInputStream((File) currValue);
                    byte[] bytes = new byte[1024];
                    int len = 0;
                    while ((len = in.read(bytes)) != -1) {
                        out.write(bytes, 0, len);
                    }
                    out.flush();
                } else if (currValue instanceof byte[]) {
                    out = new FileOutputStream(filePath);
                    byte[] bytes = (byte[]) currValue;
                    out.write(bytes, 0, bytes.length);
                    out.flush();
                }
                isSuccess = true;
            } catch (Exception e) {
                errorMsg = e.getMessage();
            } finally {
                if (writer != null) {
                    try {
                        writer.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }

        public void cancel() {
        //empty
        }

        public void finish() {
        //empty
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return isSuccess;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.msgExportFieldData);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        if (isOpenProgram) {
            return true;
        }
        CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgExportSuccess);
        return true;
    }
    return false;
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) FileOutputStream(java.io.FileOutputStream) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 4 with AbstractUITask

use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.

the class CommonTaskExec method exec.

/**
	 * Execute the task
	 * 
	 * @param monitor the monitor
	 * @return <code>true</code>if success;<code>false</code> otherwise
	 */
public boolean exec(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return false;
    }
    if (taskName != null) {
        monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
    }
    for (final ITask task : taskList) {
        if (task instanceof AbstractUITask) {
            ((AbstractUITask) task).execute(monitor);
        } else {
            task.execute();
        }
        String errorMsg = task.getErrorMsg();
        if (messageHandler != null) {
            errorMsg = messageHandler.translate(task.getErrorMsg());
        }
        if (openErrorBox(null, errorMsg, monitor)) {
            return false;
        }
        //			});
        if (taskExeStatus != null && taskExeStatus == Status.CANCEL_STATUS) {
            return false;
        }
        if (taskExeStatus != null && taskExeStatus != Status.OK_STATUS) {
            errorMsg = taskExeStatus.getMessage();
            if (messageHandler != null) {
                errorMsg = messageHandler.translate(taskExeStatus.getMessage());
            }
            openErrorBox(null, errorMsg, monitor);
            return false;
        }
        if (monitor.isCanceled()) {
            return false;
        }
    }
    //		});
    return true;
}
Also used : AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) AbstractUITask(com.cubrid.common.core.task.AbstractUITask)

Example 5 with AbstractUITask

use of com.cubrid.common.core.task.AbstractUITask in project cubrid-manager by CUBRID.

the class CommonTaskJobExec method exec.

/**
	 * Execute the task
	 * 
	 * @param monitor the monitor
	 * @return <code>true</code>if success;<code>false</code> otherwise
	 */
public IStatus exec(IProgressMonitor monitor) {
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            setDialogVisible(false);
        }
    });
    if (monitor.isCanceled()) {
        cancel();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                closeDialog();
            }
        });
        return Status.CANCEL_STATUS;
    }
    for (final ITask task : taskList) {
        if (task instanceof AbstractUITask) {
            ((AbstractUITask) task).execute(monitor);
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    setDialogVisible(true);
                }
            });
            return new Status(IStatus.ERROR, CommonUIPlugin.PLUGIN_ID, msg);
        } else {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    taskExeStatus = refresh(task);
                }
            });
        }
        if (taskExeStatus != Status.OK_STATUS) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    setDialogVisible(true);
                }
            });
            return taskExeStatus;
        }
        if (monitor.isCanceled()) {
            cancel();
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    closeDialog();
                }
            });
            return Status.CANCEL_STATUS;
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) AbstractUITask(com.cubrid.common.core.task.AbstractUITask)

Aggregations

AbstractUITask (com.cubrid.common.core.task.AbstractUITask)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)8 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)8 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ITask (com.cubrid.common.core.task.ITask)6 ArrayList (java.util.ArrayList)4 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3 IOException (java.io.IOException)3 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 TableSchemaComparator (com.cubrid.common.ui.compare.schema.TableSchemaComparator)2 TableSchemaCompareModelInputLazy (com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy)2 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)2 TableSchemaModel (com.cubrid.common.ui.compare.schema.model.TableSchemaModel)2 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2