Search in sources :

Example 61 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project MonjaDB by Kanatoko.

the class MDocumentEditor method drawItem.

//--------------------------------------------------------------------------------
private void drawItem(String parentFieldName, TreeItem parentItem, List data, boolean expand) {
    for (int i = 0; i < data.size(); ++i) {
        TreeItem newItem = new TreeItem(parentItem, SWT.NONE);
        Object value = data.get(i);
        newItem.setText(1, getClassName(value));
        String fieldName = parentFieldName + "." + i;
        if (fieldName.startsWith(".")) {
            fieldName = fieldName.substring(1);
        }
        newItem.setData("fieldName", fieldName);
        newItem.setData("value", value);
        fieldNameTreeItemMap.put(fieldName, newItem);
        if (value instanceof Map) {
            newItem.setText("[" + i + "]");
            newItem.setImage(mapImage);
            drawItem(fieldName, newItem, (Map) value, expand);
        } else if (value instanceof List) {
            newItem.setText("[" + i + "]");
            newItem.setImage(listImage);
            drawItem(fieldName, newItem, (List) value, expand);
        } else {
            setItemInfo(newItem, "[" + i + "]", value);
        }
        if (expand) {
            parentItem.setExpanded(expand);
            newItem.setExpanded(expand);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 62 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project MonjaDB by Kanatoko.

the class MDocumentEditor method onEditField.

//--------------------------------------------------------------------------------
private void onEditField(final MEditFieldAction action) {
    MSystemUtil.sleep(100);
    final String fieldName = action.getFieldName();
    editingFieldName = fieldName;
    final TreeItem item = (TreeItem) fieldNameTreeItemMap.get(fieldName);
    if (item == null) {
        debug("item not found");
        //debug( fieldNameTreeItemMap );
        return;
    }
    //Object document = dataManager.getLastEditedDocument();
    final MDocumentEditor view = this;
    shell.getDisplay().asyncExec(new Runnable() {

        public void run() {
            if (action.getOriginView() != view) {
                tree.select(item);
            }
            if (fieldName.equals("_id")) {
                valueText.setEditable(false);
                valueText.setEnabled(true);
                typeCombo.setEnabled(false);
                nameText.setText(fieldName);
                editingData = item.getData("value");
                {
                    if (editingData.getClass() == Double.class) {
                        valueText.setText((new BigDecimal(((Double) editingData).doubleValue())).toString());
                    } else {
                        valueText.setText(editingData.toString());
                    }
                }
                typeCombo.select(((Integer) typeComboIndexMap.get(editingData.getClass())).intValue());
                updateButton.setEnabled(false);
            } else {
                valueText.setEditable(true);
                valueText.setEnabled(true);
                typeCombo.setEnabled(true);
                nameText.setText(fieldName);
                editingData = item.getData("value");
                valueText.setText(editingData + "");
                if (editingData == null) {
                    typeCombo.select(11);
                    verifyData();
                } else {
                    typeCombo.select(((Integer) typeComboIndexMap.get(editingData.getClass())).intValue());
                    verifyData();
                }
            }
        }
    });
//********
//valueText.setText( docum )
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) BigDecimal(java.math.BigDecimal)

Example 63 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class QueryPlanComposite method printSubPlanTerm.

/**
	 * print the sub plan term.
	 *
	 * @param treeItem TreeItem
	 * @param term PlanTerm
	 * @param typeName String
	 * @param isOddRow boolean
	 */
private void printSubPlanTerm(TreeItem treeItem, PlanTerm term, String typeName, boolean isOddRow) {
    PlanTermItem[] termItems = term.getTermItems();
    if (termItems == null) {
        return;
    }
    String icon = "icons/queryeditor/qe_explain_table.png";
    int len = termItems.length;
    if (len == 1) {
        TreeItem termTreeItem = new TreeItem(treeItem, SWT.NONE);
        termTreeItem.setText(0, typeName);
        termTreeItem.setImage(0, CommonUIPlugin.getImage(icon));
        termTreeItem.setText(3, term.getTermString());
        if (termItems[0] != null) {
            termTreeItem.setText(7, termItems[0].getAttribute());
        }
    } else {
        PlanTermItem planTermItem = termItems[0];
        if (planTermItem == null || planTermItem.getCondition() == null) {
            return;
        }
        for (int j = 0; j < len; j++) {
            planTermItem = termItems[j];
            if (planTermItem == null || planTermItem.getCondition() == null) {
                continue;
            }
            TreeItem item = new TreeItem(treeItem, SWT.NONE);
            // Type
            item.setText(0, typeName + " " + (j + 1));
            item.setImage(0, CommonUIPlugin.getImage(icon));
            int i = 1;
            // Table
            item.setText(i++, "");
            // Index
            item.setText(i++, "");
            // Terms
            item.setText(i++, planTermItem.getCondition());
            // Cost
            item.setText(i++, "");
            // Card
            item.setText(i++, "");
            // Row/Page
            item.setText(i++, "");
            // Extra informations
            item.setText(i++, planTermItem.getAttribute());
            item.setExpanded(true);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) PlanTermItem(com.cubrid.common.core.queryplan.model.PlanTermItem)

Example 64 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class QueryPlanComposite method printSubPlan.

/**
	 * print the sub plan.
	 *
	 * @param tabItem PlanTabItem
	 * @param treeItem TreeItem
	 * @param node PlanNode
	 * @param sql String
	 */
private TreeItem printSubPlan(TreeItem treeItem, PlanNode node, String sql) {
    boolean isRoot = treeItem == null;
    boolean existChildren = node.getChildren() != null && node.getChildren().size() > 0;
    TreeItem item = null;
    if (isRoot) {
        item = new TreeItem(planTree, SWT.NONE);
        item.setData(sql);
    } else {
        item = new TreeItem(treeItem, SWT.NONE);
        item.setData(sql);
    }
    String icon = null;
    boolean isIndex = node.getIndex() != null;
    boolean isTable = node.getTable() != null && node.getTable().getPartitions() != null;
    if ("idx-join".equals(node.getMethod())) {
        icon = "icons/queryeditor/qe_explain_index_join.png";
    } else if (existChildren) {
        icon = "icons/queryeditor/qe_explain_folder.png";
    } else if (isIndex) {
        icon = "icons/queryeditor/qe_explain_index.png";
    } else if (isTable) {
        icon = "icons/queryeditor/qe_explain_partition.png";
    } else {
        icon = "icons/queryeditor/qe_explain_table.png";
    }
    // Type
    int i = 0;
    item.setImage(i, CommonUIPlugin.getImage(icon));
    if (node.getMethod() != null) {
        item.setText(i++, node.getMethodTitle());
        if (node.getMethod().startsWith("temp") || node.getMethod().startsWith("sscan")) {
            item.setBackground(BG_SSCAN);
        } else if (node.getMethod().startsWith("iscan")) {
            item.setBackground(BG_ISCAN);
        }
    }
    // Table
    if (node.getTable() == null) {
        item.setText(i++, "");
    } else {
        item.setForeground(i, FG_TABLE);
        item.setText(i++, node.getTable().getName());
    }
    // Index
    if (node.getIndex() == null) {
        item.setText(i++, "");
    } else {
        item.setForeground(i, FG_INDEX);
        PlanTerm index = node.getIndex();
        item.setText(i++, index.getName());
    }
    // Terms
    if (node.getTable() == null || node.getTable().getPartitions() == null) {
        item.setText(i++, "");
    } else {
        item.setText(i++, node.getTable().getTextPartitions());
    }
    // Cost
    if (node.getCost() == null) {
        item.setText(i++, "");
        item.setText(i++, "");
    } else {
        PlanCost cost = node.getCost();
        item.setText(i++, String.valueOf(cost.getTotal()));
        if (node.getCost().getCard() < 0) {
            item.setText(i++, "-");
        } else {
            item.setText(i++, String.valueOf(cost.getCard()));
        }
    }
    // Row/Page
    if (node.getTable() == null) {
        item.setText(i++, "");
    } else {
        item.setText(i++, node.getTable().getCard() + "/" + node.getTable().getPage());
    }
    // Extra information
    if (node.getSort() == null) {
        item.setText(i++, "");
    } else {
        item.setText(i++, "(sort " + node.getSort() + ")");
    }
    boolean isOddRow = false;
    if (node.getIndex() != null) {
        PlanTerm subTerm = node.getIndex();
        // It do not make a child node if it is iscan and it has only 1 child.
        if ("iscan".equals(node.getMethod()) && subTerm.hasSingleTerm()) {
            overwritePlanTreeItem(item, subTerm);
        } else {
            printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
        }
    }
    if (node.getEdge() != null) {
        PlanTerm subTerm = node.getEdge();
        // It do not make a child node if it is iscan and it has only 1 child.
        if (("follow".equals(node.getMethod()) || node.getMethod().startsWith("nl-join")) && subTerm.hasSingleTerm()) /*&& "join".equals(subTerm.getName())*/
        {
            overwritePlanTreeItem(item, subTerm);
        } else {
            printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
        }
    }
    if (node.getSargs() != null) {
        PlanTerm subTerm = node.getSargs();
        // It do not make a child node if it is iscan and it has only 1 child.
        if ("sscan".equals(node.getMethod()) && subTerm.hasSingleTerm()) {
            overwritePlanTreeItem(item, subTerm);
        } else {
            printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
        }
    }
    if (node.getFilter() != null) {
        printSubPlanTerm(item, node.getFilter(), node.getFilter().getTypeString(), (isOddRow = !isOddRow));
    }
    item.setExpanded(true);
    if (!isRoot) {
        treeItem.setExpanded(true);
    }
    if (existChildren) {
        for (PlanNode childNode : node.getChildren()) {
            printSubPlan(item, childNode, null);
        }
    }
    return item;
}
Also used : PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) TreeItem(org.eclipse.swt.widgets.TreeItem) PlanCost(com.cubrid.common.core.queryplan.model.PlanCost) PlanTerm(com.cubrid.common.core.queryplan.model.PlanTerm)

Example 65 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project dbeaver by serge-rider.

the class CustomTreeEditor method mouseUp.

@Override
public void mouseUp(MouseEvent e) {
    if (e.button != 1) {
        // Only on left click
        return;
    }
    final TreeItem item = tree.getItem(new Point(e.x, e.y));
    if (item != null) {
        columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                showEditor(item);
            }
        });
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)226 Tree (org.eclipse.swt.widgets.Tree)71 Point (org.eclipse.swt.graphics.Point)56 TreeColumn (org.eclipse.swt.widgets.TreeColumn)30 GridData (org.eclipse.swt.layout.GridData)29 Test (org.junit.Test)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)27 ArrayList (java.util.ArrayList)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 Composite (org.eclipse.swt.widgets.Composite)22 TableItem (org.eclipse.swt.widgets.TableItem)21 Button (org.eclipse.swt.widgets.Button)20 Table (org.eclipse.swt.widgets.Table)20 TreeViewer (org.eclipse.jface.viewers.TreeViewer)19 FillLayout (org.eclipse.swt.layout.FillLayout)19 Label (org.eclipse.swt.widgets.Label)18 Group (org.eclipse.swt.widgets.Group)17 Text (org.eclipse.swt.widgets.Text)17 SelectionListener (org.eclipse.swt.events.SelectionListener)16 Rectangle (org.eclipse.swt.graphics.Rectangle)16