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

The following examples show how to use org.eclipse.nebula.widgets.grid.GridItem#getItemCount() . 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: 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 3
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 4
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 5
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 6
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;
}