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

16:42:57.844 INFO  jd.cli.Main - Decompiling org.eclipse.e4.ui.bindings_0.10.3.v20130123-162658.jar
package org.eclipse.e4.ui.bindings;

import javax.annotation.PostConstruct;
import org.eclipse.core.commands.contexts.ContextManager;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.bindings.internal.BindingServiceCreationFunction;
import org.eclipse.e4.ui.bindings.internal.BindingTableManager;
import org.eclipse.e4.ui.bindings.internal.ContextSet;
import org.eclipse.e4.ui.bindings.internal.ContextSet.CComp;

public class BindingServiceAddon
{
  @PostConstruct
  public void init(IEclipseContext context)
  {
    ContextManager contextManager = (ContextManager)context.get(ContextManager.class);
    ContextSet.setComparator(new ContextSet.CComp(contextManager));
    
    context.set(BindingTableManager.class, 
      (BindingTableManager)ContextInjectionFactory.make(BindingTableManager.class, context));
    
    context.set(EBindingService.class.getName(), new BindingServiceCreationFunction());
  }
}

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

import java.util.Collection;
import java.util.Map;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.TriggerSequence;

public abstract interface EBindingService
{
  public static final String DIALOG_CONTEXT_ID = "org.eclipse.ui.contexts.dialog";
  public static final String DEFAULT_SCHEME_ID = "org.eclipse.ui.defaultAcceleratorConfiguration";
  public static final String MODEL_TO_BINDING_KEY = "binding";
  public static final String ACTIVE_SCHEME_TAG = "activeSchemeId";
  public static final String SCHEME_ID_ATTR_TAG = "schemeId";
  public static final String LOCALE_ATTR_TAG = "locale";
  public static final String PLATFORM_ATTR_TAG = "platform";
  public static final String TYPE_ATTR_TAG = "type";
  public static final String DELETED_BINDING_TAG = "deleted";
  
  public abstract Binding createBinding(TriggerSequence paramTriggerSequence, ParameterizedCommand paramParameterizedCommand, String paramString, Map<String, String> paramMap);
  
  public abstract void activateBinding(Binding paramBinding);
  
  public abstract void deactivateBinding(Binding paramBinding);
  
  public abstract TriggerSequence createSequence(String paramString);
  
  public abstract Collection<Binding> getConflictsFor(TriggerSequence paramTriggerSequence);
  
  public abstract Collection<Binding> getAllConflicts();
  
  public abstract Binding getPerfectMatch(TriggerSequence paramTriggerSequence);
  
  public abstract boolean isPartialMatch(TriggerSequence paramTriggerSequence);
  
  public abstract boolean isPerfectMatch(TriggerSequence paramTriggerSequence);
  
  public abstract TriggerSequence getBestSequenceFor(ParameterizedCommand paramParameterizedCommand);
  
  public abstract Collection<TriggerSequence> getSequencesFor(ParameterizedCommand paramParameterizedCommand);
  
  public abstract Collection<Binding> getPartialMatches(TriggerSequence paramTriggerSequence);
  
  public abstract Collection<Binding> getActiveBindings();
  
  public abstract Collection<Binding> getBindingsFor(ParameterizedCommand paramParameterizedCommand);
}

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

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

public class Activator
  implements BundleActivator
{
  private static Activator plugin = null;
  
  public static Activator getDefault()
  {
    return plugin;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
  }
}

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

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

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

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.core.commands.ParameterizedCommand;
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.core.di.annotations.Optional;
import org.eclipse.e4.ui.bindings.EBindingService;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.KeyBinding;
import org.eclipse.jface.bindings.keys.KeySequence;
import org.eclipse.jface.bindings.keys.ParseException;

public class BindingServiceImpl
  implements EBindingService
{
  static final String ACTIVE_CONTEXTS = "activeContexts";
  static final String USER_TYPE = "user";
  @Inject
  private IEclipseContext context;
  @Inject
  private BindingTableManager manager;
  @Inject
  private ContextManager contextManager;
  private ContextSet contextSet = ContextSet.EMPTY;
  
  public Binding createBinding(TriggerSequence sequence, ParameterizedCommand command, String contextId, Map<String, String> attributes)
  {
    String schemeId = "org.eclipse.ui.defaultAcceleratorConfiguration";
    String locale = null;
    String platform = null;
    int bindingType = 0;
    if ((sequence != null) && (!sequence.isEmpty()) && (contextId != null))
    {
      if (attributes != null)
      {
        String tmp = (String)attributes.get("schemeId");
        if ((tmp != null) && (tmp.length() > 0)) {
          schemeId = tmp;
        }
        locale = (String)attributes.get("locale");
        platform = (String)attributes.get("platform");
        if ("user".equals(attributes.get("type"))) {
          bindingType = 1;
        }
      }
      return new KeyBinding((KeySequence)sequence, command, schemeId, contextId, locale, 
        platform, null, bindingType);
    }
    return null;
  }
  
  public void activateBinding(Binding binding)
  {
    String contextId = binding.getContextId();
    BindingTable table = manager.getTable(contextId);
    if (table == null) {
      return;
    }
    table.addBinding(binding);
  }
  
  public void deactivateBinding(Binding binding)
  {
    String contextId = binding.getContextId();
    BindingTable table = manager.getTable(contextId);
    if (table == null) {
      return;
    }
    table.removeBinding(binding);
  }
  
  public TriggerSequence createSequence(String sequence)
  {
    try
    {
      return KeySequence.getInstance(sequence);
    }
    catch (ParseException localParseException) {}
    return null;
  }
  
  public Collection<Binding> getConflictsFor(TriggerSequence sequence)
  {
    return manager.getConflictsFor(contextSet, sequence);
  }
  
  public Collection<Binding> getAllConflicts()
  {
    return manager.getAllConflicts();
  }
  
  public Binding getPerfectMatch(TriggerSequence trigger)
  {
    return manager.getPerfectMatch(contextSet, trigger);
  }
  
  public boolean isPartialMatch(TriggerSequence keySequence)
  {
    return manager.isPartialMatch(contextSet, keySequence);
  }
  
  public TriggerSequence getBestSequenceFor(ParameterizedCommand command)
  {
    Binding binding = manager.getBestSequenceFor(contextSet, command);
    return binding == null ? null : binding.getTriggerSequence();
  }
  
  public Collection<TriggerSequence> getSequencesFor(ParameterizedCommand command)
  {
    Collection<Binding> bindings = manager.getSequencesFor(contextSet, command);
    ArrayList<TriggerSequence> sequences = new ArrayList(bindings.size());
    for (Binding binding : bindings) {
      sequences.add(binding.getTriggerSequence());
    }
    return sequences;
  }
  
  public Collection<Binding> getBindingsFor(ParameterizedCommand command)
  {
    return manager.getBindingsFor(contextSet, command);
  }
  
  public boolean isPerfectMatch(TriggerSequence sequence)
  {
    return getPerfectMatch(sequence) != null;
  }
  
  public Collection<Binding> getPartialMatches(TriggerSequence sequence)
  {
    return manager.getPartialMatches(contextSet, sequence);
  }
  
  public IEclipseContext getContext()
  {
    return context;
  }
  
  @Inject
  public void setContextIds(@Named("activeContexts") @Optional Set<String> set)
  {
    if ((set == null) || (set.isEmpty()) || (contextManager == null))
    {
      contextSet = ContextSet.EMPTY;
      return;
    }
    ArrayList<Context> contexts = new ArrayList();
    for (String id : set) {
      contexts.add(contextManager.getContext(id));
    }
    contextSet = manager.createContextSet(contexts);
  }
  
  public Collection<Binding> getActiveBindings()
  {
    return manager.getActiveBindings();
  }
}

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

import java.util.Comparator;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.Trigger;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.IKeyLookup;
import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.jface.bindings.keys.KeyStroke;

class BindingTable$BindingComparator
  implements Comparator<Binding>
{
  private String[] activeSchemeIds;
  
  private final int compareSchemes(String schemeId1, String schemeId2)
  {
    if ((activeSchemeIds == null) || (activeSchemeIds.length == 0)) {
      return 0;
    }
    if (!schemeId2.equals(schemeId1)) {
      for (int i = 0; i < activeSchemeIds.length; i++)
      {
        String schemePointer = activeSchemeIds[i];
        if (schemeId2.equals(schemePointer)) {
          return 1;
        }
        if (schemeId1.equals(schemePointer)) {
          return -1;
        }
      }
    }
    return 0;
  }
  
  public void setActiveSchemes(String[] activeSchemeIds)
  {
    this.activeSchemeIds = activeSchemeIds;
  }
  
  public int compare(Binding o1, Binding o2)
  {
    int rc = compareSchemes(o1.getSchemeId(), o2.getSchemeId());
    if (rc != 0) {
      return rc;
    }
    Trigger[] bestTriggers = o1.getTriggerSequence().getTriggers();
    Trigger[] currentTriggers = o2.getTriggerSequence().getTriggers();
    int compareTo = bestTriggers.length - currentTriggers.length;
    if (compareTo != 0) {
      return compareTo;
    }
    compareTo = countStrokes(bestTriggers) - countStrokes(currentTriggers);
    if (compareTo != 0) {
      return compareTo;
    }
    return o1.getTriggerSequence().format().length() - 
      o2.getTriggerSequence().format().length();
  }
  
  private final int countStrokes(Trigger[] triggers)
  {
    int strokeCount = triggers.length;
    for (int i = 0; i < triggers.length; i++)
    {
      Trigger trigger = triggers[i];
      if ((trigger instanceof KeyStroke))
      {
        KeyStroke keyStroke = (KeyStroke)trigger;
        int modifierKeys = keyStroke.getModifierKeys();
        IKeyLookup lookup = KeyLookupFactory.getDefault();
        if ((modifierKeys & lookup.getAlt()) != 0) {
          strokeCount += 8;
        }
        if ((modifierKeys & lookup.getCtrl()) != 0) {
          strokeCount += 2;
        }
        if ((modifierKeys & lookup.getShift()) != 0) {
          strokeCount += 4;
        }
        if ((modifierKeys & lookup.getCommand()) != 0) {
          strokeCount += 2;
        }
      }
      else
      {
        strokeCount += 99;
      }
    }
    return strokeCount;
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.Trigger;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.IKeyLookup;
import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.jface.bindings.keys.KeyStroke;

public class BindingTable
{
  static class BindingComparator
    implements Comparator<Binding>
  {
    private String[] activeSchemeIds;
    
    private final int compareSchemes(String schemeId1, String schemeId2)
    {
      if ((activeSchemeIds == null) || (activeSchemeIds.length == 0)) {
        return 0;
      }
      if (!schemeId2.equals(schemeId1)) {
        for (int i = 0; i < activeSchemeIds.length; i++)
        {
          String schemePointer = activeSchemeIds[i];
          if (schemeId2.equals(schemePointer)) {
            return 1;
          }
          if (schemeId1.equals(schemePointer)) {
            return -1;
          }
        }
      }
      return 0;
    }
    
    public void setActiveSchemes(String[] activeSchemeIds)
    {
      this.activeSchemeIds = activeSchemeIds;
    }
    
    public int compare(Binding o1, Binding o2)
    {
      int rc = compareSchemes(o1.getSchemeId(), o2.getSchemeId());
      if (rc != 0) {
        return rc;
      }
      Trigger[] bestTriggers = o1.getTriggerSequence().getTriggers();
      Trigger[] currentTriggers = o2.getTriggerSequence().getTriggers();
      int compareTo = bestTriggers.length - currentTriggers.length;
      if (compareTo != 0) {
        return compareTo;
      }
      compareTo = countStrokes(bestTriggers) - countStrokes(currentTriggers);
      if (compareTo != 0) {
        return compareTo;
      }
      return o1.getTriggerSequence().format().length() - 
        o2.getTriggerSequence().format().length();
    }
    
    private final int countStrokes(Trigger[] triggers)
    {
      int strokeCount = triggers.length;
      for (int i = 0; i < triggers.length; i++)
      {
        Trigger trigger = triggers[i];
        if ((trigger instanceof KeyStroke))
        {
          KeyStroke keyStroke = (KeyStroke)trigger;
          int modifierKeys = keyStroke.getModifierKeys();
          IKeyLookup lookup = KeyLookupFactory.getDefault();
          if ((modifierKeys & lookup.getAlt()) != 0) {
            strokeCount += 8;
          }
          if ((modifierKeys & lookup.getCtrl()) != 0) {
            strokeCount += 2;
          }
          if ((modifierKeys & lookup.getShift()) != 0) {
            strokeCount += 4;
          }
          if ((modifierKeys & lookup.getCommand()) != 0) {
            strokeCount += 2;
          }
        }
        else
        {
          strokeCount += 99;
        }
      }
      return strokeCount;
    }
  }
  
  public static final BindingComparator BEST_SEQUENCE = new BindingComparator();
  private Context tableId;
  private ArrayList<Binding> bindings = new ArrayList();
  private Map<TriggerSequence, Binding> bindingsByTrigger = new HashMap();
  private Map<ParameterizedCommand, ArrayList<Binding>> bindingsByCommand = new HashMap();
  private Map<TriggerSequence, ArrayList<Binding>> bindingsByPrefix = new HashMap();
  private Map<TriggerSequence, ArrayList<Binding>> conflicts = new HashMap();
  
  public BindingTable(Context context)
  {
    tableId = context;
  }
  
  public Context getTableId()
  {
    return tableId;
  }
  
  public String getId()
  {
    return tableId.getId();
  }
  
  public Collection<Binding> getConflicts()
  {
    Collection<Binding> conflictsList = new ArrayList();
    for (TriggerSequence key : conflicts.keySet())
    {
      ArrayList<Binding> conflictsForTrigger = (ArrayList)conflicts.get(key);
      if (conflictsForTrigger != null) {
        conflictsList.addAll(conflictsForTrigger);
      }
    }
    return conflictsList;
  }
  
  public Collection<Binding> getConflictsFor(TriggerSequence triggerSequence)
  {
    return (Collection)conflicts.get(triggerSequence);
  }
  
  public void addBinding(Binding binding)
  {
    if (!getId().equals(binding.getContextId())) {
      throw new IllegalArgumentException("Binding context " + binding.getContextId() + 
        " does not match " + getId());
    }
    boolean isConflict = false;
    if (bindingsByTrigger.containsKey(binding.getTriggerSequence()))
    {
      Binding conflict = (Binding)bindingsByTrigger.get(binding.getTriggerSequence());
      removeBinding(conflict);
      ArrayList<Binding> conflictsList = new ArrayList();
      conflictsList.add(conflict);
      conflicts.put(binding.getTriggerSequence(), conflictsList);
      isConflict = true;
    }
    if ((conflicts.containsKey(binding.getTriggerSequence())) && 
      (((ArrayList)conflicts.get(binding.getTriggerSequence())).size() > 0))
    {
      ArrayList<Binding> conflictsList = (ArrayList)conflicts.get(binding.getTriggerSequence());
      if (!conflictsList.contains(binding)) {
        conflictsList.add(binding);
      }
      isConflict = true;
    }
    if (!isConflict)
    {
      this.bindings.add(binding);
      bindingsByTrigger.put(binding.getTriggerSequence(), binding);
      
      ArrayList<Binding> sequences = (ArrayList)bindingsByCommand.get(binding.getParameterizedCommand());
      if (sequences == null)
      {
        sequences = new ArrayList();
        bindingsByCommand.put(binding.getParameterizedCommand(), sequences);
      }
      sequences.add(binding);
      Collections.sort(sequences, BEST_SEQUENCE);
      
      TriggerSequence[] prefs = binding.getTriggerSequence().getPrefixes();
      for (int i = 1; i < prefs.length; i++)
      {
        ArrayList<Binding> bindings = (ArrayList)bindingsByPrefix.get(prefs[i]);
        if (bindings == null)
        {
          bindings = new ArrayList();
          bindingsByPrefix.put(prefs[i], bindings);
        }
        bindings.add(binding);
      }
    }
  }
  
  public void removeBinding(Binding binding)
  {
    if (!getId().equals(binding.getContextId())) {
      throw new IllegalArgumentException("Binding context " + binding.getContextId() + 
        " does not match " + getId());
    }
    ArrayList<Binding> conflictBindings = (ArrayList)conflicts.get(binding.getTriggerSequence());
    if ((!bindingsByTrigger.containsKey(binding.getTriggerSequence())) && 
      (conflictBindings != null))
    {
      conflictBindings.remove(binding);
      if (conflictBindings.size() == 1)
      {
        Binding bindingToReAdd = (Binding)conflictBindings.remove(0);
        addBinding(bindingToReAdd);
      }
    }
    else
    {
      this.bindings.remove(binding);
      bindingsByTrigger.remove(binding.getTriggerSequence());
      ArrayList<Binding> sequences = (ArrayList)bindingsByCommand.get(binding.getParameterizedCommand());
      if (sequences != null) {
        sequences.remove(binding);
      }
      TriggerSequence[] prefs = binding.getTriggerSequence().getPrefixes();
      for (int i = 1; i < prefs.length; i++)
      {
        ArrayList<Binding> bindings = (ArrayList)bindingsByPrefix.get(prefs[i]);
        bindings.remove(binding);
      }
    }
  }
  
  public Binding getPerfectMatch(TriggerSequence trigger)
  {
    return (Binding)bindingsByTrigger.get(trigger);
  }
  
  public Binding getBestSequenceFor(ParameterizedCommand command)
  {
    ArrayList<Binding> sequences = (ArrayList)bindingsByCommand.get(command);
    if ((sequences != null) && (sequences.size() > 0)) {
      return (Binding)sequences.get(0);
    }
    return null;
  }
  
  public Collection<Binding> getSequencesFor(ParameterizedCommand command)
  {
    ArrayList<Binding> triggers = (ArrayList)bindingsByCommand.get(command);
    return (Collection)(triggers == null ? Collections.EMPTY_LIST : triggers.clone());
  }
  
  public Collection<Binding> getPartialMatches(TriggerSequence sequence)
  {
    return (Collection)bindingsByPrefix.get(sequence);
  }
  
  public boolean isPartialMatch(TriggerSequence seq)
  {
    return bindingsByPrefix.get(seq) != null;
  }
  
  public Collection<Binding> getBindings()
  {
    return Collections.unmodifiableCollection(bindings);
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import javax.inject.Inject;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.TriggerSequence;

public class BindingTableManager
{
  private static final String BINDING_TABLE_PREFIX = "bindingTable:";
  @Inject
  private IEclipseContext eclipseContext;
  private ContextSet definedTables = ContextSet.EMPTY;
  private String[] activeSchemeIds;
  
  public void addTable(BindingTable table)
  {
    String contextId = getTableId(table.getId());
    if (eclipseContext.containsKey(contextId)) {
      return;
    }
    eclipseContext.set(contextId, table);
    List<Context> contexts = definedTables.getContexts();
    if (!contexts.contains(table.getTableId()))
    {
      contexts.add(table.getTableId());
      definedTables = createContextSet(contexts);
    }
  }
  
  private String getTableId(String id)
  {
    return "bindingTable:" + id;
  }
  
  public void removeTable(BindingTable table)
  {
    String contextId = getTableId(table.getId());
    if (!eclipseContext.containsKey(contextId)) {
      throw new IllegalArgumentException("Does not contains table " + contextId);
    }
    eclipseContext.remove(contextId);
    List<Context> contexts = definedTables.getContexts();
    if (contexts.contains(table.getTableId()))
    {
      contexts.remove(table.getTableId());
      definedTables = createContextSet(contexts);
    }
  }
  
  public BindingTable getTable(String id)
  {
    return (BindingTable)eclipseContext.get(getTableId(id));
  }
  
  public Collection<Binding> getActiveBindings()
  {
    ArrayList<Binding> bindings = new ArrayList();
    for (Context ctx : definedTables.getContexts())
    {
      BindingTable table = getTable(ctx.getId());
      if (table != null) {
        bindings.addAll(table.getBindings());
      }
    }
    return bindings;
  }
  
  public ContextSet createContextSet(Collection<Context> contexts)
  {
    return new ContextSet(contexts);
  }
  
  public Collection<Binding> getConflictsFor(ContextSet contextSet, TriggerSequence triggerSequence)
  {
    Collection<Binding> matches = new ArrayList();
    for (Context ctx : contextSet.getContexts())
    {
      BindingTable table = getTable(ctx.getId());
      if (table != null)
      {
        Collection<Binding> matchesFor = table.getConflictsFor(triggerSequence);
        if (matchesFor != null) {
          matches.addAll(matchesFor);
        }
      }
    }
    return matches.size() == 0 ? null : matches;
  }
  
  public Collection<Binding> getAllConflicts()
  {
    Collection<Binding> conflictsList = new ArrayList();
    for (Context ctx : definedTables.getContexts())
    {
      BindingTable table = getTable(ctx.getId());
      if (table != null)
      {
        Collection<Binding> conflictsInTable = table.getConflicts();
        if (conflictsInTable != null) {
          conflictsList.addAll(conflictsInTable);
        }
      }
    }
    return conflictsList;
  }
  
  public Binding getPerfectMatch(ContextSet contextSet, TriggerSequence triggerSequence)
  {
    Binding result = null;
    Binding currentResult = null;
    List<Context> contexts = contextSet.getContexts();
    ListIterator<Context> it = contexts.listIterator(contexts.size());
    while (it.hasPrevious())
    {
      Context c = (Context)it.previous();
      BindingTable table = getTable(c.getId());
      if (table != null) {
        currentResult = table.getPerfectMatch(triggerSequence);
      }
      if (currentResult != null)
      {
        if (isMostActiveScheme(currentResult)) {
          return currentResult;
        }
        if (result == null)
        {
          result = currentResult;
        }
        else
        {
          int rc = compareSchemes(result.getSchemeId(), currentResult.getSchemeId());
          if (rc < 0) {
            result = currentResult;
          }
        }
      }
    }
    return result;
  }
  
  private boolean isMostActiveScheme(Binding currentResult)
  {
    if ((activeSchemeIds == null) || (activeSchemeIds.length < 2)) {
      return true;
    }
    String mostActive = activeSchemeIds[0];
    return mostActive == null ? false : mostActive.equals(currentResult.getSchemeId());
  }
  
  public Binding getBestSequenceFor(ContextSet contextSet, ParameterizedCommand parameterizedCommand)
  {
    ArrayList<Binding> bindings = (ArrayList)getSequencesFor(contextSet, 
      parameterizedCommand);
    if (bindings.size() == 0) {
      return null;
    }
    return (Binding)bindings.get(0);
  }
  
  public Collection<Binding> getSequencesFor(ContextSet contextSet, ParameterizedCommand parameterizedCommand)
  {
    ArrayList<Binding> bindings = new ArrayList();
    List<Context> contexts = contextSet.getContexts();
    ListIterator<Context> it = contexts.listIterator(contexts.size());
    while (it.hasPrevious())
    {
      Context c = (Context)it.previous();
      BindingTable table = getTable(c.getId());
      if (table != null)
      {
        Collection<Binding> sequences = table.getSequencesFor(parameterizedCommand);
        if (sequences != null) {
          bindings.addAll(sequences);
        }
      }
    }
    Collections.sort(bindings, BindingTable.BEST_SEQUENCE);
    return bindings;
  }
  
  public Collection<Binding> getBindingsFor(ContextSet contextSet, ParameterizedCommand cmd)
  {
    Collection<Binding> bindings = new ArrayList();
    for (Context ctx : contextSet.getContexts())
    {
      BindingTable table = getTable(ctx.getId());
      if (table != null)
      {
        Collection<Binding> matches = table.getSequencesFor(cmd);
        if (matches != null) {
          bindings.addAll(matches);
        }
      }
    }
    return bindings;
  }
  
  public boolean isPartialMatch(ContextSet contextSet, TriggerSequence sequence)
  {
    List<Context> contexts = contextSet.getContexts();
    ListIterator<Context> it = contexts.listIterator(contexts.size());
    while (it.hasPrevious())
    {
      Context c = (Context)it.previous();
      BindingTable table = getTable(c.getId());
      if ((table != null) && 
        (table.isPartialMatch(sequence))) {
        return true;
      }
    }
    return false;
  }
  
  public Collection<Binding> getPartialMatches(ContextSet contextSet, TriggerSequence sequence)
  {
    ArrayList<Binding> bindings = new ArrayList();
    List<Context> contexts = contextSet.getContexts();
    ListIterator<Context> it = contexts.listIterator(contexts.size());
    while (it.hasPrevious())
    {
      Context c = (Context)it.previous();
      BindingTable table = getTable(c.getId());
      if (table != null)
      {
        Collection<Binding> partialMatches = table.getPartialMatches(sequence);
        if (partialMatches != null) {
          bindings.addAll(partialMatches);
        }
      }
    }
    return bindings;
  }
  
  public void setActiveSchemes(String[] activeSchemeIds)
  {
    this.activeSchemeIds = activeSchemeIds;
    BindingTable.BEST_SEQUENCE.setActiveSchemes(activeSchemeIds);
  }
  
  private final int compareSchemes(String schemeId1, String schemeId2)
  {
    if (activeSchemeIds == null) {
      return 0;
    }
    if (!schemeId2.equals(schemeId1)) {
      for (int i = 0; i < activeSchemeIds.length; i++)
      {
        String schemePointer = activeSchemeIds[i];
        if (schemeId2.equals(schemePointer)) {
          return 1;
        }
        if (schemeId1.equals(schemePointer)) {
          return -1;
        }
      }
    }
    return 0;
  }
}

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

import java.util.Comparator;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.core.commands.contexts.ContextManager;

public class ContextSet$CComp
  implements Comparator<Context>
{
  private ContextManager manager;
  
  public ContextSet$CComp(ContextManager manager)
  {
    this.manager = manager;
  }
  
  public int compare(Context o1, Context o2)
  {
    if (o1.equals(o2)) {
      return 0;
    }
    int l1 = getLevel(o1);
    int l2 = getLevel(o2);
    if (l1 != l2) {
      return l1 - l2;
    }
    return o1.getId().compareTo(o2.getId());
  }
  
  private int getLevel(Context c)
  {
    int l = 0;
    try
    {
      String parentId = c.getParentId();
      while (parentId != null)
      {
        l++;
        Context context = manager.getContext(parentId);
        parentId = context.getParentId();
      }
    }
    catch (NotDefinedException e)
    {
      e.printStackTrace();
    }
    return l;
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.core.commands.contexts.ContextManager;

public class ContextSet
{
  public static ContextSet EMPTY = new ContextSet(Collections.EMPTY_LIST);
  
  public static class CComp
    implements Comparator<Context>
  {
    private ContextManager manager;
    
    public CComp(ContextManager manager)
    {
      this.manager = manager;
    }
    
    public int compare(Context o1, Context o2)
    {
      if (o1.equals(o2)) {
        return 0;
      }
      int l1 = getLevel(o1);
      int l2 = getLevel(o2);
      if (l1 != l2) {
        return l1 - l2;
      }
      return o1.getId().compareTo(o2.getId());
    }
    
    private int getLevel(Context c)
    {
      int l = 0;
      try
      {
        String parentId = c.getParentId();
        while (parentId != null)
        {
          l++;
          Context context = manager.getContext(parentId);
          parentId = context.getParentId();
        }
      }
      catch (NotDefinedException e)
      {
        e.printStackTrace();
      }
      return l;
    }
  }
  
  private static Comparator<Context> CONTEXT_COMP = null;
  private List<Context> contexts;
  
  public static void setComparator(Comparator<Context> comp)
  {
    CONTEXT_COMP = comp;
  }
  
  public static Comparator<Context> getComparator()
  {
    return CONTEXT_COMP;
  }
  
  public ContextSet(Collection<Context> c)
  {
    contexts = new ArrayList(c);
    Collections.sort(contexts, CONTEXT_COMP);
  }
  
  public List<Context> getContexts()
  {
    return contexts;
  }
  
  public boolean equals(Object o)
  {
    if (o == this) {
      return true;
    }
    if (!(o instanceof ContextSet)) {
      return false;
    }
    return contexts.equals(contexts);
  }
  
  public int hashCode()
  {
    return contexts.hashCode();
  }
}

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

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

class KeyAssistDialog$1
  implements Listener
{
  KeyAssistDialog$1(KeyAssistDialog paramKeyAssistDialog) {}
  
  public void handleEvent(Event event)
  {
    KeyAssistDialog.access$0(this$0, event);
  }
}

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

import java.util.Comparator;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.jface.bindings.Binding;

class KeyAssistDialog$2
  implements Comparator<Binding>
{
  KeyAssistDialog$2(KeyAssistDialog paramKeyAssistDialog) {}
  
  public int compare(Binding binding1, Binding binding2)
  {
    ParameterizedCommand cmdA = binding1.getParameterizedCommand();
    ParameterizedCommand cmdB = binding2.getParameterizedCommand();
    int result = 0;
    try
    {
      result = cmdA.getName().compareTo(cmdB.getName());
    }
    catch (NotDefinedException localNotDefinedException) {}
    return result;
  }
}

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

import java.util.Comparator;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.jface.bindings.Binding;

class KeyAssistDialog$3
  implements Comparator<Binding>
{
  KeyAssistDialog$3(KeyAssistDialog paramKeyAssistDialog) {}
  
  public int compare(Binding a, Binding b)
  {
    Binding bindingA = a;
    Binding bindingB = b;
    ParameterizedCommand commandA = bindingA.getParameterizedCommand();
    ParameterizedCommand commandB = bindingB.getParameterizedCommand();
    try
    {
      return commandA.getName().compareTo(commandB.getName());
    }
    catch (NotDefinedException localNotDefinedException) {}
    return 0;
  }
}

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

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.CommandException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.bindings.EBindingService;
import org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class KeyAssistDialog
  extends PopupDialog
{
  private static final String BINDING_KEY = "Binding.bindings.jface.eclipse.org";
  private static final int NO_REMEMBERED_WIDTH = -1;
  private List<Binding> bindings = new ArrayList();
  private Table completionsTable = null;
  private int previousWidth = -1;
  private KeyBindingDispatcher workbenchKeyboard;
  private Collection<Binding> matches;
  private IEclipseContext context;
  
  public KeyAssistDialog(IEclipseContext context, KeyBindingDispatcher associatedKeyboard)
  {
    super(null, 4, true, false, false, false, null, null);
    
    this.context = context;
    workbenchKeyboard = associatedKeyboard;
  }
  
  public void clearRememberedState()
  {
    previousWidth = -1;
  }
  
  public boolean close()
  {
    return close(false);
  }
  
  public boolean close(boolean rememberState)
  {
    return close(rememberState, true);
  }
  
  private boolean close(boolean rememberState, boolean resetState)
  {
    Shell shell = getShell();
    if (rememberState)
    {
      int widthToRemember;
      int widthToRemember;
      if ((shell != null) && (!shell.isDisposed())) {
        widthToRemember = getShellgetSizex;
      } else {
        widthToRemember = -1;
      }
      previousWidth = widthToRemember;
      completionsTable = null;
    }
    matches = null;
    return super.close();
  }
  
  private void configureLocation(Point size)
  {
    Shell shell = getShell();
    
    Shell workbenchWindowShell = (Shell)shell.getParent();
    int yCoord;
    int xCoord;
    int yCoord;
    if (workbenchWindowShell != null)
    {
      Rectangle workbenchWindowBounds = workbenchWindowShell.getBounds();
      int xCoord = x + width - x - 10;
      yCoord = y + height - y - 10;
    }
    else
    {
      xCoord = 0;
      yCoord = 0;
    }
    Rectangle bounds = new Rectangle(xCoord, yCoord, x, y);
    shell.setBounds(getConstrainedShellBounds(bounds));
  }
  
  private Point configureSize()
  {
    Shell shell = getShell();
    
    shell.pack();
    Point size = shell.getSize();
    if ((previousWidth != -1) && (previousWidth > x)) {
      x = previousWidth;
    }
    Shell workbenchWindowShell = (Shell)shell.getParent();
    if (workbenchWindowShell != null)
    {
      Point workbenchWindowSize = workbenchWindowShell.getSize();
      int maxWidth = x * 2 / 5;
      int maxHeight = y / 2;
      if (x > maxWidth) {
        x = maxWidth;
      }
      if (y > maxHeight) {
        y = maxHeight;
      }
    }
    shell.setSize(size);
    return size;
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite composite = new Composite(parent, 0);
    GridLayout compositeLayout = new GridLayout();
    marginHeight = 0;
    marginWidth = 0;
    composite.setLayout(compositeLayout);
    composite.setLayoutData(new GridData(1808));
    composite.setBackground(parent.getBackground());
    Collection<Binding> bindings;
    Collection<Binding> bindings;
    if (matches != null) {
      bindings = matches;
    } else {
      bindings = getActiveBindings();
    }
    if ((bindings == null) || (bindings.isEmpty())) {
      createEmptyDialogArea(composite);
    } else {
      createTableDialogArea(composite, bindings);
    }
    return composite;
  }
  
  private void createEmptyDialogArea(Composite parent)
  {
    Label noMatchesLabel = new Label(parent, 0);
    noMatchesLabel.setText("No matches");
    noMatchesLabel.setLayoutData(new GridData(1808));
    noMatchesLabel.setBackground(parent.getBackground());
  }
  
  private void createTableDialogArea(Composite parent, Collection<Binding> partialMatches)
  {
    completionsTable = new Table(parent, 65540);
    GridData gridData = new GridData(1808);
    completionsTable.setLayoutData(gridData);
    completionsTable.setBackground(parent.getBackground());
    completionsTable.setLinesVisible(true);
    
    bindings.clear();
    TableCol
1 2

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