org.eclipse.e4.core.commands_0.10.1.v20120523-1955

16:42:55.509 INFO  jd.cli.Main - Decompiling org.eclipse.e4.core.commands_0.10.1.v20120523-1955.jar
package org.eclipse.e4.core.commands;

import java.lang.reflect.Field;
import javax.annotation.PostConstruct;
import org.eclipse.core.commands.CommandManager;
import org.eclipse.e4.core.commands.internal.CommandServiceImpl;
import org.eclipse.e4.core.commands.internal.HandlerServiceCreationFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class CommandServiceAddon
{
  @PostConstruct
  public void init(IEclipseContext context)
  {
    CommandManager manager = (CommandManager)context.get(CommandManager.class);
    if (manager == null)
    {
      manager = new CommandManager();
      setCommandFireEvents(manager, false);
      context.set(CommandManager.class, manager);
    }
    CommandServiceImpl service = 
      (CommandServiceImpl)ContextInjectionFactory.make(CommandServiceImpl.class, context);
    context.set(ECommandService.class, service);
    
    context.set(EHandlerService.class.getName(), new HandlerServiceCreationFunction());
  }
  
  private void setCommandFireEvents(CommandManager manager, boolean b)
  {
    try
    {
      Field f = CommandManager.class.getDeclaredField("shouldCommandFireEvents");
      f.setAccessible(true);
      f.set(manager, Boolean.valueOf(b));
    }
    catch (SecurityException e)
    {
      e.printStackTrace();
    }
    catch (NoSuchFieldException e)
    {
      e.printStackTrace();
    }
    catch (IllegalArgumentException e)
    {
      e.printStackTrace();
    }
    catch (IllegalAccessException e)
    {
      e.printStackTrace();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.commands.CommandServiceAddon
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.commands;

import java.util.Map;
import org.eclipse.core.commands.Category;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IParameter;
import org.eclipse.core.commands.ParameterizedCommand;

public abstract interface ECommandService
{
  public abstract ParameterizedCommand createCommand(String paramString, Map paramMap);
  
  public abstract Category defineCategory(String paramString1, String paramString2, String paramString3);
  
  public abstract Command defineCommand(String paramString1, String paramString2, String paramString3, Category paramCategory, IParameter[] paramArrayOfIParameter);
  
  public abstract Category getCategory(String paramString);
  
  public abstract Command getCommand(String paramString);
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.commands.ECommandService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.e4.core.commands;

import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.e4.core.contexts.IEclipseContext;

public abstract interface EHandlerService
{
  public abstract IEclipseContext getContext();
  
  public abstract void activateHandler(String paramString, Object paramObject);
  
  public abstract void deactivateHandler(String paramString, Object paramObject);
  
  public abstract Object executeHandler(ParameterizedCommand paramParameterizedCommand);
  
  public abstract boolean canExecute(ParameterizedCommand paramParameterizedCommand);
  
  public abstract Object executeHandler(ParameterizedCommand paramParameterizedCommand, IEclipseContext paramIEclipseContext);
  
  public abstract boolean canExecute(ParameterizedCommand paramParameterizedCommand, IEclipseContext paramIEclipseContext);
}

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

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public static final String PLUGIN_ID = "org.eclipse.e4.core.commands";
  private static Activator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
  }
  
  public static Activator getDefault()
  {
    return plugin;
  }
}

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

import org.eclipse.core.commands.CommandManager;
import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class CommandServiceCreationFunction
  extends ContextFunction
{
  public static final String ROOT_CONTEXT = "rootContext";
  private CommandManager manager = null;
  private CommandServiceImpl service = null;
  
  public Object compute(IEclipseContext context)
  {
    if (service == null)
    {
      IEclipseContext root = getRootContext(context);
      manager = new CommandManager();
      root.set(CommandManager.class.getName(), manager);
      service = ((CommandServiceImpl)ContextInjectionFactory.make(CommandServiceImpl.class, root));
    }
    return service;
  }
  
  private IEclipseContext getRootContext(IEclipseContext context)
  {
    IEclipseContext current = (IEclipseContext)context.get("rootContext");
    if (current != null) {
      return current;
    }
    current = context;
    IEclipseContext parent = current.getParent();
    while (parent != null)
    {
      current = parent;
      parent = current.getParent();
    }
    if (current != null) {
      current.set("rootContext", current);
    }
    return current;
  }
}

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

import java.util.Map;
import javax.inject.Inject;
import org.eclipse.core.commands.Category;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.CommandManager;
import org.eclipse.core.commands.IParameter;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.e4.core.commands.ECommandService;

public class CommandServiceImpl
  implements ECommandService
{
  private CommandManager commandManager;
  
  @Inject
  public void setManager(CommandManager m)
  {
    commandManager = m;
  }
  
  public ParameterizedCommand createCommand(String id, Map parameters)
  {
    Command command = getCommand(id);
    if (command == null) {
      return null;
    }
    return ParameterizedCommand.generateCommand(command, parameters);
  }
  
  public Category defineCategory(String id, String name, String description)
  {
    Category cat = commandManager.getCategory(id);
    if (!cat.isDefined()) {
      cat.define(name, description);
    }
    return cat;
  }
  
  public Command defineCommand(String id, String name, String description, Category category, IParameter[] parameters)
  {
    Command cmd = commandManager.getCommand(id);
    if (!cmd.isDefined()) {
      cmd.define(name, description, category, parameters);
    }
    return cmd;
  }
  
  public Category getCategory(String categoryId)
  {
    return commandManager.getCategory(categoryId);
  }
  
  public Command getCommand(String commandId)
  {
    return commandManager.getCommand(commandId);
  }
}

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

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

public class HandlerServiceCreationFunction
  extends ContextFunction
{
  public Object compute(IEclipseContext context)
  {
    return ContextInjectionFactory.make(HandlerServiceImpl.class, context);
  }
}

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

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.log.Logger;

public class HandlerServiceImpl
  implements EHandlerService
{
  private static final String TMP_STATIC_CONTEXT = "tmp-staticContext";
  public static final String H_ID = "handler::";
  public static final String PARM_MAP = "parmMap::";
  public static final String CAN_EXECUTE = "HandlerServiceImpl.canExecute";
  public static final String NOT_HANDLED = "HandlerServiceImpl.notHandled";
  private IEclipseContext context;
  @Inject
  @Optional
  private Logger logger;
  
  public static Object lookUpHandler(IEclipseContext context, String commandId)
  {
    return context.getActiveLeaf().get("handler::" + commandId);
  }
  
  public static Object preExecute = null;
  
  public void activateHandler(String commandId, Object handler)
  {
    String handlerId = "handler::" + commandId;
    context.set(handlerId, handler);
  }
  
  private void addParms(ParameterizedCommand command, IEclipseContext staticContext)
  {
    Map parms = command.getParameterMap();
    Iterator i = parms.entrySet().iterator();
    while (i.hasNext())
    {
      Map.Entry entry = (Map.Entry)i.next();
      staticContext.set((String)entry.getKey(), entry.getValue());
    }
    staticContext.set("parmMap::", parms);
    staticContext.set(ParameterizedCommand.class, command);
  }
  
  public boolean canExecute(ParameterizedCommand command)
  {
    IEclipseContext staticContext = EclipseContextFactory.create("tmp-staticContext");
    try
    {
      return canExecute(command, staticContext);
    }
    finally
    {
      staticContext.dispose();
    }
  }
  
  public boolean canExecute(ParameterizedCommand command, IEclipseContext staticContext)
  {
    String commandId = command.getId();
    Object handler = lookUpHandler(context, commandId);
    if (handler == null) {
      return false;
    }
    IEclipseContext executionContext = getExecutionContext();
    addParms(command, staticContext);
    try
    {
      Boolean result = (Boolean)ContextInjectionFactory.invoke(handler, CanExecute.class, 
        executionContext, staticContext, Boolean.TRUE);
      staticContext.set("HandlerServiceImpl.canExecute", result);
      return result.booleanValue();
    }
    catch (Exception e)
    {
      if ((Command.DEBUG_HANDLERS) && (logger != null))
      {
        StringBuilder message = new StringBuilder();
        message.append("Handler (").append(handler).append(") ");
        message.append(" for command (").append(commandId).append(") ");
        message.append("threw unexpected exception");
        logger.trace(e, message.toString());
      }
    }
    return false;
  }
  
  public void deactivateHandler(String commandId, Object handler)
  {
    context.remove("handler::" + commandId);
  }
  
  public Object executeHandler(ParameterizedCommand command)
  {
    IEclipseContext staticContext = EclipseContextFactory.create("tmp-staticContext");
    try
    {
      return executeHandler(command, staticContext);
    }
    finally
    {
      staticContext.dispose();
    }
  }
  
  public Object executeHandler(ParameterizedCommand command, IEclipseContext staticContext)
  {
    String commandId = command.getId();
    IEclipseContext executionContext = getExecutionContext();
    addParms(command, staticContext);
    if (preExecute != null) {
      ContextInjectionFactory.invoke(preExecute, Execute.class, executionContext, 
        staticContext, null);
    }
    Object handler = lookUpHandler(context, commandId);
    if (handler == null)
    {
      staticContext.set("HandlerServiceImpl.notHandled", Boolean.TRUE);
      return null;
    }
    staticContext.remove("HandlerServiceImpl.notHandled");
    
    Object rc = ContextInjectionFactory.invoke(handler, CanExecute.class, executionContext, 
      staticContext, Boolean.TRUE);
    staticContext.set("HandlerServiceImpl.canExecute", rc);
    if (Boolean.FALSE.equals(rc)) {
      return null;
    }
    return ContextInjectionFactory.invoke(handler, Execute.class, executionContext, 
      staticContext, null);
  }
  
  @Inject
  public void setContext(IEclipseContext c)
  {
    context = c;
  }
  
  public IEclipseContext getContext()
  {
    return context;
  }
  
  public IEclipseContext getExecutionContext()
  {
    return context.getActiveLeaf();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.e4.core.commands.internal.HandlerServiceImpl
 * 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