Java Code Examples for org.eclipse.nebula.widgets.grid.GridItem#hasChildren()

The following examples show how to use org.eclipse.nebula.widgets.grid.GridItem#hasChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the sequence of branch lines which should be rendered for the provided item
 * @param item
 * @return an array of integers composed using the constants in {@link BranchRenderer}
 */
private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		} else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	} else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while (item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		} else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 2
Source File: CellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value) {

	GridItem item = (GridItem) value;

	if (isCheck()) {
		if (event == IInternalWidget.MouseMove) {
			if (overCheck(item, point)) {
				setHoverDetail("check");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overCheck(item, point)) {
				if (!item.getCheckable(getColumn())) {
					return false;
				}

				item.setChecked(getColumn(), !item.getChecked(getColumn()));
				item.getParent().redraw();

				item.fireCheckEvent(getColumn());

				return true;
			}
		}
	}

	if (isTree() && item.hasChildren()) {
		if (event == IInternalWidget.MouseMove) {
			if (overToggle(item, point)) {
				setHoverDetail("toggle");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overToggle(item, point)) {
				item.setExpanded(!item.isExpanded());
				item.getParent().redraw();

				if (item.isExpanded()) {
					item.fireEvent(SWT.Expand);
				} else {
					item.fireEvent(SWT.Collapse);
				}

				return true;
			}
		}
	}

	return false;
}
 
Example 3
Source File: TBSearchCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the sequence of branch lines which should be rendered for the provided item
 * @param item
 * @return an array of integers composed using the constants in {@link BranchRenderer}
 */
private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		} else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	} else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while (item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		} else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 4
Source File: TBSearchCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value) {

	GridItem item = (GridItem) value;

	if (isCheck()) {
		if (event == IInternalWidget.MouseMove) {
			if (overCheck(item, point)) {
				setHoverDetail("check");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overCheck(item, point)) {
				if (!item.getCheckable(getColumn())) {
					return false;
				}

				item.setChecked(getColumn(), !item.getChecked(getColumn()));
				item.getParent().redraw();

				item.fireCheckEvent(getColumn());

				return true;
			}
		}
	}

	if (isTree() && item.hasChildren()) {
		if (event == IInternalWidget.MouseMove) {
			if (overToggle(item, point)) {
				setHoverDetail("toggle");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overToggle(item, point)) {
				item.setExpanded(!item.isExpanded());
				item.getParent().redraw();

				if (item.isExpanded()) {
					item.fireEvent(SWT.Expand);
				} else {
					item.fireEvent(SWT.Collapse);
				}

				return true;
			}
		}
	}

	return false;
}
 
Example 5
Source File: DefaultCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Calculates the sequence of branch lines which should be rendered for the provided item
    * @param item
    * @return an array of integers composed using the constants in {@link BranchRenderer}
    */
   private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length-1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		}
		else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	}
	else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while(item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		}
		else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 6
Source File: DefaultCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value)
{

    GridItem item = (GridItem)value;

    if (isCheck())
    {
        if (event == IInternalWidget.MouseMove)
        {
            if (overCheck(item, point))
            {
                setHoverDetail("check");
                return true;
            }
        }

        if (event == IInternalWidget.LeftMouseButtonDown)
        {
            if (overCheck(item, point))
            {
                if (!item.getCheckable(getColumn()))
                {
                    return false;
                }

                item.setChecked(getColumn(), !item.getChecked(getColumn()));
                item.getParent().redraw();

                item.fireCheckEvent(getColumn());

                return true;
            }
        }
    }

    if (isTree() && item.hasChildren())
    {
        if (event == IInternalWidget.MouseMove)
        {
            if (overToggle(item, point))
            {
                setHoverDetail("toggle");
                return true;
            }
        }

        if (event == IInternalWidget.LeftMouseButtonDown)
        {
            if (overToggle(item, point))
            {
                item.setExpanded(!item.isExpanded());
                item.getParent().redraw();

                if (item.isExpanded())
                {
                    item.fireEvent(SWT.Expand);
                }
                else
                {
                    item.fireEvent(SWT.Collapse);
                }

                return true;
            }
        }
    }

    return false;
}
 
Example 7
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the sequence of branch lines which should be rendered for the provided item
 * @param item
 * @return an array of integers composed using the constants in {@link BranchRenderer}
 */
private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		} else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	} else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while (item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		} else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 8
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value) {

	GridItem item = (GridItem) value;

	if (isCheck()) {
		if (event == IInternalWidget.MouseMove) {
			if (overCheck(item, point)) {
				setHoverDetail("check");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overCheck(item, point)) {
				if (!item.getCheckable(getColumn())) {
					return false;
				}

				item.setChecked(getColumn(), !item.getChecked(getColumn()));
				item.getParent().redraw();

				item.fireCheckEvent(getColumn());

				return true;
			}
		}
	}

	if (isTree() && item.hasChildren()) {
		if (event == IInternalWidget.MouseMove) {
			if (overToggle(item, point)) {
				setHoverDetail("toggle");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overToggle(item, point)) {
				item.setExpanded(!item.isExpanded());
				item.getParent().redraw();

				if (item.isExpanded()) {
					item.fireEvent(SWT.Expand);
				} else {
					item.fireEvent(SWT.Collapse);
				}

				return true;
			}
		}
	}

	return false;
}
 
Example 9
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculates the sequence of branch lines which should be rendered for the provided item
 * @param item
 * @return an array of integers composed using the constants in {@link BranchRenderer}
 */
private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		} else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	} else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while (item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		} else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 10
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value) {

	GridItem item = (GridItem) value;

	if (isCheck()) {
		if (event == IInternalWidget.MouseMove) {
			if (overCheck(item, point)) {
				setHoverDetail("check");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overCheck(item, point)) {
				if (!item.getCheckable(getColumn())) {
					return false;
				}

				item.setChecked(getColumn(), !item.getChecked(getColumn()));
				item.getParent().redraw();

				item.fireCheckEvent(getColumn());

				return true;
			}
		}
	}

	if (isTree() && item.hasChildren()) {
		if (event == IInternalWidget.MouseMove) {
			if (overToggle(item, point)) {
				setHoverDetail("toggle");
				return true;
			}
		}

		if (event == IInternalWidget.LeftMouseButtonDown) {
			if (overToggle(item, point)) {
				item.setExpanded(!item.isExpanded());
				item.getParent().redraw();

				if (item.isExpanded()) {
					item.fireEvent(SWT.Expand);
				} else {
					item.fireEvent(SWT.Collapse);
				}

				return true;
			}
		}
	}

	return false;
}
 
Example 11
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Calculates the sequence of branch lines which should be rendered for the provided item
    * @param item
    * @return an array of integers composed using the constants in {@link BranchRenderer}
    */
   private int[] getBranches(GridItem item) {
	int[] branches = new int[item.getLevel() + 1];
	GridItem[] roots = item.getParent().getRootItems();

	// Is this a node or a leaf?
	if (item.getParentItem() == null) {
		// Add descender if not last item
		if (!item.isExpanded() && roots[roots.length-1].equals(item)) {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_L;
		}
		else {
			if (item.hasChildren())
				branches[item.getLevel()] = BranchRenderer.ROOT;
			else
				branches[item.getLevel()] = BranchRenderer.SMALL_T;
		}

	}
	else if (item.hasChildren())
		if (item.isExpanded())
			branches[item.getLevel()] = BranchRenderer.NODE;
		else
			branches[item.getLevel()] = BranchRenderer.NONE;
	else
		branches[item.getLevel()] = BranchRenderer.LEAF;

	// Branch for current item
	GridItem parent = item.getParentItem();
	if (parent == null)
		return branches;

	// Are there siblings below this item?
	if (parent.indexOf(item) < parent.getItemCount() - 1)
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// Is the next node a root?
	else if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
		branches[item.getLevel() - 1] = BranchRenderer.T;

	// This must be the last element at this level
	else
		branches[item.getLevel() - 1] = BranchRenderer.L;

	Grid grid = item.getParent();
	item = parent;
	parent = item.getParentItem();

	// Branches for parent items
	while(item.getLevel() > 0) {
		if (parent.indexOf(item) == parent.getItemCount() - 1) {
			if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
				branches[item.getLevel() - 1] = BranchRenderer.I;
			else
				branches[item.getLevel() - 1] = BranchRenderer.NONE;
		}
		else
			branches[item.getLevel() - 1] = BranchRenderer.I;
		item = parent;
		parent = item.getParentItem();
	}
	// item should be null at this point
	return branches;
}
 
Example 12
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean notify(int event, Point point, Object value)
{

    GridItem item = (GridItem)value;

    if (isCheck())
    {
        if (event == IInternalWidget.MouseMove)
        {
            if (overCheck(item, point))
            {
                setHoverDetail("check");
                return true;
            }
        }

        if (event == IInternalWidget.LeftMouseButtonDown)
        {
            if (overCheck(item, point))
            {
                if (!item.getCheckable(getColumn()))
                {
                    return false;
                }

                item.setChecked(getColumn(), !item.getChecked(getColumn()));
                item.getParent().redraw();

                item.fireCheckEvent(getColumn());

                return true;
            }
        }
    }

    if (isTree() && item.hasChildren())
    {
        if (event == IInternalWidget.MouseMove)
        {
            if (overToggle(item, point))
            {
                setHoverDetail("toggle");
                return true;
            }
        }

        if (event == IInternalWidget.LeftMouseButtonDown)
        {
            if (overToggle(item, point))
            {
                item.setExpanded(!item.isExpanded());
                item.getParent().redraw();

                if (item.isExpanded())
                {
                    item.fireEvent(SWT.Expand);
                }
                else
                {
                    item.fireEvent(SWT.Collapse);
                }

                return true;
            }
        }
    }

    return false;
}