Java Code Examples for org.apache.uima.resource.metadata.FeatureDescription#getMultipleReferencesAllowed()

The following examples show how to use org.apache.uima.resource.metadata.FeatureDescription#getMultipleReferencesAllowed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Update gui feature.
 *
 * @param fItem the f item
 * @param fd the fd
 * @param td the td
 */
private void updateGuiFeature(TreeItem fItem, FeatureDescription fd, TypeDescription td) {
  String rangeType;
  fItem.setText(NAME_COL, fd.getName());
  fItem.setText(RANGE_COL, formatName(rangeType = fd.getRangeTypeName()));
  fItem.setData(fd);
  setItemColor(fItem, null != getLocalFeatureDefinition(td, fd));
  if (isArrayOrListType(rangeType)) {
    Boolean mra = fd.getMultipleReferencesAllowed();
    fItem.setImage(MULTIPLE_REF_OK_COL,
            (null != mra && mra) ? TAEConfiguratorPlugin
                    .getImage(TAEConfiguratorPlugin.IMAGE_MREFOK) : TAEConfiguratorPlugin
                    .getImage(TAEConfiguratorPlugin.IMAGE_NOMREF));
  } else {
    fItem.setImage(MULTIPLE_REF_OK_COL, null);
  }

  String ert = fd.getElementType();
  fItem.setText(ELEMENT_TYPE_COL,
          (isFSArrayOrListType(rangeType) && ert != null) ? formatName(ert) : "");

}
 
Example 2
Source File: TypeSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Handle hover.
 *
 * @param event the event
 */
public void handleHover(Event event) {
  // next getItem call requires that table have SWT.FULL_SELECTION Style
  TreeItem item = tt.getItem(new Point(event.x, event.y));
  if (null != item) {
    Object o = item.getData();
    if (null == o)
      throw new InternalErrorCDE("invalid state");

    if (o instanceof TypeDescription) {
      setToolTipText(tt, ((TypeDescription) o).getDescription());
    } else if (o instanceof FeatureDescription) {
      FeatureDescription fd = (FeatureDescription) o;
      if (item.getBounds(MULTIPLE_REF_OK_COL).contains(event.x, event.y)
              && isArrayOrListType(fd.getRangeTypeName())) {
        Boolean mra = fd.getMultipleReferencesAllowed();
        setToolTipText(tt, (mra != null && mra) ? "Multiple References Allowed"
                : "Multiple References Not Allowed");
      } else
        setToolTipText(tt, fd.getDescription());
    } else if (o instanceof AllowedValue) {
      setToolTipText(tt, ((AllowedValue) o).getDescription());
    }
  } else
    tt.setToolTipText("");
}
 
Example 3
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Merges features into a TypeDescription.
 * 
 * @param aType
 *                TypeDescription into which to merge the features
 * @param aFeatures
 *                array of features to merge
 * 
 * @throws ResourceInitializationException
 *                 if an incompatibility exists
 */
protected static void mergeFeatures(TypeDescription aType, FeatureDescription[] aFeatures)
    throws ResourceInitializationException {
  FeatureDescription[] existingFeatures = aType.getFeatures();
  if (existingFeatures == null) {
    existingFeatures = EMPTY_FEAT_DESC_ARRAY;
  }

  for (int i = 0; i < aFeatures.length; i++) {
    String featName = aFeatures[i].getName();
    String rangeTypeName = aFeatures[i].getRangeTypeName();
    String elementTypeName = aFeatures[i].getElementType();
    Boolean multiRefsAllowed = aFeatures[i].getMultipleReferencesAllowed();

    // see if a feature already exists with this name
    FeatureDescription feat = null;
    for (int j = 0; j < existingFeatures.length; j++) {
      if (existingFeatures[j].getName().equals(featName)) {
        feat = existingFeatures[j];
        break;
      }
    }

    if (feat == null) {
      // doesn't exist; add it
      FeatureDescription featDesc = aType.addFeature(featName, aFeatures[i].getDescription(),
          rangeTypeName, elementTypeName, multiRefsAllowed);
      featDesc.setSourceUrl(aFeatures[i].getSourceUrl());
    } else {// feature does exist
      // check that the range types match
      if (!feat.getRangeTypeName().equals(rangeTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_RANGE_TYPES, new Object[] {
                aType.getName() + ":" + feat.getName(), rangeTypeName, feat.getRangeTypeName(),
                aType.getSourceUrlString() });
      }
      Boolean mra1 = feat.getMultipleReferencesAllowed();
      Boolean mra2 = multiRefsAllowed;

      // the logic here:
      // OK if both null
      // OK if both not-null, and are equals()
      // OK if one is null, the other has boolean-value of false (false is the default)
      // not ok otherwise

      if (!(((mra1 == null) && (mra2 == null)) || ((mra1 != null) && mra1.equals(mra2))
          || ((mra1 == null) && !mra2) || ((mra2 == null) && !mra1))) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_MULTI_REFS, new Object[] {
                aType.getName() + ":" + feat.getName(), aType.getSourceUrlString() });
      }

      if (!elementTypesCompatible(feat.getElementType(), elementTypeName)) {
        throw new ResourceInitializationException(
            ResourceInitializationException.INCOMPATIBLE_ELEMENT_RANGE_TYPES, new Object[] {
                aType.getName() + TypeSystem.FEATURE_SEPARATOR + feat.getName(), elementTypeName,
                feat.getElementType(), aType.getSourceUrlString() });
      }
    }
  }
}