org.eclipse.jface.bindings.keys.ParseException Java Examples

The following examples show how to use org.eclipse.jface.bindings.keys.ParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open the preferences dialog and return the corresponding shell. See also
 * {@link #pressOKishButtonInPreferences(SWTBot)} to close the dialog.
 *
 * @param bot
 *            a given workbench bot
 * @param text
 *            an alternative text for the preferences dialog, useful when a
 *            specific preference page was previously selected
 * @return the preferences shell
 */
public static SWTBotShell openPreferences(SWTBot bot, String text) {
    SWTBotShell mainShell = focusMainWindow(bot.shells());
    if (SWTUtils.isMac()) {
        // On Mac, the Preferences menu item is under the application name.
        // For some reason, we can't access the application menu anymore so
        // we use the keyboard shortcut.
        try {
            mainShell.pressShortcut(KeyStroke.getInstance(IKeyLookup.COMMAND_NAME + "+"), KeyStroke.getInstance(","));
        } catch (ParseException e) {
            fail();
        }
    } else {
        mainShell.bot().menu(WINDOW_MENU).menu(PREFERENCES_MENU_ITEM).click();
    }

    if (text != null) {
        return anyShellOf(bot, PREFERENCES_SHELL, text).activate();
    }
    return bot.shell(PREFERENCES_SHELL).activate();
}
 
Example #2
Source File: CommandDataDialog.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
private ContentProposalAdapter addContentAssistSimple(Text textControl) {
    char[] autoActivationCharacters = new char[] { '$', '{' };
    KeyStroke keyStroke = null;
    try {
        keyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // assume that myTextControl has already been created in some way
    List<Variable> variables = Variable.getVisibleVariables();
    String[] proposals = new String [variables.size()];
    for(int i=0;i<variables.size();i++) {
        proposals[i] = variables.get(i).getFullVariableName();
    }
    ContentProposalAdapter adapter = new ContentProposalAdapter(
            textControl , new TextContentAdapter(),
        new SimpleContentProposalProvider(proposals),
        keyStroke, autoActivationCharacters);
    adapter.setPropagateKeys(false);
    adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
    //adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return adapter;
}
 
Example #3
Source File: DBManagement.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public DatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		ts.menuDBManagement().click();
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new DatabaseManagementDialog(DatabaseManagementDialog.MANAGEMENT);
	return dialog;
}
 
Example #4
Source File: MemoryDBManagement.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public MemoryDatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		if (isMemory){
			ts.menuDBManagement().click();
		} else {
			ts.menuTeriDBManagement().click();
		}
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new MemoryDatabaseManagementDialog(MemoryDatabaseManagementDialog.MANAGEMENT,isMemory?"dlgTitleMemoryManagement":"dlgTitletreiTbManagement");
	return dialog;
}
 
Example #5
Source File: DBManagement.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public DatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		ts.menuDBManagement().click();
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new DatabaseManagementDialog(DatabaseManagementDialog.MANAGEMENT);
	return dialog;
}
 
Example #6
Source File: MemoryDBManagement.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param from
 *            入口,请使用 TSUIConstants 类中提供的枚举。
 * @return 打开的库管理对话框;
 */
public MemoryDatabaseManagementDialog openDBMgmgDialog(Entry from) {
	if (from.equals(TsUIConstants.Entry.MENU)) {
		if (isMemory){
			ts.menuDBManagement().click();
		} else {
			ts.menuTeriDBManagement().click();
		}
	} else if (from.equals(TsUIConstants.Entry.SHORTCUT)) {
		try {
			ts.pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), Keystrokes.SHIFT, KeyStroke.getInstance("D"));
		} catch (ParseException e) {
			e.printStackTrace();
			assertTrue("快捷键解析错误。", false);
		}
	} else {
		assertTrue("参数错误,该功能无此入口:" + from, false);
	}
	dialog = new MemoryDatabaseManagementDialog(MemoryDatabaseManagementDialog.MANAGEMENT,isMemory?"dlgTitleMemoryManagement":"dlgTitletreiTbManagement");
	return dialog;
}
 
Example #7
Source File: SarosView.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private void selectConnectAccount(String baseJID) throws RemoteException {
  SWTBotToolbarDropDownButton b = view.toolbarDropDownButton(TB_CONNECT);
  @SuppressWarnings("static-access")
  Matcher<MenuItem> withRegex = WidgetMatcherFactory.withRegex(Pattern.quote(baseJID) + ".*");
  b.menuItem(withRegex).click();
  try {
    b.pressShortcut(KeyStroke.getInstance("ESC"));
  } catch (ParseException e) {
    log.debug("", e);
  }
}
 
Example #8
Source File: KeyboardBindingsTask.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
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);
  }
}
 
Example #9
Source File: RemoteBotEditor.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void pressShortcut(String... keys) throws RemoteException {
  widget.setFocus();
  for (String key : keys) {
    try {
      widget.pressShortcut(KeyStroke.getInstance(key));
    } catch (ParseException e) {
      throw new RemoteException("could not parse \"" + key + "\"", e);
    }
  }
}
 
Example #10
Source File: InteractiveConsoleCommand.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isValid() {
    if (this.name != null && this.name.trim().length() > 0 && this.keybinding != null
            && this.keybinding.trim().length() > 0 && this.commandText != null) {
        //it may be valid, let's check if the keybinding actually resolves.
        try {
            KeyBindingHelper.getKeySequence(keybinding);
        } catch (IllegalArgumentException | ParseException e) {
            return false;
        }
        return true;
    }
    return false;
}
 
Example #11
Source File: DynamicInitializer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @throws ParseException
 */
public KeySequence getTrigger() throws ParseException {
	if (trigger == null) {
		trigger = KeySequence.getInstance(keyString);
	}
	return trigger;
}
 
Example #12
Source File: KbdMacroBindHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for C-x C-k <key> binding conflict
 * 
 * @param editor
 * @param c
 * @return IBindingResult with C-x C-k <key> information
 */
private IBindingResult getBinding(ITextEditor editor, char c) {
	IBindingResult result = null;
	try {
		final KeySequence sequence = KeySequence.getInstance(KeySequence.getInstance(STD_KBD_PREFIX), KeyStroke.getInstance(c));
		final Binding binding = checkForBinding(editor, sequence);
		result = new IBindingResult() {
			public Binding getKeyBinding() { return binding; }
			public String getKeyString() { return sequence.format(); }
			public KeySequence getTrigger() { return sequence; }
		};
	} catch (ParseException e) { }
	return result;
}
 
Example #13
Source File: ProjectCreate.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * 从指定的入口打开新建对话框
	 * @param from
	 * @throws ParseException
	 */
	public void openCreateProjectDialog(Entry from) {
		switch (from) {
		case MENU: {
			ts.menuFileNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
			break;
		}
		case SHORTCUT: {
			try {
				ProjectTreeView.getTree().pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), KeyStroke.getInstance("N"));
			} catch (ParseException e) {
				assertTrue("快捷键解析错误。", false);
			}
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
		case CONTEXT_MENU: {
			ProjectTreeView.getTree().contextMenu("新建记忆库...").click();
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
//		case CONTEXT_MENU_ALT: {
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
//			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
//			break;
//		}
		default: {
			assertTrue("参数错误:创建项目入口 from 不正确。", false);
		}
		}
		assertTrue(dialog.isActive());

		// 选择新建类型为 Project,下一步
//		dialog.treeiProject().select();
//		assertTrue(dialog.btnNext().isEnabled());
//		dialog.btnNext().click();
	}
 
Example #14
Source File: ProjectCreate.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * 从指定的入口打开新建对话框
	 * @param from
	 * @throws ParseException
	 */
	public void openCreateProjectDialog(Entry from) {
		switch (from) {
		case MENU: {
			ts.menuFileNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
			break;
		}
		case SHORTCUT: {
			try {
				ProjectTreeView.getTree().pressShortcut(SWTBotUtils.getCtrlOrCmdKey(), KeyStroke.getInstance("N"));
			} catch (ParseException e) {
				assertTrue("快捷键解析错误。", false);
			}
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
		case CONTEXT_MENU: {
			ProjectTreeView.getTree().contextMenu("新建记忆库...").click();
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
			dialog = new NewProjectDialog(FileNewDialog.NEW);
			break;
		}
//		case CONTEXT_MENU_ALT: {
//			ProjectTreeView.getInstance().ctxMenuNewProject().click();
//			dialog = new NewProjectDialog(FileNewDialog.NEW_TYPE_PROJECT);
//			break;
//		}
		default: {
			assertTrue("参数错误:创建项目入口 from 不正确。", false);
		}
		}
		assertTrue(dialog.isActive());

		// 选择新建类型为 Project,下一步
//		dialog.treeiProject().select();
//		assertTrue(dialog.btnNext().isEnabled());
//		dialog.btnNext().click();
	}
 
Example #15
Source File: KeyBindingUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getKeySequence
 * 
 * @return
 */
public static KeySequence[] getKeySequences(CommandElement command)
{
	String[] bindings = command.getKeyBindings();
	if (ArrayUtil.isEmpty(bindings))
	{
		return NO_BINDINGS;
	}

	List<KeySequence> result = new ArrayList<KeySequence>(bindings.length);
	for (String binding : bindings)
	{
		try
		{
			// Need to convert the format
			String normalizedKeyBinding = normalizeKeyBinding(binding);
			KeySequence sequence = KeySequence.getInstance(normalizedKeyBinding);

			result.add(sequence);
		}
		catch (ParseException e)
		{
			String message = MessageFormat.format(Messages.CommandElement_Invalid_Key_Binding, new Object[] {
					binding, command.getDisplayName(), command.getPath(), e.getMessage() });
			// Log to scripting console
			ScriptLogger.logError(message);
			IdeLog.logError(ScriptingUIPlugin.getDefault(), message);
		}
	}

	return result.toArray(new KeySequence[result.size()]);
}
 
Example #16
Source File: NpmInstallWidget.java    From typescript.java with MIT License 5 votes vote down vote up
private void addContentProposal(Text text) {
	char[] autoActivationCharacters = null;// new char[] { '.' };
	KeyStroke keyStroke = null;
	try {
		keyStroke = KeyStroke.getInstance("Ctrl+Space");
	} catch (ParseException e) {
		e.printStackTrace();
	}
	adapter = new VersionContentProposalAdapter(text, new TextContentAdapter(),
			new VersionContentProposalProvider(), keyStroke, autoActivationCharacters);
	adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
	adapter.setPropagateKeys(true);
	adapter.setLabelProvider(VersionLabelProvider.getInstance());

}
 
Example #17
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public static KeySequence getKeySequence(String text) throws ParseException, IllegalArgumentException {
    KeySequence keySequence = KeySequence.getInstance(KeyStroke.getInstance(text));
    return keySequence;
}