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

The following examples show how to use org.eclipse.jface.viewers.StructuredSelection#toList() . 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: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Returns the current selection.
 *
 * @return the current selection
 */
protected StructuredSelection getSelectedItems() {

	StructuredSelection selection = (StructuredSelection) list
			.getSelection();

	List selectedItems = selection.toList();
	Object itemToRemove = null;

	for (Iterator it = selection.iterator(); it.hasNext();) {
		Object item = it.next();
		if (item instanceof ItemsListSeparator) {
			itemToRemove = item;
			break;
		}
	}

	if (itemToRemove == null)
		return new StructuredSelection(selectedItems);
	// Create a new selection without the collision
	List newItems = new ArrayList(selectedItems);
	newItems.remove(itemToRemove);
	return new StructuredSelection(newItems);

}
 
Example 2
Source File: TreeNodeFilteredItemsSelectionDialog.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void handleSelected(StructuredSelection selection) {
	String nameTextStr = "";
	for (Object o : selection.toList()) {
		int counter = 1;
		String name = o.toString().toLowerCase();
		while (currentChildren.contains(name)) {
			name += "_" + counter;
		}

		nameTextStr += name + " ; ";
	}
	nameTextStr = nameTextStr.substring(0, nameTextStr.length() - 2);
	nameText.setText(nameTextStr);
	currentNameText = nameTextStr;

	super.handleSelected(selection);
	return;
}
 
Example 3
Source File: MakrosComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(){
	StructuredSelection selection = (StructuredSelection) viewer.getSelection();
	if(selection  != null && !selection.isEmpty()) {
		if (MessageDialog.openConfirm(getShell(), "Makros löschen",
			"Möchten Sie die Makros wirklich löschen?")) {
			for (Object obj : selection.toList()) {
				if (obj instanceof MakroDTO) {
					MakroDetailComposite.removeMakro((MakroDTO) obj);
				}
			}
			if (viewer != null) {
				viewer.setInput(getUserMakros(CoreHub.getLoggedInContact()));
			}
		}
	}
}
 
Example 4
Source File: MakrosComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(){
	StructuredSelection selection = (StructuredSelection) viewer.getSelection();
	if (selection != null && !selection.isEmpty()) {
		for (Object obj : selection.toList()) {
			if (obj instanceof MakroDTO) {
				MakroDTO makro = (MakroDTO) obj;
				if (copyExists(makro)) {
					if (MessageDialog.openConfirm(getShell(), "Makro kopieren",
						"Das Makro " + makro.getMakroName() + " existiert bei "
							+ user.getLabel()
							+ " bereits. Wollen Sie das Makro überschreiben?")) {
						copy(makro);
					}
				} else {
					copy(makro);
				}
			}
		}
	}
}
 
Example 5
Source File: DragAndDropSupport.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void dragSetData(DragSourceEvent event){
	// we know that we use the RowSelectionModel with single selection
	StructuredSelection selection = (StructuredSelection) tableWrapper.getSelection();
	
	if (!selection.isEmpty()) {
		this.draggedObjects = new ArrayList<>(selection.toList());
		StringBuilder builder = new StringBuilder();
		for (Object object : draggedObjects) {
			if(builder.length() > 0) {
				builder.append(DATA_SEPARATOR);
			}
			builder.append(getStringForObject(object));
		}
		event.data = builder.toString();
	}
}
 
Example 6
Source File: GraphicalEditorWithFlyoutPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private List getModelList( ISelection selection )
{
	List list = new ArrayList( );
	if ( selection == null )
		return list;
	if ( !( selection instanceof StructuredSelection ) )
		return list;

	StructuredSelection structured = (StructuredSelection) selection;
	if ( structured.getFirstElement( ) instanceof ReportElementEditPart )
	{
		boolean bool = false;
		for ( Iterator it = structured.iterator( ); it.hasNext( ); )
		{
			ReportElementEditPart object = (ReportElementEditPart) it.next( );
			if ( object instanceof DummyEditpart )
			{
				list.add( object.getModel( ) );
				bool = true;
			}
			if ( !bool )
			{
				list.add( object.getModel( ) );
			}
		}
	}
	else
	{
		list = structured.toList( );
	}
	return list;
}
 
Example 7
Source File: AttributeViewPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parse out the DE models for all kinds of input source.
 * 
 * @param selection
 *            the current selection.
 * @return
 */
protected List getModelList( ISelection selection )
{
	List list = new ArrayList( );
	if ( selection == null )
		return list;
	if ( !( selection instanceof StructuredSelection ) )
		return list;

	StructuredSelection structured = (StructuredSelection) selection;
	if ( structured.getFirstElement( ) instanceof ReportElementEditPart )
	{
		boolean bool = false;
		for ( Iterator it = structured.iterator( ); it.hasNext( ); )
		{
			ReportElementEditPart object = (ReportElementEditPart) it.next( );
			if ( object instanceof DummyEditpart )
			{
				list.add( object.getModel( ) );
				bool = true;
			}
			if ( !bool )
			{
				list.add( object.getModel( ) );
			}
		}
	}
	else
	{
		list = structured.toList( );
	}
	return list;
}
 
Example 8
Source File: AbortLocalDocumentHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	
	IEclipseContext iEclipseContext =
		PlatformUI.getWorkbench().getService(IEclipseContext.class);
	StructuredSelection selection = (StructuredSelection) iEclipseContext
		.get(event.getCommand().getId().concat(".selection"));
	iEclipseContext.remove(event.getCommand().getId().concat(".selection"));
	if (selection != null && !selection.isEmpty()) {
		List<?> selected = selection.toList();
		Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		for (Object object : selected) {
			LocalDocumentServiceHolder.getService().ifPresent(service -> {
				if (service.contains(object)) {
					Optional<LocalLock> lock = LocalLock.getManagedLock(object);
					lock.ifPresent(localDocumentLock -> localDocumentLock.unlock());
					
					service.remove(object);
				} else {
					MessageDialog.openInformation(parentShell,
						Messages.AbortLocalDocumentHandler_infotitle,
						Messages.AbortLocalDocumentHandler_infomessage);
				}
			});
		}
	}
	return null;
}
 
Example 9
Source File: ReminderDetailDialog.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void performOk(){
	String due = null;
	if (btnHasDueDate.getSelection()) {
		due = dateDue.toString(TimeTool.DATE_GER);
	}
	if (reminder == null) {
		reminder = new Reminder(null, due, Visibility.ALWAYS, "", "");
	}
	
	String contactId =
		(btnNotPatientRelated.getSelection()) ? reminder.getCreator().getId() : patient.getId();
	Visibility visibility = rvapc.getConfiguredVisibility();
	
	String[] fields = new String[] {
		Reminder.FLD_SUBJECT, Reminder.FLD_MESSAGE, Reminder.FLD_PRIORITY, Reminder.FLD_STATUS,
		Reminder.FLD_KONTAKT_ID, Reminder.FLD_VISIBILITY, Reminder.FLD_DUE, Reminder.FLD_ACTION_TYPE
	};
	reminder.set(fields, txtSubject.getText(), txtDescription.getText(),
		Integer.toString(priority.numericValue()),
		Integer.toString(processStatus.numericValue()), contactId,
		Integer.toString(visibility.numericValue()), due,
		Integer.toString(actionType.numericValue()));
	
	StructuredSelection ss = (StructuredSelection) lvResponsible.getSelection();
	@SuppressWarnings("unchecked")
	List<Object> selectionList = ss.toList();
	if (selectionList.contains(TX_ALL)) {
		reminder.setResponsible(null);
	} else {
		reminder.setResponsible(
			selectionList.stream().map(e -> (Anwender) e).collect(Collectors.toList()));
	}
	
	super.okPressed();
}
 
Example 10
Source File: AbstractExportHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
	config = new ExportConfig();
	Shell shell = HandlerUtil.getActiveShell(event);
	String partId = HandlerUtil.getActivePartId(event);

	if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {// 导航视图处于激活状态
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
		StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider()
				.getSelection();
		if (selection != null && !selection.isEmpty()) {
			for (Object obj : selection.toList()) {
				if (obj instanceof IFile) {
					addXLFFile((IFile) obj);
				} else if (obj instanceof IFolder) {
					traversalFile((IFolder) obj);
				} else if (obj instanceof IProject) {
					IProject proj = (IProject) obj;
					traversalFile(proj.getFolder(XLF));
				}
			}
			if (config.getProjects() == null || config.getProjects().size() < 1) {
				MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
						Messages.getString("xlf2tmx.info.notfoundxlf"));
				return false;
			}
		}
	} else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {// nattable 处于激活状态
		IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
		IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
		IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		IXliffEditor xliffEditor = (IXliffEditor) editor;

		if (xliffEditor.isMultiFile()) {
			MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"),
					Messages.getString("ExportDocxHandler.msg2"));
			return false;
		} else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
			addXLFFile(iFile);
		}
	}

	return true;
}
 
Example 11
Source File: ReportPropertySheetPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param selection
 * @return
 */
private List<Object> getModelList( ISelection selection )
{
	List<Object> list = new ArrayList<Object>( );
	if ( selection == null )
		return list;
	if ( !( selection instanceof StructuredSelection ) )
		return list;

	StructuredSelection structured = (StructuredSelection) selection;
	if ( structured.getFirstElement( ) instanceof ReportElementEditPart )
	{
		for ( Iterator it = structured.iterator( ); it.hasNext( ); )
		{
			ReportElementEditPart object = (ReportElementEditPart) it.next( );
			if ( object instanceof DummyEditpart )
			{
				list.clear( );
				list.add( object.getModel( ) );
				break;
			}
			list.add( object.getModel( ) );

		}
	}
	else
	{
		list = structured.toList( );
		if ( list != null && list.size( ) > 0 )
		{
			List<Object> modelList = new ArrayList<Object>( );
			for ( int i = 0; i < list.size( ); i++ )
			{
				Object obj = list.get( i );
				if ( obj instanceof IAdaptable )
				{
					Object realModel = ( (IAdaptable) obj ).getAdapter( DesignElementHandle.class );
					if ( realModel != null )
						modelList.add( realModel );
					else
						modelList.add( obj );
				}
				else
					modelList.add( obj );
			}

			list = modelList;
		}
	}
	return list;
}
 
Example 12
Source File: EndLocalDocumentHandler.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	IEclipseContext iEclipseContext =
		PlatformUI.getWorkbench().getService(IEclipseContext.class);
	StructuredSelection selection =
		(StructuredSelection) iEclipseContext
			.get(event.getCommand().getId().concat(".selection"));
	iEclipseContext.remove(event.getCommand().getId().concat(".selection"));
	if (selection != null && !selection.isEmpty()) {
		List<?> selected = selection.toList();
		Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		for (Object object : selected) {
			LocalDocumentServiceHolder.getService().ifPresent(service -> {
				if (service.contains(object)) {
					Optional<LocalLock> lock = LocalLock.getManagedLock(object);
					lock.ifPresent(localDocumentLock -> localDocumentLock.unlock());
					
					if (!service.save(object)) {
						MessageDialog.openError(parentShell,
							Messages.EndLocalDocumentHandler_errorttitle,
							Messages.EndLocalDocumentHandler_errormessage);
					}
					
					service.remove(object, new IConflictHandler() {
						@Override
						public Result getResult(){
							if (MessageDialog.openQuestion(parentShell,
								Messages.EndLocalDocumentHandler_conflicttitle,
								Messages.EndLocalDocumentHandler_conflictmessage)) {
								return Result.OVERWRITE;
							} else {
								return Result.ABORT;
							}
						}
					});
				} else {
					MessageDialog.openInformation(parentShell,
						Messages.EndLocalDocumentHandler_infotitle,
						Messages.EndLocalDocumentHandler_infomessage);
				}
			});
		}
	}
	return null;
}