Search in sources :

Example 1 with RenameHostDialog

use of com.cubrid.cubridmanager.ui.host.dialog.RenameHostDialog in project cubrid-manager by CUBRID.

the class RenameHostAction method doRun.

private void doRun(CubridServer server) {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    RenameHostDialog dlg = new RenameHostDialog(shell, server);
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        server.setLabel(dlg.getNewName());
        server.getServerInfo().setServerName(dlg.getNewName());
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            LOGGER.error("Error: Can't find the navigator view:" + CubridHostNavigatorView.ID);
            return;
        }
        // Fire all the databases which are in the server logout
        List<ICubridNode> children = server.getChildren();
        if (children != null) {
            for (ICubridNode child : children) {
                if (!NodeType.DATABASE_FOLDER.equals(child.getType())) {
                    continue;
                }
                List<ICubridNode> childList = child.getChildren();
                if (childList == null) {
                    continue;
                }
                for (ICubridNode node : childList) {
                    if (!NodeType.DATABASE.equals(node.getType())) {
                        continue;
                    }
                    CubridDatabase database = (CubridDatabase) node;
                    database.setLogined(false);
                    CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
                }
            }
        }
        // Refresh the tree view
        server.removeAllChild();
        if (server.getLoader() != null) {
            server.getLoader().setLoaded(false);
        }
        treeViewer.refresh(server, true);
        treeViewer.expandToLevel(server, 1);
        treeViewer.setSelection(null, true);
        treeViewer.setSelection(new StructuredSelection(server), true);
        setEnabled(false);
        // Save the data
        CMHostNodePersistManager.getInstance().addServer(server.getServerInfo().getHostAddress(), server.getServerInfo().getHostMonPort(), server.getServerInfo().getUserName(), server.getServerInfo());
        QueryOptions.removePref(server.getServerInfo());
        BrokerIntervalSettingManager.getInstance().removeAllBrokerIntervalSettingInServer(server.getLabel());
        CMGroupNodePersistManager.getInstance().saveAllGroupNode();
        CMHostNodePersistManager.getInstance().saveServers();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) RenameHostDialog(com.cubrid.cubridmanager.ui.host.dialog.RenameHostDialog) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 RenameHostDialog (com.cubrid.cubridmanager.ui.host.dialog.RenameHostDialog)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Shell (org.eclipse.swt.widgets.Shell)1