Java Code Examples for org.eclipse.swt.widgets.Tree.getItem()

The following are Jave code examples for showing how to use getItem() of the org.eclipse.swt.widgets.Tree class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: n4js   File: TestResultsView.java   Source Code and License Vote up 6 votes
@Override
protected boolean shouldCreateToolTip(final Event e) {
	this.lastDescriptor = null;
	if (e.widget instanceof Tree) {
		final Tree tree = (Tree) e.widget;
		final TreeItem item = tree.getItem(new Point(e.x, e.y));

		if (null != item && item.getData() instanceof ResultNode) {
			final ResultNode node = (ResultNode) item.getData();
			if (node.getElement() instanceof TestCase) {
				final URI uri = ((TestCase) node.getElement()).getURI();
				if (null != uri) {
					final StyledTextDescriptor descriptor = getDescriptor(uri);
					if (null != descriptor) {
						this.lastDescriptor = descriptor;
					}
				}
			}
		}
	}

	return null != this.lastDescriptor;
}
 
Example 2
Project: triquetrum   File: PaletteTreeViewer.java   Source Code and License Vote up 6 votes
/**
 * @see org.eclipse.gef.EditPartViewer#findObjectAtExcluding(Point, Collection, EditPartViewer.Conditional)
 */
@Override
public EditPart findObjectAtExcluding(Point pt, Collection exclude, Conditional condition) {
  if (getControl() == null)
    return null;

  final Tree tree = getTreeControl();
  Rectangle area = tree.getClientArea();
  if (pt.x < area.x || pt.y < area.y || pt.x >= area.x + area.width || pt.y >= area.y + area.height)
    return null;

  EditPart result = null;
  TreeItem tie = tree.getItem(new org.eclipse.swt.graphics.Point(pt.x, pt.y));

  if (tie != null) {
    result = (EditPart) tie.getData();
  } else if (tree.getData() instanceof EditPart) {
    result = (EditPart) tree.getData();
  }
  while (result != null) {
    if ((condition == null || condition.evaluate(result)) && !exclude.contains(result))
      return result;
    result = result.getParent();
  }
  return null;
}
 
Example 3
Project: typescript.java   File: AbstractInformationControl.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse up action for the tree viewer
 * 
 * @param tree
 *            current tree
 * @param e
 *            mouse event
 */
private void handleTreeViewerMouseUp(final Tree tree, MouseEvent e) {
	// Ensure a selection was made, the first mouse button was
	// used and the event happened in the tree
	if ((tree.getSelectionCount() < 1) || (e.button != 1) || !tree.equals(e.getSource())) {
		return;
	}
	// Selection is made in the selection changed listener
	Object object = tree.getItem(new Point(e.x, e.y));
	TreeItem selection = tree.getSelection()[0];
	if (selection.equals(object)) {
		gotoSelectedElement();
	}
}
 
Example 4
Project: hssd   File: MultiDiffView.java   Source Code and License Vote up 5 votes
private Object[] locateEntryValue(int x, int y) {
    final MultiDiffInput input = (MultiDiffInput)viewer.getInput();
    if(input == null) {
        return null;
    }

    final Tree tree = (Tree)viewer.getControl();
    final Point p = new Point(x, y);
    final TreeItem item = tree.getItem(p);
    if(item == null) {
        return null;
    }

    int columnIndex = -1;
    int numCols = tree.getColumnCount();
    for(int i = 0; i < numCols; ++i) {
        Rectangle rect = item.getBounds(i);
        if(rect.contains(p)) {
            columnIndex = i;
            break;
        }
    }
    
    if(columnIndex <= 0) {
        return null;
    }

    TreeNode en = input.entries.get(columnIndex - 1);
    TreeNodeLike vn = (TreeNodeLike)item.getData();

    EntryData ed = EntryData.of(en);
    vn = ed.valueTree().find(vn.path()).get();

    return new Object[]{en, vn};
}
 
Example 5
Project: PDFReporter-Studio   File: JSSTemplateTransferDropTargetListener.java   Source Code and License Vote up 4 votes
/**
 * Check if the user is dragging a detail band to move it before or after another detail band. In this case it return
 * the command to do this operation, otherwise null
 * 
 * @return command to move the detail band or null if the user is not moving the band
 */
private JSSCompoundCommand dropDetailBands() {
	DropTargetEvent cEvent = getCurrentEvent();
	if (cEvent.detail != DND.DROP_MOVE)
		return null;
	if (cEvent.item == null || !(cEvent.item instanceof TreeItem))
		return null;
	
	//Get the list of element from the event or from the selection (as fallback)
	List<?> selectedItems = null;
	if (cEvent.data != null){
		if (cEvent.data instanceof List) {
			selectedItems = (List<?>) cEvent.data;
		} else {
			//I'm dragging something that it isn't a list, probably an element from the 
			//outline, so it isn't a drag band command
			return null;
		}
	} else {
		selectedItems = getViewer().getSelectedEditParts();
	}
	 
	List<MBand> movedBands = new ArrayList<MBand>();
	BandTypeEnum moveType = ReorderBandCommandBySibling.getMoveType(selectedItems, movedBands);
	if (moveType == null) return null;
	
	//Calculate the two element between the dragged element is moved
	Tree tree = ((TreeItem) cEvent.item).getParent();
	Point pt = tree.getDisplay().map(null, tree, cEvent.x, cEvent.y);
	TreeItem firstItem = tree.getItem(new Point(pt.x, pt.y-5));
	TreeItem secondItem = tree.getItem(new Point(pt.x, pt.y+5));

	if (firstItem == null || !(firstItem.getData() instanceof NotDragableContainerTreeEditPart))
		return null;
	if (secondItem == null || !(secondItem.getData() instanceof NotDragableContainerTreeEditPart))
		return null;
	Object model1 = ((NotDragableContainerTreeEditPart) firstItem.getData()).getModel();
	Object model2 = ((NotDragableContainerTreeEditPart) secondItem.getData()).getModel();
	MBand band1 = null;
	MBand band2 = null;
	if (model1 instanceof MBand){
		band1 = (MBand) model1;
	} 
	if (model2 instanceof MBand){
		band2 = (MBand) model2;
	}
	//One of the two element must be a band, otherwise the drag can't be done
	if (band1 == null || band2 == null) return null;
	JRBand targetNode = null;
	if (band1.getBandType().equals(moveType)) targetNode = band1.getValue();
	else if (!band2.getBandType().equals(moveType)) return null; //the destination bands are both different from the dragged band
	
	return ReorderBandCommandBySibling.moveBandsCommand(movedBands, targetNode, ((NotDragableContainerTreeEditPart) firstItem.getData()).getParent());
}
 
Example 6
Project: mytourbook   File: ProfileDropAdapter.java   Source Code and License Vote up 4 votes
private boolean reorderMapProvider(final TVIMapProvider droppedMP) {

		final Tree mpTree = fMpViewer.getTree();
		final TVIMapProviderRoot rootItem = fDialogMPProfile.getRootItem();

		// remove drop item before it is inserted
		fMpViewer.remove(droppedMP);

		int itemIndex;

		if (fTargetTreeItem == null) {

			// a tree item is not hovered

			fMpViewer.add(rootItem, droppedMP);
			itemIndex = mpTree.getItemCount() - 1;

		} else {

			// get index of the target in the table
			itemIndex = mpTree.indexOf((TreeItem) fTargetTreeItem);
			if (itemIndex == -1) {
				return false;
			}

			// insert into the tree
			final int location = getCurrentLocation();
			if (location == LOCATION_BEFORE) {
				fMpViewer.insert(rootItem, droppedMP, itemIndex);
			} else if (location == LOCATION_AFTER) {
				fMpViewer.insert(rootItem, droppedMP, ++itemIndex);
			}
		}

		// reselect filter item
		fMpViewer.setSelection(new StructuredSelection(droppedMP));

		// set focus and selection
		final TreeItem droppedTreeItem = mpTree.getItem(itemIndex);

		mpTree.select(droppedTreeItem);
		mpTree.setFocus();

		fDialogMPProfile.updateLiveView();

		return true;
	}
 
Example 7
Project: mytourbook   File: ProfileDropAdapter.java   Source Code and License Vote up 4 votes
private boolean reorderMapProvider(final TVIMapProvider droppedMP) {

		final Tree mpTree = fMpViewer.getTree();
		final TVIMapProviderRoot rootItem = fDialogMPProfile.getRootItem();

		// remove drop item before it is inserted
		fMpViewer.remove(droppedMP);

		int itemIndex;

		if (fTargetTreeItem == null) {

			// a tree item is not hovered

			fMpViewer.add(rootItem, droppedMP);
			itemIndex = mpTree.getItemCount() - 1;

		} else {

			// get index of the target in the table
			itemIndex = mpTree.indexOf((TreeItem) fTargetTreeItem);
			if (itemIndex == -1) {
				return false;
			}

			// insert into the tree
			final int location = getCurrentLocation();
			if (location == LOCATION_BEFORE) {
				fMpViewer.insert(rootItem, droppedMP, itemIndex);
			} else if (location == LOCATION_AFTER) {
				fMpViewer.insert(rootItem, droppedMP, ++itemIndex);
			}
		}

		// reselect filter item
		fMpViewer.setSelection(new StructuredSelection(droppedMP));

		// set focus and selection
		final TreeItem droppedTreeItem = mpTree.getItem(itemIndex);

		mpTree.select(droppedTreeItem);
		mpTree.setFocus();

		fDialogMPProfile.updateLiveView();

		return true;
	}