Search in sources :

Example 11 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.

the class ExportSettingPage method setOptionsToExportConfigModel.

/**
	 * set page parameter to config model
	 *
	 * @param exportConfig
	 */
public boolean setOptionsToExportConfigModel(ExportConfig exportConfig) {
    exportConfig.setExportSchema(schemaButton.getSelection());
    exportConfig.setExportData(dataButton.getSelection());
    exportConfig.setExportIndex(indexButton.getSelection());
    exportConfig.setExportSerial(serialButton.getSelection());
    exportConfig.setExportView(viewButton.getSelection());
    exportConfig.setExportSerialStartValue(startValueButton.getSelection());
    int fileType = ExportConfig.FILE_TYPE_SQL;
    if (sqlButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_SQL;
    } else if (csvButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_CSV;
    } else if (xlsButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_XLS;
    } else if (xlsxButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_XLSX;
    } else if (obsButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_OBS;
    } else if (txtButton.getSelection()) {
        fileType = ExportConfig.FILE_TYPE_TXT;
    }
    exportConfig.setExportFileType(fileType);
    exportConfig.setThreadCount(threadCountSpinner.getSelection());
    exportConfig.setFileCharset(fileCharsetCombo.getText());
    exportConfig.setFirstRowAsColumnName(useFirstAsColumnBtn.getSelection());
    exportConfig.setRowDelimeter(getRowDelimeter());
    exportConfig.setColumnDelimeter(getColumnDelimeter());
    String nullValue = "";
    if (nullOneButton.getSelection()) {
        nullValue = "NULL";
    } else if (nullTwoButton.getSelection()) {
        nullValue = "\\N";
    } else if (nullThreeButton.getSelection()) {
        nullValue = "(NULL)";
    } else if (otherButton.getSelection()) {
        nullValue = otherText.getText();
    }
    exportConfig.setNULLValueTranslation(nullValue);
    List<String> checkedTableList = new ArrayList<String>();
    List<ICubridNode> selectedTableOrViews = new ArrayList<ICubridNode>();
    Object[] objects = treeViewer.getCheckedElements();
    for (Object object : objects) {
        ICubridNode node = (ICubridNode) object;
        if (node.getType() == NodeType.TABLE_COLUMN_FOLDER && "false".equals(node.getData(VIEWNODEFLAG))) {
            selectedTableOrViews.add(node);
            checkedTableList.add(node.getName());
        }
    }
    exportConfig.setTableNameList(checkedTableList);
    removeUncheckedTablesOnConfig(exportConfig, checkedTableList);
    String fileExt = getFileType();
    File savedDirFile = new File(pathText.getText());
    String[] filesInSavedDir = savedDirFile.list();
    if (filesInSavedDir.length > 0) {
        String duplicatedErrorMessage = Messages.bind(Messages.canceledBecauseOfExistsWithFolderName, pathText.getText());
        CommonUITool.openErrorBox(duplicatedErrorMessage);
        return false;
    }
    for (ICubridNode tableOrView : selectedTableOrViews) {
        String filePath = savedDirFile.getAbsolutePath() + File.separator + tableOrView.getName() + fileExt;
        Object whereCondition = tableOrView.getData(ExportObjectLabelProvider.CONDITION);
        if (whereCondition != null) {
            String sqlFilterPart = ((String) whereCondition).trim();
            // append "where" if necessary
            if (StringUtil.isNotEmpty(sqlFilterPart)) {
                if (!sqlFilterPart.startsWith("where")) {
                    sqlFilterPart = " where " + sqlFilterPart;
                }
                exportConfig.setWhereCondition(tableOrView.getName(), sqlFilterPart);
            }
        }
        exportConfig.setDataFilePath(tableOrView.getName(), filePath);
    }
    exportConfig.setDataFileFolder(pathText.getText());
    if (exportLobButton.isEnabled()) {
        exportConfig.setExportLob(exportLobButton.getSelection());
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) File(java.io.File)

Example 12 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.

the class AddTableFileDialog method handleSelectEventForFirstRowAsColBtn.

/**
	 * Handle with the selection event for button of first row as column
	 */
private void handleSelectEventForFirstRowAsColBtn() {
    ICubridNode classNode = mappingComposite.getTableNode(tableName);
    int noEmptySheetNum = 0;
    if (itemsNumberOfSheets != null) {
        for (Integer itemsNum : itemsNumberOfSheets) {
            if (itemsNum != 0) {
                noEmptySheetNum++;
            }
        }
    }
    if (firstRowAsColumnBtn.getSelection()) {
        totalLine = totalLine - noEmptySheetNum;
    } else {
        totalLine = totalLine + noEmptySheetNum;
    }
    if (mappingComposite.isNewClassNode(classNode)) {
        mappingComposite.removeClassNode(classNode);
        ICubridNode node = mappingComposite.createClassNode(classNode.getName(), firstRowAsColumnBtn.getSelection(), firstRowColsLst, new ArrayList<String>(), new ArrayList<String>());
        node.setData(ImportObjectLabelProvider.IS_MAPPED, true);
        node.setData(ImportObjectLabelProvider.FILE_PAHT, fileNameTxt.getText());
        node.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
        refreshInToList(node);
        mappingComposite.refreshTable();
    }
    fillInFromList();
    validate();
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 13 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.

the class FileToTableMappingComposite method loadClassInfo.

public List<ICubridNode> loadClassInfo() {
    // FIXME move this logic to core module
    allTableList = new ArrayList<ICubridNode>();
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progress.setCancelable(true);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.taskLoading, 2);
                Connection conn = null;
                Statement stmt = null;
                ResultSet rsTable = null;
                try {
                    monitor.subTask(Messages.taskLoadingTable);
                    monitor.worked(1);
                    StringBuilder sql = new StringBuilder();
                    sql.append("SELECT c.class_name ");
                    sql.append("FROM db_class c, db_attribute a ");
                    sql.append("WHERE c.class_name = a.class_name AND c.is_system_class = 'NO' ");
                    sql.append("AND a.from_class_name IS NULL ");
                    sql.append("AND c.class_type = 'CLASS' ");
                    sql.append("GROUP BY c.class_name ");
                    sql.append("ORDER BY c.class_name");
                    conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
                    stmt = conn.createStatement();
                    rsTable = stmt.executeQuery(sql.toString());
                    while (rsTable.next()) {
                        //$NON-NLS-1$
                        String tableName = rsTable.getString(1);
                        if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
                            continue;
                        }
                        String iconPath = "icons/navigator/schema_table_item.png";
                        ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
                        classNode.setContainer(true);
                        allTableList.add(classNode);
                    }
                    monitor.subTask(Messages.taskLoadingColumn);
                    monitor.worked(1);
                } catch (SQLException e) {
                    String msg = e.getErrorCode() + StringUtil.NEWLINE + Messages.importErrorHead + e.getMessage();
                    CommonUITool.openErrorBox(getShell(), msg);
                    LOGGER.error("", e);
                } finally {
                    QueryUtil.freeQuery(conn, stmt, rsTable);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return allTableList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet)

Example 14 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.

the class FileToTableMappingComposite method createClassNode.

public ICubridNode createClassNode(String tableName, boolean isFirstRowAsColumnName, List<String> firstRowColsLst, List<String> colNameList, List<String> colTypeList) {
    // FIXME move this logic to core module
    int columnCount = firstRowColsLst.size();
    String iconPath = "icons/navigator/schema_table_item.png";
    ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
    classNode.setContainer(true);
    List<String> columnNames;
    if (isFirstRowAsColumnName) {
        columnNames = firstRowColsLst;
    } else {
        columnNames = new ArrayList<String>();
        for (int i = 0; i < columnCount; i++) {
            columnNames.add("Column_" + String.valueOf(i));
        }
    }
    for (String columnName : columnNames) {
        colNameList.add(columnName);
        colTypeList.add(NEW_ATTR_TYPE);
    }
    classNode.setData(ImportObjectLabelProvider.IS_NEW, true);
    classNode.setData(ImportObjectLabelProvider.CREATE_DDL, getCreateTableDDL(classNode, colNameList, colTypeList));
    allTableList.add(classNode);
    refreshTable();
    return classNode;
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode)

Example 15 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.

the class DropTriggerAction method run.

public void run(ISchemaNode[] nodeArray) {
    // FIXME move this logic to core module
    if (nodeArray == null) {
        LOGGER.error("The nodeArray is a null.");
        return;
    }
    List<String> triggerNameList = new ArrayList<String>();
    StringBuffer bf = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
        triggerNameList.add(trigger.getName());
        if (i == 0) {
            bf.append(trigger.getName());
        }
    }
    if (nodeArray.length > 1) {
        bf.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
    boolean ret = CommonUITool.openConfirmBox(cfmMsg);
    if (!ret) {
        return;
    }
    ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
    CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
    for (String triggerName : triggerNameList) {
        String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
        task.addSqls(sql);
    }
    String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
    TaskExecutor taskExecutor = new CommonTaskExec(taskName);
    taskExecutor.addTask(task);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (!taskExecutor.isSuccess()) {
        return;
    }
    String title = com.cubrid.common.ui.common.Messages.titleSuccess;
    String msg = Messages.dropTriggerSuccessMsg;
    CommonUITool.openInformationBox(title, msg);
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = triggerNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ISchemaNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Aggregations

ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)362 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)67 ArrayList (java.util.ArrayList)67 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)62 TreeViewer (org.eclipse.jface.viewers.TreeViewer)62 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)55 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)55 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)41 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)33 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)32 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)31 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)26 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)25 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)25 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)25 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)25 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)23 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)22