Search in sources :

Example 1 with HostDialog

use of com.cubrid.cubridmanager.ui.host.dialog.HostDialog 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)

Example 2 with HostDialog

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

the class GroupNodeDnDHandler method handle.

/**
	 * Handle the node to be DND.
	 * 
	 * @param dragNode the drag node
	 * @param dropNode the drop node
	 * @param insertBefore insert into the drop node before or after
	 * @param dropOperation the drop operation type <code>DND.DROP_COPY</code>
	 *        <code>DND.DROP_MOVE</code>
	 * @return boolean whether to handle with the drop
	 */
public boolean handle(ICubridNode dragNode, ICubridNode dropNode, boolean insertBefore, int dropOperation) {
    ICubridNode newDragNode = dragNode;
    if (DND.DROP_COPY == dropOperation && dragNode instanceof CubridServer) {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        HostDialog dialog = new HostDialog(shell, true, false);
        dialog.setServer((CubridServer) dragNode);
        int returnCode = dialog.open();
        if (returnCode == HostDialog.ADD_ID || returnCode == HostDialog.CONNECT_ID) {
            ServerInfo serverInfo = dialog.getServerInfo();
            CubridServer server = new CubridServer(serverInfo.getServerName(), serverInfo.getServerName(), "icons/navigator/host.png", "icons/navigator/host_connected.png");
            server.setServerInfo(serverInfo);
            server.setLoader(new CubridServerLoader());
            server.setAutoSavePassword(dialog.isSavePassword());
            CMHostNodePersistManager.getInstance().addServer(server);
            newDragNode = server;
        } else {
            return false;
        }
    }
    return super.handle(newDragNode, dropNode, insertBefore, dropOperation);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog) CubridServerLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)

Example 3 with HostDialog

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

the class ItemNodeDnDHandler method handle.

/**
	 * Handle the node to be DND.
	 * 
	 * @param dragNode the drag node
	 * @param dropNode the drop node
	 * @param insertBefore insert into the drop node before or after
	 * @param dropOperation the drop operation type <code>DND.DROP_COPY</code>
	 *        <code>DND.DROP_MOVE</code>
	 * @return boolean whether to handle with the drop
	 */
public boolean handle(ICubridNode dragNode, ICubridNode dropNode, boolean insertBefore, int dropOperation) {
    ICubridNode newDragNode = dragNode;
    if (DND.DROP_COPY == dropOperation && dragNode instanceof CubridServer) {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        HostDialog dialog = new HostDialog(shell, true, false);
        dialog.setServer((CubridServer) dragNode);
        int returnCode = dialog.open();
        if (returnCode == HostDialog.ADD_ID || returnCode == HostDialog.CONNECT_ID) {
            ServerInfo serverInfo = dialog.getServerInfo();
            CubridServer server = new CubridServer(serverInfo.getServerName(), serverInfo.getServerName(), "icons/navigator/host.png", "icons/navigator/host_connected.png");
            server.setServerInfo(serverInfo);
            server.setLoader(new CubridServerLoader());
            server.setAutoSavePassword(dialog.isSavePassword());
            CMHostNodePersistManager.getInstance().addServer(server);
            CubridGroupNode groupNode = CMGroupNodePersistManager.getInstance().getDefaultGroup();
            groupNode.addChild(server);
            newDragNode = server;
        } else {
            return false;
        }
    }
    return super.handle(newDragNode, dropNode, insertBefore, dropOperation);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog) CubridServerLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)

Example 4 with HostDialog

use of com.cubrid.cubridmanager.ui.host.dialog.HostDialog 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 5 with HostDialog

use of com.cubrid.cubridmanager.ui.host.dialog.HostDialog 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

CubridServer (com.cubrid.common.ui.spi.model.CubridServer)5 HostDialog (com.cubrid.cubridmanager.ui.host.dialog.HostDialog)5 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)4 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 CubridServerLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CubridServerLoader)2 Shell (org.eclipse.swt.widgets.Shell)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 BrokerIntervalSettingManager (com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSettingManager)1 MultiHostEditDialog (com.cubrid.cubridmanager.ui.host.dialog.MultiHostEditDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Tree (org.eclipse.swt.widgets.Tree)1