Search in sources :

Example 26 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView 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)

Example 27 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class EditDatabaseLoginAction method doRun.

public void doRun(CubridDatabase[] databaseArray) {
    if (databaseArray == null || databaseArray.length == 0) {
        return;
    }
    CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
    if (navigationView != null) {
        final TreeViewer treeViewer = navigationView.getViewer();
        CubridDatabase database = (CubridDatabase) databaseArray[0];
        LoginDatabaseDialog dialog = new LoginDatabaseDialog(getShell(), database);
        int returnVal = dialog.open();
        if (returnVal == IDialogConstants.OK_ID && provider instanceof TreeViewer) {
            database.removeAllChild();
            if (database.getLoader() != null) {
                database.getLoader().setLoaded(false);
            }
            treeViewer.refresh(database, true);
            treeViewer.expandToLevel(database, 1);
            ActionManager.getInstance().fireSelectionChanged(getSelection());
            LayoutManager.getInstance().fireSelectionChanged(getSelection());
            if (dialog.isFireLogoutEvent()) {
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
            }
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        } else if (returnVal == LoginDatabaseDialog.SAVE_ID && provider instanceof TreeViewer) {
            treeViewer.refresh(database, true);
            treeViewer.expandToLevel(database, 1);
        }
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) LoginDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.LoginDatabaseDialog) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 28 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class AddHostAction method doRun.

public void doRun(Object[] nodes) {
    CubridGroupNode parent = getParentGroupNode(nodes);
    if (parent == null) {
        LOGGER.error("parent is null.");
        return;
    }
    HostDialog dialog = new HostDialog(getShell(), true, false);
    int returnCode = dialog.open();
    if (returnCode == HostDialog.ADD_ID || returnCode == HostDialog.CONNECT_ID) {
        CubridServer server = getServerNode(dialog);
        if (server == null) {
            LOGGER.error("server is null.");
            return;
        }
        CMHostNodePersistManager.getInstance().addServer(server);
        TreeItem item = null;
        parent.addChild(server);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        if (navigatorView != null) {
            boolean isShowGroup = navigatorView.isShowGroup();
            TreeViewer treeViewer = navigatorView.getViewer();
            if (isShowGroup) {
                item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
            } else {
                item = new TreeItem(treeViewer.getTree(), SWT.NONE);
            }
            CMGroupNodePersistManager.getInstance().saveAllGroupNode();
            item.setText(server.getLabel());
            item.setData(server);
            treeViewer.refresh(server, true);
            treeViewer.expandToLevel(server, 1);
            treeViewer.setSelection(new StructuredSelection(server), true);
            if (returnCode == HostDialog.CONNECT_ID) {
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
            }
        } else {
            dialog.closeTestServerConnection();
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 29 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class ConnectHostAction method doRun.

public void doRun(CubridServer[] servers) {
    if (servers.length == 0) {
        return;
    }
    if (servers.length == 1) {
        CubridServer server = servers[0];
        if (server.isAutoSavePassword() && CubridWorkbenchContrItem.connectHost(server.getServerInfo(), true)) {
            server.getLoader().setLoaded(false);
            CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
            if (view == null) {
                LOGGER.error("view is null.");
                return;
            }
            TreeViewer treeViewer = view.getViewer();
            treeViewer.refresh(server, true);
            treeViewer.expandToLevel(server, 1);
            ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
            LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
            CubridNodeChangedEvent event = new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED);
            CubridNodeManager.getInstance().fireCubridNodeChanged(event);
        } else {
            EditHostAction editHostAction = (EditHostAction) ActionManager.getInstance().getAction(EditHostAction.ID);
            if (editHostAction != null) {
                editHostAction.doRun(servers, true);
            }
        }
    } else {
        List<FailedHostServerInfo> failedServerList = new ArrayList<FailedHostServerInfo>();
        for (CubridServer object : servers) {
            CubridServer server = (CubridServer) object;
            String errMsg = null;
            if (server.isAutoSavePassword()) {
                errMsg = CubridWorkbenchContrItem.connectHostWithErrMsg(server.getServerInfo(), false);
            } else {
                errMsg = "Incorrect or missing password.";
            }
            if (errMsg == null) {
                server.getLoader().setLoaded(false);
                CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
                TreeViewer treeViewer = view.getViewer();
                treeViewer.refresh(server, true);
                treeViewer.expandToLevel(server, 1);
                ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
            } else {
                failedServerList.add(new FailedHostServerInfo(server, errMsg));
            }
        }
        if (failedServerList.size() > 0) {
            NewMultiHostConnectionDialog dialog = new NewMultiHostConnectionDialog(getShell(), failedServerList);
            dialog.open();
        }
    }
}
Also used : FailedHostServerInfo(com.cubrid.cubridmanager.ui.host.dialog.FailedHostServerInfo) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) NewMultiHostConnectionDialog(com.cubrid.cubridmanager.ui.host.dialog.NewMultiHostConnectionDialog) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 30 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class PasteHostAction method run.

/**
	 * Paste the host
	 */
public void run() {
    Object[] objs = this.getSelectedObj();
    if (!isSupported(objs[0])) {
        setEnabled(false);
        return;
    }
    objs = null;
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection strSelection = (IStructuredSelection) selection;
        objs = strSelection.toArray();
    }
    if (objs == null || objs.length == 0) {
        return;
    }
    if (!(objs[0] instanceof CubridServer)) {
        return;
    }
    CubridServer pastedServer = (CubridServer) objs[0];
    HostDialog dialog = new HostDialog(getShell(), true, false);
    dialog.setServer(pastedServer);
    int returnCode = dialog.open();
    if (returnCode == HostDialog.ADD_ID || returnCode == HostDialog.CONNECT_ID) {
        CubridServer server = getServerNode(dialog);
        CMHostNodePersistManager.getInstance().addServer(server);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            return;
        }
        TreeItem item;
        Tree tree = treeViewer.getTree();
        CubridGroupNode parent = getParentGroupNode();
        parent.addChild(server);
        if (navigatorView.isShowGroup()) {
            item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
        } else {
            item = new TreeItem(tree, SWT.NONE);
        }
        CMGroupNodePersistManager.getInstance().saveAllGroupNode();
        item.setText(server.getLabel());
        item.setData(server);
        treeViewer.refresh(server, true);
        treeViewer.expandToLevel(server, 1);
        treeViewer.setSelection(new StructuredSelection(server), true);
        if (returnCode == HostDialog.CONNECT_ID) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog)

Aggregations

CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)50 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)25 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)15 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)13 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 ArrayList (java.util.ArrayList)6 Tree (org.eclipse.swt.widgets.Tree)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)5 ISelection (org.eclipse.jface.viewers.ISelection)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)4 DatabaseMenuItem (com.cubrid.common.ui.query.control.DatabaseMenuItem)3