Search in sources :

Example 6 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 7 with CubridDatabase

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

the class OIDNavigatorAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        this.setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        OIDNavigatorDialog dialog = new OIDNavigatorDialog(getShell(), conn, null);
        dialog.open();
    } catch (SQLException e) {
        LOGGER.error("Can not request oid information by jdbc.", e);
        //TODO: error message localizing
        String message = Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage());
        CommonUITool.openErrorBox(message);
    } finally {
        QueryUtil.freeQuery(conn);
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) OIDNavigatorDialog(com.cubrid.common.ui.common.dialog.OIDNavigatorDialog)

Example 8 with CubridDatabase

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

the class JdbcManageComposite method isJdbcDriverUsing.

/**
	 * 
	 * Return whether the JDBC driver is using
	 * 
	 * @param jdbcVersion String
	 * @return boolean
	 */
private boolean isJdbcDriverUsing(String jdbcVersion) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return false;
    }
    IViewReference[] viewReference = page.getViewReferences();
    for (int i = 0; viewReference != null && i < viewReference.length; i++) {
        IViewPart viewPart = viewReference[i].getView(false);
        if (!(viewPart instanceof CubridNavigatorView)) {
            continue;
        }
        CubridNavigatorView navigatorView = (CubridNavigatorView) viewPart;
        List<ICubridNode> list = getUsingJdbcNodeList(navigatorView);
        if (list == null) {
            continue;
        }
        for (ICubridNode node : list) {
            if (NodeType.SERVER.equals(node.getType())) {
                CubridServer server = (CubridServer) node;
                ServerInfo serverInfo = server.getServerInfo();
                if (serverInfo == null) {
                    continue;
                }
                if (serverInfo.isConnected() && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcServer, new Object[] { serverInfo.getServerName(), jdbcVersion }));
                    return true;
                }
            } else if (NodeType.DATABASE.equals(node.getType())) {
                CubridDatabase database = (CubridDatabase) node;
                if (database == null || database.getServer() == null || database.getServer().getServerInfo() == null) {
                    continue;
                }
                ServerInfo serverInfo = database.getServer().getServerInfo();
                if (serverInfo == null) {
                    LOGGER.error("The serverInfo is a null.");
                    return false;
                }
                boolean isSameVersion = StringUtil.isEqual(serverInfo.getJdbcDriverVersion(), jdbcVersion);
                if (isSameVersion && database.isLogined()) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcConn, new Object[] { database.getName(), jdbcVersion }));
                    return true;
                }
            }
        }
    }
    IEditorReference[] editorReference = page.getEditorReferences();
    for (int i = 0; editorReference != null && i < editorReference.length; i++) {
        IEditorPart editorPart = editorReference[i].getEditor(false);
        if (!(editorPart instanceof QueryEditorPart)) {
            continue;
        }
        QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
        CubridServer server = queryEditorPart.getSelectedServer();
        ServerInfo serverInfo = server == null ? null : server.getServerInfo();
        String partName = queryEditorPart.getPartName();
        if (serverInfo != null && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
            CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcQuery, new Object[] { partName, jdbcVersion }));
            return true;
        }
    }
    return false;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 9 with CubridDatabase

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

the class CheckQueryEditorTask method doSave.

public void doSave() {
    ApplicationPersistUtil.getInstance().clearAllEditorStatus();
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            Date createTime = new Date();
            List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
            for (QueryEditorPart editor : editorPartList) {
                ArrayList<RestorableQueryEditorInfo> sqlTabItemList = new ArrayList<RestorableQueryEditorInfo>();
                for (CombinedQueryEditorComposite combinedQueryEditorComposite : editor.getAllCombinedQueryEditorComposite()) {
                    StyledText text = combinedQueryEditorComposite.getSqlEditorComp().getText();
                    if (text == null) {
                        LOGGER.warn("The editor.getSqlTextEditor() is a null.");
                        continue;
                    }
                    if (StringUtil.isEmpty(text.getText())) {
                        LOGGER.warn("The text.getText() is a null.");
                        continue;
                    }
                    CubridDatabase cubridDatabase = editor.getSelectedDatabase();
                    RestorableQueryEditorInfo editorStatus = new RestorableQueryEditorInfo();
                    if (cubridDatabase != null) {
                        DatabaseInfo dbInfo = cubridDatabase.getDatabaseInfo();
                        if (dbInfo != null) {
                            editorStatus.setDatabaseName(dbInfo.getDbName());
                        }
                        CubridServer cubridServer = cubridDatabase.getServer();
                        if (cubridServer != null) {
                            editorStatus.setServerName(cubridServer.getId());
                        }
                    }
                    editorStatus.setQueryContents(text.getText());
                    editorStatus.setCreatedTime(createTime);
                    sqlTabItemList.add(editorStatus);
                }
                ApplicationPersistUtil.getInstance().addEditorStatus(sqlTabItemList);
            }
        }
    });
    ApplicationPersistUtil.getInstance().save();
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) Date(java.util.Date)

Example 10 with CubridDatabase

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

the class RunSQLFileDialog method registerContextMenu.

/**
	 * register context menu
	 */
private void registerContextMenu() {
    sqlFileTableViewer.getTable().addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(sqlFileTableViewer.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(sqlFileTableViewer.getTable());
    sqlFileTableViewer.getTable().setMenu(contextMenu);
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
    itemDelete.setText("delete");
    itemDelete.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            List<String> deleteFiles = new ArrayList<String>();
            for (int i = 0; i < sqlFileTableViewer.getTable().getSelectionIndices().length; i++) {
                int index = sqlFileTableViewer.getTable().getSelectionIndices()[i];
                deleteFiles.add(filesList.get(index));
            }
            filesList.removeAll(deleteFiles);
            sqlFileTableViewer.setInput(filesList);
            sqlFileTableViewer.refresh();
        }
    });
    sqlFileTableViewer.getTable().setMenu(menu);
    Menu dbTablecontextMenu = menuManager.createContextMenu(databaseTableViewer.getTable());
    databaseTableViewer.getTable().setMenu(dbTablecontextMenu);
    Menu dbTableMenu = new Menu(getShell(), SWT.POP_UP);
    final MenuItem dbTableItemDelete = new MenuItem(dbTableMenu, SWT.PUSH);
    dbTableItemDelete.setText("delete");
    dbTableItemDelete.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            List<CubridDatabase> deleteCubridDatabase = new ArrayList<CubridDatabase>();
            for (int i = 0; i < databaseTableViewer.getTable().getSelectionIndices().length; i++) {
                int index = databaseTableViewer.getTable().getSelectionIndices()[i];
                deleteCubridDatabase.add(cubridDatabases[index]);
            }
            List<CubridDatabase> dbList = Arrays.asList(cubridDatabases);
            ArrayList<CubridDatabase> newDbList = new ArrayList<CubridDatabase>();
            for (CubridDatabase cubridDatabase : dbList) {
                if (deleteCubridDatabase.contains(cubridDatabase)) {
                    continue;
                }
                newDbList.add(cubridDatabase);
            }
            cubridDatabases = newDbList.toArray(new CubridDatabase[newDbList.size()]);
            databaseTableViewer.setInput(cubridDatabases);
            databaseTableViewer.refresh();
        }
    });
    sqlFileTableViewer.getTable().setMenu(menu);
    databaseTableViewer.getTable().setMenu(dbTableMenu);
    runSQLFileDialogDNDController = new RunSQLFileDialogDNDController(this);
    runSQLFileDialogDNDController.registerDropTarget();
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) MenuItem(org.eclipse.swt.widgets.MenuItem) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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