Search in sources :

Example 1 with DecorationContext

use of org.eclipse.jface.viewers.DecorationContext in project eclipse.jdt.ui by eclipse-jdt.

the class HierarchicalDecorationContext method getContext.

public static IDecorationContext getContext() {
    if (fgContext == null) {
        DecorationContext context = new DecorationContext();
        context.putProperty(SynchronizationStateTester.PROP_TESTER, new HierarchicalSynchronizationStateTester());
        fgContext = context;
    }
    return fgContext;
}
Also used : IDecorationContext(org.eclipse.jface.viewers.IDecorationContext) DecorationContext(org.eclipse.jface.viewers.DecorationContext)

Example 2 with DecorationContext

use of org.eclipse.jface.viewers.DecorationContext in project m2e-core by eclipse-m2e.

the class MavenPomSelectionComponent method init.

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);
    }
    if (artifacts != null) {
        for (ArtifactKey a : artifacts) {
            // $NON-NLS-1$
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId());
            // $NON-NLS-1$ //$NON-NLS-2$
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
        }
    }
    if (managed != null) {
        for (ArtifactKey a : managed) {
            // $NON-NLS-1$
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId());
            // $NON-NLS-1$ //$NON-NLS-2$
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
        }
    }
    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(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 = file.getAdapter(ArtifactKey.class);
                IStatus status = filterManager.filter(MavenPomSelectionComponent.this.project, key);
                if (!status.isOK()) {
                    setStatus(IStatus.ERROR, status.getMessage());
                    // TODO not nice to exit method like this
                    return;
                }
            }
            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();
    // $NON-NLS-1$
    setStatus(IStatus.ERROR, "");
    scheduleSearch(queryText, false);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) DecoratingStyledCellLabelProvider(org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) DecorationContext(org.eclipse.jface.viewers.DecorationContext) ArtifactFilterManager(org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

DecorationContext (org.eclipse.jface.viewers.DecorationContext)2 IStatus (org.eclipse.core.runtime.IStatus)1 DecoratingStyledCellLabelProvider (org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider)1 IDecorationContext (org.eclipse.jface.viewers.IDecorationContext)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ArtifactKey (org.eclipse.m2e.core.embedder.ArtifactKey)1 IndexedArtifactFile (org.eclipse.m2e.core.internal.index.IndexedArtifactFile)1 ArtifactFilterManager (org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager)1