/** * getActionId * * @param beanType presenters bean type to create an action for * @param packedInList whether it is a bean instance or a bean container * @param actionName simple action name * @return full action id */ public static final String getActionId(Class<?> beanType, boolean packedInList, String actionName) { final String type = BeanClass.getName(beanType).toLowerCase() + (packedInList ? Messages.getString("tsl2nano.list") .toLowerCase() : ""); return type + "." + actionName.toLowerCase(); }
/** * constructor * * @param method */ public MethodAction(Method method) { super(createId(method), createName(method), Messages.getStringOpt(method.toGenericString())); setMethod(method); String imagePath = getId() + ".icon"; if (Messages.hasKey(imagePath)) { setImagePath(Messages.getString(imagePath)); } else { setImagePath(DEFAULT_ICON); } }
/** * provides a map containing all formatted single value attributes of the given bean * * @param bean bean to evaluate * @param keyPrefix (optional) key name prefix (normally ending with a dot) * @param translateKeys if true, all keys will be translated * @param filterAttributes attributes to be filtered (ignored) * @param format formatter (use {@link DefaultFormat} if unknown) * @return map containing formatted values */ public static Map<String, Object> toFormattedMap(Object bean, String keyPrefix, boolean translateKeys, Format format, String... filterAttributes) { final Map<String, Object> valueMap = keyPrefix != null ? BeanUtil.toValueMap(bean, keyPrefix, true, filterAttributes) : BeanUtil.toValueMap(bean, true, true, false, filterAttributes); final Set<String> keySet = valueMap.keySet(); final Map<String, Object> formattedMap = new LinkedHashMap<String, Object>(); for (final String k : keySet) { final String key = translateKeys ? Messages.getString(k) : k; formattedMap.put(key, format.format(valueMap.get(k))); } return formattedMap; }
/** * checkPrincipal, throws SecurityException if not * * @param principal principal */ public void checkPrincipal(Principal principal) { if (!hasPrincipal(principal)) { final String msg = Messages.getFormattedString(Messages.getString("tsl2nano.login.noprincipal"), new Object[] { getUser(), principal.getName() }); throw new SecurityException(msg); } }
/** * will search for the actionId in the resource bundle - then in tsl2nano base bundle - if not found, the action * simple name will be returned * * @param actionId full action id * @param actionSimpleName simple action name * @param if true, the tooltip for the action will be evaluated * @return text to show on action */ public static final String getActionText(String actionId, boolean tooltip) { final String tooltip_postfix = (tooltip ? Messages.POSTFIX_TOOLTIP : ""); final String actionSimpleName = actionId.substring(actionId.lastIndexOf(".") + 1); String text = Messages.getString(actionId + tooltip_postfix); if (Messages.unknown(text)) { text = Messages.getString("tsl2nano." + actionSimpleName + tooltip_postfix); if (Messages.unknown(text)) { return StringUtil.toFirstUpper(actionSimpleName); } else if (tooltip) { return ""; } else { return text; } } return text; }
@Override public Object action() throws Exception { //TODO: fire refresh event getBeanFinder().reset(); if (!isStaticCollection && collection != null) { collection.clear(); } setSelected(); searchStatus = isStaticCollection || !hasMode(MODE_SEARCHABLE) ? "" : Messages .getString("tsl2nano.searchdialog.nosearch"); return null; }
/** * creates a save action for the given bean. the action-id will be 'bean.getClass().save' - that will be used as * permission id, too. * * @param bean bean to save * @param actionId action id (important for user permissions!) */ protected SecureAction<T> createSaveAction(final Object bean, String actionId) { final String saveLabel = BeanContainer.isInitialized() && BeanContainer.instance().isPersistable(getDefiningClass(clazz)) && !CompositionFactory.contains(bean) ? Messages .getString("tsl2nano.save") : Messages.getString("tsl2nano.assign"); return new SaveAction(bean, actionId, saveLabel, saveLabel, IAction.MODE_DLG_OK); }