Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection#iterator()

The following examples show how to use org.eclipse.jface.viewers.IStructuredSelection#iterator() . 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 Project: thym   File: EnginePropertyPage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isValid() {
	setMessage(null);
	setErrorMessage(null);
	IStructuredSelection sel = (IStructuredSelection) engineSection.getSelection();
	if(sel != null){
		for (Iterator<?> iterator = sel.iterator(); iterator.hasNext();) {
			HybridMobileEngine engine = (HybridMobileEngine) iterator.next();
			try {
				List<CordovaPlugin> installedPlugins = getProject().getPluginManager().getInstalledPlugins();
				for (CordovaPlugin cordovaPlugin : installedPlugins) {
					IStatus status = cordovaPlugin.isEngineCompatible(engine);
					if( !status.isOK())
					{
						setMessage(status.getMessage(), status.getSeverity());
						return status.getSeverity() != IStatus.ERROR;
					}
				}
			} catch (CoreException e) {
				HybridUI.log(IStatus.WARNING, "Error while checking engine and plug-in compatability ",  e);
			}
			
		}
	}
	return true;
}
 
Example 2
public static boolean isInferTypeArgumentsAvailable(final IStructuredSelection selection) throws JavaModelException {
	if (selection.isEmpty())
		return false;

	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		Object element= iter.next();
		if (!(element instanceof IJavaElement))
			return false;
		if (element instanceof ICompilationUnit) {
			ICompilationUnit unit= (ICompilationUnit) element;
			if (!unit.exists() || unit.isReadOnly())
				return false;

			return true;
		}
		if (!isInferTypeArgumentsAvailable((IJavaElement) element))
			return false;
	}
	return true;
}
 
Example 3
private static IMember[] getSelectedMembers(IStructuredSelection selection) {
	if (selection.isEmpty())
		return null;
	if (selection.size() == 1) {
		try {
			final IType type= RefactoringAvailabilityTester.getSingleSelectedType(selection);
			if (type != null)
				return new IType[] { type};
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
	}
	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		if (!(iter.next() instanceof IMember))
			return null;
	}
	Set<Object> memberSet= new HashSet<Object>();
	memberSet.addAll(Arrays.asList(selection.toArray()));
	return memberSet.toArray(new IMember[memberSet.size()]);
}
 
Example 4
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(CompositeProcessorPropertiesEditionPartImpl.this, EipViewsRepository.CompositeProcessor.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example 5
/**
 * 
 */
protected void addFromChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(fromChannels.getInput(), fromChannelsFilters, fromChannelsBusinessFilters,
	"fromChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(SplitterPropertiesEditionPartImpl.this, EipViewsRepository.Splitter.Properties.fromChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			fromChannels.refresh();
		}
	};
	dialog.open();
}
 
Example 6
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(GatewayPropertiesEditionPartForm.this, EipViewsRepository.Gateway.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example 7
/**
 * 当使用该对话框作为数据库选择时 ;
 */
private void executeSelectDatabase() {
	ISelection selection = getDbTableViewer().getSelection();
	if (selection.isEmpty()) {
		return;
	}
	hasSelected = new HashMap<DatabaseModelBean, String>();
	IStructuredSelection structuredSelection = (IStructuredSelection) selection;

	Iterator<?> it = structuredSelection.iterator();
	while (it.hasNext()) {
		DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
		DatabaseModelBean dbModelBean = new DatabaseModelBean();
		currServer.copyToOtherIntance(dbModelBean);
		dbModelBean.setDbName(dbBean.getDbName());
		hasSelected.put(dbModelBean, dbBean.getLangs());
	}
}
 
Example 8
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(InvocableEndpointPropertiesEditionPartImpl.this, EipViewsRepository.InvocableEndpoint.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example 9
Source Project: neoscada   File: BasicEditor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void handleDelete ()
{
    final ISelection sel = this.viewer.getSelection ();
    if ( sel == null || sel.isEmpty () || ! ( sel instanceof IStructuredSelection ) )
    {
        return;
    }

    final IStructuredSelection selection = (IStructuredSelection)sel;

    final Iterator<?> i = selection.iterator ();
    while ( i.hasNext () )
    {
        final Object o = i.next ();
        final Map.Entry<?, ?> entry = AdapterHelper.adapt ( o, Map.Entry.class );
        if ( entry != null )
        {
            deleteEntry ( "" + entry.getKey () );
        }
    }
}
 
Example 10
/**
 * Get all items from the selection
 *
 * @return a data of all selected items
 */
protected Collection<Item> getItems ()
{
    final Collection<Item> result = new LinkedList<Item> ();

    final IStructuredSelection sel = getSelection ();

    if ( sel != null && !sel.isEmpty () )
    {
        for ( final Iterator<?> i = sel.iterator (); i.hasNext (); )
        {
            final Object o = i.next ();

            final Item holder = AdapterHelper.adapt ( o, Item.class );
            if ( holder != null )
            {
                result.add ( holder );
            }
        }
    }

    return result;
}
 
Example 11
/**
 * Returns the resource selection from the LocalSelectionTransfer.
 * 
 * @return the resource selection from the LocalSelectionTransfer
 */
private IResource[] getSelectedResources(IStructuredSelection selection) {
	ArrayList selectedResources = new ArrayList();

	for (Iterator i = selection.iterator(); i.hasNext();) {
		Object o = i.next();
		if (o instanceof IResource) {
			selectedResources.add(o);
		} else if (o instanceof IAdaptable) {
			IAdaptable a = (IAdaptable) o;
			IResource r = (IResource) a.getAdapter(IResource.class);
			if (r != null) {
				selectedResources.add(r);
			}
		}
	}
	return (IResource[]) selectedResources
			.toArray(new IResource[selectedResources.size()]);
}
 
Example 12
/**
 * 删除列表中的非译元素
 */
@SuppressWarnings("unchecked")
public void deleteElement() {
	ISelection selection = tableViewer.getSelection();
	if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
		boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("qa.preference.NonTranslationQAPage.enter"),
				Messages.getString("qa.preference.NonTranslationQAPage.enterDelete"));
		if (!confirm) {
			return;
		}
		
		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		Iterator<NontransElementBean> iter = structuredSelection.iterator();
		while (iter.hasNext()) {
			NontransElementBean selectElement = iter.next();
			dataList.remove(selectElement);
		}
		tableViewer.refresh();
	}
}
 
Example 13
/**
 * 
 */
protected void addToChannels() {
	TabElementTreeSelectionDialog dialog = new TabElementTreeSelectionDialog(toChannels.getInput(), toChannelsFilters, toChannelsBusinessFilters,
	"toChannels", propertiesEditionComponent.getEditingContext().getAdapterFactory(), current.eResource()) {
		@Override
		public void process(IStructuredSelection selection) {
			for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
				EObject elem = (EObject) iter.next();
				propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(EnricherPropertiesEditionPartForm.this, EipViewsRepository.Enricher.Properties.toChannels,
					PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
			}
			toChannels.refresh();
		}
	};
	dialog.open();
}
 
Example 14
/**
 * 当使用该对话框作为数据库选择时 ;
 */
private void executeSelectDatabase() {
	ISelection selection = getDbTableViewer().getSelection();
	if (selection.isEmpty()) {
		return;
	}
	hasSelected = new HashMap<DatabaseModelBean, String>();
	IStructuredSelection structuredSelection = (IStructuredSelection) selection;

	Iterator<?> it = structuredSelection.iterator();
	while (it.hasNext()) {
		DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
		DatabaseModelBean dbModelBean = new DatabaseModelBean();
		currServer.copyToOtherIntance(dbModelBean);
		dbModelBean.setDbName(dbBean.getDbName());
		// Fix Bug #3290 导出TMX/TBX--导出内容异常 去掉语言前后的空格
		hasSelected.put(dbModelBean, dbBean.getLangs().replace(" ", ""));
	}
}
 
Example 15
Source Project: xds-ide   File: SelectionUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the selected elements of the given class as a unmodifiable list.
 *
 * @param selection - a selection containing elements.
 * @param tagClass - expected class of elements in selection - only objects of this class will be returned 
 * @return the selected elements of given class as a immutable list 
 */
public static <T> List<T> getObjectsFromStructuredSelection( ISelection selection
                                                           , Class<T> tagClass ) 
{
    List<T> objectList = Collections.emptyList(); 
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection)selection;
        objectList = new ArrayList<T>(structuredSelection.size());
        Iterator<?> selectionIterator = structuredSelection.iterator();
        while (selectionIterator.hasNext()) {
            Object object = selectionIterator.next();
            T adapted = AdapterUtilities.getAdapter(object, tagClass);
            if (adapted != null){
            	objectList.add(adapted);
            }
        }
    }
    return objectList;
}
 
Example 16
private CustomizeData getCustTableSelection() {
   IStructuredSelection selection = (IStructuredSelection) custTable.getViewer().getSelection();
   if (selection.isEmpty()) {
      return null;
   }
   Iterator<?> i = selection.iterator();
   return (CustomizeData) i.next();
}
 
Example 17
/**
 * setInputFromSelection
 * 
 * @param selection
 */
private void setInputFromSelection(ISelection selection)
{
	IStructuredSelection ss = (IStructuredSelection) selection;

	if (ss != null && treeViewer != null && !treeViewer.getTree().isDisposed())
	{
		Iterator<?> items = ss.iterator();

		while (items.hasNext())
		{
			Object item = items.next();

			if (item instanceof IResource)
			{
				IProject project = ((IResource) item).getProject();

				if (project.isOpen())
				{
					treeViewer.setInput(project);
				}
				else
				{
					treeViewer.setInput(null);
				}

				break;
			}
		}
	}
}
 
Example 18
private List<NLSSubstitution> getExternalizedElements(IStructuredSelection selection) {
	ArrayList<NLSSubstitution> res= new ArrayList<NLSSubstitution>();
	for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
		NLSSubstitution substitution= (NLSSubstitution) iter.next();
		if (substitution.getState() == NLSSubstitution.EXTERNALIZED && !substitution.hasStateChanged()) {
			res.add(substitution);
		}
	}
	return res;
}
 
Example 19
Source Project: thym   File: EssentialsPage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private boolean selectionContainsEngine(IStructuredSelection selection, Engine engine) {
	for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
		HybridMobileEngine hybridEngine = (HybridMobileEngine) iter.next();
		if (hybridEngine.getName().equals(engine.getName())) {
			return true;
		}
	}
	return false;
}
 
Example 20
/**
 * Builds the context menu. Single selection menu and multiple selection
 * menu are created while selecting just single element or multiple elements
 * 
 * 
 * @param menu
 *            the menu
 */
public void buildContextMenu( IMenuManager menu )
{
	menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
	TreeViewer treeViewer = (TreeViewer) getViewer( );

	IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection( );

	// temporary solution
	Object input = treeViewer.getInput( );
	if ( input instanceof Object[] )
	{
		Object[] inputs = (Object[]) input;
		if ( inputs.length == 1 && inputs[0] instanceof ReportDesignHandle )
		{
			for ( Iterator iter = selection.iterator( ); iter.hasNext( ); )
			{
				if ( isIncludedLibrary( iter.next( ) ) )
				{
					return;
				}
			}
		}
	}

	if ( selection.size( ) == 1 )
	{
		// Create Single Selection Menu
		Object obj = selection.getFirstElement( );
		if ( ProviderFactory.createProvider( obj ) != null )
		{
			ProviderFactory.createProvider( obj )
					.createContextMenu( treeViewer, obj, menu );
		}
		if ( Policy.TRACING_MENU_SHOW )
		{
			System.out.println( "Menu(for Views) >> Shows for " + ProviderFactory.createProvider( obj ).getNodeDisplayName( obj ) ); //$NON-NLS-1$
		}
	}
	else
	{
		// Added by ywang on 2004.9.15
		// Create Multiple Selection Menu
		if ( ProviderFactory.getDefaultProvider( ) != null)
		{
			ProviderFactory.getDefaultProvider( )
					.createContextMenu( treeViewer, selection, menu );
		}

		if ( Policy.TRACING_MENU_SHOW )
		{
			System.out.println( "Menu(for Views) >> Shows for multi-selcetion." ); //$NON-NLS-1$
		}
	}
}