Пример #1
0
  /** @param control control that may fill vertically */
  protected boolean willFillVertically(Control control, Map<String, String> attributes) {

    if (attributes != null && TRUE.equals(attributes.get(LARGE))) {
      return true;
    }

    return false;
  }
Пример #2
0
  protected String layoutBeforeChild(
      Control control,
      String labelText,
      String elementName,
      Map<String, String> attributes,
      Composite composite,
      SwtMetawidget metawidget) {

    // Add label

    if (SimpleLayoutUtils.needsLabel(labelText, elementName)) {
      Label label = new Label(composite, SWT.None);
      label.setData(NAME, attributes.get(NAME) + LABEL_NAME_SUFFIX);

      if (mLabelFont != null) {
        label.setFont(mLabelFont);
      }

      if (mLabelForeground != null) {
        label.setForeground(mLabelForeground);
      }

      label.setAlignment(mLabelAlignment);

      // Required

      String labelTextToUse = labelText;

      if (mRequiredText != null
          && TRUE.equals(attributes.get(REQUIRED))
          && !WidgetBuilderUtils.isReadOnly(attributes)
          && !metawidget.isReadOnly()) {
        if (mRequiredAlignment == SWT.CENTER) {
          labelTextToUse += mRequiredText;
        } else if (mRequiredAlignment == SWT.LEFT) {
          labelTextToUse = mRequiredText + labelTextToUse;
        }
      }

      if (mLabelSuffix != null) {
        labelTextToUse += mLabelSuffix;
      }

      label.setText(labelTextToUse);

      GridData labelLayoutData = new GridData();
      labelLayoutData.horizontalAlignment = SWT.FILL;
      labelLayoutData.verticalAlignment = SWT.FILL;

      label.setLayoutData(labelLayoutData);
      label.moveAbove(control);
    }

    return labelText;
  }
  public StaticXmlWidget processWidget(
      StaticXmlWidget widget,
      String elementName,
      Map<String, String> attributes,
      StaticXmlMetawidget metawidget) {

    if (TRUE.equals(attributes.get(REQUIRED))) {
      widget.putAttribute(REQUIRED, TRUE);
    }

    return widget;
  }
  public UIComponent buildWidget(
      String elementName, Map<String, String> attributes, UIMetawidget metawidget) {

    // Not for Tomahawk?

    if (TRUE.equals(attributes.get(HIDDEN))) {
      return null;
    }

    if (attributes.containsKey(FACES_LOOKUP) || attributes.containsKey(LOOKUP)) {
      return null;
    }

    Application application = FacesContext.getCurrentInstance().getApplication();
    String type = WidgetBuilderUtils.getActualClassOrType(attributes);

    if (type == null) {
      return null;
    }

    Class<?> clazz = ClassUtils.niceForName(type);

    if (clazz == null) {
      return null;
    }

    // HtmlInputFileUpload

    if (UploadedFile.class.isAssignableFrom(clazz)) {
      return application.createComponent("org.apache.myfaces.HtmlInputFileUpload");
    }

    // Not for Tomahawk

    return null;
  }
  public JComponent buildWidget(
      String elementName, Map<String, String> attributes, SwingMetawidget metawidget) {

    // Not read-only?

    if (!WidgetBuilderUtils.isReadOnly(attributes)) {
      return null;
    }

    // Hidden

    if (TRUE.equals(attributes.get(HIDDEN))) {
      return new Stub();
    }

    // Action

    if (ACTION.equals(elementName)) {
      JButton button = new JButton(metawidget.getLabelString(attributes));
      button.setEnabled(false);

      return button;
    }

    // Masked (return a JPanel, so that we DO still render a label)

    if (TRUE.equals(attributes.get(MASKED))) {
      return new JPanel();
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
      // May have alternate labels

      String lookupLabels = attributes.get(LOOKUP_LABELS);

      if (lookupLabels != null && !"".equals(lookupLabels)) {
        return new LookupLabel(
            CollectionUtils.newHashMap(
                CollectionUtils.fromString(lookup), CollectionUtils.fromString(lookupLabels)));
      }

      return new JLabel();
    }

    // Lookup the Class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class);

    if (clazz != null) {
      // Primitives

      if (clazz.isPrimitive()) {
        return new JLabel();
      }

      if (String.class.equals(clazz)) {
        if (TRUE.equals(attributes.get(LARGE))) {
          // Do not use a JLabel: JLabels do not support carriage returns like JTextAreas
          // do, so a multi-line JTextArea formats to a single line JLabel. Instead use
          // a non-editable JTextArea within a borderless JScrollPane

          JTextArea textarea = new JTextArea();

          // Since we know we are dealing with Strings, we consider
          // word-wrapping a sensible default

          textarea.setLineWrap(true);
          textarea.setWrapStyleWord(true);
          textarea.setEditable(false);

          // We also consider 2 rows a sensible default, so that the
          // read-only JTextArea is always distinguishable from a JLabel

          textarea.setRows(2);
          JScrollPane scrollPane = new JScrollPane(textarea);
          scrollPane.setBorder(null);

          return scrollPane;
        }

        return new JLabel();
      }

      if (Character.class.equals(clazz)) {
        return new JLabel();
      }

      if (Date.class.equals(clazz)) {
        return new JLabel();
      }

      if (Boolean.class.equals(clazz)) {
        return new JLabel();
      }

      if (Number.class.isAssignableFrom(clazz)) {
        return new JLabel();
      }

      // Collections

      if (Collection.class.isAssignableFrom(clazz)) {
        return new Stub();
      }
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
      return new JLabel();
    }

    // Nested Metawidget

    return null;
  }
Пример #6
0
  @Override
  public StaticJavaWidget buildWidget(
      String elementName, Map<String, String> attributes, StaticJavaMetawidget metawidget) {
    // Drill down

    if (ENTITY.equals(elementName)) {
      return null;
    }

    // Suppress

    if (TRUE.equals(attributes.get(HIDDEN))) {
      return new StaticJavaStub();
    }

    String type = WidgetBuilderUtils.getActualClassOrType(attributes);
    Class<?> clazz = ClassUtils.niceForName(type);
    String name = attributes.get(NAME);

    // String

    if (String.class.equals(clazz)) {
      StaticJavaStub toReturn = new StaticJavaStub();
      toReturn
          .getChildren()
          .add(
              new JavaStatement(
                  "String " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
      JavaStatement ifNotEmpty =
          new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
      ifNotEmpty
          .getChildren()
          .add(
              new JavaStatement(
                  "predicatesList.add(builder.like(root.<String>get(\""
                      + name
                      + "\"), '%' + "
                      + name
                      + " + '%'))"));
      toReturn.getChildren().add(ifNotEmpty);
      return toReturn;
    }

    // int

    if (int.class.equals(clazz)) {
      StaticJavaStub toReturn = new StaticJavaStub();
      toReturn
          .getChildren()
          .add(
              new JavaStatement(
                  "int " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
      JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
      ifNotEmpty
          .getChildren()
          .add(
              new JavaStatement(
                  "predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))"));
      toReturn.getChildren().add(ifNotEmpty);
      return toReturn;
    }

    // Lookup

    if (attributes.containsKey(FACES_LOOKUP)) {
      StaticJavaStub toReturn = new StaticJavaStub();
      JavaStatement getValue =
          new JavaStatement(
              ClassUtils.getSimpleName(type)
                  + " "
                  + name
                  + " = this.search.get"
                  + StringUtils.capitalize(name)
                  + "()");
      getValue.putImport(type);
      toReturn.getChildren().add(getValue);
      JavaStatement ifNotEmpty =
          new JavaStatement("if (" + name + " != null && " + name + ".getId() != null)");
      ifNotEmpty
          .getChildren()
          .add(
              new JavaStatement(
                  "predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))"));
      toReturn.getChildren().add(ifNotEmpty);
      return toReturn;
    }

    // We tried searching against N_TO_MANY relationships, but had the following problems:
    //
    // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following
    // items'. For 'a Set
    // having the following item' can do:
    // predicatesList.add(root.join("customers").in(this.search.getCustomer()));
    // 2. Cumbersome to have a new class for this.search that only has a single Customer, as opposed
    // to a Set
    // 3. Difficult to make JSF's h:selectOne* bind to a Set
    // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
    //
    // So we've left it out for now

    return new StaticJavaStub();
  }
Пример #7
0
  public UIComponent buildWidget(
      String elementName, Map<String, String> attributes, UIMetawidget metawidget) {

    // Not for RichFaces?

    if (TRUE.equals(attributes.get(HIDDEN))) {
      return null;
    }

    // Note: we tried implementing lookups using org.richfaces.ComboBox, but that
    // allows manual input and if you set enableManualInput=false it behaves a
    // bit screwy for our liking (ie. if you hit backspace the browser goes back)

    if (attributes.containsKey(FACES_LOOKUP) || attributes.containsKey(LOOKUP)) {
      return null;
    }

    // Lookup the class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);

    if (clazz == null) {
      return null;
    }

    // Primitives

    if (clazz.isPrimitive()) {
      // Not for RichFaces

      if (boolean.class.equals(clazz) || char.class.equals(clazz)) {
        return null;
      }

      // Ranged

      UIComponent ranged = createRanged(attributes);

      if (ranged != null) {
        return ranged;
      }

      // Not-ranged

      HtmlInputNumberSpinner spinner = VERSION_SPECIFIC_WIDGET_BUILDER.createInputNumberSpinner();

      // May be ranged in one dimension only. In which case, explictly range the *other*
      // dimension because RichFaces defaults to 0-100

      String minimumValue = attributes.get(MINIMUM_VALUE);

      if (minimumValue != null && !"".equals(minimumValue)) {
        spinner.setMinValue(minimumValue);
      } else if (byte.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(Byte.MIN_VALUE));
      } else if (short.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(Short.MIN_VALUE));
      } else if (int.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(Integer.MIN_VALUE));
      } else if (long.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(Long.MIN_VALUE));
      } else if (float.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(-Float.MAX_VALUE));
      } else if (double.class.equals(clazz)) {
        spinner.setMinValue(String.valueOf(-Double.MAX_VALUE));
      }

      String maximumValue = attributes.get(MAXIMUM_VALUE);

      if (maximumValue != null && !"".equals(maximumValue)) {
        spinner.setMaxValue(maximumValue);
      } else if (byte.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Byte.MAX_VALUE));
      } else if (short.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Short.MAX_VALUE));
      } else if (int.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Integer.MAX_VALUE));
      } else if (long.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Long.MAX_VALUE));
      } else if (float.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Float.MAX_VALUE));
      } else if (double.class.equals(clazz)) {
        spinner.setMaxValue(String.valueOf(Double.MAX_VALUE));
      }

      // Wraps around?

      spinner.setCycled(false);

      // Stepped

      if (float.class.equals(clazz) || double.class.equals(clazz)) {
        spinner.setStep("0.1");
      }

      return spinner;
    }

    // Dates
    //
    // Note: when http://jira.jboss.org/jira/browse/RF-2023 gets implemented, that
    // would allow external, app-level configuration of this Calendar

    if (Date.class.isAssignableFrom(clazz)) {
      UICalendar calendar =
          FacesUtils.createComponent(HtmlCalendar.COMPONENT_TYPE, "org.richfaces.CalendarRenderer");

      if (attributes.containsKey(DATETIME_PATTERN)) {
        calendar.setDatePattern(attributes.get(DATETIME_PATTERN));
      }

      if (attributes.containsKey(LOCALE)) {
        calendar.setLocale(new Locale(attributes.get(LOCALE)));
      }

      if (attributes.containsKey(TIME_ZONE)) {
        calendar.setTimeZone(TimeZone.getTimeZone(attributes.get(TIME_ZONE)));
      }

      return calendar;
    }

    // Object primitives

    if (Number.class.isAssignableFrom(clazz)) {
      // Ranged

      UIComponent ranged = createRanged(attributes);

      if (ranged != null) {
        return ranged;
      }

      // Not-ranged
      //
      // Until https://jira.jboss.org/jira/browse/RF-4450 is fixed, do not use
      // UIInputNumberSpinner for nullable numbers
    }

    // RichFaces version-specific

    return VERSION_SPECIFIC_WIDGET_BUILDER.buildWidget(elementName, attributes, metawidget);
  }
  public View buildWidget(
      String elementName, Map<String, String> attributes, AndroidMetawidget metawidget) {

    // Not read-only?

    if (!WidgetBuilderUtils.isReadOnly(attributes)) {
      return null;
    }

    // Hidden

    if (TRUE.equals(attributes.get(HIDDEN))) {
      return new Stub(metawidget.getContext());
    }

    // Action

    if (ACTION.equals(elementName)) {
      return new Stub(metawidget.getContext());
    }

    // Masked (return an invisible View, so that we DO still
    // render a label and reserve some blank space)

    if (TRUE.equals(attributes.get(MASKED))) {
      TextView view = new TextView(metawidget.getContext());
      view.setVisibility(View.INVISIBLE);

      return view;
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
      return new TextView(metawidget.getContext());
    }

    // Lookup the Class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class);

    if (clazz != null) {
      if (clazz.isPrimitive()) {
        return new TextView(metawidget.getContext());
      }

      if (String.class.equals(clazz)) {
        return new TextView(metawidget.getContext());
      }

      if (Character.class.equals(clazz)) {
        return new TextView(metawidget.getContext());
      }

      if (Date.class.equals(clazz)) {
        return new TextView(metawidget.getContext());
      }

      if (Boolean.class.equals(clazz)) {
        return new TextView(metawidget.getContext());
      }

      if (Number.class.isAssignableFrom(clazz)) {
        return new TextView(metawidget.getContext());
      }

      // Collections

      if (Collection.class.isAssignableFrom(clazz)) {
        return new Stub(metawidget.getContext());
      }
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
      return new TextView(metawidget.getContext());
    }

    // Nested Metawidget

    return null;
  }