Search in sources :

Example 31 with CubridDatabase

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

the class FavoriteQueryNavigatorView method getCurrentDatabase.

/**
	 * Return current selected database from the navigation tree.
	 * @return CubridDatabase
	 */
private CubridDatabase getCurrentDatabase() {
    CubridDatabase cubridDatabase = null;
    CubridNavigatorView nav = CubridNavigatorView.findNavigationView();
    if (nav != null) {
        TreeItem[] items = nav.getSelectedItems();
        if (items.length > 0 && items[0] != null && items[0].getData() instanceof ISchemaNode) {
            ISchemaNode node = (ISchemaNode) items[0].getData();
            CubridDatabase tempDatabase = node.getDatabase();
            if (tempDatabase != null && tempDatabase.isLogined()) {
                cubridDatabase = tempDatabase;
            }
        }
    }
    return cubridDatabase;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 32 with CubridDatabase

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

the class FavoriteQueryNavigatorView method executeSql.

/**
	 * Execute selected queries
	 */
private void executeSql() {
    CubridDatabase cubridDatabase = getCurrentDatabase();
    if (cubridDatabase == null || cubridDatabase.getDatabaseInfo() == null) {
        CommonUITool.openErrorBox(com.cubrid.common.ui.query.Messages.errNoConnectionBatchRun);
        return;
    }
    // Judge the file is exist
    int[] indexes = tv.getTable().getSelectionIndices();
    List<Map<String, String>> list = FavoriteQueryPersistUtil.getInstance().getListData();
    for (int i = 0; i < indexes.length; i++) {
        Map<String, String> item = list.get(indexes[i]);
        String filename = item.get("1");
        String fullpath = item.get("4") + File.separator + filename;
        if (!new File(fullpath).exists()) {
            String msg = Messages.bind(com.cubrid.common.ui.query.Messages.errFileNotExist, fullpath);
            CommonUITool.openErrorBox(msg);
            return;
        }
    }
    String targetDbName = cubridDatabase.getDatabaseInfo().getDbName() + "@" + cubridDatabase.getServer().getServerInfo().getHostAddress();
    String msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteSql, targetDbName);
    if (!CommonUITool.openConfirmBox(msg)) {
        return;
    }
    String charset = StringUtil.getDefaultCharset();
    ImportConfig importConfig = new ImportConfig();
    importConfig.setImportType(ImportConfig.IMPORT_FROM_SQL);
    importConfig.setThreadCount(1);
    importConfig.setCommitLine(100);
    Set<String> charsets = new HashSet<String>();
    for (int i = 0; i < indexes.length; i++) {
        Map<String, String> item = list.get(indexes[i]);
        String filename = item.get("1");
        String fullpath = item.get("4") + File.separator + filename;
        charset = item.get("5");
        if (StringUtil.isEmpty(charset)) {
            charset = StringUtil.getDefaultCharset();
        } else {
            charsets.add(charset);
        }
        TableConfig fileConfig = new TableConfig(filename);
        fileConfig.setFilePath(fullpath);
        fileConfig.setFileType(TableConfig.TYPE_DATA);
        importConfig.addTableConfig(fileConfig);
    }
    importConfig.setFilesCharset(charset);
    if (charsets.size() > 1) {
        msg = Messages.bind(com.cubrid.common.ui.query.Messages.msgDoYouWantExecuteWithNotSameCharset, charset);
        if (!CommonUITool.openConfirmBox(msg)) {
            return;
        }
    }
    ImportDataEditorInput input = new ImportDataEditorInput();
    input.setDatabase(cubridDatabase);
    input.setImportConfig(importConfig);
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, ImportDataViewPart.ID);
    } catch (Exception e) {
        CommonUITool.openErrorBox(Display.getCurrent().getActiveShell(), e.getMessage());
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ImportConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportConfig) TableConfig(com.cubrid.common.ui.cubrid.table.dialog.imp.TableConfig) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ImportDataEditorInput(com.cubrid.common.ui.cubrid.table.dialog.imp.ImportDataEditorInput) Map(java.util.Map) File(java.io.File) HashSet(java.util.HashSet)

Example 33 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase 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 34 with CubridDatabase

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

the class ExportConnectionUtil method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element instanceof CubridServer && columnIndex == 0) {
        CubridServer server = (CubridServer) element;
        return server.getName();
    }
    if (element instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) element;
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            LOGGER.warn("DatabaseInfo is a null.");
            return "";
        }
        switch(columnIndex) {
            case 0:
                return dbInfo.getDbName();
            case 1:
                return dbInfo.getBrokerIP();
            case 2:
                return dbInfo.getBrokerPort();
            case 3:
                return dbInfo.getAuthLoginedDbUserInfo().getName();
            case 4:
                DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
                if (editorConfig != null) {
                    return editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment();
                }
                return "";
            case 5:
                return NodeUtil.getJavaConnectionUrl(database.getDatabaseInfo());
            case 6:
                return NodeUtil.getPHPConnectionUrl(database.getDatabaseInfo());
        }
    }
    return null;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 35 with CubridDatabase

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

the class BackupDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    final CubridDatabase database = node.getDatabase();
    final BackupDatabaseDialog dialog = new BackupDatabaseDialog(getShell());
    dialog.setDatabase(database);
    final Shell shell = getShell();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadDbBackupInfoTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetDbBackupInfoTask) {
                    GetDbBackupInfoTask getDbBackupInfoTask = (GetDbBackupInfoTask) task;
                    dialog.setDbBackupInfo(getDbBackupInfoTask.getDbBackupInfo());
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
                    Map<String, String> commonParas = confParas.get(ConfConstants.COMMON_SECTION_NAME);
                    Map<String, String> dbParas = confParas.get("[@" + database.getLabel() + "]");
                    String str = dbParas == null ? null : dbParas.get(ConfConstants.REPLICATION);
                    boolean isReplication = "yes".equals(str);
                    if (!isReplication) {
                        str = commonParas == null ? null : commonParas.get(ConfConstants.REPLICATION);
                        isReplication = "yes".equals(str);
                    }
                    dialog.setReplication(isReplication);
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    taskExcutor.addTask(getCubridConfParameterTask);
    GetDbBackupInfoTask getDbBackupInfoTask = new GetDbBackupInfoTask(serverInfo);
    getDbBackupInfoTask.setDbName(database.getLabel());
    taskExcutor.addTask(getDbBackupInfoTask);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (taskExcutor.isSuccess()) {
        dialog.open();
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetDbBackupInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDbBackupInfoTask) BackupDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.BackupDatabaseDialog) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Map(java.util.Map)

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)278 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)104 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)79 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)67 ArrayList (java.util.ArrayList)45 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)43 TreeViewer (org.eclipse.jface.viewers.TreeViewer)42 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)36 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)33 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)30 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)29 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)28 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)25 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)22 Shell (org.eclipse.swt.widgets.Shell)22 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)19 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)18 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)18 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)18 ITask (com.cubrid.common.core.task.ITask)17