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 File: EnginePropertyPage.java    From thym with 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
Source File: SelectionUtils.java    From xds-ide with 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 3
Source File: TmDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当使用该对话框作为数据库选择时 ;
 */
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 4
Source File: EnricherPropertiesEditionPartForm.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
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 5
Source File: NonTranslationQAPage.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 删除列表中的非译元素
 */
@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 6
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 7
Source File: AbstractItemHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 8
Source File: BasicEditor.java    From neoscada with 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 9
Source File: InvocableEndpointPropertiesEditionPartImpl.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
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 10
Source File: TmDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 当使用该对话框作为数据库选择时 ;
 */
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 11
Source File: GatewayPropertiesEditionPartForm.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
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 12
Source File: SplitterPropertiesEditionPartImpl.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
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 13
Source File: CompositeProcessorPropertiesEditionPartImpl.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
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 14
Source File: PullUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 15
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 16
Source File: IndexView.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 17
Source File: ExternalizeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 18
Source File: XViewerCustomizeDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private CustomizeData getCustTableSelection() {
   IStructuredSelection selection = (IStructuredSelection) custTable.getViewer().getSelection();
   if (selection.isEmpty()) {
      return null;
   }
   Iterator<?> i = selection.iterator();
   return (CustomizeData) i.next();
}
 
Example 19
Source File: EssentialsPage.java    From thym with 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
Source File: ViewContextMenuProvider.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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$
		}
	}
}