Search in sources :

Example 66 with CubridNodeChangedEvent

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

Example 67 with CubridNodeChangedEvent

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

the class DisConnectHostAction method doRun.

public void doRun(Object[] objArr) {
    if (CubridNavigatorView.findNavigationView() == null) {
        LOGGER.error("CubridNavigatorView.findNavigationView() is null.");
        return;
    }
    ISelectionProvider provider = CubridNavigatorView.findNavigationView().getViewer();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    List<CubridServer> connectedServers = new ArrayList<CubridServer>();
    StringBuffer hostNames = new StringBuffer();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            continue;
        }
        ICubridNode node = (ICubridNode) objArr[i];
        if (node instanceof CubridServer) {
            connectedServers.add((CubridServer) node);
            hostNames.append(node.getLabel());
            if (i != objArr.length - 1) {
                hostNames.append(",");
            }
        }
    }
    String msg = Messages.bind(Messages.msgConfirmDisconnectHost, hostNames.toString());
    boolean isDisconnectHost = CommonUITool.openConfirmBox(getShell(), msg);
    if (!isDisconnectHost) {
        return;
    }
    for (CubridServer server : connectedServers) {
        boolean isContinue = HostUtils.processHostDisconnected(server);
        if (isContinue) {
            TreeViewer viewer = (TreeViewer) provider;
            viewer.refresh(server, true);
            viewer.setSelection(null, true);
            viewer.setSelection(new StructuredSelection(server), true);
            ActionManager.getInstance().fireSelectionChanged(getSelection());
            LayoutManager.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) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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 68 with CubridNodeChangedEvent

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

the class MultiDatabaseLoginFailedDialog method editHost.

/**
	 *
	 * @param multiDatabaseloginFailedInfo
	 */
public void editHost(MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo) {
    if (multiDatabaseloginFailedInfo == null) {
        return;
    }
    CubridDatabase database = multiDatabaseloginFailedInfo.getCubridDatabase();
    //if login ,can't edit
    if (database.isLogined()) {
        return;
    }
    String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
    ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
    QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID) {
        database.removeAllChild();
        CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        TreeViewer treeViewer = view.getViewer();
        if (database != null) {
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
            if (editorConfig == null) {
                editorConfig = new DatabaseEditorConfig();
            }
            editorConfig.setBackGround(dialog.getSelectedBackground());
            QueryOptions.putEditorConfig(database, editorConfig, false);
        }
        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(treeViewer.getSelection());
        LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        multiDatabaseloginFailedInfo.setErrMsg("");
    }
    databaseTable.refresh();
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 69 with CubridNodeChangedEvent

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

the class CubridWorkbenchContrItem method processDoubleClickNavigatorEvent.

/**
	 * @see
	 *      WorkbenchContrItem.processDoubleClickNavigatorEvent(DoubleClickEvent)
	 * @param event DoubleClickEvent
	 */
public void processDoubleClickNavigatorEvent(DoubleClickEvent event) {
    ISelection selection = event.getSelection();
    if (selection == null || selection.isEmpty()) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    ICubridNode cubridNode = (ICubridNode) obj;
    if (NodeType.DATABASE.equals(cubridNode.getType())) {
        CubridDatabase database = (CubridDatabase) cubridNode;
        if (!database.isLogined() && database.isAutoSavePassword()) {
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
            if (EditorConstance.isNeedSetBackground(editorConfig)) {
                new ShortSetEditorConfigAction(database).run();
            }
        }
        if (database.isLogined()) {
            ActionManager.getInstance().getAction(EditQueryConnAction.ID).run();
        } else if (database.isAutoSavePassword() && connectDatabase(database.getDatabaseInfo())) {
            try {
                CommonUITool.openQueryEditor(database, true);
            } catch (PartInitException e) {
                LOGGER.error(e.getMessage(), e);
            }
            CQBGroupNodePersistManager.getInstance().fix();
            database.getLoader().setLoaded(false);
            CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
            TreeViewer treeViewer = view.getViewer();
            treeViewer.refresh(database, true);
            treeViewer.expandToLevel(database, 1);
            ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
            LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        } else {
            ActionManager.getInstance().getAction(EditQueryConnAction.ID).run();
        }
    }
    if (cubridNode.getType() == NodeType.TABLE_FOLDER || cubridNode.getType() == NodeType.TABLE_FOLDER || cubridNode.getType() == NodeType.VIEW_FOLDER || cubridNode.getType() == NodeType.TRIGGER_FOLDER || cubridNode.getType() == NodeType.SERIAL_FOLDER || cubridNode.getType() == NodeType.USER_FOLDER) {
        CubridDatabase database = (CubridDatabase) cubridNode.getParent();
        CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        //if not expand ,expand the node and wait until all children be added
        TreeViewer treeViewer = view.getViewer();
        if (cubridNode.getType() == NodeType.TABLE_FOLDER) {
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
                int sleepCount = 0;
                while (cubridNode.getChildren().size() == 0) {
                    try {
                        Thread.sleep(500);
                        sleepCount++;
                        if (sleepCount > 5) {
                            break;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            openTablesDetailInfoPart(database);
        } else if (cubridNode.getType() == NodeType.VIEW_FOLDER) {
            //if not open child node ,edit serial from dashboard can not open edit dialog
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
            }
            openViewsDetailInfoPart(database);
        } else if (cubridNode.getType() == NodeType.TRIGGER_FOLDER) {
            //if not open child node ,edit serial from dashboard can not open edit dialog
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
            }
            openTriggersDetailInfoPart(database);
        } else if (cubridNode.getType() == NodeType.SERIAL_FOLDER) {
            //if not open child node ,edit trigger from dashboard can not open edit dialog
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
            }
            openSerialsDetailInfoPart(database);
        } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.USER_FOLDER)) {
            if (!treeViewer.getExpandedState(cubridNode)) {
                treeViewer.expandToLevel(cubridNode, 1);
            }
            openUsersDetailInfoPart(database);
        }
    }
    if (cubridNode.getType() == NodeType.SERIAL) {
        CubridDatabase database = (CubridDatabase) cubridNode.getParent().getParent();
        openSerialsDetailInfoPart(database, cubridNode.getName());
    }
    if (!LayoutManager.getInstance().isUseClickOnce()) {
        if (ActionSupportUtil.isSupportMultiSelection(obj, new String[] { NodeType.USER_TABLE, NodeType.USER_VIEW, NodeType.SYSTEM_TABLE, NodeType.SYSTEM_VIEW, NodeType.USER_PARTITIONED_TABLE_FOLDER }, false)) {
            openSelectQuery(selection);
        } else {
            openEditorOrView(cubridNode);
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) ISelection(org.eclipse.jface.viewers.ISelection) ShortSetEditorConfigAction(com.cubrid.cubridquery.ui.common.action.ShortSetEditorConfigAction) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 70 with CubridNodeChangedEvent

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

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