Java源码示例:org.eclipse.jface.bindings.Scheme

示例1
private EvaluationResult doEvaluate(
    final KbaChangeSet changeSet) {

  final KeyBindings bindings = new KeyBindings(bindingService.getBindings());

  final Scheme scheme = bindingService.getScheme(changeSet.getSchemeId());

  switch (changeSet.getAction()) {
  case ADD:
    modifyBindingsForAddChangeSet(changeSet, bindings, scheme);
    break;
  case REMOVE:
    modifyBindingsForRemoveChangeSet(changeSet, bindings, scheme);
    break;
  default:
    throw new UnsupportedOperationException();  
  }

  return new EvaluationResult(scheme, bindings);
}
 
示例2
private static String getKeyboardShortcut(ParameterizedCommand command) {
	IBindingService bindingService= (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
	fgLocalBindingManager.setBindings(bindingService.getBindings());
	try {
		Scheme activeScheme= bindingService.getActiveScheme();
		if (activeScheme != null)
			fgLocalBindingManager.setActiveScheme(activeScheme);
	} catch (NotDefinedException e) {
		JavaPlugin.log(e);
	}

	TriggerSequence[] bindings= fgLocalBindingManager.getActiveBindingsDisregardingContextFor(command);
	if (bindings.length > 0)
		return bindings[0].format();
	return null;
}
 
示例3
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
示例4
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
示例5
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
示例6
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
示例7
private static BindingManager loadModelBackend(IServiceLocator locator) {
	IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class);
	BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager());
	final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
	try {
		Scheme modelActiveScheme = null;
		for (int i = 0; i < definedSchemes.length; i++) {
			final Scheme scheme = definedSchemes[i];
			final Scheme copy = bindingManager.getScheme(scheme.getId());
			copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
			if (definedSchemes[i] == bindingService.getActiveScheme()) {
				modelActiveScheme = copy;
			}
		}
		bindingManager.setActiveScheme(modelActiveScheme);
	} catch (final NotDefinedException e) {
		StatusManager.getManager()
				.handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
						"Keys page found an undefined scheme", e)); //$NON-NLS-1$
	}
	bindingManager.setLocale(bindingService.getLocale());
	bindingManager.setPlatform(bindingService.getPlatform());
	bindingManager.setBindings(bindingService.getBindings());
	return bindingManager;
}
 
示例8
/**
 * Sets the bindings to default.
 * @param bindingService
 * @throws NotDefinedException
 */
public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException {
	// Fix the scheme in the local changes.
	final String defaultSchemeId = bindingService.getDefaultSchemeId();
	final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId);
	try {
		fBindingManager.setActiveScheme(defaultScheme);
	} catch (final NotDefinedException e) {
		// At least we tried....
	}

	// Restore any User defined bindings
	Binding[] bindings = fBindingManager.getBindings();
	for (int i = 0; i < bindings.length; i++) {
		ParameterizedCommand pCommand = bindings[i].getParameterizedCommand();
		String commandId = null;
		if (pCommand != null) {
			commandId = pCommand.getCommand().getId();
		}
		if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) {
			fBindingManager.removeBinding(bindings[i]);
		}
	}
	bindingModel.refresh(contextModel, lstRemove);
	saveBindings(bindingService);
}
 
示例9
public void earlyStartup() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	workbench.getDisplay().asyncExec(new Runnable() {
		
		public void run() {
			// 在工作台初始化后,移除平台默认的 scheme
			IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);
			
			Scheme[] schemes = bindingService.getDefinedSchemes();
			for (int i = 0; i < schemes.length; i++) {
				String id = schemes[i].getId();
				if (id.equals(platformDefaultScheme) || id.equals(platformEmacsScheme)) {
					schemes[i].undefine();
				}
			}
		}
	});
}
 
示例10
/**
 * Bind a scheme / platform / context / trigger sequence to a command.
 */
public void addIfNotPresent(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    ParameterizedCommand command) {
  Map<String,String> params = commandParamMap(command);
  Binding binding = find(scheme, platform, triggerSequence, command.getId(), params);
  // If no binding exists, create the user binding, add it and return true.
  if (binding == null) {
    Binding bindingToAdd = createBinding(scheme, platform, contextId, triggerSequence, command);
    addUserBinding(bindingToAdd);
    addedBindings.add(bindingToAdd);
    return;
  }

  /*
   * If a system binding exists for this scheme / sequence, find out if there's a
   * user binding hiding it, and if so remove it.
   */
  if ((binding.getType() == Binding.SYSTEM)) {
    // Finding a user binding to a null command.
    // ZORZELLA: do we even need to supply params?
    Binding userBinding = find(scheme, platform, triggerSequence, null, params, userBindings);
    if (userBinding != null) {
      userBindings.remove(userBinding);
      return;
    }
  }
  return;
}
 
示例11
/**
 * Remove a binding.
 */
public void removeBindingIfPresent(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    Command command,
    Map<String, String> params) {

  Binding binding = find(scheme, platform, triggerSequence, command.getId(), params, userBindings);

  if (binding != null) {
    userBindings.remove(binding);
    removedBindings.add(binding);
    return;
  }

  binding = find(scheme, platform, triggerSequence, command.getId(), params, systemBindings);
  if (binding != null) {
    if (find(scheme, platform, triggerSequence, null, params, userBindings) == null) {
      Binding bindingToRemoveWithNullCommand = createBinding(scheme, platform, contextId, triggerSequence, null);
      // Removing a system binding means creating a weird system binding with
      // a null command
      addUserBinding(bindingToRemoveWithNullCommand);
      removedBindings.add(binding);
      return;
    }
  }
  return;
}
 
示例12
private Binding find(
    Scheme scheme,
    String platform,
    KeySequence triggerSequence,
    String cid,
    Map<String, String> params) {
  Binding userBinding = find(scheme, platform, triggerSequence, cid, params, userBindings);
  if (userBinding != null) {
    return userBinding;
  }
  return find(scheme, platform, triggerSequence, cid, params, systemBindings);
}
 
示例13
/**
 * Finds a binding in {@code list} that matches the given
 * {@code triggerSequence}, {@code scheme} and {@code cid}. If not found,
 * return {@code null}.
 */
private static Binding find(
    Scheme scheme,
    String platform,
    KeySequence triggerSequence,
    String cid,
    Map<String,String> params,
    List<Binding> list) {
  for (Binding binding : list) {
    if (binding.getSchemeId().equals(scheme.getId())
      && (binding.getTriggerSequence().equals(triggerSequence))
      && Objects.equal(binding.getPlatform(),  platform)) {
        ParameterizedCommand param = binding.getParameterizedCommand();
        if (param == null) {
          if (cid == null) {
            return binding;
          }
          continue;
        }
        Command command = param.getCommand();
        if (cid == null) {
          return command == null ? binding : null;
        }
        if (cid.equals(command.getId())) {
          Map<String,String> temp = commandParamMap(param);
          if (equalMaps(temp, params)) {
            return binding;
          }
        }
      }
  }
  return null;
}
 
示例14
private Binding createBinding(
    Scheme scheme,
    String platform,
    String contextId,
    KeySequence triggerSequence,
    ParameterizedCommand parameterizedCommand) {

  Binding newBinding =
      new KeyBinding(triggerSequence, parameterizedCommand, scheme.getId(),
          contextId, null, platform, null, Binding.USER);

  return newBinding;
}
 
示例15
private void modifyBindingsForAddChangeSet(final KbaChangeSet changeSet,
    final KeyBindings bindings, final Scheme scheme) {
  for (KbaBinding toAdd : changeSet.getBindingList()) {
    Command commandToAdd = commandService.getCommand(toAdd.getCid());
    if (!commandToAdd.isDefined()) {
      log.logWarning("Command '" + toAdd.getCid() + "' does not exist. Skipping.");
      continue;
    }
    ParameterizedCommand parameterizedCommandToAdd =
        ParameterizedCommand.generateCommand(commandToAdd, toAdd.getParameters());

    KeySequence triggerSequence;
    try {
      triggerSequence = KeySequence.getInstance(toAdd.getKeySequence());
    } catch (ParseException e) {
      log.logError(e, "Invalid key sequence: %s", toAdd.getKeySequence());
      throw new RuntimeException(e);
    }

    bindings.addIfNotPresent(
        scheme, 
        changeSet.getPlatform(), 
        changeSet.getContextId(), 
        triggerSequence,
        parameterizedCommandToAdd);
  }
}
 
示例16
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
示例17
public void earlyStartup() {
	IWorkbench workbench = PlatformUI.getWorkbench();
	// 在工作台初始化后,移除平台默认的 scheme
	IBindingService bindingService = (IBindingService) workbench.getService(IBindingService.class);

	Scheme[] schemes = bindingService.getDefinedSchemes();
	for (int i = 0; i < schemes.length; i++) {
		String id = schemes[i].getId();
		if (id.equals(platformDefaultScheme) || id.equals(platformEmacsScheme)) {
			schemes[i].undefine();
		}
	}
}
 
示例18
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
示例19
/**
 * @param oldScheme
 * @param newScheme
 */
protected void changeScheme(SchemeElement oldScheme, SchemeElement newScheme) {
	if (newScheme == null || newScheme.getModelObject() == fBindingManager.getActiveScheme()) {
		return;
	}
	try {
		fBindingManager.setActiveScheme((Scheme) newScheme.getModelObject());
		bindingModel.refresh(contextModel);
		bindingModel.setSelectedElement(null);
	} catch (NotDefinedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
示例20
/**
 * @param force if true, we'll create the user binding regardless of having some existing binding. Otherwise,
 * we'll not allow the creation if a binding already exists for it.
 *
 * Note: conflicting bindings should be removed before (through removeUserBindingsWithFilter). If they're
 * not removed, a conflict will be created in the bindings.
 */
public void addUserBindings(KeySequence keySequence, ParameterizedCommand command) throws Exception {
    Scheme activeScheme = bindingService.getActiveScheme();
    String schemeId = activeScheme.getId();

    localChangeManager.addBinding(new KeyBinding(keySequence, command,
            schemeId, contextId, null, null, null, Binding.USER));

}
 
示例21
public EvaluationResult(
    final Scheme scheme,
    final KeyBindings keyBindings) {
  this.scheme = scheme;
  this.keyBindings = keyBindings;
}
 
示例22
/**
 * @param contextId defines the keys context we'll work with...
 *
 * We'll only remove/add bindings to this context.
 */
public BindKeysHelper(String contextId) {
    Assert.isNotNull(contextId);
    this.contextId = contextId;

    // Set the context we're working with.
    Set<String> activeContextIds = new HashSet<>();
    activeContextIds.add(contextId);
    contextManager.setActiveContextIds(activeContextIds);

    // Check that the context we're working with actually exists
    IWorkbench workbench = PlatformUI.getWorkbench();
    bindingService = (IBindingService) workbench.getService(IBindingService.class);
    IContextService contextService = (IContextService) workbench.getService(IContextService.class);
    Context context = contextService.getContext(contextId);
    if (context == null || context.isDefined() == false) {
        throw new RuntimeException("The context: " + contextId + " does not exist.");
    }

    Scheme activeScheme = bindingService.getActiveScheme();
    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();

    // Make a copy we can work with locally (we'll apply changes later based on this copy).
    try {
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = localChangeManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        localChangeManager.setActiveScheme(activeScheme);
    } catch (final NotDefinedException e) {
        throw new Error("There is a programmer error in the bind keys helper"); //$NON-NLS-1$
    }
    localChangeManager.setLocale(bindingService.getLocale());
    localChangeManager.setPlatform(bindingService.getPlatform());
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        initialState.add(binding);
    }
    localChangeManager.setBindings(bindings);
}