Search in sources :

Example 21 with CubridGroupNode

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

the class CubridNavigatorView method addTreeDropTarget.

/**
	 * Add drop target
	 *
	 * @param tree Tree
	 */
private void addTreeDropTarget(final Tree tree) {
    // DropTarget for tree
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    DropTarget target = new DropTarget(tree, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        /**
			 * Drag item enter the tree items
			 */
        public void dragEnter(DropTargetEvent event) {
            TreeItem[] selectedItems = tree.getSelection();
            //do not support multi DROP_COPY
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        /**
			 * When drag operation change, check whether to support this operation
			 */
        public void dragOperationChanged(DropTargetEvent event) {
            dragEnter(event);
        }

        /**
			 * Drag item over the tree items.
			 */
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            if (event.item == null) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //do not support multi DROP_COPY
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //Target TreeItem
            TreeItem targetTreeItem = (TreeItem) event.item;
            ICubridNode data = (ICubridNode) targetTreeItem.getData();
            if (dataSupportDragOver(data)) {
                if (data instanceof CubridGroupNode) {
                    event.feedback |= DND.FEEDBACK_SELECT;
                    return;
                }
                //Convert drop coordinate from Display to Tree
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = targetTreeItem.getBounds();
                if (pt.y < (bounds.y + bounds.height / 2)) {
                    event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
                } else {
                    //if (pt.y > bounds.y + 2 * bounds.height / 3)
                    event.feedback |= DND.FEEDBACK_INSERT_AFTER;
                }
            } else {
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                return;
            }
            final int dropOperation = event.detail;
            ICubridNode dropNode = null;
            boolean insertBefore = false;
            if (event.item == null) {
                List<CubridGroupNode> allGroup = getGroupNodeManager().getAllGroupNodes();
                dropNode = allGroup.get(allGroup.size() - 1);
            } else {
                //Move under a TreeItem node
                TreeItem dropItem = (TreeItem) event.item;
                dropNode = (ICubridNode) dropItem.getData();
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = dropItem.getBounds();
                if (pt.y < bounds.y + bounds.height / 2) {
                    insertBefore = true;
                }
            }
            CubridDnDNodeHandler handler = getCubridDnDNodeHandler();
            boolean isSuccess = false;
            if (insertBefore) {
                for (TreeItem si : selectedItems) {
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            } else {
                for (int i = selectedItems.length - 1; i >= 0; i--) {
                    TreeItem si = selectedItems[i];
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            }
            if (isSuccess) {
                Object[] objs = tv.getExpandedElements();
                setTreeInput();
                tv.setExpandedElements(objs);
            }
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridDnDNodeHandler(com.cubrid.common.ui.common.navigator.dnd.CubridDnDNodeHandler) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) ArrayList(java.util.ArrayList) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 22 with CubridGroupNode

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

the class CubridGroupDnDNodeHandler 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) {
    if (dropOperation != DND.DROP_COPY) {
        dragNode.getParent().removeChild(dragNode);
    }
    if (dropNode == null) {
        List<CubridGroupNode> allGroupNodes = navigator.getGroupNodeManager().getAllGroupNodes();
        CubridGroupNode cgn = allGroupNodes.get(allGroupNodes.size() - 1);
        cgn.addChild(dragNode);
    } else if (dropNode instanceof CubridGroupNode) {
        CubridGroupNode cgn = (CubridGroupNode) dropNode;
        cgn.addChild(dragNode);
    } else {
        if (dropNode.getParent() instanceof CubridGroupNode) {
            CubridGroupNode cgn = (CubridGroupNode) dropNode.getParent();
            int index = cgn.position(dropNode);
            if (!insertBefore) {
                index += 1;
            }
            cgn.addChild(dragNode, index);
        }
    }
    navigator.getGroupNodeManager().saveAllGroupNode();
    return true;
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode)

Example 23 with CubridGroupNode

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

the class GroupSettingDialog method initDialogData.

/**
	 * Fill object data to dialog composites.
	 * 
	 */
private void initDialogData() {
    groupList.removeAll();
    groups.clear();
    java.util.List<CubridGroupNode> nodes = nodeManager.getAllGroupNodes();
    for (CubridGroupNode node : nodes) {
        CubridGroupNode grp = new CubridGroupNode(node.getId(), node.getName(), node.getIconPath());
        copyForSetup(node, grp);
        groups.add(grp);
        groupList.add(node.getName());
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode)

Example 24 with CubridGroupNode

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

the class GroupSettingDialog method setButtonStatus.

/**
	 * Set buttons status.
	 * 
	 */
private void setButtonStatus() {
    if (groupList.getSelectionCount() == 0) {
        btnEdit.setEnabled(false);
        btnRemove.setEnabled(false);
        btnTop.setEnabled(false);
        btnUp.setEnabled(false);
        btnDown.setEnabled(false);
        btnBottom.setEnabled(false);
        return;
    }
    boolean firstSelected = groupList.getSelectionIndex() == 0;
    boolean lastSelected = groupList.getSelectionIndex() == (groupList.getItemCount() - 1);
    CubridGroupNode currentGroup = getGroupByName(groupList.getSelection()[0]);
    boolean defaultSelected = nodeManager.isDefaultGroup(currentGroup);
    btnEdit.setEnabled(!defaultSelected);
    btnRemove.setEnabled(!defaultSelected);
    btnTop.setEnabled(!firstSelected);
    btnUp.setEnabled(!firstSelected);
    btnDown.setEnabled(!lastSelected);
    btnBottom.setEnabled(!lastSelected);
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode)

Example 25 with CubridGroupNode

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

the class GroupEditDialog method fillData.

/**
	 * Fill group information to dialog.
	 */
private void fillData() {
    if (this.group == null) {
        txtGroupName.setText(Messages.defaultGroupNodeName);
        txtGroupName.setFocus();
        txtGroupName.selectAll();
    } else {
        txtGroupName.setText(group.getLabel());
        java.util.List<ICubridNode> groups = this.group.getChildren();
        if (groups == null) {
            LOGGER.warn("groups = {}", groups);
        } else {
            for (ICubridNode node : groups) {
                groupItemList.add(node.getName());
            }
        }
    }
    CubridGroupNode groupNode = getDefaultGroup();
    if (groupNode == null || allItemList == null) {
        LOGGER.warn("groupNode = {}, allItemList = {}", groupNode, allItemList);
        return;
    }
    java.util.List<ICubridNode> nodes = groupNode.getChildren();
    if (nodes == null) {
        LOGGER.warn("nodes = {}", nodes);
    } else {
        for (ICubridNode node : nodes) {
            if (node == null) {
                LOGGER.warn("CubridNode is a null.");
            } else {
                allItemList.add(node.getName());
            }
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

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