Search in sources :

Example 1 with IDecorationContext

use of org.eclipse.jface.viewers.IDecorationContext 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 IDecorationContext

use of org.eclipse.jface.viewers.IDecorationContext in project eclipse.platform.ui by eclipse-platform.

the class DecorationScheduler method createDecorationJob.

/**
 * Create the Thread used for running decoration.
 */
private Job createDecorationJob() {
    Job decorationJob = new Job(WorkbenchMessages.DecorationScheduler_CalculationJobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            synchronized (DecorationScheduler.this) {
                if (shutdown) {
                    return Status.CANCEL_STATUS;
                }
            }
            while (updatesPending()) {
                try {
                    jobFinishListener.sleep(100);
                } catch (InterruptedException e) {
                    // Cancel and try again if there was an error
                    schedule();
                    return Status.CANCEL_STATUS;
                }
            }
            SubMonitor subMonitor = SubMonitor.convert(monitor, WorkbenchMessages.DecorationScheduler_CalculatingTask, awaitingDecoration.size() + 1);
            // will block if there are no resources to be decorated
            DecorationReference reference;
            boolean queued = false;
            // for each in awaitingDecorationValues, but not locking the map during the whole iteration:
            while ((reference = removeNextReference()) != null) {
                subMonitor.split(1);
                queued = true;
                Object element = reference.getElement();
                boolean force = reference.shouldForceUpdate();
                Collection<IDecorationContext> contexts = reference.getContexts();
                for (IDecorationContext context : contexts) {
                    queued |= queue(element, force, context);
                }
                // may grow asynchronously
                subMonitor.setWorkRemaining(awaitingDecoration.size() + 1);
            // Only notify listeners when we have exhausted the
            // queue of decoration requests.
            }
            if (queued) {
                scheduleUpdateJob();
            }
            return Status.OK_STATUS;
        }

        /**
         * Ensure that a result is cached for the given element and context
         *
         * @param element the elements
         * @param force   whether an update should be forced
         * @param context the decoration context
         */
        private boolean queue(Object element, boolean force, IDecorationContext context) {
            DecorationBuilder cacheResult = new DecorationBuilder(context);
            // Calculate the decoration
            decoratorManager.getLightweightManager().getDecorations(element, cacheResult);
            // anyways
            if (cacheResult.hasValue() || force) {
                // Synchronize on the result lock as we want to
                // be sure that we do not try and decorate during
                // label update servicing.
                // Note: resultCache and pendingUpdate modifications
                // must be done atomically.
                // Add the decoration even if it's empty in
                // order to indicate that the decoration is
                // ready
                internalPutResult(element, context, cacheResult.createResult());
                // prevent multiple updates and clear the cache.
                synchronized (pendingUpdate) {
                    pendingUpdate.add(element);
                }
                return true;
            }
            return false;
        }

        @Override
        public boolean belongsTo(Object family) {
            return DecoratorManager.FAMILY_DECORATE == family;
        }

        @Override
        public boolean shouldRun() {
            return PlatformUI.isWorkbenchRunning();
        }
    };
    decorationJob.setSystem(true);
    decorationJob.setPriority(Job.DECORATE);
    return decorationJob;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SubMonitor(org.eclipse.core.runtime.SubMonitor) IDecorationContext(org.eclipse.jface.viewers.IDecorationContext) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Example 3 with IDecorationContext

use of org.eclipse.jface.viewers.IDecorationContext in project org.eclipse.rap by eclipse-rap.

the class DecorationScheduler method createDecorationJob.

/**
 * Create the Thread used for running decoration.
 */
private void createDecorationJob() {
    decorationJob = new Job(WorkbenchMessages.get().DecorationScheduler_CalculationJobName) {

        /*
       * (non-Javadoc)
       * 
       * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
       */
        public IStatus run(final IProgressMonitor monitor) {
            final IStatus[] result = { null };
            // RAP [rh] fake service context
            RWT.getUISession(display).exec(new Runnable() {

                public void run() {
                    result[0] = doRun(monitor);
                }
            });
            return result[0];
        }

        public IStatus doRun(IProgressMonitor monitor) {
            synchronized (DecorationScheduler.this) {
                if (shutdown) {
                    return Status.CANCEL_STATUS;
                }
            }
            while (updatesPending()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // Cancel and try again if there was an error
                    // RAP [rh] fake service context
                    RWT.getUISession(display).exec(new Runnable() {

                        public void run() {
                            decorationJob.schedule();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            // RAP [if] Scheduler could be shutdown at this point
            synchronized (DecorationScheduler.this) {
                if (shutdown) {
                    return Status.CANCEL_STATUS;
                }
            }
            monitor.beginTask(WorkbenchMessages.get().DecorationScheduler_CalculatingTask, 100);
            // will block if there are no resources to be decorated
            DecorationReference reference;
            monitor.worked(5);
            int workCount = 5;
            while ((reference = nextElement()) != null) {
                // Count up to 90 to give the appearance of updating
                if (workCount < 90) {
                    monitor.worked(1);
                    workCount++;
                }
                monitor.subTask(reference.getSubTask());
                Object element = reference.getElement();
                boolean force = reference.shouldForceUpdate();
                IDecorationContext[] contexts = reference.getContexts();
                for (int i = 0; i < contexts.length; i++) {
                    IDecorationContext context = contexts[i];
                    ensureResultCached(element, force, context);
                }
                // queue of decoration requests.
                synchronized (DecorationScheduler.this) {
                    if (awaitingDecoration.isEmpty()) {
                        decorated();
                    }
                }
            }
            monitor.worked(100 - workCount);
            monitor.done();
            return Status.OK_STATUS;
        }

        /**
         * Ensure that a result is cached for the given element and context
         *
         * @param element
         *            the elements
         * @param force
         *            whether an update should be forced
         * @param context
         *            the decoration context
         */
        private void ensureResultCached(Object element, boolean force, IDecorationContext context) {
            boolean elementIsCached = internalGetResult(element, context) != null;
            if (elementIsCached) {
                synchronized (pendingKey) {
                    pendingUpdate.add(element);
                }
            }
            if (!elementIsCached) {
                DecorationBuilder cacheResult = new DecorationBuilder(context);
                // Calculate the decoration
                decoratorManager.getLightweightManager().getDecorations(element, cacheResult);
                // anyways
                if (cacheResult.hasValue() || force) {
                    // Synchronize on the result lock as we want to
                    // be sure that we do not try and decorate during
                    // label update servicing.
                    // Note: resultCache and pendingUpdate modifications
                    // must be done atomically.
                    // Add the decoration even if it's empty in
                    // order to indicate that the decoration is
                    // ready
                    internalPutResult(element, context, cacheResult.createResult());
                    // prevent multiple updates and clear the cache.
                    synchronized (pendingKey) {
                        pendingUpdate.add(element);
                    }
                }
            }
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
			 */
        public boolean belongsTo(Object family) {
            return DecoratorManager.FAMILY_DECORATE == family;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.core.runtime.jobs.Job#shouldRun()
			 */
        public boolean shouldRun() {
            final boolean[] result = { false };
            // RAP [rh] fake service context
            RWT.getUISession(display).exec(new Runnable() {

                public void run() {
                    // result[ 0 ] = PatformUI.isWorkbenchRunning();
                    result[0] = !shutdown && PlatformUI.isWorkbenchRunning();
                }
            });
            return result[0];
        }
    };
    decorationJob.setSystem(true);
    decorationJob.setPriority(Job.DECORATE);
    decorationJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IDecorationContext(org.eclipse.jface.viewers.IDecorationContext) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Aggregations

IDecorationContext (org.eclipse.jface.viewers.IDecorationContext)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 UIJob (org.eclipse.ui.progress.UIJob)2 WorkbenchJob (org.eclipse.ui.progress.WorkbenchJob)2 IStatus (org.eclipse.core.runtime.IStatus)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 DecorationContext (org.eclipse.jface.viewers.DecorationContext)1