Search in sources :

Example 26 with CubridGroupNode

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

the class GroupEditDialog method okPressed.

/**
	 * Event when OK pressed.
	 */
protected void okPressed() {
    String groupName = txtGroupName.getText().trim();
    if (group == null) {
        //add group
        group = new CubridGroupNode(generateGroupId(), groupName, ICubridGroupNodeManager.DEFAULT_GROUP_NODE.getIconPath());
    } else {
        CubridGroupNode gnode = nodeManager.getGroupByName(group.getName());
        if (gnode != null) {
            gnode.setLabel(groupName);
        }
    }
    group.setLabel(groupName);
    //group children.
    group.removeAllChild();
    for (String name : groupItemList.getItems()) {
        ICubridNode node = nodeManager.getGroupItemByItemName(name);
        if (node == null) {
            continue;
        }
        group.addChild(node);
    }
    CubridGroupNode defaultGrp = getGroupByName(ICubridGroupNodeManager.DEFAULT_GROUP_NODE.getName());
    defaultGrp.removeAllChild();
    for (String name : allItemList.getItems()) {
        ICubridNode node = nodeManager.getGroupItemByItemName(name);
        if (node == null) {
            continue;
        }
        defaultGrp.addChild(node);
    }
    super.okPressed();
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 27 with CubridGroupNode

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

the class GroupPropertyAction method run.

/**
	 * Filter
	 */
public void run() {
    Object[] selected = this.getSelectedObj();
    if (selected == null || selected.length == 0) {
        return;
    }
    if (!(selected[0] instanceof CubridGroupNode)) {
        return;
    }
    CubridNavigatorView cubridNavigatorView = CubridNavigatorView.getNavigatorView(navigatorViewId);
    if (cubridNavigatorView == null) {
        return;
    }
    TreeViewer tv = cubridNavigatorView.getViewer();
    CubridGroupNode group = (CubridGroupNode) selected[0];
    GroupEditDialog dialog = new GroupEditDialog(shell, cubridNavigatorView.getGroupNodeManager(), cubridNavigatorView.getGroupNodeManager().getAllGroupNodes(), group);
    if (dialog.open() == Dialog.OK) {
        Object[] objs = tv.getExpandedElements();
        cubridNavigatorView.setShowGroup(true);
        if (objs != null) {
            tv.setExpandedElements(objs);
        }
    }
}
Also used : GroupEditDialog(com.cubrid.common.ui.common.dialog.GroupEditDialog) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Example 28 with CubridGroupNode

use of com.cubrid.common.ui.spi.model.CubridGroupNode 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 29 with CubridGroupNode

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

the class CMGroupNodePersistManager method reorderGroup.

/**
	 * Reorder the groups by input string array.
	 *
	 * @param orderedName the ordered group names.
	 */
public void reorderGroup(String[] orderedName) {
    List<CubridGroupNode> tempNode = new ArrayList<CubridGroupNode>();
    for (String name : orderedName) {
        CubridGroupNode cgn = getGroupByName(name);
        if (cgn == null) {
            continue;
        }
        tempNode.add(cgn);
    }
    groupNodeList.clear();
    groupNodeList.addAll(tempNode);
    saveAllGroupNode();
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ArrayList(java.util.ArrayList)

Example 30 with CubridGroupNode

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

the class CMGroupNodePersistManager method addGroupNode.

/**
	 * Add a new group node to list. The default group node only contain the
	 * items which has no parent group.
	 *
	 * @param group new group node.
	 */
public void addGroupNode(CubridGroupNode group) {
    synchronized (this) {
        if (!groupNodeList.contains(group)) {
            groupNodeList.add(group);
        }
        //refresh the default node.
        List<ICubridNode> nodesHasParent = new ArrayList<ICubridNode>();
        CubridGroupNode dftNode = null;
        for (CubridGroupNode grp : groupNodeList) {
            //if is default node, don't add children here.
            if (isDefaultGroup(grp)) {
                dftNode = grp;
            } else {
                nodesHasParent.addAll(grp.getChildren());
            }
        }
        dftNode.removeAllChild();
        List<CubridServer> servers = CMHostNodePersistManager.getInstance().getAllServers();
        for (CubridServer ser : servers) {
            if (!nodesHasParent.contains(ser)) {
                dftNode.addChild(ser);
            }
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Aggregations

CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)46 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)15 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)15 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)15 ArrayList (java.util.ArrayList)11 TreeViewer (org.eclipse.jface.viewers.TreeViewer)11 TreeItem (org.eclipse.swt.widgets.TreeItem)9 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 Tree (org.eclipse.swt.widgets.Tree)6 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)5 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)4 HostDialog (com.cubrid.cubridmanager.ui.host.dialog.HostDialog)4 ISelection (org.eclipse.jface.viewers.ISelection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 MenuItem (org.eclipse.swt.widgets.MenuItem)4 DatabaseMenuItem (com.cubrid.common.ui.query.control.DatabaseMenuItem)3 QueryConnDialog (com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)3 List (java.util.List)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3