protected RadioMenuItem getMenuItemFor(int dataIndex) { if (dataIndex < 0) return null; int loopIndex = dataIndex; while (loopIndex < popup.getItems().size()) { MenuItem item = popup.getItems().get(loopIndex); ObservableMap<Object, Object> properties = item.getProperties(); Object object = properties.get("data-index"); if ((object instanceof Integer) && dataIndex == (Integer) object) { return item instanceof RadioMenuItem ? (RadioMenuItem)item : null; } loopIndex++; } return null; }
/** * Finds out if a {@code default value} has been registered with the target {@code Node}, returning the value if found. * * @param node the target node on which the value may have been registered. * * @return the value registered with the target {@code Node} or {@code null} if not found. * * @since 2.9.0 */ @Nullable public static String getI18nDefaultValue(@Nonnull MenuItem node) { requireNonNull(node, ERROR_NODE_NULL); return (String) node.getProperties().get(MessageSource.class.getName() + SUFFIX_DEFAULT_VALUE); }
/** * Associates an default value {@code node}. * The value will be used alongside a key to resolve a message via the application's {@code MessageSource}. * * @param node the target node on which the key will be registered. * @param defaultValue the value to be registered. * * @since 2.9.0 */ public static void setI18nDefaultValue(@Nonnull MenuItem node, @Nullable String defaultValue) { requireNonNull(node, ERROR_NODE_NULL); node.getProperties().put(MessageSource.class.getName() + SUFFIX_DEFAULT_VALUE, defaultValue); }
/** * Finds out if an {@code Action} has been registered with the target {@code MenuItem}, returning the action id if found. * * @param menuItem the target menuItem on which the action may have been registered. * * @return the name of the action registered with the target {@code MenuItem} or {@code null} if not found. * * @since 2.8.0 */ @Nullable public static String getGriffonActionId(@Nonnull MenuItem menuItem) { requireNonNull(menuItem, ERROR_NODE_NULL); return (String) menuItem.getProperties().get(Action.class.getName()); }
/** * Finds out if an {@code arguments array} has been registered with the target {@code Node}, returning the array if found. * * @param node the target node on which the arguments may have been registered. * * @return the arguments registered with the target {@code Node} or {@code null} if not found. * * @since 2.9.0 */ @Nullable public static String getI18nArgs(@Nonnull MenuItem node) { requireNonNull(node, ERROR_NODE_NULL); return (String) node.getProperties().get(MessageSource.class.getName() + SUFFIX_ARGS); }
/** * Finds out if an i18n {@code key} has been registered with the target {@code Node}, returning the key if found. * * @param node the target node on which the key may have been registered. * * @return the key registered with the target {@code Node} or {@code null} if not found. * * @since 2.9.0 */ @Nullable public static String getI18nKey(@Nonnull MenuItem node) { requireNonNull(node, ERROR_NODE_NULL); return (String) node.getProperties().get(MessageSource.class.getName() + SUFFIX_KEY); }
/** * Associates an i18n key to a {@code node}. The key is used to resolve a message via the application's {@code MessageSource}. * * @param node the target node on which the key will be registered. * @param key the message key to be registered. * * @since 2.9.0 */ public static void setI18nKey(@Nonnull MenuItem node, @Nonnull String key) { requireNonNull(node, ERROR_NODE_NULL); requireNonBlank(key, ERROR_KEY_BLANK); node.getProperties().put(MessageSource.class.getName() + SUFFIX_KEY, key); }
/** * Associates an i18n arrays of arguments to a {@code node}. * These arguments will be used alongside a key to resolve a message via the application's {@code MessageSource}. * * @param node the target node on which the key will be registered. * @param args the array of arguments to be registered. * * @since 2.9.0 */ public static void setI18nArgs(@Nonnull MenuItem node, @Nullable String args) { requireNonNull(node, ERROR_NODE_NULL); requireNonBlank(args, ERROR_ARGS_BLANK); node.getProperties().put(MessageSource.class.getName() + SUFFIX_ARGS, args); }
/** * Associates a {@code Action} with a target {@code MenuItem}. * * @param menuItem the target menuItem on which the action will be registered. * @param actionId the id of the action to be registered. * * @since 2.8.0 */ public static void setGriffonActionId(@Nonnull MenuItem menuItem, @Nonnull String actionId) { requireNonNull(menuItem, ERROR_NODE_NULL); requireNonBlank(actionId, ERROR_ID_BLANK); menuItem.getProperties().put(Action.class.getName(), actionId); }
@Override public void onChanged(MapChangeListener.Change<?, ?> change) { T menuItem = menuItemWeakReference.get(); if (menuItem == null) { action.getProperties().removeListener(this); } else { menuItem.getProperties().clear(); menuItem.getProperties().putAll(action.getProperties()); } }
menuItem.getProperties().putAll(action.getProperties()); action.getProperties().addListener(new MenuItemPropertiesMapChangeListener<>(menuItem, action));