Example usage for org.eclipse.jface.viewers DecoratingStyledCellLabelProvider setDecorationContext

List of usage examples for org.eclipse.jface.viewers DecoratingStyledCellLabelProvider setDecorationContext

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers DecoratingStyledCellLabelProvider setDecorationContext.

Prototype

public void setDecorationContext(IDecorationContext decorationContext) 

Source Link

Document

Set the decoration context that will be based to the decorator for this label provider if that decorator implements LabelDecorator .

Usage

From source file:org.eclipse.m2e.core.ui.internal.wizards.MavenPomSelectionComponent.java

License:Open Source License

public void init(String queryText, String queryType, IProject project, Set<ArtifactKey> artifacts,
        Set<ArtifactKey> managed) {
    this.queryType = queryType;
    this.project = project;

    if (queryText != null) {
        searchText.setText(queryText);/* w w  w . j  a va  2s.  co m*/
    }

    if (artifacts != null) {
        for (ArtifactKey a : artifacts) {
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId()); //$NON-NLS-1$
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
    if (managed != null) {
        for (ArtifactKey a : managed) {
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId()); //$NON-NLS-1$
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    searchResultViewer.setContentProvider(new SearchResultContentProvider());

    SearchResultLabelProvider labelProvider = new SearchResultLabelProvider(artifactKeys, managedKeys);
    DecoratingStyledCellLabelProvider decoratingLabelProvider = new DecoratingStyledCellLabelProvider(
            labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), null);
    DecorationContext decorationContext = new DecorationContext();
    if (project != null) {
        decorationContext.putProperty(PROP_DECORATION_CONTEXT_PROJECT, project);
    }
    decoratingLabelProvider.setDecorationContext(decorationContext);
    searchResultViewer.setLabelProvider(decoratingLabelProvider);

    searchResultViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                List<IndexedArtifactFile> files = getSelectedIndexedArtifactFiles(selection);

                ArtifactFilterManager filterManager = MavenPluginActivator.getDefault()
                        .getArifactFilterManager();

                for (IndexedArtifactFile file : files) {
                    ArtifactKey key = (ArtifactKey) file.getAdapter(ArtifactKey.class);
                    IStatus status = filterManager.filter(MavenPomSelectionComponent.this.project, key);
                    if (!status.isOK()) {
                        setStatus(IStatus.ERROR, status.getMessage());
                        return; // TODO not nice to exit method like this
                    }
                }

                if (files.size() == 1) {
                    IndexedArtifactFile f = files.get(0);
                    // int severity = artifactKeys.contains(f.group + ":" + f.artifact) ? IStatus.ERROR : IStatus.OK;
                    int severity = IStatus.OK;
                    String date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
                            .format(f.date);
                    setStatus(severity, NLS.bind(Messages.MavenPomSelectionComponent_detail1, f.fname,
                            (f.size != -1 ? NLS.bind(Messages.MavenPomSelectionComponent_details2, date, f.size)
                                    : date)));
                } else {
                    setStatus(IStatus.OK,
                            NLS.bind(Messages.MavenPomSelectionComponent_selected, selection.size()));
                }
            } else {
                setStatus(IStatus.ERROR, Messages.MavenPomSelectionComponent_nosel);
            }
        }
    });
    setupClassifiers();
    setStatus(IStatus.ERROR, ""); //$NON-NLS-1$
    scheduleSearch(queryText, false);
}

From source file:org.eclipse.team.internal.ui.mapping.CommonViewerAdvisor.java

License:Open Source License

/**
 * Create the advisor using the given configuration
 * @param parent the parent//from w  ww .  j  a va2  s. com
 * @param configuration the configuration
 */
public CommonViewerAdvisor(Composite parent, ISynchronizePageConfiguration configuration) {
    super(configuration);
    final CommonViewer viewer = CommonViewerAdvisor.createViewer(parent, configuration, this);
    TeamUI.getTeamContentProviderManager().addPropertyChangeListener(this);
    configuration.addPropertyChangeListener(this);
    GridData data = new GridData(GridData.FILL_BOTH);
    viewer.getControl().setLayoutData(data);
    viewer.getNavigatorContentService().addListener(this);
    initializeViewer(viewer);
    IBaseLabelProvider provider = viewer.getLabelProvider();
    if (provider instanceof DecoratingLabelProvider) {
        DecoratingLabelProvider dlp = (DecoratingLabelProvider) provider;
        ILabelDecorator decorator = ((SynchronizePageConfiguration) configuration).getLabelDecorator();
        if (decorator != null) {
            ILabelProvider lp = dlp.getLabelProvider();
            dlp = new DecoratingLabelProvider(new DecoratingLabelProvider(lp, decorator),
                    PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
            viewer.setLabelProvider(dlp);
        }
        DecorationContext decorationContext = new DecorationContext();
        decorationContext.putProperty(SynchronizationStateTester.PROP_TESTER, new SynchronizationStateTester() {
            public boolean isStateDecorationEnabled() {
                return false;
            }
        });
        dlp.setDecorationContext(decorationContext);
    } else if (provider instanceof DecoratingStyledCellLabelProvider) {
        DecoratingStyledCellLabelProvider dsclp = (DecoratingStyledCellLabelProvider) provider;
        ILabelDecorator decorator = ((SynchronizePageConfiguration) configuration).getLabelDecorator();
        if (decorator != null) {
            IStyledLabelProvider slp = dsclp.getStyledStringProvider();
            dsclp = new DecoratingStyledCellLabelProvider(
                    new MyDecoratingStyledCellLabelProvider(slp, decorator),
                    PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), null);
            viewer.setLabelProvider(dsclp);
        }
        DecorationContext decorationContext = new DecorationContext();
        decorationContext.putProperty(SynchronizationStateTester.PROP_TESTER, new SynchronizationStateTester() {
            public boolean isStateDecorationEnabled() {
                return false;
            }
        });
        dsclp.setDecorationContext(decorationContext);
    }
}