Search in sources :

Example 36 with ICubridNode

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

the class CubridNavigatorView method addListener.

/**
	 *
	 * Add listener
	 *
	 */
protected void addListener() {
    tv.getTree().addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
        }

        public void mouseUp(MouseEvent event) {
            if (event.button == 1 && LayoutManager.getInstance().isUseClickOnce()) {
                ISelection selection = tv.getSelection();
                if (selection == null || selection.isEmpty()) {
                    return;
                }
                Object obj = ((IStructuredSelection) selection).getFirstElement();
                if (!(obj instanceof ICubridNode)) {
                    return;
                }
                ICubridNode cubridNode = (ICubridNode) obj;
                LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(cubridNode);
            }
        }
    });
    tv.getTree().addMouseTrackListener(new MouseTrackAdapter() {

        public void mouseHover(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            int x = event.x;
            int y = event.y;
            TreeItem item = tv.getTree().getItem(new Point(x, y));
            if (item == null) {
                return;
            }
            showToolTip(item);
        }
    });
    tv.getTree().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            TreeItem[] items = tv.getTree().getSelection();
            if (items == null || items.length == 0) {
                return;
            }
            showToolTip(items[0]);
            if (items.length == 1) {
                showSchemaInfo(items[0]);
            } else {
                showSchemaInfo(null);
            }
        }
    });
    addDragDropSupport(tv.getTree());
    tv.getTree().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            // prevent to make events by key press for a long time
            if (e.character == ' ') {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                if (items.length == 1) {
                    showSchemaInfo(items[0]);
                } else {
                    showSchemaInfo(null);
                }
            }
            lastKeyInputTimestamp = System.currentTimeMillis();
            // by showing object information tab on the query editor.
            if (e.keyCode == SWT.F2) {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                for (TreeItem item : items) {
                    Object obj = item.getData();
                    if (obj instanceof ICubridNode) {
                        ICubridNode node = (ICubridNode) obj;
                        if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
                            DefaultSchemaNode table = (DefaultSchemaNode) obj;
                            OpenTargetAction action = new OpenTargetAction();
                            action.showObjectInfo(table);
                        } else if (NodeType.TABLE_FOLDER.equals(node.getType())) {
                            CubridNavigatorView view = CubridNavigatorView.getNavigatorView(ID_CQB);
                            if (view == null) {
                                view = CubridNavigatorView.getNavigatorView(ID_CM);
                            }
                            if (view == null) {
                                return;
                            }
                            TreeViewer treeViewer = view.getViewer();
                            //if not expand ,expand the node and wait until all children be added
                            if (!treeViewer.getExpandedState(node)) {
                                treeViewer.expandToLevel(node, 1);
                                while (node.getChildren().size() == 0) {
                                    try {
                                        Thread.sleep(500);
                                    } catch (Exception ignored) {
                                    }
                                }
                            }
                            CubridDatabase database = (CubridDatabase) node.getParent();
                            OpenTargetAction action = new OpenTargetAction();
                            action.showTableDashboard(database);
                        }
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) OpenTargetAction(com.cubrid.common.ui.common.action.OpenTargetAction) KeyEvent(org.eclipse.swt.events.KeyEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 37 with ICubridNode

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

the class ExportObjectLabelProvider method update.

/**
	 * update
	 *
	 * @param cell ViewerCell
	 */
public void update(ViewerCell cell) {
    if (cell.getColumnIndex() == 0) {
        if (cell.getElement() instanceof ICubridNode) {
            ICubridNode node = (ICubridNode) cell.getElement();
            cell.setImage(CommonUIPlugin.getImage(node.getIconPath()));
            cell.setText(node.getName());
        } else if (cell.getElement() instanceof PendingUpdateAdapter) {
            cell.setText(Messages.msgLoading);
        }
    } else if (cell.getColumnIndex() == 1 && cell.getElement() instanceof ICubridNode) {
        ICubridNode node = (ICubridNode) cell.getElement();
        String condition = (String) node.getData(CONDITION);
        if (condition != null) {
            cell.setText(condition);
        }
        // cell can't edit ,set it to gray color
        if (node.getType().equals(NodeType.TABLE_COLUMN)) {
            cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
        }
    }
}
Also used : PendingUpdateAdapter(org.eclipse.ui.progress.PendingUpdateAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 38 with ICubridNode

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

the class CubridDeferredTreeContentManager method addChildren.

/**
	 * Create a UIJob to add the children to the parent in the tree viewer.
	 * 
	 * @param parent the parent tree container node
	 * @param children the added children array
	 * @param monitor the monitor object
	 */
protected void addChildren(final Object parent, final Object[] children, IProgressMonitor monitor) {
    WorkbenchJob updateJob = new WorkbenchJob(Messages.msgAddingChildren) {

        public IStatus runInUIThread(IProgressMonitor updateMonitor) {
            // Cancel the job if the tree viewer got closed
            if (treeViewer.getControl().isDisposed() || updateMonitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            treeViewer.add(parent, children);
            if (parent instanceof ICubridNode && ((ICubridNode) parent).isContainer()) {
                treeViewer.update(parent, null);
                ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
            }
            ICubridNode parentNode = null;
            if (parent instanceof ICubridNode) {
                parentNode = (ICubridNode) parent;
            }
            boolean isExpandNextLevel = parentNode != null && (parentNode.getType().equals(NodeType.USER_TABLE) || parentNode.getType().equals(NodeType.SERVER)) && expandedElements == null;
            if (isExpandNextLevel) {
                expandToNextLevel(children);
            } else {
                for (int i = 0; children != null && i < children.length; i++) {
                    if ((children[i] instanceof ICubridNode)) {
                        ICubridNode node = (ICubridNode) children[i];
                        for (int j = 0; expandedElements != null && j < expandedElements.length; j++) {
                            if (expandedElements[j] instanceof ICubridNode && node.getId().equals(((ICubridNode) expandedElements[j]).getId())) {
                                treeViewer.expandToLevel(children[i], 1);
                            }
                        }
                    }
                }
            }
            // set user/table folder node label, add children count
            if (hasChildCount(parentNode)) {
                int count = 0;
                if (parentNode.getType().equals(NodeType.TABLE_FOLDER)) {
                    count = 0;
                    for (ICubridNode tableNode : parentNode.getChildren()) {
                        if (tableNode.getType().equals(NodeType.USER_TABLE) || tableNode.getType().equals(NodeType.USER_PARTITIONED_TABLE_FOLDER)) {
                            count++;
                        }
                    }
                } else if (parentNode.getType().equals(NodeType.VIEW_FOLDER)) {
                    for (ICubridNode viewNode : parentNode.getChildren()) {
                        if (viewNode.getType().equals(NodeType.USER_VIEW)) {
                            count++;
                        }
                    }
                } else {
                    count = parentNode.getChildren().size();
                }
                String suffix = "(" + Integer.valueOf(count) + ")";
                String beforeLable = parentNode.getLabel();
                if (beforeLable.endsWith(")") && beforeLable.indexOf("(") > -1) {
                    String beforeCount = beforeLable.substring(beforeLable.indexOf("(") + 1, beforeLable.length() - 1);
                    // if children count not change, do not update label
                    if (String.valueOf(count).equals(beforeCount)) {
                        return Status.OK_STATUS;
                    }
                    beforeLable = beforeLable.substring(0, beforeLable.indexOf("("));
                }
                parentNode.setLabel(beforeLable + suffix);
                treeViewer.refresh(parentNode, true);
            }
            return Status.OK_STATUS;
        }
    };
    updateJob.setSystem(true);
    updateJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 39 with ICubridNode

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

the class CubridDeferredTreeContentManager method expandToNextLevel.

/**
	 * Expand to next level
	 * 
	 * @param children Object[]
	 */
private void expandToNextLevel(final Object[] children) {
    for (int i = 0; children != null && i < children.length; i++) {
        ICubridNode node = null;
        if (children[i] instanceof ICubridNode) {
            node = (ICubridNode) children[i];
        }
        if (node != null && node.getType().equals(NodeType.TABLE_INDEX_FOLDER)) {
            continue;
        }
        treeViewer.expandToLevel(children[i], 1);
    }
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 40 with ICubridNode

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

the class GroupSettingDialog method refreshDefaultNode.

/**
	 * Refresh the default node's children.
	 * 
	 */
private void refreshDefaultNode() {
    java.util.List<ICubridNode> nodeWithParent = new ArrayList<ICubridNode>();
    CubridGroupNode defaultGrp = null;
    for (CubridGroupNode grp : groups) {
        if (nodeManager.isDefaultGroup(grp)) {
            defaultGrp = grp;
        } else {
            nodeWithParent.addAll(grp.getChildren());
        }
    }
    if (defaultGrp == null) {
        LOGGER.warn("The defaultGrp is a null.");
        return;
    }
    defaultGrp.removeAllChild();
    java.util.List<ICubridNode> allItems = nodeManager.getAllGroupItems();
    for (ICubridNode item : allItems) {
        if (nodeWithParent.indexOf(item) < 0) {
            defaultGrp.addChild(item);
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Aggregations

ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)362 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)67 ArrayList (java.util.ArrayList)67 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)62 TreeViewer (org.eclipse.jface.viewers.TreeViewer)62 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)55 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)55 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)41 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)40 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)33 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)32 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)31 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)27 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)26 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)25 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)25 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)25 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)25 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)23 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)22