List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:org.eclipse.ant.internal.ui.preferences.AntClasspathContentProvider.java
License:Open Source License
public void remove(IStructuredSelection selection) { Object[] array = selection.toArray(); model.removeAll(array);//from w w w. j av a 2 s . c om treeViewer.remove(array); refresh(); }
From source file:org.eclipse.ant.internal.ui.preferences.AntContentProvider.java
License:Open Source License
/** * Removes the given selection of the listing of elements and from the backing viewer * /* w w w. j ava 2 s .c om*/ * @param selection */ public void remove(IStructuredSelection selection) { Object[] array = selection.toArray(); elements.removeAll(Arrays.asList(array)); tableViewer.remove(array); }
From source file:org.eclipse.babel.build.ui.wizard.FilteredListComponent.java
License:Open Source License
private void handleAdd() { IStructuredSelection ssel = (IStructuredSelection) fAvailableViewer.getSelection(); if (ssel.size() > 0) { Table table = fAvailableViewer.getTable(); int index = table.getSelectionIndices()[0]; Object[] selection = ssel.toArray(); setBlockSelectionListeners(true); setRedraw(false);/*from ww w . jav a 2s .c o m*/ for (int i = 0; i < selection.length; i++) { doAdd(selection[i]); } setRedraw(true); setBlockSelectionListeners(false); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); } }
From source file:org.eclipse.babel.build.ui.wizard.FilteredListComponent.java
License:Open Source License
private void handleRemove() { IStructuredSelection ssel = (IStructuredSelection) fSelectedViewer.getSelection(); if (ssel.size() > 0) { Table table = fSelectedViewer.getTable(); int index = table.getSelectionIndices()[0]; Object[] selection = ssel.toArray(); setBlockSelectionListeners(true); setRedraw(false);//w ww . j a va2 s. c om for (int i = 0; i < selection.length; i++) { doRemove(selection[i]); } setRedraw(true); setBlockSelectionListeners(false); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); } }
From source file:org.eclipse.birt.report.designer.ui.ide.navigator.SetupReportProjectAction.java
License:Open Source License
private Object[] getTargetObjects() { if (navigator != null) { IStructuredSelection selection = (IStructuredSelection) navigator.getViewSite().getSelectionProvider() .getSelection();//from w w w .j av a2s. c om return selection.toArray(); } return null; }
From source file:org.eclipse.bpel.common.ui.tray.AdaptingSelectionProvider.java
License:Open Source License
@Override protected IStructuredSelection calculateSelection(IStructuredSelection selection) { if (selection == null || selection.isEmpty()) { return StructuredSelection.EMPTY; }//ww w . ja v a2s .com List<EObject> list = new ArrayList<EObject>(); Set<EObject> newSet = new HashSet<EObject>(); for (Object model : selection.toArray()) { if (model instanceof EditPart) { model = ((EditPart) model).getModel(); } if (model instanceof EObject) { EObject eObj = (EObject) model; if (newSet.add(eObj)) { list.add(eObj); } } } if (list.isEmpty()) { return StructuredSelection.EMPTY; } return new StructuredSelection(list); }
From source file:org.eclipse.bpel.common.ui.tray.AdaptingSelectionProvider.java
License:Open Source License
/** * Set selection to each of the viewers and make sure we ignore callbacks * /*from ww w . j a v a 2s. com*/ */ @Override protected void internalSetSelection(IStructuredSelection selection) { if (selection == null || selection.isEmpty()) { return; } try { changingSelection = true; for (EditPartViewer viewer : viewers) { List<EditPart> newList = new ArrayList<EditPart>(); Map<Object, EditPart> registry = viewer.getEditPartRegistry(); for (Object o : selection.toArray()) { EditPart editPart = registry.get(o); if (editPart != null) { newList.add(editPart); } } viewer.setSelection(new StructuredSelection(newList)); } } finally { changingSelection = false; } }
From source file:org.eclipse.bpel.common.ui.tray.MultiViewerSelectionProvider.java
License:Open Source License
protected IStructuredSelection calculateSelection(IStructuredSelection baseSelection) { List<EditPart> result = new ArrayList<EditPart>(); for (EditPartViewer viewer : viewers) { Map<Object, EditPart> registry = viewer.getEditPartRegistry(); for (Object n : baseSelection.toArray()) { EditPart part = (EditPart) n; Object model = part.getModel(); EditPart viewerEditPart = registry.get(model); if (viewerEditPart != null) { result.add(viewerEditPart); }/* w w w . j ava 2s . c om*/ } } if (result.isEmpty()) { return StructuredSelection.EMPTY; } return new StructuredSelection(result); }
From source file:org.eclipse.bpel.common.ui.tray.MultiViewerSelectionProvider.java
License:Open Source License
protected void internalSetSelection(IStructuredSelection selection) { if (selection == null || selection.isEmpty()) { return;/*from ww w .j a v a 2s.c o m*/ } try { changingSelection = true; for (EditPartViewer viewer : viewers) { Map<Object, EditPart> registry = viewer.getEditPartRegistry(); List<EditPart> newList = new ArrayList<EditPart>(); Set<EditPart> newSet = new HashSet<EditPart>(); for (Object n : selection.toArray()) { EditPart part = (EditPart) n; Object model = part.getModel(); EditPart viewerEditPart = registry.get(model); if (viewerEditPart != null && newSet.add(viewerEditPart)) { newList.add(viewerEditPart); } } viewer.setSelection(new StructuredSelection(newList)); } } finally { changingSelection = false; } }
From source file:org.eclipse.bpel.ui.properties.ValidateVariablesSection.java
License:Open Source License
protected void createVariablesWidgets(final Composite composite) { FlatFormData data;//from www. j a v a 2s . co m fAddButton = fWidgetFactory.createButton(composite, Messages.ValidateDetails_1, SWT.PUSH); fRemoveButton = fWidgetFactory.createButton(composite, Messages.ValidateDetails_2, SWT.PUSH); Label validateVariablesLabel = fWidgetFactory.createLabel(composite, Messages.ValidateDetails_3); fVariableList = fWidgetFactory.createList(composite, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER); data = new FlatFormData(); data.left = new FlatFormAttachment(0, IDetailsAreaConstants.HSPACE); data.top = new FlatFormAttachment(0, IDetailsAreaConstants.VSPACE); validateVariablesLabel.setLayoutData(data); data = new FlatFormData(); data.width = BPELUtil.calculateButtonWidth(fAddButton, STANDARD_BUTTON_WIDTH); data.right = new FlatFormAttachment(fRemoveButton, -IDetailsAreaConstants.HSPACE); data.top = new FlatFormAttachment(0, IDetailsAreaConstants.VSPACE); fAddButton.setLayoutData(data); data = new FlatFormData(); data.width = BPELUtil.calculateButtonWidth(fRemoveButton, STANDARD_BUTTON_WIDTH); data.right = new FlatFormAttachment(100, (-2) * IDetailsAreaConstants.HSPACE); data.top = new FlatFormAttachment(0, IDetailsAreaConstants.VSPACE); fRemoveButton.setLayoutData(data); fRemoveButton.setEnabled(false); fAddButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Shell shell = composite.getShell(); EObject model = getInput(); VariableSelectorDialog dialog = new VariableSelectorDialog(shell, model, ModelHelper.getVariableType(model, ModelHelper.OUTGOING)) { @Override protected void computeResult() { Object[] results = getSelectedElements(); setResult(Arrays.asList(results)); } }; dialog.setMultipleSelection(true); dialog.setTitle(Messages.ValidateDetails_4); if (dialog.open() == Window.OK) { CompoundCommand ccmd = new CompoundCommand(); Variable variable = null; for (Object next : dialog.getResult()) { variable = (Variable) next; ccmd.add(new AddVariableToValidateCommand(getInput(), variable)); } runCommand(ccmd); fVariablesViewer.setSelection(new StructuredSelection(variable), true); } } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); Listener removeListener = new Listener() { public void handleEvent(Event e) { if (e.type == SWT.KeyUp && e.character != SWT.DEL) { return; } IStructuredSelection sel = (IStructuredSelection) fVariablesViewer.getSelection(); int selectionIndex = fVariableList.getSelectionIndex(); CompoundCommand ccmd = new CompoundCommand(); for (Object next : sel.toArray()) { Variable var = (Variable) next; ccmd.add(new RemoveValidateVariableCommand(getInput(), var)); } runCommand(ccmd); // selects the element at the deleted element position int items = fVariableList.getItemCount(); if (items > 0) { selectionIndex = (selectionIndex < items) ? selectionIndex : 0; fVariableList.setSelection(selectionIndex); } else { fVariablesViewer.setSelection(StructuredSelection.EMPTY); } } }; fVariableList.addListener(SWT.KeyUp, removeListener); fRemoveButton.addListener(SWT.Selection, removeListener); fRemoveButton.addListener(SWT.DefaultSelection, removeListener); data = new FlatFormData(); data.left = new FlatFormAttachment(0, IDetailsAreaConstants.HSPACE); data.right = new FlatFormAttachment(100, (-2) * IDetailsAreaConstants.HSPACE); data.top = new FlatFormAttachment(fAddButton, IDetailsAreaConstants.VSPACE); data.bottom = new FlatFormAttachment(100, (-1) * IDetailsAreaConstants.VSPACE); fVariableList.setLayoutData(data); fVariablesViewer = new ListViewer(fVariableList); fVariablesViewer.setLabelProvider(new ModelLabelProvider()); fVariablesViewer.setContentProvider(new AbstractContentProvider() { @Override public Object[] getElements(Object inputElement) { try { Validate input = (Validate) inputElement; EList<?> l = input.getVariables(); return (l == null) ? EMPTY_ARRAY : l.toArray(); } catch (Throwable t) { return EMPTY_ARRAY; } } }); fVariablesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { fRemoveButton.setEnabled(fVariablesViewer.getSelection().isEmpty() == false); } }); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.PROPERTY_PAGE_VALIDATE_DETAILS); }