Search in sources :

Example 1 with ICubridNode

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

the class DeleteSerialAction method run.

/**
	 * Delete the selected serials
	 */
public void run(ISchemaNode[] nodeArray) {
    if (nodeArray == null) {
        LOGGER.error("The nodeArray parameter is a null.");
        return;
    }
    final List<String> serialNameList = new ArrayList<String>();
    final StringBuffer serialNames = new StringBuffer();
    for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
        if (!isSupported(nodeArray[i])) {
            setEnabled(false);
            return;
        }
        ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
        if (i == 0) {
            serialNames.append(schemaNode.getLabel());
        }
        serialNameList.add(schemaNode.getLabel());
    }
    if (nodeArray.length > 1) {
        serialNames.append(", ...");
    }
    String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
    if (!isDelete) {
        return;
    }
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                if (task instanceof DeleteSerialTask) {
                    DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
                    String[] serialNames = new String[serialNameList.size()];
                    deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
    CubridDatabase database = schemaNode.getDatabase();
    DatabaseInfo databaseInfo = database.getDatabaseInfo();
    DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
    taskExcutor.addTask(deleteSerialTask);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    ICubridNode parent = schemaNode.getParent();
    if (provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
            parent.removeChild((ICubridNode) nodeArray[i]);
        }
        viewer.remove(parent, nodeArray);
        viewer.setSelection(new StructuredSelection(parent), true);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DeleteSerialTask(com.cubrid.cubridmanager.core.cubrid.serial.task.DeleteSerialTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 2 with ICubridNode

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

the class CreateOrEditSerialDialog method valid.

/**
	 * Check the value validity
	 */
private void valid() {
    String name = serialNameText.getText();
    String startVal = startValText.getText();
    String incrementVal = incrementValText.getText();
    String minVal = minValText.getText();
    String maxVal = maxValText.getText();
    boolean isNoMinValue = noMinValueBtn.getSelection();
    boolean isNoMaxValue = noMaxValueBtn.getSelection();
    if (!ValidateUtil.isValidIdentifier(name)) {
        setErrorMessage(Messages.errSerialName);
        setEnabled(false);
        return;
    }
    if (!StringUtil.isValidNameLength(name, ValidateUtil.MAX_SCHEMA_NAME_LENGTH)) {
        setErrorMessage(Messages.bind(Messages.errSerialNameLength, ValidateUtil.MAX_SCHEMA_NAME_LENGTH));
        setEnabled(false);
        return;
    }
    boolean isExist = false;
    if (editedNode == null) {
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSerialFolderLoader.SERIAL_FOLDER_ID);
        isExist = folderNode != null && folderNode.getChild(folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + name) != null;
    }
    if (isExist) {
        setErrorMessage(Messages.errSerialExist);
        setEnabled(false);
        return;
    }
    boolean isValidStartVal = verifyBigValue(startVal);
    if (!isValidStartVal) {
        if (editedNode == null) {
            setErrorMessage(Messages.bind(Messages.errStartValue, Messages.msgStartValue));
            setEnabled(false);
            return;
        } else {
            setErrorMessage(Messages.bind(Messages.errStartValue, Messages.msgCurrentValue));
            setEnabled(false);
            return;
        }
    }
    boolean isValidIncrementVal = verifyBigValue(incrementVal);
    if (!isValidIncrementVal) {
        setErrorMessage(Messages.errIncrementValue);
        setEnabled(false);
        return;
    }
    boolean isValidMinVal = true;
    if (!isNoMinValue) {
        isValidMinVal = verifyBigValue(minVal);
        if (!isValidMinVal) {
            setErrorMessage(Messages.errMinValue);
            setEnabled(false);
            return;
        }
    }
    boolean isValidMaxVal = true;
    if (!isNoMaxValue) {
        isValidMaxVal = verifyBigValue(maxVal);
        if (!isValidMaxVal) {
            setErrorMessage(Messages.errMaxValue);
            setEnabled(false);
            return;
        }
    }
    BigInteger startBigVal = new BigInteger(startVal);
    BigInteger minBigValue = null;
    if (!isNoMinValue) {
        minBigValue = new BigInteger(minVal);
        isValidStartVal = startBigVal.compareTo(minBigValue) >= 0;
    }
    BigInteger maxBigValue = null;
    if (!isNoMaxValue && isValidStartVal) {
        maxBigValue = new BigInteger(maxVal);
        isValidStartVal = maxBigValue.compareTo(startBigVal) >= 0;
    }
    if (!isValidStartVal) {
        if (editedNode == null) {
            setErrorMessage(Messages.bind(Messages.errValue, Messages.msgStartValue));
            setEnabled(false);
            return;
        } else {
            setErrorMessage(Messages.bind(Messages.errValue, Messages.msgCurrentValue));
            setEnabled(false);
            return;
        }
    }
    if (minBigValue != null && maxBigValue != null) {
        BigInteger incrBigVal = new BigInteger(incrementVal.replaceAll("-", ""));
        isValidIncrementVal = maxBigValue.subtract(minBigValue).compareTo(incrBigVal) >= 0;
        if (!isValidIncrementVal) {
            setErrorMessage(Messages.errDiffValue);
            setEnabled(false);
            return;
        }
    }
    if (isSupportCache && !noCacheBtn.getSelection()) {
        String cacheCount = cacheCountText.getText().trim();
        if (!cacheCount.matches("\\d+") || Integer.parseInt(cacheCount) <= 0) {
            setErrorMessage(Messages.errCacheCount);
            setEnabled(false);
            return;
        }
    }
    setErrorMessage(null);
    setEnabled(true);
}
Also used : BigInteger(java.math.BigInteger) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 3 with ICubridNode

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

the class RunSQLFileDialog method addDatabase.

public void addDatabase(Object[] selectedNodes) {
    List<CubridDatabase> dbList = new ArrayList<CubridDatabase>();
    for (CubridDatabase db : cubridDatabases) {
        dbList.add(db);
    }
    for (Object o : selectedNodes) {
        if (!(o instanceof ISchemaNode)) {
            continue;
        }
        ICubridNode node = (ICubridNode) o;
        if (node.getType() != NodeType.DATABASE) {
            continue;
        }
        CubridDatabase database = ((ISchemaNode) o).getDatabase();
        if (!dbList.contains(database)) {
            dbList.add(database);
        }
    }
    cubridDatabases = dbList.toArray(new CubridDatabase[dbList.size()]);
    databaseTableViewer.setInput(cubridDatabases);
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with ICubridNode

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

the class FileToTableMappingComposite method openFileDialog.

/**
	 * open file dialog
	 */
private String openFileDialog(String fileDir) {
    ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
    if (!checkDelimiter(importConfig)) {
        return "";
    }
    FileDialog dialog = new FileDialog(getShell(), SWT.MULTI | SWT.APPLICATION_MODAL);
    if (fileDir == null || fileDir.trim().length() == 0) {
        fileDir = CommonUIPlugin.getSettingValue(ImportDataWizard.SESSION_IMPORT_KEY);
    }
    // FIXME can be duplicated to handle file extensions
    String supportExtString = null;
    if (importConfig.getImportType() == ImportConfig.IMPORT_FROM_EXCEL) {
        dialog.setFilterExtensions(new String[] { "*.*", "*.csv", /*, "*.xlsx"*/
        "*.xls" });
        dialog.setFilterNames(new String[] { Messages.allFileType, Messages.csvFileType, /*,
					Messages.xlsxFileType*/
        Messages.xlsFileType });
        supportExtString = "csv, xls";
    } else if (importConfig.getImportType() == ImportConfig.IMPORT_FROM_TXT) {
        dialog.setFilterExtensions(new String[] { "*.txt", "*.*" });
        dialog.setFilterNames(new String[] { Messages.txtFileType, Messages.allFileType });
        supportExtString = "txt";
    } else if (importConfig.getImportType() == ImportConfig.IMPORT_FROM_SQL) {
        dialog.setFilterExtensions(new String[] { "*.sql", "*.*" });
        dialog.setFilterNames(new String[] { Messages.sqlFileType, Messages.allFileType });
        supportExtString = "sql";
    } else if (importConfig.getImportType() == ImportConfig.IMPORT_FROM_LOADDB) {
        dialog.setFilterExtensions(new String[] { "*.txt", "*.*" });
        dialog.setFilterNames(new String[] { Messages.txtFileType, Messages.allFileType });
        supportExtString = "LoadDB";
    }
    dialog.setFilterPath(fileDir);
    dialog.open();
    // FIXME move this logic to core module
    Set<String> tableSet = new HashSet<String>();
    for (ICubridNode node : allTableList) {
        tableSet.add(node.getName());
    }
    StringBuilder newTables = new StringBuilder();
    String[] fileNames = dialog.getFileNames();
    String path = dialog.getFilterPath();
    Map<String, String> tableToFileMap = new HashMap<String, String>();
    if (fileNames.length > 0) {
        try {
            for (String fileName : fileNames) {
                String tableName = fileName;
                int dotIndex = fileName.lastIndexOf(".");
                if (dotIndex >= 0) {
                    tableName = fileName.substring(0, dotIndex);
                }
                String filePath = path + File.separator + fileName;
                tableToFileMap.put(tableName, filePath);
                if (!tableSet.contains(tableName)) {
                    if (newTables.length() > 0) {
                        newTables.append(", ");
                    }
                    newTables.append(tableName);
                }
            }
            parseData(tableToFileMap);
        } catch (Exception ex) {
            String msg = Messages.errorOpenFile;
            if (supportExtString != null) {
                msg += Messages.bind(Messages.errorOpenFileDetail, supportExtString);
            }
            CommonUITool.openErrorBox(msg);
            LOGGER.error("Open file failed:" + ex.getMessage(), ex);
        }
        computeLineCount();
        fireSelectionChanged();
    }
    if (newTables.length() > 0) {
        if (importConfig.isCreateTableAccordingData()) {
            CommonUITool.openWarningBox(Messages.bind(Messages.warnImportNewTableDetectedCreate, newTables));
        } else {
            CommonUITool.openWarningBox(Messages.bind(Messages.warnImportNewTableDetectedSkip, newTables));
        }
    }
    return "";
}
Also used : HashMap(java.util.HashMap) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) FileDialog(org.eclipse.swt.widgets.FileDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) HashSet(java.util.HashSet)

Example 5 with ICubridNode

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

the class FileToTableMappingComposite method parseData.

@SuppressWarnings("unchecked")
private void parseData(final Map<String, String> tableToFile) throws Exception {
    allTableList = (List<ICubridNode>) treeViewer.getInput();
    final List<ICubridNode> newMappedNodeList = new ArrayList<ICubridNode>();
    final ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
    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.taskParsingData, tableToFile.size());
            for (Entry<String, String> entry : tableToFile.entrySet()) {
                // FIXME move this logic to core module
                String tableName = entry.getKey();
                String filePath = entry.getValue();
                File file = new File(filePath);
                String fileName = file.getName();
                monitor.subTask(Messages.bind(Messages.taskParsingFile, fileName));
                List<String> fileColumnList = new ArrayList<String>();
                List<String> firstRowColsLst = new ArrayList<String>();
                List<String> colNameList = new ArrayList<String>();
                List<String> colTypeList = new ArrayList<String>();
                int totalLine = 0;
                List<Integer> itemsNumberOfSheets = null;
                /*Find the class node*/
                ICubridNode classNode = getTableNode(tableName);
                /*Process file*/
                ImportFileHandler importFileHandler = ImportFileHandlerFactory.getHandler(file.getAbsolutePath(), importConfig);
                ImportFileDescription ifd = getFileDescription(importFileHandler);
                firstRowColsLst.addAll(ifd.getFirstRowCols());
                totalLine = ifd.getTotalCount();
                itemsNumberOfSheets = ifd.getItemsNumberOfSheets();
                boolean isFirstLineAsColumnName = isFirstLineAsColumnName(tableName);
                fillInFromList(fileColumnList, firstRowColsLst, isFirstLineAsColumnName);
                if (isFirstLineAsColumnName) {
                    handleSelectEventForFirstRowAsColBtn(itemsNumberOfSheets, fileColumnList, firstRowColsLst, totalLine, isFirstLineAsColumnName);
                }
                if (classNode != null) {
                    Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
                    if (isNew == null || !(Boolean) isNew) {
                        SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
                        List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
                        if (attributes == null) {
                            return;
                        }
                        for (DBAttribute attr : attributes) {
                            String column = attr.getName();
                            String dataType = attr.getType();
                            colNameList.add(column);
                            colTypeList.add(dataType);
                        }
                    } else {
                        removeClassNode(classNode);
                        classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
                    }
                } else if (importConfig.isCreateTableAccordingData()) {
                    classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
                } else {
                    failedFileList.add(file.getAbsolutePath());
                    continue;
                }
                if (fileColumnList.size() == colNameList.size()) {
                    classNode.setData(ImportObjectLabelProvider.IS_MAPPED, true);
                    classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
                    classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
                    List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
                    for (int i = 0; i < fileColumnList.size(); i++) {
                        PstmtParameter pstmtParameter = new PstmtParameter(colNameList.get(i), i + 1, colTypeList.get(i), String.valueOf(i));
                        pstmtParameter.setFileColumnName(fileColumnList.get(i));
                        parameterList.add(pstmtParameter);
                    }
                    TableConfig tableConfig = new TableConfig(classNode.getName());
                    tableConfig.setPstmList(parameterList);
                    tableConfig.setFilePath(file.getAbsolutePath());
                    tableConfig.setInsertDML(getInsertDML(classNode, colNameList, colTypeList));
                    tableConfig.setLineCount(totalLine);
                    tableConfig.setMapped(true);
                    Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
                    if (isNew != null && (Boolean) isNew) {
                        tableConfig.setCreateDDL(classNode.getData(ImportObjectLabelProvider.CREATE_DDL).toString());
                    }
                    importConfig.addTableConfig(tableConfig);
                    newMappedNodeList.add(classNode);
                } else {
                    classNode.setData(ImportObjectLabelProvider.IS_MAPPED, false);
                    classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
                    classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
                    TableConfig tableConfig = importConfig.getSelectedMap().get(classNode.getName());
                    if (tableConfig != null) {
                        tableConfig.setMapped(false);
                        tableConfig.setFilePath(filePath);
                        tableConfig.setLineCount(totalLine);
                        tableConfig.getPstmList().clear();
                        tableConfig.setInsertDML("");
                    }
                    failedFileList.add(fileName);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    return;
                }
            }
        }
    });
    for (ICubridNode node : allTableList) {
        if (newMappedNodeList.contains(node)) {
            treeViewer.setChecked(node, true);
        }
    }
    treeViewer.refresh();
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ImportFileHandler(com.cubrid.common.ui.cubrid.table.importhandler.ImportFileHandler) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) PstmtParameter(com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ImportFileDescription(com.cubrid.common.ui.cubrid.table.importhandler.ImportFileDescription) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

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