Search in sources :

Example 1 with QueryConnDialog

use of com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog in project cubrid-manager by CUBRID.

the class PasteQueryConnAction method run.

/**
	 * Paste the query connection
	 */
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 CubridDatabase)) {
        return;
    }
    CubridDatabase pastedDb = (CubridDatabase) objs[0];
    QueryConnDialog dialog = new QueryConnDialog(getShell(), pastedDb, true);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
        CubridDatabase database = dialog.getDatabase();
        CQBDBNodePersistManager.getInstance().addDatabase(database, false);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            return;
        }
        Tree tree = treeViewer.getTree();
        TreeItem item;
        CubridGroupNode parent = getParentGroupNode();
        if (navigatorView.isShowGroup()) {
            item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
        } else {
            item = new TreeItem(tree, SWT.NONE);
        }
        parent.addChild(database);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        item.setText(database.getLabel());
        item.setData(database);
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        treeViewer.setSelection(new StructuredSelection(database), true);
        if (returnCode == QueryConnDialog.CONNECT_ID) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        }
    }
}
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) 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) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 2 with QueryConnDialog

use of com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog 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 CubridDatabase) {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        QueryConnDialog dialog = new QueryConnDialog(shell, (CubridDatabase) dragNode, true);
        int returnCode = dialog.open();
        if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
            newDragNode = dialog.getDatabase();
            CQBDBNodePersistManager.getInstance().addDatabase((CubridDatabase) newDragNode, false);
        } else {
            return false;
        }
    }
    return super.handle(newDragNode, dropNode, insertBefore, dropOperation);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 3 with QueryConnDialog

use of com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog 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 CubridDatabase) {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        QueryConnDialog dialog = new QueryConnDialog(shell, (CubridDatabase) dragNode, true);
        int returnCode = dialog.open();
        if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
            newDragNode = dialog.getDatabase();
            CQBDBNodePersistManager.getInstance().addDatabase((CubridDatabase) newDragNode, false);
            CubridGroupNode groupNode = CQBGroupNodePersistManager.getInstance().getDefaultGroup();
            groupNode.addChild(newDragNode);
        } 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) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 4 with QueryConnDialog

use of com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog in project cubrid-manager by CUBRID.

the class EditQueryConnAction method run.

/**
	 * Open the query connection
	 */
public void run() {
    // TODO remove later
    CQBGroupNodePersistManager.getInstance().fix();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    ConnectionInfo oldInfo = null;
    ConnectionInfo newInfo = null;
    if (cubridDatabases.length > 1) {
        MultiQueryConnEditDialog dialog = new MultiQueryConnEditDialog(getShell(), Arrays.asList(cubridDatabases));
        if (dialog.open() != MultiQueryConnEditDialog.SAVE_ID) {
            return;
        }
        List<CubridDatabase> newDBList = dialog.getNewDBList();
        for (int i = 0; i < cubridDatabases.length; i++) {
            CubridDatabase saveCubridDatabase = cubridDatabases[i];
            CubridDatabase newCubridDatabase = newDBList.get(i);
            oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(saveCubridDatabase);
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(newCubridDatabase);
            saveCubridDatabase.setLabel(newCubridDatabase.getLabel());
            saveCubridDatabase.getDatabaseInfo().setDbName(newCubridDatabase.getDatabaseInfo().getDbName());
            saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setName(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getName());
            saveCubridDatabase.setAutoSavePassword(newCubridDatabase.isAutoSavePassword());
            if (saveCubridDatabase.isAutoSavePassword()) {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword());
            } else {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(null);
            }
            saveCubridDatabase.getDatabaseInfo().setBrokerIP(newCubridDatabase.getDatabaseInfo().getBrokerIP());
            saveCubridDatabase.getDatabaseInfo().setBrokerPort(newCubridDatabase.getDatabaseInfo().getBrokerPort());
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(saveCubridDatabase, false);
            if (editorConfig == null) {
                editorConfig = new DatabaseEditorConfig();
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            } else if (editorConfig.getBackGround() == null) {
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            }
            if (newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY) != null) {
                editorConfig.setDatabaseComment((String) newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY));
            }
            QueryOptions.putEditorConfig(saveCubridDatabase, editorConfig, false);
            CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(saveCubridDatabase);
            if (isContinue) {
                TreeViewer viewer = (TreeViewer) provider;
                viewer.refresh(saveCubridDatabase, true);
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(saveCubridDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
            }
        }
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        return;
    }
    CubridDatabase database = (CubridDatabase) cubridDatabases[0];
    if (database.getParent() == null) {
        CQBGroupNodePersistManager.getInstance();
    }
    String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
    ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
    oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
    QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID) {
        database.removeAllChild();
        newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
        TreeViewer treeViewer = (TreeViewer) provider;
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        if (!preName.equals(database.getServer().getName())) {
            QueryOptions.removePref(preServerInfo);
        }
        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));
        CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
        try {
            CommonUITool.openQueryEditor(database, true);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    } else if (returnCode == QueryConnDialog.SAVE_ID) {
        TreeViewer treeViewer = (TreeViewer) provider;
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) MultiQueryConnEditDialog(com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 5 with QueryConnDialog

use of com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog in project cubrid-manager by CUBRID.

the class NewQueryConnAction method run.

/**
	 * Open the QueryConnDialog
	 */
public void run() {
    QueryConnDialog dialog = new QueryConnDialog(getShell(), null, true);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
        CubridDatabase database = dialog.getDatabase();
        CQBDBNodePersistManager.getInstance().addDatabase(database, false);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            return;
        }
        Tree tree = treeViewer.getTree();
        TreeItem item;
        CubridGroupNode parent = getParentGroupNode();
        if (navigatorView.isShowGroup()) {
            item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
        } else {
            item = new TreeItem(tree, SWT.NONE);
        }
        parent.addChild(database);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        item.setText(database.getLabel());
        item.setData(database);
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        treeViewer.setSelection(new StructuredSelection(database), true);
        if (returnCode == QueryConnDialog.CONNECT_ID) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        }
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Tree(org.eclipse.swt.widgets.Tree) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 QueryConnDialog (com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)5 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)3 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 Tree (org.eclipse.swt.widgets.Tree)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 ConnectionInfo (com.cubrid.common.ui.common.persist.ConnectionInfo)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 MultiQueryConnEditDialog (com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PartInitException (org.eclipse.ui.PartInitException)1