@Override public final void categoryChanged(CategoryEvent categoryEvent) { if (categoryEvent.isDefinedChanged()) { final Category category = categoryEvent.getCategory(); final String categoryId = category.getId(); final boolean categoryIdAdded = category.isDefined(); if (categoryIdAdded) { definedCategoryIds.add(categoryId); } else { definedCategoryIds.remove(categoryId); } if (isListenerAttached()) { fireCommandManagerChanged(new CommandManagerEvent(this, null, false, false, categoryId, categoryIdAdded, true)); } } }
/** * Gets the category with the given identifier. If no such category * currently exists, then the category will be created (but be undefined). * * @param categoryId * The identifier to find; must not be <code>null</code>. If * the category is <code>null</code>, then a category suitable * for uncategorized items is defined and returned. * @return The category with the given identifier; this value will never be * <code>null</code>, but it might be undefined. * @see Category */ public Category getCategory(final String categoryId) { if (categoryId == null) { return getCategory(AUTOGENERATED_CATEGORY_ID); } checkId(categoryId); Category category = categoriesById.get(categoryId); if (category == null) { category = new Category(categoryId); categoriesById.put(categoryId, category); category.addCategoryListener(this); } return category; }
protected static String getText(Object obj) { if (obj instanceof Command) { Command com = (Command) obj; try { return com.getName(); } catch (NotDefinedException e) { return com.getId(); } } else if (obj instanceof Category) { Category cat = (Category) obj; try { return cat.getName(); } catch (NotDefinedException e) { return cat.getId(); } } return ""; //$NON-NLS-1$ }
/** * @param commandManager */ private void generateCategories(MApplication application, CommandManager commandManager) { for (Category cat : commandManager.getDefinedCategories()) { if (categories.containsKey(cat.getId())) { continue; } try { MCategory catModel = modelService.createModelElement(MCategory.class); catModel.setElementId(cat.getId()); catModel.setName(cat.getName()); catModel.setDescription(cat.getDescription()); application.getCategories().add(catModel); categories.put(catModel.getElementId(), catModel); } catch (NotDefinedException e) { // Since we asked for defined commands, this shouldn't be an // issue WorkbenchPlugin.log(e); } } }
@Override public String getCategoryId() throws NotDefinedException { try { return command.getCategory().getId(); } catch (final org.eclipse.core.commands.common.NotDefinedException e) { throw new NotDefinedException(e); } }
/** * Sets the name and description of the category for uncategorized commands. * This is the category that will be returned if * {@link #getCategory(String)} is called with <code>null</code>. * * @param name * The name of the category for uncategorized commands; must not * be <code>null</code>. * @param description * The description of the category for uncategorized commands; * may be <code>null</code>. * @since 3.2 */ public final void defineUncategorizedCategory(final String name, final String description) { final Category category = getCategory(AUTOGENERATED_CATEGORY_ID); category.define(name, description); }
@Override public void undefine() { string = null; final boolean definedChanged = defined; defined = false; final boolean nameChanged = name != null; name = null; final boolean descriptionChanged = description != null; description = null; fireCategoryChanged(new CategoryEvent(this, definedChanged, descriptionChanged, nameChanged)); }
if (!category.isDefined()) { addWarning( warningsToLog,
buffer.newLine(); buffer.write("\t\t"); //$NON-NLS-1$ buffer.write(category==null?"":category.toString()); //$NON-NLS-1$ buffer.write(','); buffer.newLine();
try { commandName = command.getName(); categoryName = command.getCommand().getCategory().getName(); } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
String categoryId = command.getCategory().getId(); Collection commandIds = (Collection) commandIdsByCategoryId .get(categoryId); if (commandIdsByCategoryId.containsKey(category.getId())) { String name = category.getName(); Collection categories = (Collection) categoriesByName .get(name); categoryIdsByUniqueName.put(name, category.getId()); categoryUniqueNamesById.put(category.getId(), name); } else { while (iterator2.hasNext()) { Util.translateString(RESOURCE_BUNDLE, "uniqueName"), new Object[] { name, //$NON-NLS-1$ category.getId() }); categoryIdsByUniqueName.put(uniqueName, category .getId()); categoryUniqueNamesById.put(category.getId(), uniqueName);
final MCategory categoryModel = categories.get(cmd.getCategory().getId());
/** * Sets the name and description of the category for uncategorized commands. * This is the category that will be returned if * {@link #getCategory(String)} is called with <code>null</code>. * * @param name * The name of the category for uncategorized commands; must not * be <code>null</code>. * @param description * The description of the category for uncategorized commands; * may be <code>null</code>. * @since 3.2 */ public void defineUncategorizedCategory(final String name, final String description) { final Category category = getCategory(AUTOGENERATED_CATEGORY_ID); category.define(name, description); }
@Override public void undefine() { string = null; final boolean definedChanged = defined; defined = false; final boolean nameChanged = name != null; name = null; final boolean descriptionChanged = description != null; description = null; fireCategoryChanged(new CategoryEvent(this, definedChanged, descriptionChanged, nameChanged)); }
buffer.newLine(); buffer.write("\t\t"); //$NON-NLS-1$ buffer.write(category==null?"":category.toString()); //$NON-NLS-1$ buffer.write(','); buffer.newLine();
/** * @param bindingCommand */ private void setCommandInfo(ParameterizedCommand bindingCommand) { setId(bindingCommand.getId()); try { setName(bindingCommand.getName()); } catch (NotDefinedException e) { setName(NewKeysPreferenceMessages.Undefined_Command); } try { setDescription(bindingCommand.getCommand().getDescription()); } catch (NotDefinedException e) { setDescription(Util.ZERO_LENGTH_STRING); } try { setCategory(bindingCommand.getCommand().getCategory().getName()); } catch (NotDefinedException e) { setCategory(NewKeysPreferenceMessages.Unavailable_Category); } setConflict(Boolean.FALSE); }
@Override public void categoryChanged(CategoryEvent categoryEvent) { if (categoryEvent.isDefinedChanged()) { final Category category = categoryEvent.getCategory(); final String categoryId = category.getId(); final boolean categoryIdAdded = category.isDefined(); if (categoryIdAdded) { definedCategoryIds.add(categoryId); } else { definedCategoryIds.remove(categoryId); } if (isListenerAttached()) { fireCommandManagerChanged(new CommandManagerEvent(this, null, false, false, categoryId, categoryIdAdded, true)); } } }
@SuppressWarnings("restriction") @Override public void commandManagerChanged(CommandManagerEvent commandManagerEvent) { if (commandManagerEvent.isCommandChanged()) { if (commandManagerEvent.isCommandDefined()) { final String commandId = commandManagerEvent.getCommandId(); if (findCommand(commandId) != null) { return; } final Command command = commandManagerEvent.getCommandManager().getCommand( commandId); if (command.getHandler() == null) { command.setHandler(HandlerServiceImpl.getHandler(commandId)); } try { MCategory categoryModel = findCategory(command.getCategory().getId()); final MCommand createdCommand = createCommand(command, modelService, categoryModel); application.getCommands().add(createdCommand); } catch (NotDefinedException e) { Activator.getDefault().getLogService() .log(0, "Failed to create command " + commandId, e); //$NON-NLS-1$ } } } } };