Search in sources :

Example 46 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class EditUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    EditUserDialog dlg = new EditUserDialog(shell);
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(false);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        if (database.getServer() != null) {
            persisteManager.updateDBPassword(database.getServer().getServerName(), database.getServer().getHostAddress(), database.getServer().getMonPort(), database.getDatabaseInfo().getDbName(), database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName(), dlg.getInputtedPassword(), database.isAutoSavePassword());
        }
        CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
        if (navigationView != null) {
            TreeViewer treeViewer = navigationView.getViewer();
            if (treeViewer != null) {
                DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
                if (userInfo != null && userInfo.getName().equalsIgnoreCase(node.getName())) {
                    CommonUITool.openInformationBox(Messages.titleLogout, Messages.msgLogoutInfomation);
                    database.setLogined(false);
                    database.setAutoSavePassword(false);
                    CubridNodeChangedEvent event = new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT);
                    CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                    database.removeAllChild();
                    treeViewer.refresh(database, true);
                } else {
                    CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                    setEnabled(false);
                }
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        persisteManager.savaAllServers();
        persisteManager.saveAllGroupNodes();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 47 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class AddUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    //		if (database.getDatabaseInfo().isHAMode()) {
    //			CommonUITool.openErrorBox(Messages.errNoSupportInHA);
    //			return;
    //		}
    String childId = database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridNodeLoader.USERS_FOLDER_ID;
    ICubridNode folderNode = database.getChild(childId);
    if (folderNode == null) {
        return;
    }
    EditUserDialog dlg = new EditUserDialog(getShell());
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(true);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                if (userInfo.getName().equals(node.getName())) {
                    userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
                }
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        //Don't count the child
        if (!folderNode.getLoader().isLoaded()) {
            return;
        }
        CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
        if (navigatorView != null) {
            TreeViewer treeViewer = navigatorView.getViewer();
            if (treeViewer != null) {
                CubridNodeChangedEvent event = new CubridNodeChangedEvent(folderNode, CubridNodeChangedEventType.NODE_REFRESH);
                CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
            } else {
                CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                setEnabled(false);
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 48 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class MultiDBQueryComposite method setInput.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void setInput() {
    // on CM
    CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
    if (navigatorView != null) {
        //navigatorView.setTreeInputNoGroup(ctv);
        List<ICubridNode> newItems = null;
        List<ICubridNode> items = (List<ICubridNode>) navigatorView.getRootList();
        if (items.size() > 0 && items.get(0) instanceof CubridServer) {
            newItems = new ArrayList<ICubridNode>();
            for (Object citem : (List) navigatorView.getRootList()) {
                CubridServer cubridServer = (CubridServer) citem;
                if (cubridServer.getChildren() == null || cubridServer.getChildren().size() == 0) {
                    continue;
                }
                ICubridNode databaseFolder = cubridServer.getChildren().get(0);
                for (ICubridNode cubridDatabase : databaseFolder.getChildren()) {
                    newItems.add(cubridDatabase);
                }
            }
            items = newItems;
        }
        Collections.sort(items, new Comparator<ICubridNode>() {

            public int compare(ICubridNode db1, ICubridNode db2) {
                if (db1.getLabel() == null && db2.getLabel() == null) {
                    return 0;
                } else if (db2.getLabel() == null) {
                    return -1;
                } else if (db1.getLabel() == null) {
                    return 1;
                }
                return (db1.getLabel().compareTo(db2.getLabel()));
            }
        });
        int index = 1;
        for (ICubridNode item : items) {
            if (selectedNodes.contains(item)) {
                item.setData(INDEXKEY, String.valueOf(index++));
            } else {
                item.setData(INDEXKEY, "0");
            }
        }
        ctv.setInput(items);
        initialIndex();
    //			setExpand();
    //			refresh(editor.getSelectedDatabase());
    //			setCheckedDatabase(navigatorView.getMultiDBQuerySelectedDBList());
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) List(java.util.List) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 49 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class ERDBNavigatorMenuWrapper method addSelectionListener.

/**
	 * Add selection listener
	 */
public void addSelectionListener() {
    // FIXME need modulation because of
    // complicated codes
    MenuItem[] allNodes = getAllMenuNodes();
    for (final MenuItem item : allNodes) {
        item.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                if (item.getStyle() != SWT.CHECK && item.getStyle() != SWT.RADIO) {
                    CommonUITool.openErrorBox(parent.getShell(), Messages.plsSelectDb);
                    return;
                }
                CubridDatabase oldSelectedDb = (CubridDatabase) getSelectedDb();
                final DatabaseMenuItem dbItem = (DatabaseMenuItem) item;
                CubridDatabase selectedDb = dbItem.getDatabase();
                if (selectedDb != null && selectedDb.getId().equals(IND_DATABASE_ID)) {
                    if (oldSelectedDb == null) {
                        return;
                    }
                    dbItem.setSelection(false);
                    // on CM mode
                    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
                        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CM);
                        if (navigatorView != null) {
                            TreeViewer treeViewer = navigatorView.getViewer();
                            Tree tree = treeViewer.getTree();
                            if (tree == null) {
                                return;
                            }
                            for (int i = 0; i < tree.getItemCount(); i++) {
                                TreeItem itm = tree.getItem(i);
                                if (itm == null) {
                                    continue;
                                }
                                showDatabaseOnEditingWithHostOnGroup(dbItem, oldSelectedDb, treeViewer, tree, itm);
                            }
                            return;
                        }
                    } else if (ApplicationType.CUBRID_QUERY_BROWSER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
                        // on CQB mode
                        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CQB);
                        if (navigatorView != null) {
                            TreeViewer treeViewer = navigatorView.getViewer();
                            Tree tree = treeViewer.getTree();
                            if (tree == null) {
                                return;
                            }
                            for (int i = 0; i < tree.getItemCount(); i++) {
                                TreeItem itm = tree.getItem(i);
                                if (itm == null) {
                                    continue;
                                }
                                showDatabaseOnEditingOnGroup(oldSelectedDb, treeViewer, tree, itm);
                            }
                            return;
                        }
                    }
                    return;
                } else if (oldSelectedDb != null && selectedDb != null && oldSelectedDb.getId().equals(selectedDb.getId())) {
                    return;
                } else if (selectedDb != null && selectedDb.getId().equals(SELF_DATABASE_ID)) {
                    if (!NULL_DATABASE_ID.equals(oldSelectedDb.getId())) {
                        boolean confirm = CommonUITool.openConfirmBox(erSchemaEditor.getSite().getShell(), Messages.changeDbConfirm);
                        if (!confirm) {
                            dbItem.setSelection(false);
                            return;
                        }
                    }
                    if (!handleWithSelfConn(dbItem)) {
                        return;
                    }
                } else if (oldSelectedDb != null && !oldSelectedDb.getId().equals(NULL_DATABASE_ID)) {
                    boolean confirm = CommonUITool.openConfirmBox(erSchemaEditor.getSite().getShell(), Messages.changeDbConfirm);
                    if (!confirm) {
                        dbItem.setSelection(false);
                        return;
                    }
                }
                selectMenuItem(dbItem);
            }

            // on cm
            private void showDatabaseOnEditingWithHost(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem itm) {
                if (itm != null && itm.getData() != null && itm.getData() instanceof ICubridNode && NodeType.SERVER.equals(((ICubridNode) itm.getData()).getType())) {
                    String serverName = ((ICubridNode) itm.getData()).getServer().getServerName();
                    if (serverName == null || oldSelectedDb == null || oldSelectedDb.getServer() == null) {
                        return;
                    }
                    if (!serverName.equals(oldSelectedDb.getServer().getName())) {
                        return;
                    }
                    if (treeViewer != null && !itm.getExpanded()) {
                        treeViewer.expandToLevel(itm.getData(), 1);
                    }
                    Display.getDefault().timerExec(100, new Runnable() {

                        public void run() {
                            showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, 1);
                        }
                    });
                }
            }

            // on cqb
            private void showDatabaseOnEditing(CubridDatabase oldSelectedDb, TreeViewer treeViewer, Tree tree, TreeItem itm) {
                ISchemaNode cNode = (ISchemaNode) itm.getData();
                String user = cNode.getDatabase().getUserName();
                String dbName = cNode.getDatabase().getDatabaseInfo().getDbName();
                String hostName = cNode.getDatabase().getDatabaseInfo().getBrokerIP();
                if (user == null || dbName == null || hostName == null) {
                    return;
                }
                if (user.equals(oldSelectedDb.getUserName()) && dbName.equals(oldSelectedDb.getDatabaseInfo().getDbName()) && hostName.equals(oldSelectedDb.getDatabaseInfo().getBrokerIP())) {
                    tree.setSelection(itm);
                    tree.setTopItem(itm);
                    final String origDbName = itm.getText();
                    final TreeItem updatableItem = itm;
                    itm.setText("[ [ [ " + origDbName + " ] ] ]");
                    Display.getDefault().timerExec(500, new Runnable() {

                        public void run() {
                            updatableItem.setText("[ [ " + origDbName + " ] ]");
                        }
                    });
                    Display.getDefault().timerExec(530, new Runnable() {

                        public void run() {
                            updatableItem.setText("[ " + origDbName + " ]");
                        }
                    });
                    Display.getDefault().timerExec(560, new Runnable() {

                        public void run() {
                            updatableItem.setText(origDbName);
                        }
                    });
                }
            }

            private void showDatabaseOnEditingWithHostLoop(final CubridDatabase oldSelectedDb, final Tree tree, final TreeItem itm, final int count) {
                if (count > 10) {
                    return;
                }
                boolean ok = false;
                try {
                    for (int j = 0; j < itm.getItemCount(); j++) {
                        TreeItem sub = itm.getItem(j);
                        if (sub.getData() instanceof ICubridNode && NodeType.DATABASE_FOLDER.equals(((ICubridNode) sub.getData()).getType())) {
                            ok = true;
                            for (int k = 0; k < sub.getItemCount(); k++) {
                                TreeItem dbNode = sub.getItem(k);
                                if (dbNode == null || dbNode.getData() == null) {
                                    continue;
                                }
                                String dbName = ((ICubridNode) dbNode.getData()).getName();
                                if (dbName != null && dbName.equals(oldSelectedDb.getName())) {
                                    tree.setSelection(dbNode);
                                    tree.setTopItem(dbNode);
                                    final String origDbName = dbNode.getText();
                                    final TreeItem updatableItem = dbNode;
                                    dbNode.setText("[ [ [ " + origDbName + " ] ] ]");
                                    Display.getDefault().timerExec(500, new Runnable() {

                                        public void run() {
                                            updatableItem.setText("[ [ " + origDbName + " ] ]");
                                        }
                                    });
                                    Display.getDefault().timerExec(530, new Runnable() {

                                        public void run() {
                                            updatableItem.setText("[ " + origDbName + " ]");
                                        }
                                    });
                                    Display.getDefault().timerExec(560, new Runnable() {

                                        public void run() {
                                            updatableItem.setText(origDbName);
                                        }
                                    });
                                }
                            }
                        }
                    }
                } catch (Exception ignored) {
                    ok = false;
                }
                if (!ok) {
                    final int nextCount = count + 1;
                    Display.getDefault().timerExec(500, new Runnable() {

                        public void run() {
                            showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, nextCount);
                        }
                    });
                }
            }

            // on group mode
            private void showDatabaseOnEditingWithHostOnGroup(final DatabaseMenuItem dbItem, final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
                if (item == null || item.getData() == null) {
                    return;
                }
                if (item.getData() instanceof CubridGroupNode) {
                    CubridGroupNode grp = (CubridGroupNode) item.getData();
                    if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
                        return;
                    }
                    if (treeViewer != null && !item.getExpanded()) {
                        treeViewer.expandToLevel(item.getData(), 1);
                        Display.getDefault().timerExec(500, new Runnable() {

                            public void run() {
                                for (int i = 0; i < item.getItemCount(); i++) {
                                    final TreeItem itm = item.getItem(i);
                                    if (itm == null) {
                                        continue;
                                    }
                                    showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
                                }
                            }
                        });
                    } else {
                        for (int i = 0; i < item.getItemCount(); i++) {
                            final TreeItem itm = item.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
                        }
                    }
                } else {
                    showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, item);
                }
            }

            // on group mode
            private void showDatabaseOnEditingOnGroup(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
                if (item == null || item.getData() == null) {
                    return;
                }
                if (item.getData() instanceof CubridGroupNode) {
                    CubridGroupNode grp = (CubridGroupNode) item.getData();
                    if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
                        return;
                    }
                    if (treeViewer != null && !item.getExpanded()) {
                        treeViewer.expandToLevel(item.getData(), 1);
                        Display.getDefault().timerExec(500, new Runnable() {

                            public void run() {
                                for (int i = 0; i < item.getItemCount(); i++) {
                                    final TreeItem itm = item.getItem(i);
                                    if (itm == null) {
                                        continue;
                                    }
                                    showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
                                }
                            }
                        });
                    } else {
                        for (int i = 0; i < item.getItemCount(); i++) {
                            final TreeItem itm = item.getItem(i);
                            if (itm == null) {
                                continue;
                            }
                            showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
                        }
                    }
                } else {
                    showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, item);
                }
            }
        });
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) DatabaseMenuItem(com.cubrid.common.ui.query.control.DatabaseMenuItem) DatabaseMenuItem(com.cubrid.common.ui.query.control.DatabaseMenuItem) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 50 with CubridNavigatorView

use of com.cubrid.common.ui.common.navigator.CubridNavigatorView in project cubrid-manager by CUBRID.

the class CQDatabaseNavigatorMenu method loadNavigatorMenu.

/**
	 * load all database on all server. if not login or database not started,
	 * the item disabled.
	  * 
	  * @param dbSelectionMenu
	 */
public void loadNavigatorMenu(Menu dbSelectionMenu) {
    setSelectedImage(CubridQueryUIPlugin.getImage("/icons/navigator/eclipse_dot.png"));
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
    boolean isShowGroup = navigatorView == null ? false : navigatorView.isShowGroup();
    List<CubridGroupNode> groupList = CQBGroupNodePersistManager.getInstance().getAllGroupNodes();
    if (groupList == null || groupList.isEmpty()) {
        return;
    }
    Collections.sort(groupList, new Comparator<CubridGroupNode>() {

        public int compare(CubridGroupNode o1, CubridGroupNode o2) {
            if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
                return 0;
            }
            return o1.getLabel().compareToIgnoreCase(o2.getLabel());
        }
    });
    int count = 0;
    for (CubridGroupNode groupNode : groupList) {
        //			if (NodeFilterManager.getInstance().isHidden(groupNode)) {
        //				continue;
        //			}
        List<ICubridNode> nodeList = groupNode.getChildren();
        if (nodeList == null || nodeList.isEmpty()) {
            continue;
        }
        DatabaseMenuItem groupMenuItem = null;
        Menu groupSub = null;
        String groupName = null;
        if (isShowGroup) {
            groupName = groupNode.getLabel();
            groupMenuItem = new DatabaseMenuItem(groupNode.getId(), dbSelectionMenu, SWT.CASCADE);
            groupMenuItem.setImage(CubridQueryUIPlugin.getImage("/icons/navigator/group.png"));
            groupMenuItem.setText(groupNode.getLabel());
            groupSub = new Menu(dbSelectionMenu);
            groupMenuItem.setMenu(groupSub);
        }
        Collections.sort(nodeList, new Comparator<ICubridNode>() {

            public int compare(ICubridNode o1, ICubridNode o2) {
                if (o1 == null || o2 == null || o1.getLabel() == null || o2.getLabel() == null) {
                    return 0;
                }
                return o1.getLabel().compareToIgnoreCase(o2.getLabel());
            }
        });
        int itemCountInGroup = 0;
        for (ICubridNode node : nodeList) {
            //				}
            if (node instanceof CubridDatabase) {
                CubridDatabase database = (CubridDatabase) node;
                if (!database.isLogined()) {
                    continue;
                }
                itemCountInGroup++;
                DatabaseMenuItem dbItem = null;
                if (isShowGroup) {
                    dbItem = new DatabaseMenuItem(database.getId(), groupSub, SWT.RADIO);
                } else {
                    dbItem = new DatabaseMenuItem(database.getId(), dbSelectionMenu, SWT.RADIO);
                }
                dbItem.setText(database.getLabelWithUser());
                dbItem.setDatabase((CubridDatabase) database);
                dbItem.setEnabled(database.isLogined() && database.getRunningType() == DbRunningType.CS);
                dbItem.setGroupName(groupName);
                count++;
            }
        }
        // If it has no active item on the group, it's group should be disposed
        if (isShowGroup && itemCountInGroup <= 0 && groupSub != null && groupMenuItem != null) {
            groupSub.dispose();
            groupMenuItem.dispose();
        }
    }
    if (count > 0) {
        new MenuItem(dbSelectionMenu, SWT.SEPARATOR);
    }
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) DatabaseMenuItem(com.cubrid.common.ui.query.control.DatabaseMenuItem) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DatabaseMenuItem(com.cubrid.common.ui.query.control.DatabaseMenuItem) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) DatabaseNavigatorMenu(com.cubrid.common.ui.query.control.DatabaseNavigatorMenu) Menu(org.eclipse.swt.widgets.Menu) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)50 TreeViewer (org.eclipse.jface.viewers.TreeViewer)36 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)25 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)22 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)21 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)15 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)13 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 TreeItem (org.eclipse.swt.widgets.TreeItem)7 ArrayList (java.util.ArrayList)6 Tree (org.eclipse.swt.widgets.Tree)6 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)6 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)5 ISelection (org.eclipse.jface.viewers.ISelection)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)4 DatabaseMenuItem (com.cubrid.common.ui.query.control.DatabaseMenuItem)3