org.eclipse.jface.viewers.ContentViewer Java Examples

The following examples show how to use org.eclipse.jface.viewers.ContentViewer. 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: FileFolderSorter.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private String getLabel(final Viewer viewer, final Object e1) {
	String name1;
	if (viewer == null || !(viewer instanceof ContentViewer)) {
		name1 = e1.toString();
	} else {
		final IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
		if (prov instanceof ILabelProvider) {
			final ILabelProvider lprov = (ILabelProvider) prov;
			name1 = lprov.getText(e1);
		} else {
			name1 = e1.toString();
		}
	}
	if (name1 == null) {
		name1 = "";//$NON-NLS-1$
	}
	return name1;
}
 
Example #2
Source File: JavaElementComparator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getNonJavaElementLabel(Viewer viewer, Object element) {
	// try to use the workbench adapter for non - java resources or if not available, use the viewers label provider
	if (element instanceof IResource) {
		return ((IResource) element).getName();
	}
	if (element instanceof IStorage) {
		return ((IStorage) element).getName();
	}
	if (element instanceof IAdaptable) {
		IWorkbenchAdapter adapter= (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
		if (adapter != null) {
			return adapter.getLabel(element);
		}
	}
	if (viewer instanceof ContentViewer) {
		IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
		if (prov instanceof ILabelProvider) {
			return ((ILabelProvider) prov).getText(element);
		}
	}
	return null;
}
 
Example #3
Source File: CPListElementSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int compare(Viewer viewer, Object e1, Object e2) {

       int cat1 = category(e1);
       int cat2 = category(e2);

       if (cat1 != cat2)
           return cat1 - cat2;

       if (cat1 == ATTRIBUTE || cat1 == CONTAINER_ENTRY) {
       	return 0; // do not sort attributes or container entries
       }

	if (viewer instanceof ContentViewer) {
		IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
           if (prov instanceof ILabelProvider) {
               ILabelProvider lprov = (ILabelProvider) prov;
               String name1 = lprov.getText(e1);
               String name2 = lprov.getText(e2);
               return getComparator().compare(name1, name2);
           }
	}
	return 0;
}
 
Example #4
Source File: NavigationComparator.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private String getLabel(Viewer viewer, Object e1) {
	if (!(viewer instanceof ContentViewer))
		return e1.toString();
	var prov = ((ContentViewer) viewer).getLabelProvider();
	if (prov instanceof ILabelProvider) {
		var lprov = (ILabelProvider) prov;
		var label = lprov.getText(e1);
		if (label == null)
			return "";
		String changed = RepositoryLabel.CHANGED_STATE;
		if (label.startsWith(changed))
			return label.substring(changed.length());
		return label;
	}
	return e1.toString();
}
 
Example #5
Source File: PShelfViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.jface.viewers.ContentViewer#labelProviderChanged()
 */
protected void labelProviderChanged() {
	Assert.isNotNull(getLabelProvider());
	if (!(getLabelProvider() instanceof ILabelProvider))
		throw new IllegalArgumentException("Label provider must implement ILabelProvider" + ", got " + getLabelProvider() == null ? "null" : getLabelProvider().getClass().toString());

	if (pshelf != null) {
		PShelfItem[] shelfItems = pshelf.getItems();

		for (int i = 0; i < shelfItems.length; i++) {
			PShelfItem item = shelfItems[i];

			// re-query texts and images for pshelf items
			ILabelProvider lp = (ILabelProvider) getLabelProvider();
			item.setText(lp.getText(item.getData()));
			item.setImage(lp.getImage(item.getData()));

			// change provider for sub-viewers
			Viewer viewer = getViewerForItem(item);
			ContentViewer contentViewer = (ContentViewer) viewer;
			if (contentViewer != null)
				contentViewer.setLabelProvider(lp);
		}
	}

	// refresh in super impl
	super.labelProviderChanged();
}
 
Example #6
Source File: AbstractManageDiagramWizard.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public boolean deleteDiagrams(final List<DiagramFileStore> files, ContentViewer viewer) {
    if (!files.isEmpty()) {
        try {
            for (final DiagramFileStore file : files) {
                for (final AbstractProcess process : file.getProcesses()) {
                    final String uuid = ModelHelper.getEObjectID(process);
                    final IRepositoryFileStore confFile = getConfigurationRepositoryStore()
                            .getChild(uuid + "." + ProcessConfigurationRepositoryStore.CONF_EXT, true);
                    if (confFile != null) {
                        confFile.delete();
                    }
                }

                for (final IEditorPart editor : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                        .getDirtyEditors()) {
                    if (editor.getEditorInput().getName().equals(file.getName())) {
                        file.save(editor);
                        break;
                    }
                }
                final Map<String, Object> parameters = new HashMap<String, Object>();
                parameters.put(AbstractFileStore.ASK_ACTION_ON_CLOSE, false);
                file.setParameters(parameters);
                file.close();
                file.delete();
            }
            if (viewer != null) {
                viewer.setInput(getDiagramRepositoryStore());
            }
            return true;
        } catch (final Exception e1) {
            BonitaStudioLog.error(e1);
        }
    }
    return false;
}
 
Example #7
Source File: ResourceEditDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public int compare( Viewer viewer, Object e1, Object e2 )
{
	String name1;
	String name2;

	if ( viewer == null || !( viewer instanceof ContentViewer ) )
	{
		if ( descent )
		{
			name1 = e2.toString( );
			name2 = e1.toString( );
		}
		else
		{
			name1 = e1.toString( );
			name2 = e2.toString( );
		}
	}
	else
	{
		IBaseLabelProvider prov = ( (ContentViewer) viewer ).getLabelProvider( );
		if ( prov instanceof ITableLabelProvider )
		{
			ITableLabelProvider lprov = (ITableLabelProvider) prov;
			if ( second )
			{
				if ( descent )
				{
					name1 = lprov.getColumnText( e2, 1 );
					name2 = lprov.getColumnText( e1, 1 );
				}
				else
				{
					name1 = lprov.getColumnText( e1, 1 );
					name2 = lprov.getColumnText( e2, 1 );
				}
			}
			else
			{
				if ( descent )
				{
					name1 = lprov.getColumnText( e2, 0 );
					name2 = lprov.getColumnText( e1, 0 );
				}
				else
				{
					name1 = lprov.getColumnText( e1, 0 );
					name2 = lprov.getColumnText( e2, 0 );
				}
			}
		}
		else
		{
			if ( descent )
			{
				name1 = e2.toString( );
				name2 = e1.toString( );
			}
			else
			{
				name1 = e1.toString( );
				name2 = e2.toString( );
			}
		}
	}
	if ( name1 == null )
	{
		name1 = ""; //$NON-NLS-1$
	}
	if ( name2 == null )
	{
		name2 = ""; //$NON-NLS-1$
	}

	return collator.compare( name1, name2 );
}