Java Code Examples for org.eclipse.jface.viewers.StructuredViewer#getSelection()

The following examples show how to use org.eclipse.jface.viewers.StructuredViewer#getSelection() . 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: InvoiceActions.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private List<Rechnung> getInvoiceSelections(StructuredViewer viewer){
	IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
	List<Rechnung> ret = new ArrayList<>();
	if (sel != null) {
		Object[] array = sel.toArray();
		for (Object object : array) {
			if (object instanceof Rechnung) {
				ret.add((Rechnung) object);
			} else if (object instanceof InvoiceEntry) {
				String invoiceId = ((InvoiceEntry) object).getInvoiceId();
				ret.add(Rechnung.load(invoiceId));
			}
		}
		return ret;
	}
	return Collections.emptyList();
	
}
 
Example 2
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * Returns the current selection.
   * @return selection
   */
  protected ISelection getSelection() {
  	StructuredViewer viewerInFocus= fSelectionProviderMediator.getViewerInFocus();
if (viewerInFocus != null) {
	return viewerInFocus.getSelection();
}
return StructuredSelection.EMPTY;
  }
 
Example 3
Source File: PackagesView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void switchViewer(int state) {
	//Indicate which viewer is to be used
	if (fCurrViewState == state)
		return;
	else {
		fCurrViewState= state;
		IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
		store.setValue(getViewSite().getId() + TAG_VIEW_STATE, state);
	}

	//get the information from the existing viewer
	StructuredViewer viewer= fWrappedViewer.getViewer();
	Object object= viewer.getInput();
	ISelection selection= viewer.getSelection();

	// create and set up the new viewer
	Control control= createViewer(fWrappedViewer.getControl().getParent()).getControl();

	setUpViewer(fWrappedViewer);

	createSelectAllAction();

	// add the selection information from old viewer
	fWrappedViewer.setViewerInput(object);
	fWrappedViewer.getControl().setFocus();
	fWrappedViewer.setSelection(selection, true);

	// dispose old viewer
	viewer.getContentProvider().dispose();
	viewer.getControl().dispose();

	// layout the new viewer
	if (control != null && !control.isDisposed()) {
		control.setVisible(true);
		control.getParent().layout(true);
	}
}
 
Example 4
Source File: PersistentObjectDragSource.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public PersistentObjectDragSource(final StructuredViewer v){
	dragSource = v.getControl();
	renderer = new ISelectionRenderer() {
		
		public List<PersistentObject> getSelection(){
			IStructuredSelection sel = (IStructuredSelection) v.getSelection();
			return sel.toList();
		}
		
	};
	setup();
}
 
Example 5
Source File: GenericImporterBlatt.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private Field getViewerSelection(StructuredViewer viewer){
	IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
	Object obj = sel.getFirstElement();
	if (obj instanceof Field) {
		return (Field) obj;
	}
	
	return null;
}
 
Example 6
Source File: Viewers.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/** Get the first selected element from the given viewer. */
public static <T> T getFirstSelected(StructuredViewer viewer) {
	if (viewer == null)
		return null;
	ISelection selection = viewer.getSelection();
	return getFirst(selection);
}
 
Example 7
Source File: Viewers.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/** Get all selected elements from the given viewer. */
public static <T> List<T> getAllSelected(StructuredViewer viewer) {
	if (viewer == null)
		return Collections.emptyList();
	IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
	return getAll(s);
}