List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.metaaps.eoclipse.datasets.internal.NCE.DeleteHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); Object obj = currentSelection.iterator().next(); if (obj instanceof IDataContent) { IDataContent data = (IDataContent) obj; IDataSets datasets = (IDataSets) data.getParent(); datasets.removeDataContent(data); }//from w ww. j a va 2 s . c om return null; }
From source file:com.metaaps.eoclipse.workflowmanager.NCE.DeleteHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); Object obj = currentSelection.iterator().next(); if (obj instanceof WorkFlow) { WorkFlowManager.getInstance().removeChild(obj); WorkFlowManager.getInstance().fireChanged(obj, Model.REMOVED); }//ww w .jav a 2 s. c o m return null; }
From source file:com.metaaps.eoclipse.workflowmanager.NCE.SaveAsHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); Object obj = currentSelection.iterator().next(); if (obj instanceof WorkFlow) { WorkFlow workflow = (WorkFlow) obj; workflow.save(true);/*w w w.j a v a2 s . c om*/ } return null; }
From source file:com.metaaps.eoclipse.workflowmanager.NCE.SaveHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection currentSelection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); Object obj = currentSelection.iterator().next(); if (obj instanceof WorkFlow) { WorkFlow workflow = (WorkFlow) obj; workflow.save(false);//from w w w. jav a2 s .c o m } return null; }
From source file:com.microsoft.tfs.client.common.ui.framework.helper.SelectionHelper.java
License:Open Source License
public static Collection fromSelection(final ISelection selection, final Transformer transformer) { final List items = new ArrayList(); if (selection != null) { if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (final Iterator it = structuredSelection.iterator(); it.hasNext();) { final Object input = it.next(); final Object transformed = transformer.transform(input); items.add(transformed);/* w ww. ja v a 2 s . c o m*/ } } } return items; }
From source file:com.microsoft.tfs.client.common.ui.framework.helper.SelectionUtils.java
License:Open Source License
/** * <p>/* w w w .j av a 2 s. co m*/ * Returns the elements contained in the selection as an array. The runtime * type of the array is specified by <code>targetType</code>. If * <code>adapt</code> is <code>true</code>, each element in the selection is * adapted to the specified target type. The array is computed in the * following way: * <ul> * <li>If the selection is <code>null</code>, an empty array (of the * specified target type) is returned</li> * <li>If the selection is not an {@link IStructuredSelection}, an * {@link IllegalArgumentException} is thrown</li> * <li>Otherwise, the selection's elements are optionally adapted and * converted to an array (of the specified target type) and returned</li> * </ul> * </p> * * <p> * You must not specify a primitive type as the <code>targetType</code>. * </p> * * @param selection * the {@link ISelection} to get the elements for (can be * <code>null</code> but if non-<code>null</code> must be an * {@link IStructuredSelection}) * @throws IllegalArgumentException * if the specified {@link ISelection} is not <code>null</code> and * is not an {@link IStructuredSelection}, or if the specified * <code>targetType</code> is a primitive type, or if * <code>adapt</code> is <code>true</code> and any of the selection * elements could not be adapted to the target type * @throws ArrayStoreException * if any of the (possibly adapted) selection elements are not * compatible with the specified <code>targetType</code> * @return the (possibly adapted) selection elements as an array of the * target type (never <code>null</code>) */ public static final Object[] selectionToArray(final ISelection selection, final Class targetType, final boolean adapt) { Check.notNull(targetType, "targetType"); //$NON-NLS-1$ final IStructuredSelection structuredSelection = getStructuredSelection(selection); if (targetType.isPrimitive()) { throw new IllegalArgumentException("You must specify a non-primitive target type"); //$NON-NLS-1$ } final Object[] result = (Object[]) Array.newInstance(targetType, (structuredSelection == null ? 0 : structuredSelection.size())); if (structuredSelection == null) { return result; } int ix = 0; for (final Iterator it = structuredSelection.iterator(); it.hasNext();) { final Object sourceElement = it.next(); Object targetElement = sourceElement; if (adapt && sourceElement != null) { targetElement = Adapters.getAdapter(sourceElement, targetType); if (targetElement == null) { final String messageFormat = "adaptSelectionToArray({0}): could not adapt [{1}]"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, targetType.getName(), sourceElement.getClass().getName()); throw new IllegalArgumentException(message); } } result[ix++] = targetElement; } return result; }
From source file:com.microsoft.tfs.client.common.ui.framework.table.TableControl.java
License:Open Source License
/** * Called when a {@link CheckStateChangedEvent} occurs on the * {@link CheckboxTableViewer} backing this {@link TableControl}. * * @param event// ww w.ja v a2s .co m * the {@link CheckStateChangedEvent} */ protected void onCheckStateChanged(final CheckStateChangedEvent event) { final boolean checked = event.getChecked(); if (isChecksAffectSelection()) { /* * propagate checked state to all elements in the current selection */ viewer.getTable().setRedraw(false); final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.size() == viewer.getTable().getItemCount()) { ((CheckboxTableViewer) viewer).setAllChecked(checked); } else { /* * Make sure the element being checked is part of the selection. * Otherwise, we ignore the selected elements. Avoids the case * where you have some elements selected, and check a * non-selected element. The checkstate of the selected elements * should NOT change in this case. */ boolean checkedElementInSelection = false; for (final Iterator it = selection.iterator(); it.hasNext();) { if (it.next().equals(event.getElement())) { checkedElementInSelection = true; break; } } if (checkedElementInSelection) { for (final Iterator it = selection.iterator(); it.hasNext();) { ((CheckboxTableViewer) viewer).setChecked(it.next(), checked); } } } viewer.getTable().setRedraw(true); } computeCheckedElements(true); final Object element = event.getElement(); if (!hideElementFromCollections(element)) { notifyCheckStateListeners(element, event.getChecked()); } }
From source file:com.microsoft.tfs.client.common.ui.vcexplorer.versioncontrol.actions.helper.ActionEnablementHelper.java
License:Open Source License
/** * @return true if any item in the selection matches, false if no items * match/*from w w w. ja v a 2s . co m*/ */ private static boolean selectionAnySearch(final ISelection selection, final Matcher matcher) { if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (final Iterator it = structuredSelection.iterator(); it.hasNext();) { final Object selectionPart = it.next(); if (matcher.matches(selectionPart)) { return true; } } } return false; }
From source file:com.microsoft.tfs.client.common.ui.wit.dialogs.WorkItemPickerDialog.java
License:Open Source License
private void resultsControlSelectionChanged(final ISelection selection) { if (selection.isEmpty()) { selectedWorkItems = null;/*from www. ja v a 2 s. com*/ } else { final ArrayList selections = new ArrayList(); final IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (final Iterator it = structuredSelection.iterator(); it.hasNext();) { selections.add(it.next()); } selectedWorkItems = (WorkItem[]) selections.toArray(new WorkItem[selections.size()]); } setOKEnablement(); }
From source file:com.microsoft.tfs.client.eclipse.ui.actions.ActionHelpers.java
License:Open Source License
/** * Calculates this action's current enablement by filtering the current * selection, returning true if <em>any item</em> is accepted by the filter. * * @param selection//from w w w .j a v a2 s . c o m * the selection to filter (must not be <code>null</code>) * @param filter * the filter to use (must not be <code>null</code>) * @return true if this action should be enabled (the filter accepts * <em>any item</em> in the selection), false if it should not be * enabled (the filter rejects <em>all items</em> in the selection) */ public static boolean filterAcceptsAnyResource(final ISelection selection, final ResourceFilter filter) { if (selection instanceof IStructuredSelection == false) { return false; } final IStructuredSelection ss = (IStructuredSelection) selection; /* * Adapt each item as we encounter it, so we can filter it directly, and * possibly return early in a large selection without adapting every * element. */ @SuppressWarnings("rawtypes") final Iterator it; for (it = ss.iterator(); it.hasNext();) { final IResource resource = (IResource) Adapters.getAdapter(it.next(), IResource.class); if (resource == null) { continue; } if (filter.filter(resource).isAccept()) { return true; } } return false; }