Search in sources :

Example 66 with ICubridNode

use of com.cubrid.common.ui.spi.model.ICubridNode 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)

Example 67 with ICubridNode

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

the class DeleteHostAction method doRun.

/**
	 * Perform do run
	 *
	 * @param objArr
	 */
public void doRun(Object[] objArr) {
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
    if (navigatorView == null) {
        return;
    }
    StringBuilder hostNames = new StringBuilder();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ICubridNode node = (ICubridNode) objArr[i];
        hostNames.append(node.getLabel());
        if (i != objArr.length - 1) {
            hostNames.append(",");
        }
    }
    String msg = Messages.bind(Messages.msgConfirmDeleteHost, hostNames.toString());
    boolean isDelete = CommonUITool.openConfirmBox(getShell(), msg);
    if (!isDelete) {
        return;
    }
    TreeViewer viewer = navigatorView.getViewer();
    if (objArr == null) {
        LOGGER.error("objArr is null.");
        return;
    }
    for (int i = 0; i < objArr.length; i++) {
        CubridServer server = (CubridServer) objArr[i];
        boolean isContinue = HostUtils.processHostDeleted(server);
        List<CubridGroupNode> groups = CMGroupNodePersistManager.getInstance().getAllGroupNodes();
        for (CubridGroupNode grp : groups) {
            grp.removeChild(server);
        }
        if (isContinue) {
            viewer.remove(server);
        }
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 68 with ICubridNode

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

the class UserEditor method nodeChanged.

/**
	 * When node changed,call it
	 * 
	 * @param event the node changed event
	 */
public void nodeChanged(CubridNodeChangedEvent event) {
    ICubridNode eventNode = event.getCubridNode();
    if (eventNode == null || event.getType() != CubridNodeChangedEventType.CONTAINER_NODE_REFRESH) {
        return;
    }
    ICubridNode node = eventNode.getChild(cubridNode == null ? "" : cubridNode.getId());
    if (node == null) {
        return;
    }
    synchronized (this) {
        loadData();
    }
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 69 with ICubridNode

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

the class ChangeManagerPasswordAction method run.

/**
	 * Open change password dialog and change CUBRID Manager user password
	 */
public void run() {
    final Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        return;
    }
    ICubridNode node = (ICubridNode) obj[0];
    CubridServer server = node.getServer();
    ChangePasswordDialog changePasswordDialog = new ChangePasswordDialog(getShell(), false);
    changePasswordDialog.setServerInfo(server.getServerInfo());
    ISelectionProvider provider = this.getSelectionProvider();
    if (IDialogConstants.OK_ID == changePasswordDialog.open() && provider instanceof TreeViewer) {
        TreeViewer viewer = (TreeViewer) provider;
        boolean isContinue = HostUtils.processHostDisconnected(server);
        if (isContinue) {
            viewer.refresh(server, true);
            ActionManager.getInstance().fireSelectionChanged(getSelection());
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        }
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ChangePasswordDialog(com.cubrid.cubridmanager.ui.host.dialog.ChangePasswordDialog) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 70 with ICubridNode

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

the class EditHostAction method doRun.

/**
	 * Perform do run
	 * 
	 * @param obj
	 */
public void doRun(CubridServer[] servers, boolean actionIsConnect) {
    //multi edit
    if (servers.length > 1) {
        MultiHostEditDialog dialog = new MultiHostEditDialog(getShell(), Arrays.asList(servers));
        if (dialog.open() != MultiHostEditDialog.SAVE_ID) {
            return;
        }
        BrokerIntervalSettingManager brokerManager = BrokerIntervalSettingManager.getInstance();
        //new server infolist
        List<CubridServer> newServerInfoList = dialog.getNewServerList();
        for (int i = 0; i < servers.length; i++) {
            CubridServer newServer = newServerInfoList.get(i);
            CubridServer server = servers[i];
            if (server == null) {
                continue;
            }
            // if the server is not changed, ignore it.
            if (!checkServerChanges(newServer, server)) {
                continue;
            }
            ServerInfo oldServerInfo = server.getServerInfo();
            if (oldServerInfo == null) {
                LOGGER.error("oldServerInfo is null.");
                continue;
            }
            ServerInfo newServerInfo = newServer.getServerInfo();
            if (newServerInfo == null) {
                LOGGER.error("newServerInfo is null.");
                continue;
            }
            if (!newServerInfo.getServerName().equals(server.getLabel())) {
                QueryOptions.removePref(server.getServerInfo());
                brokerManager.removeAllBrokerIntervalSettingInServer(server.getLabel());
            }
            if (oldServerInfo.isConnected()) {
                HostUtils.processHostDisconnected(server);
            }
            server.setAutoSavePassword(newServer.isAutoSavePassword());
            server.getServerInfo().setServerName(newServerInfo.getServerName());
            server.getServerInfo().setHostAddress(newServerInfo.getHostAddress());
            server.getServerInfo().setHostMonPort(newServerInfo.getHostMonPort());
            server.getServerInfo().setJdbcDriverVersion(newServerInfo.getJdbcDriverVersion());
            server.getServerInfo().setUserName(newServerInfo.getUserName());
            if (newServer.isAutoSavePassword()) {
                server.getServerInfo().setUserPassword(newServerInfo.getUserPassword());
            } else {
                server.getServerInfo().setUserPassword(null);
            }
            server.setId(newServerInfo.getServerName());
            server.setLabel(newServerInfo.getServerName());
            CMHostNodePersistManager.getInstance().addServer(newServerInfo.getHostAddress(), newServerInfo.getHostMonPort(), newServerInfo.getUserName(), newServerInfo);
            CMGroupNodePersistManager.getInstance().saveAllGroupNode();
            CMHostNodePersistManager.getInstance().saveServers();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
            CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
            if (navigatorView != null) {
                navigatorView.getViewer().refresh(server, true);
            }
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        }
        return;
    }
    // single edit
    HostDialog dialog = new HostDialog(getShell(), false, actionIsConnect);
    CubridServer server = null;
    try {
        server = servers[0];
        //read it from hostgroup preference first
        if (server.getParent() == null) {
            CMGroupNodePersistManager.getInstance();
        }
    } catch (ClassCastException cce) {
        CubridGroupNode node = (CubridGroupNode) getSelectedObj()[0];
        for (ICubridNode icNode : node.getChildren()) {
            if (icNode instanceof CubridServer) {
                if (!((CubridServer) icNode).isConnected())
                    server = (CubridServer) icNode;
            }
        }
    }
    ServerInfo oldServerInfo = server.getServerInfo();
    if (oldServerInfo == null) {
        LOGGER.error("oldServerInfo is null.");
        return;
    }
    dialog.setServer(server);
    int returnCode = dialog.open();
    if (returnCode != HostDialog.SAVE_ID && returnCode != HostDialog.CONNECT_ID) {
        return;
    }
    // Save the server info
    ServerInfo serverInfo = dialog.getServerInfo();
    if (serverInfo == null) {
        LOGGER.error("serverInfo is null.");
        return;
    }
    if (!serverInfo.getServerName().equals(server.getLabel())) {
        QueryOptions.removePref(server.getServerInfo());
        BrokerIntervalSettingManager.getInstance().removeAllBrokerIntervalSettingInServer(server.getLabel());
    }
    if (oldServerInfo.isConnected() && !oldServerInfo.equals(serverInfo)) {
        HostUtils.processHostDisconnected(server);
    }
    server.setId(serverInfo.getServerName());
    server.setLabel(serverInfo.getServerName());
    server.setServerInfo(serverInfo);
    server.setAutoSavePassword(dialog.isSavePassword());
    CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
    // Refresh the tree node
    if (returnCode == HostDialog.CONNECT_ID) {
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            server.removeAllChild();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            TreeViewer treeViewer = (TreeViewer) provider;
            treeViewer.refresh(server, true);
            treeViewer.expandToLevel(server, 1);
            treeViewer.setSelection(null, true);
            treeViewer.setSelection(new StructuredSelection(server), true);
            setEnabled(false);
        }
    }
    CMGroupNodePersistManager.getInstance().saveAllGroupNode();
    CMHostNodePersistManager.getInstance().saveServers();
    ActionManager.getInstance().fireSelectionChanged(getSelection());
    LayoutManager.getInstance().fireSelectionChanged(getSelection());
    CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
Also used : BrokerIntervalSettingManager(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSettingManager) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MultiHostEditDialog(com.cubrid.cubridmanager.ui.host.dialog.MultiHostEditDialog) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog)

Aggregations

ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)362 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)67 ArrayList (java.util.ArrayList)67 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)62 TreeViewer (org.eclipse.jface.viewers.TreeViewer)62 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)55 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)55 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)41 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)33 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)32 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)31 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)26 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)25 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)25 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)25 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)25 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)23 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)22