コード例 #1
0
  protected Component buildReportSelection() {
    FormLayout content = new FormLayout();
    content.setSpacing(true);
    // Create reporting selection
    reportSelection =
        ModelBasedFieldFactory.getInstance(entityModel, getMessageService())
            .createEnumCombo(reportDefinition.getClass(), ComboBox.class);
    reportSelection.setCaption(
        getMessageService()
            .getMessage(
                entityModel.getReference() + "." + reportDefinition.getClass().getSimpleName()));
    reportSelection.setNullSelectionAllowed(false);
    reportSelection.setRequired(true);
    reportSelection.select(reportSelection.getItemIds().iterator().next());
    reportSelection.setSizeFull();
    reportSelection.addValueChangeListener(
        new Property.ValueChangeListener() {
          private static final long serialVersionUID = -3358229370015557129L;

          @Override
          public void valueChange(Property.ValueChangeEvent event) {
            if (exportPDF != null) {
              exportPDF.setEnabled(false);
            }
          }
        });
    // Add combo
    content.addComponent(reportSelection);
    return content;
  }
コード例 #2
0
 @Override
 protected String getEnumName(Enum e) {
   String name = enumClassToNameMap.get(e.getClass());
   if (name == null) {
     throw new IllegalArgumentException("Enum class not known to factory:" + e.getClass());
   }
   return name;
 }
コード例 #3
0
 private String getMessageKey(Enum<?> enumInstance) {
   StringBuffer result = new StringBuffer();
   result.append(enumInstance.getClass().getSimpleName());
   result.append(".");
   result.append(enumInstance.name());
   return result.toString();
 }
コード例 #4
0
  private void addErrorUnsupported(Enum<?> val) {

    delim()
        .append(UNSUPPORTED)
        .append(val.toString())
        .append(Strings.TYPE)
        .append(val.getClass().getSimpleName());
  }
コード例 #5
0
ファイル: TableInspector.java プロジェクト: gitblit/iciql
 void addEnum(String parameter, Enum<?> value) {
   appendExceptFirst(", ");
   if (!StringUtils.isNullOrEmpty(parameter)) {
     append(parameter);
     append('=');
   }
   append(value.getClass().getSimpleName() + "." + value.name());
 }
コード例 #6
0
ファイル: DictionaryImpl.java プロジェクト: raffopazzo/Jamal
 @Override
 public String getLabel(Enum enumValue) {
   if (enumValue != null) {
     return getLabel(enumValue.getClass().getName() + "." + enumValue.toString());
   } else {
     return "";
   }
 }
コード例 #7
0
 /**
  * Helper method that can be used to dynamically figure out formal enumeration type (class) for
  * given enumeration. This is either class of enum instance (for "simple" enumerations), or its
  * superclass (for enums with instance fields or methods)
  */
 @SuppressWarnings("unchecked")
 public static Class<? extends Enum<?>> findEnumType(Enum<?> en) {
   // enums with "body" are sub-classes of the formal type
   Class<?> ec = en.getClass();
   if (ec.getSuperclass() != Enum.class) {
     ec = ec.getSuperclass();
   }
   return (Class<? extends Enum<?>>) ec;
 }
コード例 #8
0
 public void setContainer(Container container, boolean defineProperties) {
   this.container = container;
   if (defineProperties) {
     // Prepare the container by adding all properties needed for the reports
     for (ReportDefinition type :
         (ReportDefinition[]) reportDefinition.getClass().getEnumConstants()) {
       if (!type.requiresDatabaseConnection()) {
         JRUtils.addContainerPropertiesFromReport(
             container, reportGenerator.loadTemplate(getFullPath(type)));
       }
     }
   }
 }
コード例 #9
0
 public String apply(Enum<?> from) {
   Field field;
   try {
     field = SecureReflections.getField(from.getClass(), from.name());
   } catch (NoSuchFieldException e) {
     throw new IllegalArgumentException(
         "Cannot reflect on key to obtain @MessageId. Key: "
             + from
             + "; Key Type: "
             + from.getClass());
   }
   if (!field.isAnnotationPresent(MessageId.class)) {
     throw new IllegalArgumentException(
         "@MessageId must be present. Key: " + from + "; Key Type: " + from.getClass());
   }
   String messageId = field.getAnnotation(MessageId.class).value();
   return new StringBuilder()
       .append(subsystem)
       .append(SEPARATOR)
       .append(messageId)
       .append(" ")
       .toString();
 }
コード例 #10
0
 public static org.lgna.project.ast.JavaField getEnumConstantFieldIfOneAndOnly(
     org.lgna.project.ast.AbstractType<?, ?, ?> type) {
   org.lgna.project.ast.JavaField rv = null;
   if (type instanceof org.lgna.project.ast.JavaType) {
     org.lgna.project.ast.JavaType javaType = (org.lgna.project.ast.JavaType) type;
     if (type.isAssignableTo(Enum.class)) {
       Class<Enum<?>> cls = (Class<Enum<?>>) javaType.getClassReflectionProxy().getReification();
       Enum<?>[] constants = cls.getEnumConstants();
       if (constants.length == 1) {
         Enum<?> constant = constants[0];
         rv = org.lgna.project.ast.JavaField.getInstance(constant.getClass(), constant.name());
       }
     }
   }
   return rv;
 }
コード例 #11
0
 @SuppressWarnings("unchecked")
 @Override
 protected Enum createEnum(String name, String value) {
   Class enumClass = nameToEnumClassMap.get(name);
   if (enumClass == null) {
     throw new IllegalArgumentException("Enum name not known to factory:" + name);
   }
   Set<Enum> enums = valueToEnumMap.get(value);
   if (enums == null) {
     return Enum.valueOf(enumClass, value);
   }
   for (Enum e : enums) {
     if (e.getClass() == enumClass) {
       return e;
     }
   }
   throw new IllegalArgumentException("Enum value not known to factory:" + value);
 }
コード例 #12
0
  public static Enum<?> setUpEnumAttribute(Scanner scan, Attributes.AttributeEnum attribute) {
    int num;
    Attributes.printEnumNValuesOfEnumAttribute(attribute);
    num =
        makeSureValInRange(
                scan,
                1,
                Attributes.getEnumAttrValues(attribute).length,
                attribute.toString(),
                ValType.INTEGER,
                true,
                true)
            .intValue();

    Enum<?> attr = Attributes.getEnumAttrByVal(num, attribute);
    System.out.println(
        inputString(attr.getClass().getSimpleName(), attr.toString(), StringOption.SELECTED, true));
    return attr;
  }
コード例 #13
0
 public static String getEnumValue(Enum enumWithValue) {
   Class<?> type = enumWithValue.getClass();
   Field[] fields = type.getDeclaredFields();
   Field field;
   switch (fields.length) {
     case 0:
       return enumWithValue.toString();
     case 1:
       field = fields[0];
       break;
     default:
       try {
         field = type.getField("value");
       } catch (NoSuchFieldException ex) {
         return enumWithValue.toString();
       }
       break;
   }
   return TryCatchUtil.tryGetResult(() -> field.get(enumWithValue).toString());
 }
コード例 #14
0
ファイル: JsonDataSource.java プロジェクト: celavek/iosched
 private String getKeyProperty(JsonObject obj) {
   JsonElement idEl = obj.get("id");
   if (idEl == null) {
     // reflection is not efficient in general, but the overhead should be insignificant
     // compared to the usual times taken to load a datasource (either from HTTP, disk or
     // cloud storage)
     Method m;
     try {
       m = sourceType.getClass().getMethod("getKey");
       if (m != null) {
         return (String) m.invoke(sourceType);
       }
     } catch (Exception e) {
       throw new IllegalArgumentException(
           "Error! Cannot add JsonArray of type "
               + sourceType.name()
               + " because there is no property \"id\" in the JsonArray element "
               + "nor a static getKey() method in the enum.",
           e);
     }
   }
   return "id";
 }
コード例 #15
0
 /**
  * Decorate an enum to provide i18n display string. By default, the resource key is the enum class
  * name if namePrefix is not provided.
  *
  * @param value
  * @param namePrefix
  */
 public EnumOption(Enum value, String namePrefix) {
   this.id = value.name();
   name =
       getDisplayValue(
           id, StringUtils.defaultString(namePrefix, value.getClass().getSimpleName()));
 }
コード例 #16
0
 private static Map<String, Object> adapt(Enum<?> e) {
   Map<String, Object> result = new TreeMap<String, Object>();
   result.put("enum", e.getClass().getName());
   result.put("value", e.name());
   return result;
 }
コード例 #17
0
 private String getCounterKey(Enum key) {
   return key.getClass().getName() + ":" + key.name();
 }
コード例 #18
0
ファイル: I18NKey.java プロジェクト: kidaak/krail
 /**
  * returns a full string representation of an I18NKey enum constant (for example
  * uk.q3c.krail.i18n.LabelKey.Yes)
  *
  * @param key
  * @return
  */
 static String fullName(I18NKey key) {
   Enum e = (Enum) key;
   return e.getClass().getName() + "." + e.name();
 }
コード例 #19
0
ファイル: EnumHelper.java プロジェクト: phlocbg/phloc-commons
 /**
  * Get the unique name of the passed enum entry.
  *
  * @param aEnum The enum to use. May not be <code>null</code>.
  * @return The unique ID as a combination of the class name and the enum entry name. Never <code>
  *     null</code>.
  */
 @Nonnull
 public static String getEnumID(@Nonnull final Enum<?> aEnum) {
   // No explicit null check, because this method is used heavily in pdaf
   // locale resolving, so we want to spare some CPU cycles :)
   return aEnum.getClass().getName() + '.' + aEnum.name();
 }
コード例 #20
0
ファイル: Messages.java プロジェクト: Teiid-Designer/komodo
 /**
  * @param enumValue the value
  * @return the name
  */
 public static String getEnumName(Enum<?> enumValue) {
   String className = enumValue.getClass().getName();
   String[] components = className.split("\\$"); // $NON-NLS-1$
   return components[components.length - 1];
 }
コード例 #21
0
 protected Expression instantiate(Object oldInstance, Encoder out) {
   Enum<?> e = (Enum<?>) oldInstance;
   return new Expression(e, e.getClass(), "valueOf", new Object[] {e.name()});
 }