Search in sources :

Example 1 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class ExportConnectionUtil method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 *
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == COPY_CLIPBOARD_ID) {
        List<CubridDatabase> databaseList = getCheckedDatabases();
        if (databaseList.size() <= 0) {
            CommonUITool.openErrorBox(getShell(), Messages.expConDialogCopyErrorMsg);
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (CubridDatabase db : databaseList) {
            if (sb.length() > 0) {
                sb.append(StringUtil.NEWLINE);
            }
            sb.append(NodeUtil.getJavaConnectionUrl(db.getDatabaseInfo()));
        }
        TextTransfer textTransfer = TextTransfer.getInstance();
        Clipboard clipboard = CommonUITool.getClipboard();
        clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
        CommonUITool.openInformationBox(Messages.titleSuccess, Messages.expConDialogCopySucessMsg);
        return;
    } else if (buttonId == IDialogConstants.OK_ID) {
        if (!verify()) {
            return;
        }
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
        String[] filterExtensions = new String[] { "*.xls" };
        //Windows wild cards
        dialog.setFilterExtensions(filterExtensions);
        String fileName = dialog.open();
        if (fileName == null) {
            return;
        }
        /*Process the file extensions*/
        if (!ExportConnectionUtil.isTxtFile(fileName) && !ExportConnectionUtil.isXlsFile(fileName) && !ExportConnectionUtil.isXlsxFile(fileName)) {
            int filterIndex = dialog.getFilterIndex();
            if (filterIndex == 0 || filterIndex == 2) {
                fileName = fileName + ".xls";
            } else if (filterIndex == 1) {
                fileName = fileName + ".txt";
            }
        }
        TaskExecutor taskExec = new CommonTaskExec(Messages.nameExportConnectionTask);
        File file = new File(fileName);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                LOGGER.error("Create file failed:" + e.getMessage());
            }
        }
        ExportConnectionsTask task = new ExportConnectionsTask(getCheckedDatabases(), file);
        taskExec.addTask(task);
        new ExecTaskWithProgress(taskExec).busyCursorWhile();
        if (taskExec.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgConnectionUrlExported);
            super.okPressed();
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IOException(java.io.IOException) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Clipboard(org.eclipse.swt.dnd.Clipboard) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 2 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method doRefresh.

private void doRefresh(boolean collectRecordCount) {
    // FIXME logic code move to core module
    Map<String, DataCompare> dataCompareMap = new HashMap<String, DataCompare>();
    if (compareList != null) {
        for (DataCompare dataCompare : compareList) {
            dataCompareMap.put(dataCompare.getTableName(), dataCompare);
        }
    }
    DatabaseInfo sourceDB = ((DataCompareEditorInput) getEditorInput()).getSourceDB();
    DatabaseInfo targetDB = ((DataCompareEditorInput) getEditorInput()).getTargetDB();
    if (logFileBaseName != null) {
        FileUtil.delete(logFileBasePath + File.separatorChar + logFileBaseName);
        logFileBaseName = null;
    }
    logFileBaseName = sourceDB.getDbName() + "_" + System.currentTimeMillis();
    GetAllSchemaTask sourceSchemaTask = new GetAllSchemaTask(sourceDB);
    GetAllSchemaTask targetSchemaTask = new GetAllSchemaTask(targetDB);
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
    taskExecutor.addTask(sourceSchemaTask);
    taskExecutor.addTask(targetSchemaTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        synchronized (compareList) {
            compareList.clear();
            Set<String> partitions = new HashSet<String>();
            List<SchemaInfo> sourceList = sourceSchemaTask.getSchemaList();
            List<SchemaInfo> targetList = targetSchemaTask.getSchemaList();
            for (SchemaInfo schemaInfo : sourceList) {
                if (schemaInfo.getPartitionList() != null) {
                    for (PartitionInfo partition : schemaInfo.getPartitionList()) {
                        String partClassName = partition.getPartitionClassName();
                        partitions.add(partClassName);
                    }
                }
            }
            for (SchemaInfo schemaInfo : sourceList) {
                DataCompare dataCompare = dataCompareMap.get(schemaInfo.getClassname());
                if (dataCompare == null) {
                    dataCompare = new DataCompare();
                    dataCompare.setTableName(schemaInfo.getClassname());
                    dataCompare.setSchemaInfo(schemaInfo);
                    dataCompare.setRefreshed(false);
                } else {
                    dataCompare.setMatches(0);
                    dataCompare.setNotExists(0);
                    dataCompare.setNotMatches(0);
                    dataCompare.setProgressPosition(0);
                }
                if (schemaInfo.hasPK() && !partitions.contains(schemaInfo.getClassname())) {
                    SchemaInfo targetSchemeInfo = getSchemeInfoByName(schemaInfo.getClassname(), targetList);
                    boolean isSameSchema = canCompareData(schemaInfo, targetSchemeInfo);
                    dataCompare.setSameSchema(isSameSchema);
                    compareList.add(dataCompare);
                }
            }
            Collections.sort(compareList, new Comparator<DataCompare>() {

                public int compare(DataCompare o1, DataCompare o2) {
                    if (o1 == null || o1.getTableName() == null) {
                        return -1;
                    } else if (o2 == null || o2.getTableName() == null) {
                        return 1;
                    }
                    return o1.getTableName().compareToIgnoreCase(o2.getTableName());
                }
            });
        }
        compareTableViewer.refresh();
    }
    if (!collectRecordCount) {
        return;
    }
    totalRecords = 0;
    completedRecords = 0;
    refreshRecordCount();
    refreshedRecordCounts = true;
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) HashMap(java.util.HashMap) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) HashSet(java.util.HashSet) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 3 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.

the class EditProcedureAction method run.

/**
	 * Open the EditProcedureDialog and edit procedure
	 */
public void run() {
    // FIXME logic code move to core module
    Object[] objArr = this.getSelectedObj();
    if (!isSupported(objArr)) {
        this.setEnabled(false);
        return;
    }
    Shell shell = getShell();
    CubridDatabase database = null;
    ISchemaNode node = null;
    if (objArr[0] instanceof ISchemaNode && NodeType.STORED_PROCEDURE_PROCEDURE.equals(((ISchemaNode) objArr[0]).getType())) {
        node = (ISchemaNode) objArr[0];
        database = node.getDatabase();
    }
    if (database == null || node == null) {
        CommonUITool.openErrorBox(shell, Messages.errSelectProcedure);
        return;
    }
    final GetSPInfoListTask task = new GetSPInfoListTask(database.getDatabaseInfo());
    task.setSpName(node.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(null);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<SPInfo> list = task.getSPInfoList();
    if (list.size() > 1) {
        CommonUITool.openErrorBox(shell, Messages.errDuplicateName);
        return;
    }
    if (list.isEmpty()) {
        CommonUITool.openErrorBox(shell, Messages.errNotExistName);
        return;
    }
    EditProcedureDialog dlg = new EditProcedureDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(false);
    dlg.setSpInfo(list.get(0));
    if (dlg.open() == IDialogConstants.OK_ID) {
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) EditProcedureDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditProcedureDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetSPInfoListTask(com.cubrid.cubridmanager.core.cubrid.sp.task.GetSPInfoListTask)

Example 4 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress 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 5 with ExecTaskWithProgress

use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress 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)

Aggregations

ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)155 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)124 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)106 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 TreeViewer (org.eclipse.jface.viewers.TreeViewer)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 ITask (com.cubrid.common.core.task.ITask)35 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)30 ArrayList (java.util.ArrayList)29 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)26 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)25 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)23 Shell (org.eclipse.swt.widgets.Shell)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)12 IEditorPart (org.eclipse.ui.IEditorPart)12 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)11