Search in sources :

Example 1 with ExportSchemaTask

use of com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask in project cubrid-manager by CUBRID.

the class ExportERwinAction method run.

public void run() {
    // FIXME logic code move to core module
    int selected = 0;
    int logined = 0;
    Object[] objects = getSelectedObj();
    if (objects instanceof Object[]) {
        for (Object object : objects) {
            if (object instanceof CubridDatabase) {
                selected++;
                CubridDatabase database = (CubridDatabase) object;
                if (database.isLogined()) {
                    logined++;
                }
            }
        }
    }
    if (selected > 1) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLeastOneDb);
        return;
    }
    if (selected <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectExportDb);
        return;
    }
    if (logined <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDb);
        return;
    }
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE | SWT.APPLICATION_MODAL);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    String filename = dialog.open();
    if (filename == null) {
        return;
    }
    if (filename.trim().equals("")) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return;
    }
    for (Object obj : objects) {
        if (!(obj instanceof CubridDatabase)) {
            continue;
        }
        CubridDatabase database = (CubridDatabase) obj;
        final Map<String, SchemaInfo> allSchemaInfos = new HashMap<String, SchemaInfo>();
        TaskExecutor executor = new TaskExecutor() {

            public boolean exec(IProgressMonitor monitor) {
                for (ITask task : taskList) {
                    if (task instanceof ExportSchemaTask) {
                        ExportSchemaTask eTask = (ExportSchemaTask) task;
                        try {
                            eTask.initMarshaller();
                        } catch (JAXBException e) {
                            e.printStackTrace();
                            eTask.cancel();
                            return false;
                        }
                        monitor.setTaskName(Messages.msgGenerateInfo);
                        monitor.worked(50);
                        eTask.execute();
                        monitor.setTaskName(Messages.msgFinished);
                        monitor.worked(100);
                        monitor.done();
                    } else if (task instanceof GetAllSchemaTask) {
                        monitor.beginTask(Messages.msgGenerateInfo, 100);
                        GetAllSchemaTask gTask = (GetAllSchemaTask) task;
                        gTask.execute();
                        if (task.getErrorMsg() == null) {
                            allSchemaInfos.putAll(gTask.getSchemas());
                        }
                        if (allSchemaInfos.size() == 0) {
                            continue;
                        }
                    }
                }
                return true;
            }
        };
        ExportSchemaTask task = new ExportSchemaTask(allSchemaInfos, filename);
        GetAllSchemaTask schemaTask = new GetAllSchemaTask(database.getDatabaseInfo());
        executor.addTask(schemaTask);
        executor.addTask(task);
        new ExecTaskWithProgress(executor).busyCursorWhile();
        if (executor.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleExportSchema, Messages.msgExportSuccess);
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ExportSchemaTask(com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) FileDialog(org.eclipse.swt.widgets.FileDialog) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 2 with ExportSchemaTask

use of com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask in project cubrid-manager by CUBRID.

the class ExportERwinDataController method exportData.

public boolean exportData(Shell parentShell, boolean isDirectSave) {
    String fileFullName;
    if (!isDirectSave || latestFileFullName == null) {
        FileDialog dialog = new FileDialog(parentShell, SWT.SAVE | SWT.APPLICATION_MODAL);
        dialog.setFilterExtensions(new String[] { "*.xml" });
        fileFullName = dialog.open();
    } else {
        fileFullName = latestFileFullName;
    }
    if (fileFullName == null) {
        return false;
    }
    if (fileFullName.trim().length() == 0) {
        CommonUITool.openErrorBox(Messages.errFileNameIsEmpty);
        return false;
    }
    TaskExecutor executor = new TaskExecutor() {

        @Override
        public boolean exec(IProgressMonitor monitor) {
            for (ITask task : taskList) {
                if (task instanceof ExportSchemaTask) {
                    ExportSchemaTask eTask = (ExportSchemaTask) task;
                    try {
                        eTask.initMarshaller();
                    } catch (JAXBException e) {
                        e.printStackTrace();
                        eTask.cancel();
                        return false;
                    }
                    monitor.setTaskName(Messages.msgGenerateInfo);
                    monitor.worked(50);
                    eTask.execute();
                    monitor.setTaskName(Messages.msgFinished);
                    monitor.worked(100);
                    monitor.done();
                }
            }
            return true;
        }
    };
    ExportSchemaTask task = new ExportSchemaTask(getERSchema().getAllSchemaInfo(), fileFullName);
    List<ERTable> tables = getERSchema().getTables();
    Map<String, String> tablePLMap = new HashMap<String, String>();
    Map<String, Map<String, List>> tablesPhysicalLogicalMap = new HashMap<String, Map<String, List>>();
    for (ERTable table : tables) {
        tablePLMap.put(table.getName(true), table.getName(false));
        Map<String, List> columnsPLMap = new HashMap<String, List>();
        tablesPhysicalLogicalMap.put(table.getName(true), columnsPLMap);
        List<ERTableColumn> columns = table.getColumns();
        for (ERTableColumn column : columns) {
            List<String> logicalNameAndType = new LinkedList<String>();
            columnsPLMap.put(column.getName(true), logicalNameAndType);
            logicalNameAndType.add(column.getName(false));
            logicalNameAndType.add(column.getShowType(false));
        }
    }
    task.setTablePLMap(tablePLMap);
    task.setTablesPhysicalLogicalMap(tablesPhysicalLogicalMap);
    executor.addTask(task);
    new ExecTaskWithProgress(executor).busyCursorWhile();
    if (executor.isSuccess()) {
        latestFileFullName = fileFullName;
        CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.titleExport, Messages.bind(com.cubrid.common.ui.er.Messages.msgExportSuccess, fileFullName));
    }
    return executor.isSuccess();
}
Also used : ITask(com.cubrid.common.core.task.ITask) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) ERTable(com.cubrid.common.ui.er.model.ERTable) ExportSchemaTask(com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask) LinkedList(java.util.LinkedList) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) List(java.util.List) LinkedList(java.util.LinkedList) FileDialog(org.eclipse.swt.widgets.FileDialog) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ITask (com.cubrid.common.core.task.ITask)2 ExportSchemaTask (com.cubrid.common.ui.cubrid.database.erwin.task.ExportSchemaTask)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2 HashMap (java.util.HashMap)2 JAXBException (javax.xml.bind.JAXBException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 ERTable (com.cubrid.common.ui.er.model.ERTable)1 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 GetAllSchemaTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1