Search in sources :

Example 1 with ShortSetEditorConfigAction

use of com.cubrid.cubridmanager.ui.common.action.ShortSetEditorConfigAction in project cubrid-manager by CUBRID.

the class LoginDatabaseAction method doRun.

public void doRun(CubridDatabase[] databaseArray) {
    if (databaseArray == null || databaseArray.length == 0) {
        return;
    }
    CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
    if (navigationView != null && databaseArray.length > 0) {
        final TreeViewer treeViewer = navigationView.getViewer();
        if (databaseArray.length > 1) {
            List<MultiDatabaseloginFailedInfo> failedDatabaseList = new ArrayList<MultiDatabaseloginFailedInfo>();
            for (CubridDatabase object : databaseArray) {
                CubridDatabase database = (CubridDatabase) object;
                String errMsg = null;
                if (database.isAutoSavePassword()) {
                    errMsg = CubridWorkbenchContrItem.connectDatabaseWithErrMsg(database.getDatabaseInfo(), false);
                } else {
                    errMsg = "Incorrect or missing password.";
                }
                if (errMsg == null) {
                    database.getLoader().setLoaded(false);
                    database.setLogined(true);
                    treeViewer.refresh(database, true);
                    treeViewer.expandToLevel(database, 1);
                    ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                    LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                    CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
                    // open database dashboard
                    if (GeneralPreference.isUseDatabaseDashboard()) {
                        LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(database);
                    }
                } else {
                    failedDatabaseList.add(new MultiDatabaseloginFailedInfo(database, errMsg));
                }
            }
            if (failedDatabaseList.size() > 0) {
                MultiDatabaseLoginFailedDialog dialog = new MultiDatabaseLoginFailedDialog(getShell(), failedDatabaseList);
                dialog.open();
            }
            return;
        } else {
            CubridDatabase database = databaseArray[0];
            if (DbRunningType.STANDALONE.equals(database.getRunningType()) && ActionSupportUtil.hasAdminPermissionOnStopState(database)) {
                if (CommonUITool.openConfirmBox(Messages.bind(Messages.msgWhetherStartDB, database.getName()))) {
                    StartDatabaseAction startDatabaseAction = (StartDatabaseAction) ActionManager.getInstance().getAction(StartDatabaseAction.ID);
                    startDatabaseAction.doRun(new CubridDatabase[] { database });
                }
            }
            if (!database.isLogined() && database.isAutoSavePassword()) {
                DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, true);
                if (EditorConstance.isNeedSetBackground(editorConfig)) {
                    new ShortSetEditorConfigAction(database).run();
                }
            }
            if (!database.isLogined() && database.isAutoSavePassword() && CubridWorkbenchContrItem.connectDatabase(database.getDatabaseInfo(), true)) {
                database.getLoader().setLoaded(false);
                database.setLogined(true);
                treeViewer.refresh(database, true);
                treeViewer.expandToLevel(database, 1);
                ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
                // open database dashboard
                if (GeneralPreference.isUseDatabaseDashboard()) {
                    LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(database);
                }
            } else if (!database.isLogined()) {
                EditDatabaseLoginAction editDatabaseLoginAction = (EditDatabaseLoginAction) ActionManager.getInstance().getAction(EditDatabaseLoginAction.ID);
                editDatabaseLoginAction.doRun(databaseArray);
            }
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) MultiDatabaseloginFailedInfo(com.cubrid.cubridmanager.ui.cubrid.database.dialog.MultiDatabaseloginFailedInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) ShortSetEditorConfigAction(com.cubrid.cubridmanager.ui.common.action.ShortSetEditorConfigAction) MultiDatabaseLoginFailedDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.MultiDatabaseLoginFailedDialog) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Aggregations

CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 ShortSetEditorConfigAction (com.cubrid.cubridmanager.ui.common.action.ShortSetEditorConfigAction)1 MultiDatabaseLoginFailedDialog (com.cubrid.cubridmanager.ui.cubrid.database.dialog.MultiDatabaseLoginFailedDialog)1 MultiDatabaseloginFailedInfo (com.cubrid.cubridmanager.ui.cubrid.database.dialog.MultiDatabaseloginFailedInfo)1 ArrayList (java.util.ArrayList)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1