Search in sources :

Example 61 with CubridNodeChangedEvent

use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent 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 62 with CubridNodeChangedEvent

use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent 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 63 with CubridNodeChangedEvent

use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.

the class HostDialog method closeSaveServerConnection.

public void closeSaveServerConnection() {
    if (server != null) {
        CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
        server.removeAllChild();
        TreeViewer viewer = (TreeViewer) LayoutManager.getInstance().getSelectionProvider();
        viewer.refresh(server);
        viewer.setSelection(null, true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)

Example 64 with CubridNodeChangedEvent

use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.

the class FinishTask method call.

public Integer call() {
    ProgressBar bar = (ProgressBar) item.getData(MultiHostConnectionDialog.KEY_BAR);
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    boolean isRunUpdateCmUserTask = false;
    BrokerInfos brokerInfos = null;
    int size = tasks.size();
    int taskIdx = 1;
    for (ITask task : tasks) {
        if (task instanceof MonitoringTask) {
            if (!serverInfo.isConnected()) {
                CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
                MonitoringTask monitoringTask = (MonitoringTask) task;
                serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                if (serverInfo.isConnected()) {
                    CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
                } else {
                    CMHostNodePersistManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
                }
            }
        } else if ((task instanceof UpdateCMUserTask)) {
            updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0) {
            item.setText(3, msg);
            disConnect();
            isFinished = true;
            updateIcon();
            return 1;
        }
        if (task instanceof GetEnvInfoTask) {
            GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            serverInfo.setEnvInfo(envInfo);
            String clientVersion = getClientVerion();
            if (!isClientSupport(clientVersion)) {
                item.setText(3, Messages.bind(Messages.errNoSupportServerVersion, clientVersion));
                disConnect();
                isFinished = true;
                updateIcon();
                return 2;
            }
            String jdbcVersion = serverInfo.getJdbcDriverVersion();
            if (serverInfo.validateJdbcVersion(jdbcVersion)) {
                if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                    serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
                }
            } else {
                if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                    item.setText(3, Messages.errNoSupportDriver);
                } else {
                    item.setText(3, Messages.errSelectSupportDriver);
                }
                disConnect();
                isFinished = true;
                updateIcon();
                return 3;
            }
        } else if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                allDatabaseInfoList.addAll(databaseInfoList);
            }
        } else if (task instanceof GetCMConfParameterTask) {
            GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
            Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
            ServerType serverType = ServerType.BOTH;
            if (confParameters != null) {
                String target = confParameters.get(CubridManagerConfParaConstants.CM_TARGET);
                if (target != null) {
                    if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                        serverType = ServerType.BOTH;
                    } else if (target.indexOf("broker") >= 0) {
                        serverType = ServerType.BROKER;
                    } else if (target.indexOf("server") >= 0) {
                        serverType = ServerType.DATABASE;
                    }
                }
            }
            if (serverInfo != null) {
                serverInfo.setServerType(serverType);
            }
        } else if (task instanceof CommonQueryTask) {
            CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
            brokerInfos = getBrokerTask.getResultModel();
            if (serverInfo != null) {
                serverInfo.setBrokerInfos(brokerInfos);
            }
        } else if (task instanceof GetCMUserListTask) {
            if (serverInfo != null && serverInfo.isConnected()) {
                GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
                List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
                for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
                    ServerUserInfo userInfo = serverUserInfoList.get(i);
                    if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
                        serverInfo.setLoginedUserInfo(userInfo);
                        break;
                    }
                }
                List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
                if (databaseInfoList != null) {
                    authDatabaseList.addAll(databaseInfoList);
                }
                isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
                if (isRunUpdateCmUserTask) {
                    serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
                }
            }
        } else if (task instanceof GetCubridConfParameterTask) {
            GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setCubridConfParaMap(confParas);
            }
        } else if (task instanceof GetBrokerConfParameterTask) {
            GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setBrokerConfParaMap(confParas);
            }
        } else if (task instanceof FinishTask) {
            isSuccess = true;
            server.getLoader().setLoaded(false);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
        }
        bar.setSelection(taskIdx++ / size * 100);
        if (isCanceled()) {
            isFinished = true;
            updateIcon();
            return 4;
        }
    }
    bar.setSelection(100);
    item.setText(3, Messages.msgConneted);
    isFinished = true;
    return 0;
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ArrayList(java.util.ArrayList) List(java.util.List) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ProgressBar(org.eclipse.swt.widgets.ProgressBar) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) Map(java.util.Map) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Example 65 with CubridNodeChangedEvent

use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.

the class HostDialog method buttonPressed.

/**
	 * Call this method when button in button bar is pressed
	 *
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == HostDialog.TEST_CONNECT_ID || buttonId == HostDialog.ADD_ID || buttonId == HostDialog.CONNECT_ID || buttonId == HostDialog.SAVE_ID) {
        String hostName = hostNameText.getText();
        String address = addressText.getText();
        String port = portText.getText();
        String userName = userNameText.getText();
        String password = passwordText.getText();
        String jdbcDriverVersion = jdbcVersionCombo.getText();
        serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(address, Integer.parseInt(port), userName);
        if (serverInfo == null) {
            serverInfo = new ServerInfo();
            serverInfo.setHostAddress(address);
            serverInfo.setHostMonPort(Integer.parseInt(port));
            serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
            serverInfo.setUserName(userName);
        } else {
            //use a new ServerInfo instance, and never change the existing ServerInfo. for UX improvement.
            if (buttonId == HostDialog.TEST_CONNECT_ID) {
                serverInfo = new ServerInfo();
                serverInfo.setHostAddress(address);
                serverInfo.setHostMonPort(Integer.parseInt(port));
                serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
                serverInfo.setUserName(userName);
            }
        }
        serverInfo.setUserPassword(password);
        serverInfo.setServerName(hostName);
        serverInfo.setJdbcDriverVersion(jdbcDriverVersion);
        if (btnUseTimeOut.getSelection()) {
            int index = timeOutCombo.getSelectionIndex();
            serverInfo.setSoTimeOut(soTimeOutValues[index]);
        }
    }
    //use the serverInfo as testing connection server info.
    testConnServerInfo = serverInfo;
    if (buttonId == HostDialog.CONNECT_ID) {
        //must release current connection first.
        closeTestServerConnection();
        connect(buttonId);
        if (GeneralPreference.isUseHostDashboard() && serverInfo != null && serverInfo.isConnected()) {
            ((HostDashboardAction) ActionManager.getInstance().getAction(HostDashboardAction.ID)).doRun(serverInfo);
        }
    } else if (buttonId == HostDialog.TEST_CONNECT_ID) {
        //must release current connection first.
        closeTestServerConnection();
        connect(buttonId);
    } else if (buttonId == HostDialog.ADD_ID) {
        /*Save operate at the action*/
        QueryOptions.setAutoCommit(serverInfo, btnAutoCommit.getSelection());
        closeSaveServerConnection();
        setReturnCode(buttonId);
        close();
    } else if (buttonId == HostDialog.SAVE_ID) {
        CommonUITool.openInformationBox(Messages.msgSaveAndClose);
        server.setLabel(serverInfo.getServerName());
        /*Save operate at the action*/
        QueryOptions.setAutoCommit(serverInfo, btnAutoCommit.getSelection());
        /*For bug There is no error message after saving the wrong password.*/
        HostUtils.processHostDisconnected(server);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        closeSaveServerConnection();
        setReturnCode(buttonId);
        close();
    } else {
        setReturnCode(buttonId);
        close();
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) HostDashboardAction(com.cubrid.cubridmanager.ui.host.action.HostDashboardAction) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)

Aggregations

CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)98 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)55 TreeViewer (org.eclipse.jface.viewers.TreeViewer)45 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)42 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)23 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)21 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)21 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)17 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)17 ArrayList (java.util.ArrayList)13 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)11 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)10 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)10 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)10 Display (org.eclipse.swt.widgets.Display)10 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)9 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)9 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)9 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)8