Search in sources :

Example 11 with TableDetailInfo

use of com.cubrid.common.core.common.model.TableDetailInfo in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method createTablesDetailInfoTable.

/**
	 * createTablesDetailInfoTable
	 *
	 * @param parent
	 */
public void createTablesDetailInfoTable(Composite parent) {
    final Composite tableComposite = new Composite(parent, SWT.NONE);
    tableComposite.setLayout(new FillLayout());
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tableListView = new TableViewer(tableComposite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    tableListView.getTable().setHeaderVisible(true);
    tableListView.getTable().setLinesVisible(true);
    final TableViewerColumn columnTableName = new TableViewerColumn(tableListView, SWT.LEFT);
    columnTableName.getColumn().setWidth(150);
    columnTableName.getColumn().setText(Messages.tablesDetailInfoPartColTableName);
    columnTableName.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_NAME));
            tableListView.getTable().setSortColumn(columnTableName.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnTableDesc = new TableViewerColumn(tableListView, SWT.LEFT);
    columnTableDesc.getColumn().setWidth(200);
    columnTableDesc.getColumn().setText(Messages.tablesDetailInfoPartColTableMemo);
    columnTableDesc.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_MEMO));
            tableListView.getTable().setSortColumn(columnTableDesc.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnRecordsCount = new TableViewerColumn(tableListView, SWT.LEFT);
    columnRecordsCount.getColumn().setWidth(60);
    columnRecordsCount.getColumn().setText(Messages.tablesDetailInfoPartColRecordsCount);
    columnRecordsCount.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_RECORD));
            tableListView.getTable().setSortColumn(columnRecordsCount.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnColumnsCount = new TableViewerColumn(tableListView, SWT.LEFT);
    columnColumnsCount.getColumn().setWidth(80);
    columnColumnsCount.getColumn().setText(Messages.tablesDetailInfoPartColColumnsCount);
    columnColumnsCount.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_COLUMN));
            tableListView.getTable().setSortColumn(columnColumnsCount.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnPK = new TableViewerColumn(tableListView, SWT.LEFT);
    columnPK.getColumn().setWidth(50);
    columnPK.getColumn().setText(Messages.tablesDetailInfoPartColPK);
    columnPK.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_PK));
            tableListView.getTable().setSortColumn(columnPK.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnTableUK = new TableViewerColumn(tableListView, SWT.LEFT);
    columnTableUK.getColumn().setWidth(50);
    columnTableUK.getColumn().setText(Messages.tablesDetailInfoPartColUK);
    columnTableUK.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_UK));
            tableListView.getTable().setSortColumn(columnTableUK.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnFK = new TableViewerColumn(tableListView, SWT.LEFT);
    columnFK.getColumn().setWidth(50);
    columnFK.getColumn().setText(Messages.tablesDetailInfoPartColFK);
    columnFK.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_FK));
            tableListView.getTable().setSortColumn(columnFK.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnIndex = new TableViewerColumn(tableListView, SWT.LEFT);
    columnIndex.getColumn().setWidth(50);
    columnIndex.getColumn().setText(Messages.tablesDetailInfoPartColIndex);
    columnIndex.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_INDEX));
            tableListView.getTable().setSortColumn(columnIndex.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    final TableViewerColumn columnRecordsSize = new TableViewerColumn(tableListView, SWT.LEFT);
    columnRecordsSize.getColumn().setWidth(100);
    columnRecordsSize.getColumn().setText(Messages.tablesDetailInfoPartColTableRecordsSize);
    columnRecordsSize.getColumn().addSelectionListener(new SelectionAdapter() {

        boolean isAsc = false;

        public void widgetSelected(SelectionEvent e) {
            tableListView.setSorter(new ColumnViewerSorter(isAsc, ColumnViewerSorter.PROPERTY_SIZE));
            tableListView.getTable().setSortColumn(columnRecordsSize.getColumn());
            tableListView.getTable().setSortDirection(isAsc ? SWT.UP : SWT.DOWN);
            isAsc = !isAsc;
        }
    });
    tableListView.setContentProvider(new TableDashboardContentProvider());
    tableListView.setLabelProvider(new TableDashboardLabelProvider());
    tableListView.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            TableDetailInfo oneTableDetail = (TableDetailInfo) selection.getFirstElement();
            openTableDetail(oneTableDetail);
        }
    });
    tableListView.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
                copySelectedTableNamesToClipboard();
            } else if (event.keyCode == SWT.CR) {
                showEditDialog(tableListView.getTable(), tableListView.getTable().getSelectionIndex());
            }
        }
    });
    registerContextMenu();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 12 with TableDetailInfo

use of com.cubrid.common.core.common.model.TableDetailInfo in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method createPartControl.

public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    ToolBar toolBar = new ToolBar(parent, SWT.LEFT_TO_RIGHT | SWT.FLAT);
    toolBar.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    ToolItem refreshItem = new ToolItem(toolBar, SWT.PUSH);
    refreshItem.setText(Messages.tablesDetailInfoPartRefreshBtn);
    refreshItem.setToolTipText(Messages.tablesDetailInfoPartBtnRefreshTip);
    refreshItem.setImage(CommonUIPlugin.getImage("icons/action/refresh.png"));
    refreshItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            refresh();
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem countItem = new ToolItem(toolBar, SWT.PUSH);
    countItem.setText(Messages.tablesDetailInfoPartBtnEsitmateRecord);
    countItem.setToolTipText(Messages.tablesDetailInfoPartBtnEsitmateRecordTip);
    countItem.setImage(CommonUIPlugin.getImage("icons/action/count.gif"));
    countItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            List<TableDetailInfo> list = new ArrayList<TableDetailInfo>();
            TableItem[] items = tableListView.getTable().getSelection();
            for (TableItem item : items) {
                list.add((TableDetailInfo) item.getData());
            }
            // Check selected size and confirm
            if (list.size() == 0) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartAlertNotSelected);
                return;
            }
            if (CommonUITool.openConfirmBox(Messages.tablesDetailInfoPartBtnEsitmateRecordAlert)) {
                LoadTableRecordCountsProgress progress = new LoadTableRecordCountsProgress(database, list);
                progress.getTableCounts();
                tableListView.refresh();
            }
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem viewDataItem = new ToolItem(toolBar, SWT.PUSH);
    viewDataItem.setText(Messages.tablesDetailInfoPartBtnViewData);
    viewDataItem.setToolTipText(Messages.tablesDetailInfoPartBtnViewDataTip);
    viewDataItem.setImage(CommonUIPlugin.getImage("icons/action/table_select_all.png"));
    viewDataItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = tableListView.getTable().getSelection();
            if (items.length == 1) {
                TableDetailInfo tableDetailInfo = (TableDetailInfo) items[0].getData();
                String query = SQLGenerateUtils.getSelectSQLWithLimit(tableDetailInfo.getTableName(), 1, 100);
                QueryEditorUtil.openQueryEditorAndRunQuery(database, query, true, true);
            } else {
                CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnViewDataSelectOne);
            }
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem copyTableNamesItem = new ToolItem(toolBar, SWT.PUSH);
    copyTableNamesItem.setText(Messages.tablesDetailInfoPartBtnCopyTableNames);
    copyTableNamesItem.setToolTipText(Messages.tablesDetailInfoPartBtnCopyTableNamesTip);
    copyTableNamesItem.setImage(CommonUIPlugin.getImage("icons/action/copy_table_name.gif"));
    copyTableNamesItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            List<String> nameList = new ArrayList<String>();
            for (TableDetailInfo tablesDetailInfoPOJO : tableList) {
                nameList.add(tablesDetailInfoPOJO.getTableName());
            }
            if (nameList.size() == 0) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartBtnCopySuccessFailed);
                return;
            }
            copyNamesToClipboard(nameList);
            CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnCopySuccessTitle, Messages.tablesDetailInfoPartBtnCopySuccessMsg);
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem copyColumnNamesItem = new ToolItem(toolBar, SWT.PUSH);
    copyColumnNamesItem.setText(Messages.tablesDetailInfoPartBtnCopyColumnNames);
    copyColumnNamesItem.setToolTipText(Messages.tablesDetailInfoPartBtnCopyColumnNamesTip);
    copyColumnNamesItem.setImage(CommonUIPlugin.getImage("icons/action/copy_column_name.gif"));
    copyColumnNamesItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TablesDetailInfoCTabItem tabItem = (TablesDetailInfoCTabItem) tabFolder.getSelection();
            schemaInfo = tabItem.getTableInfoComposite().getData();
            if (schemaInfo == null) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartBtnCopySuccessFailed);
                return;
            }
            List<String> nameList = new ArrayList<String>();
            for (DBAttribute att : schemaInfo.getAttributes()) {
                nameList.add(att.getName());
            }
            copyNamesToClipboard(nameList);
            CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnCopySuccessTitle, Messages.tablesDetailInfoPartBtnCopySuccessMsg);
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    final NewTableAction newTableAction = (NewTableAction) ActionManager.getInstance().getAction(NewTableAction.ID);
    ToolItem newTableItem = new ToolItem(toolBar, SWT.PUSH);
    newTableItem.setText(newTableAction.getText());
    newTableItem.setImage(CommonUITool.getImage(newTableAction.getImageDescriptor()));
    newTableItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            newTableAction.run(database);
        }
    });
    ScrolledComposite scrolledComp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComp.setLayout(new FillLayout());
    scrolledComp.setExpandHorizontal(true);
    scrolledComp.setExpandVertical(true);
    scrolledComp.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    topSash = new SashForm(scrolledComp, SWT.VERTICAL);
    topSash.setBackground(ResourceManager.getColor(136, 161, 227));
    GridLayout gridLayout = new GridLayout();
    gridLayout.verticalSpacing = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.horizontalSpacing = 0;
    topSash.setLayout(gridLayout);
    topSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    topSash.SASH_WIDTH = 1;
    scrolledComp.setContent(topSash);
    createTablesDetailInfoTable(topSash);
    createTabFolder(topSash);
    topSash.setWeights(new int[] { 70, 30 });
    this.setInputs();
}
Also used : TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) NewTableAction(com.cubrid.common.ui.cubrid.table.action.NewTableAction) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ArrayList(java.util.ArrayList) List(java.util.List) LoadTableRecordCountsProgress(com.cubrid.common.ui.spi.progress.LoadTableRecordCountsProgress) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 13 with TableDetailInfo

use of com.cubrid.common.core.common.model.TableDetailInfo in project cubrid-manager by CUBRID.

the class ERSchemaEditor method compareTableSchemas.

public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> 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) {
            CubridDatabase database = erSchema.getCubridDatabase();
            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);
            wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
            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);
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.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) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) 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) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 14 with TableDetailInfo

use of com.cubrid.common.core.common.model.TableDetailInfo in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method fetchRecordCountProcess.

private void fetchRecordCountProcess(IProgressMonitor monitor, Set<String> selectedItemKeys) {
    // FIXME logic code move to core module
    if (compareModel == null) {
        return;
    }
    List<TableSchemaCompareModel> compareList = compareModel.getTableCompareList();
    if (compareList == null) {
        return;
    }
    int total = compareList.size();
    monitor.beginTask(Messages.loadDetailInfo, total);
    for (TableSchemaCompareModel compareModel : compareList) {
        monitor.worked(1);
        if (monitor.isCanceled()) {
            break;
        }
        TableDetailInfo tableInfo1 = compareModel.getSourceTableDetailInfo();
        TableDetailInfo tableInfo2 = compareModel.getTargetTableDetailInfo();
        // It should be collected only selected list on comparision table;
        String srcTableName = "";
        if (tableInfo1 != null) {
            srcTableName = StringUtil.nvl(tableInfo1.getTableName());
        }
        String dstTableName = "";
        if (tableInfo2 != null) {
            dstTableName = StringUtil.nvl(tableInfo2.getTableName());
        }
        String key = srcTableName + "$" + dstTableName;
        if (!selectedItemKeys.contains(key)) {
            continue;
        }
        if (tableInfo1 != null) {
            SchemaInfo schemaInfo = compareModel.getSourceSchemas().get(tableInfo1.getTableName());
            if (schemaInfo != null) {
                long counts = countTableRecords(sourceDB.getDatabaseInfo(), tableInfo1.getTableName());
                tableInfo1.setRecordsCount(counts);
            }
        }
        if (monitor.isCanceled()) {
            break;
        }
        if (tableInfo2 != null) {
            SchemaInfo schemaInfo = compareModel.getTargetSchemas().get(tableInfo2.getTableName());
            if (schemaInfo != null) {
                long counts = countTableRecords(targetDB.getDatabaseInfo(), tableInfo2.getTableName());
                tableInfo2.setRecordsCount(counts);
            }
        }
    }
    monitor.done();
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 15 with TableDetailInfo

use of com.cubrid.common.core.common.model.TableDetailInfo in project cubrid-manager by CUBRID.

the class SchemaCompareDialog method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 *
	 * @param buttonId
	 *            the button id
	 */
protected void buttonPressed(int buttonId) {
    isCanceled = false;
    if (buttonId == COMPARE_ID) {
        if (!isSelectedAllSideDatabases()) {
            CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errNeedSelectCompareDb);
            return;
        }
        if (isSelectedSameDatabases()) {
            CommonUITool.openWarningBox(com.cubrid.common.ui.compare.Messages.errSelectSameCompareDb);
            return;
        }
        final List<String> origDbLabel = new ArrayList<String>();
        for (int i = 0; i < selections.size(); i++) {
            origDbLabel.add(leftCombo.getItem(i));
        }
        final int leftIndex = leftCombo.getSelectionIndex();
        final int rightIndex = rightCombo.getSelectionIndex();
        final List<String> rightDbLabel = new ArrayList<String>();
        final List<CubridDatabase> sourceDBList = new ArrayList<CubridDatabase>();
        final List<CubridDatabase> targetDBList = new ArrayList<CubridDatabase>();
        final List<TableSchemaCompareEditorInput> editorInput = new ArrayList<TableSchemaCompareEditorInput>();
        ITask reportBugTask = new AbstractUITask() {

            public void cancel() {
                isCanceled = true;
            }

            public void finish() {
            }

            public boolean isCancel() {
                return isCanceled;
            }

            public boolean isSuccess() {
                return true;
            }

            public void execute(IProgressMonitor monitor) {
                // FIXME logic code move to core module
                CubridDatabase leftDb = (CubridDatabase) selections.get(leftIndex);
                sourceDBList.add(leftDb);
                List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(leftDb);
                TableSchemaCompareRunner thread = null;
                CubridDatabase rightDb = (CubridDatabase) selections.get(rightIndex);
                targetDBList.add(rightDb);
                rightDbLabel.add(origDbLabel.get(rightIndex));
                thread = new TableSchemaCompareRunner(SchemaCompareDialog.this, leftDb, rightDb, leftDbTableInfoList);
                thread.start();
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    LOGGER.error(e.getMessage(), e);
                }
                TableSchemaCompareEditorInput input = thread.getInput();
                editorInput.add(input);
            }
        };
        TaskExecutor taskExecutor = new CommonTaskExec(Messages.titleSchemaComparison);
        taskExecutor.addTask(reportBugTask);
        new ExecTaskWithProgress(taskExecutor).exec();
        if (taskExecutor.isSuccess()) {
            for (int i = 0; i < rightDbLabel.size(); i++) {
                if (isCanceled) {
                    return;
                }
                showSchemaCompareEditor(editorInput.get(i));
            }
            if (isCanceled) {
                return;
            }
            super.buttonPressed(IDialogConstants.OK_ID);
        }
    }
    super.buttonPressed(buttonId);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaCompareEditorInput(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareEditorInput) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) TableSchemaCompareRunner(com.cubrid.common.ui.compare.schema.TableSchemaCompareRunner)

Aggregations

TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)27 ArrayList (java.util.ArrayList)11 Connection (java.sql.Connection)6 HashMap (java.util.HashMap)6 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SQLException (java.sql.SQLException)5 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)4 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)4 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)4 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)4 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 TableItem (org.eclipse.swt.widgets.TableItem)4 PartInitException (org.eclipse.ui.PartInitException)4 AbstractUITask (com.cubrid.common.core.task.AbstractUITask)3 ITask (com.cubrid.common.core.task.ITask)3 TableSchemaModel (com.cubrid.common.ui.compare.schema.model.TableSchemaModel)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3 OpenTablesDetailInfoPartProgress (com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)3