Java Code Examples for org.eclipse.jface.viewers.StructuredSelection#toArray()

The following examples show how to use org.eclipse.jface.viewers.StructuredSelection#toArray() . 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: ZestContentViewer.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setSelection(ISelection selection, boolean reveal) {
	if (selection.isEmpty()) {
		getSelectionModel().clearSelection();
	} else if (selection instanceof StructuredSelection) {
		StructuredSelection structuredSelection = (StructuredSelection) selection;
		if (!structuredSelection.isEmpty()) {
			List<IContentPart<? extends javafx.scene.Node>> toBeSelectedParts = new ArrayList<>();
			for (Object toBeSelectedContent : structuredSelection.toArray()) {
				IContentPart<? extends javafx.scene.Node> toBeSelectedPart = viewer.getContentPartMap()
						.get(toBeSelectedContent);
				if (toBeSelectedPart != null) {
					toBeSelectedParts.add(toBeSelectedPart);
					if (reveal) {
						// TODO: we need to reveal all in a single step
						viewer.reveal(toBeSelectedPart);
					}
				} else {
					throw new IllegalArgumentException(
							toBeSelectedContent + " is not visualized by a content part of this viewer.");
				}
			}
			getSelectionModel().prependToSelection(toBeSelectedParts);
		}
	} else {
		throw new IllegalArgumentException(
				"A non-empty selection of unsupported type '" + selection.getClass() + "' was passed in.");
	}
}
 
Example 2
Source File: WebAppHostPageSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void handleSelected(StructuredSelection selection) {
  super.handleSelected(selection);
  Object[] objs = selection.toArray();
  if (objs.length == 1) {
    if (objs[0] instanceof IFile) {
      currentSelection = (IFile) objs[0];
    } else {
      currentSelection = null;
    }
  } else {
    currentSelection = null;
  }
  updateUrlLabelText();
}
 
Example 3
Source File: GlobalEventDispatcher.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void selectionChanged(final SelectionChangedEvent event){
	StructuredSelection sel = (StructuredSelection) event.getSelection();
	
	Object[] obj = sel.toArray();
	if ((obj != null) && (obj.length != 0)) {
		if (obj[0] instanceof PersistentObject) {
			ElexisEventDispatcher.fireSelectionEvent((PersistentObject) obj[0]);
		} else if (obj[0] instanceof Tree) {
			Tree t = (Tree) obj[0];
			if (t.contents instanceof PersistentObject) {
				ElexisEventDispatcher.fireSelectionEvent((PersistentObject) t.contents);
			}
		}
	}
}
 
Example 4
Source File: FindingsSelectionDialog.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void okPressed(){
	selections = new ArrayList<>();
	StructuredSelection structuredSelection = (StructuredSelection) viewer.getSelection();
	for (Object o : structuredSelection.toArray()) {
		if (o instanceof FindingsTemplate) {
			selections.add((FindingsTemplate) o);
		}
	}
	
	super.okPressed();
}