Ejemplo n.º 1
0
 protected void addAttributesToLookupResults(LookupView view, DataObjectEntry dataObjectEntry) {
   AttributeDefinition activeAttribute = null;
   for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
     // Check if we have been told not to display this attribute here
     boolean dontDisplay =
         hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_LOOKUP_RESULT);
     dontDisplay |= (attr.getControlField() instanceof HiddenControl);
     if (dontDisplay) {
       continue;
     }
     if (attr.getName().equals(KRADPropertyConstants.ACTIVE)) {
       activeAttribute = attr;
       continue; // leave until the end of the lookup results
     }
     DataField field = ComponentFactory.getDataField();
     field.setPropertyName(attr.getName());
     view.getResultFields().add(field);
   }
   // If there was one, add the active attribute at the end
   if (activeAttribute != null) {
     DataField field = ComponentFactory.getDataField();
     field.setPropertyName(activeAttribute.getName());
     view.getResultFields().add(field);
   }
 }
Ejemplo n.º 2
0
  @Override
  public void performApplyModel(Object model, LifecycleElement parent) {
    Object myBo =
        ObjectPropertyUtils.getPropertyValue(
            model, KcBindingInfo.getParentBindingInfo(getBindingInfo()));
    Answer answer = (Answer) myBo;
    setControl(
        (Control)
            ComponentFactory.getNewComponentInstance(
                getControlMappings().get(answer.getQuestion().getQuestionTypeId().toString())));
    getControl().getCssClasses().add("answer");
    if (StringUtils.isNotBlank(answer.getQuestion().getLookupClass())) {
      if (useSuggest) {
        getSuggest().setRender(true);
        getSuggest().setValuePropertyName(answer.getQuestion().getLookupReturn());
        getSuggest()
            .getSuggestQuery()
            .setDataObjectClassName(answer.getQuestion().getLookupClass());
      }

      getQuickfinder().setRender(true);
      getQuickfinder().setDataObjectClassName(answer.getQuestion().getLookupClass());
      getQuickfinder()
          .getFieldConversions()
          .put(answer.getQuestion().getLookupReturn(), getPropertyName());
    }
    super.performApplyModel(model, parent);
  }
  /**
   * The following actions are performed:
   *
   * <ul>
   *   <li>Add all option if enabled and control is multi-value
   * </ul>
   *
   * {@inheritDoc}
   */
  @Override
  public void performFinalize(Object model, LifecycleElement parent) {
    super.performFinalize(model, parent);

    // if enabled add option to select all values
    if (addControlSelectAllOption
        && (getControl() != null)
        && getControl() instanceof MultiValueControl) {
      String allOptionText =
          KRADServiceLocatorWeb.getMessageService()
              .getMessageText(UifConstants.MessageKeys.OPTION_ALL);

      MultiValueControl multiValueControl = (MultiValueControl) getControl();
      if (multiValueControl.getOptions() != null) {
        multiValueControl.getOptions().add(0, new ConcreteKeyValue("", allOptionText));
      }

      if (multiValueControl.getRichOptions() != null) {
        Message message = ComponentFactory.getMessage();
        message.setMessageText(allOptionText);
        message.setRenderWrapperTag(false);

        multiValueControl.getRichOptions().add(0, new KeyMessage("", allOptionText, message));
      }
    }
  }
Ejemplo n.º 4
0
 protected Group createInquirySection(String groupId, String headerText) {
   Group group = ComponentFactory.getGroupWithDisclosureGridLayout();
   group.setId(groupId);
   group.setHeaderText(headerText);
   group.setItems(new ArrayList<Component>());
   return group;
 }
Ejemplo n.º 5
0
 protected CollectionGroup createCollectionInquirySection(String groupId, String headerText) {
   CollectionGroup group = ComponentFactory.getCollectionWithDisclosureGroupTableLayout();
   group.setId(groupId);
   group.setHeaderText(headerText);
   group.setItems(new ArrayList<Component>());
   ((TableLayoutManager) group.getLayoutManager()).setRenderSequenceField(false);
   return group;
 }
Ejemplo n.º 6
0
  @SuppressWarnings("unchecked")
  protected void addCollectionSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    for (CollectionDefinition coll : dataObjectEntry.getCollections()) {
      // Create a new section
      DataObjectEntry collectionEntry =
          dataDictionaryService.getDataDictionary().getDataObjectEntry(coll.getDataObjectClass());
      // Extract the key fields on the collection which are linked to the parent.
      // When auto-generating the Inquiry Collection table, we want to exclude those.
      Collection<String> collectionFieldsLinkedToParent = new HashSet<String>();

      if (coll.getDataObjectCollection() != null) {
        for (DataObjectAttributeRelationship rel :
            coll.getDataObjectCollection().getAttributeRelationships()) {
          collectionFieldsLinkedToParent.add(rel.getChildAttributeName());
        }
      }

      if (collectionEntry == null) {
        LOG.warn(
            "Unable to find DataObjectEntry for collection class: " + coll.getDataObjectClass());
        continue;
      }

      CollectionGroup section = createCollectionInquirySection(coll.getName(), coll.getLabel());
      try {
        section.setCollectionObjectClass(Class.forName(coll.getDataObjectClass()));
      } catch (ClassNotFoundException e) {
        LOG.warn(
            "Unable to set class on collection section - class not found: "
                + coll.getDataObjectClass());
      }

      section.setPropertyName(coll.getName());
      // summary title : collection object label
      // Summary fields : PK fields?
      // add the attributes to the section
      for (AttributeDefinition attr : collectionEntry.getAttributes()) {
        boolean dontDisplay =
            hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
        dontDisplay |= (attr.getControlField() instanceof HiddenControl);
        // Auto-exclude fields linked to the parent object
        dontDisplay |= collectionFieldsLinkedToParent.contains(attr.getName());

        if (dontDisplay) {
          continue;
        }

        DataField dataField = ComponentFactory.getDataField();
        dataField.setPropertyName(attr.getName());
        ((List<Component>) section.getItems()).add(dataField);
      }
      ((List<Group>) view.getItems()).add(section);
    }
  }
Ejemplo n.º 7
0
  @SuppressWarnings("unchecked")
  protected void addAttributeSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    // Set up data structures to manage the creation of sections
    Map<String, Group> inquirySectionsById = new HashMap<String, Group>();
    Group currentGroup = createInquirySection("default", dataObjectEntry.getObjectLabel());
    inquirySectionsById.put(currentGroup.getId(), currentGroup);
    ((List<Group>) view.getItems()).add(currentGroup);

    // Loop over the attributes on the data object, adding them into the inquiry
    // If we have an @Section notation, switch to the section, creating if the ID is unknown
    List<Component> items =
        (List<Component>) currentGroup.getItems(); // needed to deal with generics issue
    for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
      boolean dontDisplay =
          hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
      dontDisplay |= (attr.getControlField() instanceof HiddenControl);
      // Check for a section hint
      // Create or retrieve existing section as determined by the ID on the annotation
      UifDisplayHint sectionHint =
          getHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.SECTION);
      if (sectionHint != null) {
        if (StringUtils.isNotBlank(sectionHint.id())) {
          currentGroup = inquirySectionsById.get(sectionHint.id());
          if (currentGroup == null) {
            String sectionLabel = sectionHint.label();
            if (StringUtils.isBlank(sectionLabel)) {
              sectionLabel = deriveHumanFriendlyNameFromPropertyName(sectionHint.id());
            }

            currentGroup = createInquirySection(sectionHint.id(), sectionHint.label());
            inquirySectionsById.put(currentGroup.getId(), currentGroup);
            ((List<Group>) view.getItems()).add(currentGroup);
          }
        } else {
          LOG.warn("SECTION UifDisplayHint given without an ID - assuming 'default'");
          currentGroup = inquirySectionsById.get("default");
        }
        items = (List<Component>) currentGroup.getItems();
      }

      // This is checked after the section test, since the @Section annotation
      // would be on the FK field
      if (dontDisplay) {
        continue;
      }

      DataField dataField = ComponentFactory.getDataField();
      dataField.setPropertyName(attr.getName());
      dataField.setLabel(attr.getLabel());
      items.add(dataField);
    }
  }
Ejemplo n.º 8
0
  /**
   * @see
   *     org.kuali.rice.krad.uif.service.UifDefaultingService#deriveLookupViewFromMetadata(org.kuali.rice.krad.datadictionary.DataObjectEntry)
   */
  @Override
  public LookupView deriveLookupViewFromMetadata(DataObjectEntry dataObjectEntry) {
    LookupView view = ComponentFactory.getLookupView();
    view.setHeaderText(dataObjectEntry.getObjectLabel() + " Lookup");
    view.setDataObjectClass(dataObjectEntry.getDataObjectClass());
    view.setCriteriaFields(new ArrayList<Component>());
    view.setResultFields(new ArrayList<Component>());
    view.setDefaultSortAttributeNames(dataObjectEntry.getPrimaryKeys());

    addAttributesToLookupCriteria(view, dataObjectEntry);
    addAttributesToLookupResults(view, dataObjectEntry);

    return view;
  }
  /**
   * If control definition is defined on the given attribute definition, converts to an appropriate
   * control for searching (if necessary) and returns a copy for setting on the field.
   *
   * @param attributeDefinition attribute definition instance to retrieve control from
   * @return Control instance or null if not found
   */
  protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
    if (attributeDefinition.getControlField() == null) {
      return null;
    }

    Control newControl = null;

    // convert checkbox to radio with yes/no/both options
    if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
      newControl =
          (RadioGroupControl)
              ComponentFactory.getNewComponentInstance(
                  ComponentFactory.CHECKBOX_CONVERTED_RADIO_CONTROL);
    }
    // text areas get converted to simple text inputs
    else if (TextAreaControl.class.isAssignableFrom(
        attributeDefinition.getControlField().getClass())) {
      newControl = ComponentFactory.getTextControl();
    } else {
      newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
    }

    return newControl;
  }
Ejemplo n.º 10
0
  /**
   * @see
   *     org.kuali.rice.krad.uif.service.UifDefaultingService#deriveInquiryViewFromMetadata(org.kuali.rice.krad.datadictionary.DataObjectEntry)
   */
  @Override
  public InquiryView deriveInquiryViewFromMetadata(DataObjectEntry dataObjectEntry) {
    // Create the main view object and set the title and BO class
    InquiryView view = ComponentFactory.getInquiryView();
    view.setHeaderText(dataObjectEntry.getObjectLabel());
    view.setDataObjectClassName(dataObjectEntry.getDataObjectClass());

    addAttributeSectionsToInquiryView(view, dataObjectEntry);

    // TODO: if there are updatable reference objects, include sections for them

    // If there are collections on the object, include sections for them
    addCollectionSectionsToInquiryView(view, dataObjectEntry);

    return view;
  }
Ejemplo n.º 11
0
  /**
   * Sets up rich message content for the label, if any exists
   *
   * <p>{@inheritDoc}
   */
  @Override
  public void performApplyModel(Object model, LifecycleElement parent) {
    super.performApplyModel(model, parent);

    if (richHeaderMessage == null
        && headerText != null
        && headerText.contains(KRADConstants.MessageParsing.LEFT_TOKEN)
        && headerText.contains(KRADConstants.MessageParsing.RIGHT_TOKEN)) {
      Message message = ComponentFactory.getMessage();
      message.setMessageText(headerText);
      message.setInlineComponents(inlineComponents);
      message.setRenderWrapperTag(false);

      this.setRichHeaderMessage(message);
    }
  }
Ejemplo n.º 12
0
 protected Control getControlInstance(
     AttributeDefinition attrDef, DataObjectAttribute dataObjectAttribute) {
   Control c = null;
   // Check for the hidden hint - if present - then use that control type
   if (dataObjectAttribute != null
       && hasHintOfType(dataObjectAttribute, UifDisplayHintType.HIDDEN)) {
     c = ComponentFactory.getHiddenControl();
   } else if (attrDef.getOptionsFinder() != null) {
     // if a values finder has been established, use a radio button group or drop-down list
     if (dataObjectAttribute != null
         && hasHintOfType(dataObjectAttribute, UifDisplayHintType.RADIO)) {
       c = ComponentFactory.getRadioGroupControl();
     } else {
       c = ComponentFactory.getSelectControl();
     }
   } else if (attrDef.getName().endsWith(".principalName") && dataObjectAttribute != null) {
     // FIXME: JHK: Yes, I know this is a *HORRIBLE* hack - but the alternative
     // would look even more "hacky" and error-prone
     c = ComponentFactory.getUserControl();
     // Need to find the relationship information
     // get the relationship ID by removing .principalName from the attribute name
     String relationshipName = StringUtils.removeEnd(attrDef.getName(), ".principalName");
     DataObjectMetadata metadata =
         dataObjectService
             .getMetadataRepository()
             .getMetadata(dataObjectAttribute.getOwningType());
     if (metadata != null) {
       DataObjectRelationship relationship = metadata.getRelationship(relationshipName);
       if (relationship != null
           && CollectionUtils.isNotEmpty(relationship.getAttributeRelationships())) {
         ((UserControl) c)
             .setPrincipalIdPropertyName(
                 relationship.getAttributeRelationships().get(0).getParentAttributeName());
         ((UserControl) c)
             .setPersonNamePropertyName(
                 relationshipName + "." + KimConstants.AttributeConstants.NAME);
         ((UserControl) c).setPersonObjectPropertyName(relationshipName);
       }
     } else {
       LOG.warn(
           "Attempt to pull relationship name: "
               + relationshipName
               + " resulted in missing metadata when looking for: "
               + dataObjectAttribute.getOwningType());
     }
   } else {
     switch (attrDef.getDataType()) {
       case STRING:
         // TODO: Determine better way to store the "200" metric below
         if (attrDef.getMaxLength() != null && attrDef.getMaxLength().intValue() > 200) {
           c = ComponentFactory.getTextAreaControl();
         } else {
           c = ComponentFactory.getTextControl();
         }
         break;
       case BOOLEAN:
         c = ComponentFactory.getCheckboxControl();
         break;
       case DATE:
       case DATETIME:
       case TRUNCATED_DATE:
         c = ComponentFactory.getDateControl();
         break;
       case CURRENCY:
       case DOUBLE:
       case FLOAT:
       case INTEGER:
       case LARGE_INTEGER:
       case LONG:
       case PRECISE_DECIMAL:
         c = ComponentFactory.getTextControl();
         break;
       case MARKUP:
         c = ComponentFactory.getTextAreaControl();
         break;
       default:
         c = ComponentFactory.getTextControl();
         break;
     }
   }
   return c;
 }