X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.debug.browser%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fbrowser%2Fcontent%2FResourceBrowserRewriterRepository.java;fp=bundles%2Forg.simantics.debug.browser%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fbrowser%2Fcontent%2FResourceBrowserRewriterRepository.java;h=ce5aa937808a91cdd24a903ac259f1357fc6bc53;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/content/ResourceBrowserRewriterRepository.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/content/ResourceBrowserRewriterRepository.java new file mode 100644 index 000000000..ce5aa9378 --- /dev/null +++ b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/content/ResourceBrowserRewriterRepository.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2016 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * THTH ry - initial API and implementation + *******************************************************************************/ +package org.simantics.debug.browser.content; + +import java.util.Arrays; +import java.util.Comparator; + +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; +import org.simantics.debug.browser.internal.Activator; + +public class ResourceBrowserRewriterRepository { + private static ServiceTracker TRACKER; + + private static final Comparator REWRITER_COMPARATOR = + new Comparator() { + @Override + public int compare(ResourceBrowserRewriter o1, + ResourceBrowserRewriter o2) { + return Double.compare(o1.getPriority(), o2.getPriority()); + } + }; + + public static ResourceBrowserRewriter[] getRewriters() { + if(TRACKER == null) { + BundleContext context = Activator.getContext(); + TRACKER = new ServiceTracker( + context, ResourceBrowserRewriter.class, null); + TRACKER.open(); + } + ResourceBrowserRewriter[] rewriters = + TRACKER.getServices(new ResourceBrowserRewriter[TRACKER.getTrackingCount()]); + Arrays.sort(rewriters, REWRITER_COMPARATOR); + return rewriters; + } +}