org.eclipse.e4.ui.services_0.10.3.v20130123-162658

16:43:01.300 INFO  jd.cli.Main - Decompiling org.eclipse.e4.ui.services_0.10.3.v20130123-162658.jar
package org.eclipse.e4.ui.internal.services;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.EventAdmin;
import org.osgi.util.tracker.ServiceTracker;

public class Activator
  implements BundleActivator
{
  public static final String PLUGIN_ID = "org.eclipse.e4.ui.services";
  private static Activator singleton;
  private ServiceRegistration contextServiceReg;
  private ServiceRegistration handlerServiceReg;
  private ServiceTracker eventAdminTracker;
  private BundleContext bundleContext;
  
  public static Activator getDefault()
  {
    return singleton;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
    singleton = this;
  }
  
  public EventAdmin getEventAdmin()
  {
    if (eventAdminTracker == null)
    {
      eventAdminTracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(), null);
      eventAdminTracker.open();
    }
    return (EventAdmin)eventAdminTracker.getService();
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    if (contextServiceReg != null)
    {
      contextServiceReg.unregister();
      contextServiceReg = null;
    }
    if (handlerServiceReg != null)
    {
      handlerServiceReg.unregister();
      handlerServiceReg = null;
    }
    if (eventAdminTracker != null)
    {
      eventAdminTracker.close();
      eventAdminTracker = null;
    }
    bundleContext = null;
    singleton = null;
  }
  
  public BundleContext getBundleContext()
  {
    return bundleContext;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.services.Activator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.services;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class ActiveContextsFunction
  extends ContextFunction
{
  public Object compute(IEclipseContext context)
  {
    IEclipseContext current = context.getActiveLeaf();
    
    boolean inDialog = false;
    Set<String> rc = new HashSet();
    while (current != null)
    {
      LinkedList<String> locals = (LinkedList)current.getLocal("localContexts");
      if (locals != null)
      {
        if ((!inDialog) || (!locals.contains("org.eclipse.ui.contexts.window"))) {
          rc.addAll(locals);
        }
        if ((!inDialog) && (locals.contains("org.eclipse.ui.contexts.dialog"))) {
          inDialog = true;
        }
      }
      current = current.getParent();
    }
    return rc;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.services.ActiveContextsFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.services;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class ContextContextFunction
  extends ContextFunction
{
  public Object compute(IEclipseContext context)
  {
    return new ContextContextService(context);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.services.ContextContextFunction
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.services;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Set;
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.core.commands.contexts.ContextManager;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.services.EContextService;

public class ContextContextService
  implements EContextService
{
  static final String LOCAL_CONTEXTS = "localContexts";
  static final String DEFERED_ACTIVATES = "localContexts.activates";
  static final String DEFERED_DEACTIVATES = "localContexts.deactivates";
  private IEclipseContext eclipseContext;
  private ContextManager contextManager;
  private boolean deferUpdates = false;
  private int cachingRef = 0;
  
  public ContextContextService(IEclipseContext context)
  {
    eclipseContext = context;
    contextManager = ((ContextManager)context.get(ContextManager.class
      .getName()));
  }
  
  public void activateContext(String id)
  {
    if (deferUpdates)
    {
      deferActivateContext(id);
      return;
    }
    LinkedList<String> locals = (LinkedList)eclipseContext
      .getLocal("localContexts");
    if (locals == null)
    {
      locals = new LinkedList();
      locals.add(id);
      eclipseContext.set("localContexts", locals);
    }
    else
    {
      boolean contained = locals.contains(id);
      if ((locals.add(id)) && (!contained)) {
        eclipseContext.set("localContexts", locals.clone());
      }
    }
  }
  
  public void deferUpdates(boolean defer)
  {
    if (defer)
    {
      cachingRef += 1;
      if (cachingRef == 1) {
        setEventCaching(true);
      }
    }
    else
    {
      cachingRef -= 1;
      if (cachingRef == 0) {
        setEventCaching(false);
      }
    }
  }
  
  private void deferActivateContext(String id)
  {
    LinkedList<String> locals = (LinkedList)eclipseContext
      .getLocal("localContexts.activates");
    if (locals == null)
    {
      locals = new LinkedList();
      eclipseContext.set("localContexts.activates", locals);
    }
    locals.add(id);
  }
  
  private void setEventCaching(boolean cache)
  {
    if (cache)
    {
      deferUpdates = true;
      return;
    }
    deferUpdates = false;
    LinkedList<String> locals = (LinkedList)eclipseContext
      .getLocal("localContexts");
    if (locals == null) {
      locals = new LinkedList();
    }
    LinkedList<String> activates = (LinkedList)eclipseContext
      .getLocal("localContexts.activates");
    if (activates != null)
    {
      eclipseContext.remove("localContexts.activates");
      for (String id : activates) {
        locals.add(id);
      }
    }
    LinkedList<String> deactivates = (LinkedList)eclipseContext
      .getLocal("localContexts.deactivates");
    if (deactivates != null)
    {
      eclipseContext.remove("localContexts.deactivates");
      for (String id : deactivates) {
        locals.remove(id);
      }
    }
    eclipseContext.set("localContexts", locals.clone());
  }
  
  public void deactivateContext(String id)
  {
    if (deferUpdates)
    {
      deferDeactivateContext(id);
      return;
    }
    LinkedList<String> locals = (LinkedList)eclipseContext
      .getLocal("localContexts");
    if ((locals != null) && (locals.remove(id)))
    {
      boolean contained = locals.contains(id);
      if (!contained) {
        eclipseContext.set("localContexts", locals.clone());
      }
    }
  }
  
  private void deferDeactivateContext(String id)
  {
    LinkedList<String> locals = (LinkedList)eclipseContext
      .getLocal("localContexts.deactivates");
    if (locals == null)
    {
      locals = new LinkedList();
      eclipseContext.set("localContexts.deactivates", locals);
    }
    locals.add(id);
  }
  
  public Collection<String> getActiveContextIds()
  {
    Set<String> set = (Set)eclipseContext
      .get("activeContexts");
    if (set != null) {
      contextManager.setActiveContextIds(set);
    }
    return set;
  }
  
  public Context getContext(String id)
  {
    Context ctx = contextManager.getContext(id);
    return ctx;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.services.ContextContextService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.internal.services;

import org.eclipse.osgi.util.NLS;

public class ServiceMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.e4.ui.internal.services.serviceMessages";
  public static String NO_EVENT_ADMIN;
  public static String NO_BUNDLE_CONTEXT;
  
  static {}
  
  public static void reloadMessages()
  {
    NLS.initializeMessages("org.eclipse.e4.ui.internal.services.serviceMessages", ServiceMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.internal.services.ServiceMessages
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services;

import java.util.Collections;
import java.util.Set;
import org.eclipse.core.commands.contexts.ContextManager;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;

class ContextServiceAddon$1
  extends RunAndTrack
{
  ContextServiceAddon$1(ContextServiceAddon paramContextServiceAddon) {}
  
  public boolean changed(IEclipseContext context)
  {
    ContextManager manager = (ContextManager)context.get(ContextManager.class);
    if (manager != null)
    {
      Object s = context.get("activeContexts");
      if ((s instanceof Set)) {
        manager.setActiveContextIds((Set)s);
      } else {
        manager.setActiveContextIds(Collections.EMPTY_SET);
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.ContextServiceAddon.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services;

import java.util.Collections;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.eclipse.core.commands.contexts.ContextManager;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.ui.internal.services.ActiveContextsFunction;
import org.eclipse.e4.ui.internal.services.ContextContextFunction;

public class ContextServiceAddon
{
  @PostConstruct
  public void init(IEclipseContext context)
  {
    ContextManager manager = (ContextManager)context.get(ContextManager.class);
    if (manager == null)
    {
      manager = new ContextManager();
      context.set(ContextManager.class, manager);
    }
    context.set(EContextService.class.getName(), new ContextContextFunction());
    context.set("activeContexts", new ActiveContextsFunction());
    context.runAndTrack(new RunAndTrack()
    {
      public boolean changed(IEclipseContext context)
      {
        ContextManager manager = (ContextManager)context.get(ContextManager.class);
        if (manager != null)
        {
          Object s = context.get("activeContexts");
          if ((s instanceof Set)) {
            manager.setActiveContextIds((Set)s);
          } else {
            manager.setActiveContextIds(Collections.EMPTY_SET);
          }
        }
        return true;
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.ContextServiceAddon
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services;

import java.util.Collection;
import org.eclipse.core.commands.contexts.Context;

public abstract interface EContextService
{
  public abstract Context getContext(String paramString);
  
  public abstract void activateContext(String paramString);
  
  public abstract void deactivateContext(String paramString);
  
  public abstract Collection<String> getActiveContextIds();
  
  public abstract void deferUpdates(boolean paramBoolean);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.EContextService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services;

public abstract interface IServiceConstants
{
  public static final String ACTIVE_SELECTION = "org.eclipse.ui.selection";
  @Deprecated
  public static final String SELECTION = "org.eclipse.ui.selection";
  public static final String ACTIVE_CONTEXTS = "activeContexts";
  public static final String ACTIVE_PART = "e4ActivePart";
  public static final String ACTIVE_SHELL = "activeShell";
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.IServiceConstants
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services;

import org.w3c.dom.css.CSSStyleDeclaration;

public abstract interface IStylingEngine
{
  public static final String SERVICE_NAME = IStylingEngine.class.getName();
  
  public abstract void setClassname(Object paramObject, String paramString);
  
  public abstract void setId(Object paramObject, String paramString);
  
  public abstract void setClassnameAndId(Object paramObject, String paramString1, String paramString2);
  
  public abstract void style(Object paramObject);
  
  public abstract CSSStyleDeclaration getStyle(Object paramObject);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.IStylingEngine
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services.events;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.services.internal.events.EventBroker;

public class EventBrokerFactory
  extends ContextFunction
{
  public Object compute(IEclipseContext context)
  {
    EventBroker broker = (EventBroker)context.getLocal(EventBroker.class);
    if (broker == null)
    {
      broker = (EventBroker)ContextInjectionFactory.make(EventBroker.class, context);
      context.set(EventBroker.class, broker);
    }
    return broker;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.events.EventBrokerFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services.internal.events;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.internal.services.Activator;
import org.eclipse.e4.ui.internal.services.ServiceMessages;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventHandler;

public class EventBroker
  implements IEventBroker
{
  private Map<EventHandler, Collection<ServiceRegistration<?>>> registrations = new HashMap();
  @Inject
  Logger logger;
  @Inject
  @Optional
  UISynchronize uiSync;
  
  static
  {
    EventAdmin eventAdmin = Activator.getDefault().getEventAdmin();
    if (eventAdmin == null)
    {
      Bundle[] bundles = Activator.getDefault().getBundleContext().getBundles();
      Bundle[] arrayOfBundle1;
      int j = (arrayOfBundle1 = bundles).length;
      for (int i = 0; i < j; i++)
      {
        Bundle bundle = arrayOfBundle1[i];
        if ("org.eclipse.equinox.event".equals(bundle.getSymbolicName())) {
          try
          {
            bundle.start(1);
          }
          catch (BundleException e)
          {
            e.printStackTrace();
          }
        }
      }
    }
  }
  
  public boolean send(String topic, Object data)
  {
    Event event = constructEvent(topic, data);
    EventAdmin eventAdmin = Activator.getDefault().getEventAdmin();
    if (eventAdmin == null)
    {
      logger.error(NLS.bind(ServiceMessages.NO_EVENT_ADMIN, event.toString()));
      return false;
    }
    eventAdmin.sendEvent(event);
    return true;
  }
  
  public boolean post(String topic, Object data)
  {
    Event event = constructEvent(topic, data);
    EventAdmin eventAdmin = Activator.getDefault().getEventAdmin();
    if (eventAdmin == null)
    {
      logger.error(NLS.bind(ServiceMessages.NO_EVENT_ADMIN, event.toString()));
      return false;
    }
    eventAdmin.postEvent(event);
    return true;
  }
  
  private Event constructEvent(String topic, Object data)
  {
    Event event;
    Event event;
    if ((data instanceof Dictionary))
    {
      event = new Event(topic, (Dictionary)data);
    }
    else
    {
      Event event;
      if ((data instanceof Map))
      {
        event = new Event(topic, (Map)data);
      }
      else
      {
        Dictionary<String, Object> d = new Hashtable(2);
        d.put("event.topics", topic);
        if (data != null) {
          d.put("org.eclipse.e4.data", data);
        }
        event = new Event(topic, d);
      }
    }
    return event;
  }
  
  public boolean subscribe(String topic, EventHandler eventHandler)
  {
    return subscribe(topic, null, eventHandler, false);
  }
  
  public boolean subscribe(String topic, String filter, EventHandler eventHandler, boolean headless)
  {
    BundleContext bundleContext = Activator.getDefault().getBundleContext();
    if (bundleContext == null)
    {
      logger.error(NLS.bind(ServiceMessages.NO_BUNDLE_CONTEXT, topic));
      return false;
    }
    String[] topics = { topic };
    Dictionary<String, Object> d = new Hashtable();
    d.put("event.topics", topics);
    if (filter != null) {
      d.put("event.filter", filter);
    }
    EventHandler wrappedHandler = new UIEventHandler(eventHandler, headless ? null : uiSync);
    ServiceRegistration<?> registration = bundleContext.registerService(
      EventHandler.class.getName(), wrappedHandler, d);
    Collection<ServiceRegistration<?>> handled = 
      (Collection)registrations.get(eventHandler);
    if (handled == null) {
      registrations.put(eventHandler, 
        handled = new ArrayList());
    }
    handled.add(registration);
    return true;
  }
  
  public boolean unsubscribe(EventHandler eventHandler)
  {
    Collection<ServiceRegistration<?>> handled = 
      (Collection)registrations.remove(eventHandler);
    if ((handled == null) || (handled.isEmpty())) {
      return false;
    }
    for (ServiceRegistration<?> r : handled) {
      r.unregister();
    }
    return true;
  }
  
  @PreDestroy
  void dispose()
  {
    Collection<Collection<ServiceRegistration<?>>> values = new ArrayList(
      registrations.values());
    registrations.clear();
    Iterator localIterator2;
    for (Iterator localIterator1 = values.iterator(); localIterator1.hasNext(); localIterator2.hasNext())
    {
      Collection<ServiceRegistration<?>> handled = (Collection)localIterator1.next();
      localIterator2 = handled.iterator(); continue;ServiceRegistration<?> registration = (ServiceRegistration)localIterator2.next();
      
      registration.unregister();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.internal.events.EventBroker
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services.internal.events;

import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

class UIEventHandler$1
  implements Runnable
{
  UIEventHandler$1(UIEventHandler paramUIEventHandler, Event paramEvent) {}
  
  public void run()
  {
    UIEventHandler.access$0(this$0).handleEvent(val$event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.internal.events.UIEventHandler.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.ui.services.internal.events;

import org.eclipse.e4.ui.di.UISynchronize;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

public class UIEventHandler
  implements EventHandler
{
  private final EventHandler eventHandler;
  private final UISynchronize uiSync;
  
  public UIEventHandler(EventHandler eventHandler, UISynchronize uiSync)
  {
    this.eventHandler = eventHandler;
    this.uiSync = uiSync;
  }
  
  public void handleEvent(final Event event)
  {
    if (uiSync == null) {
      eventHandler.handleEvent(event);
    } else {
      uiSync.syncExec(new Runnable()
      {
        public void run()
        {
          eventHandler.handleEvent(event);
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.ui.services.internal.events.UIEventHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd