Exemplo n.º 1
0
  /**
   * Create a {@link List} that acts as the input for {@link #attributeCombo}. The list is first
   * sorted by {@link SpecType} and then sorted by {@link AttributeDefinition}.
   */
  private List<?> createAttributeInput() {
    List<? super Object> list = new ArrayList<Object>();

    // Internal Attributes
    list.addAll(Arrays.asList(StringFilter.InternalAttribute.values()));
    list.addAll(Arrays.asList(DateFilter.InternalAttribute.values()));

    // All Attributes in the model
    Map<String, AttributeDefinition> attributes = new HashMap<String, AttributeDefinition>();
    for (SpecType specType : reqif.getCoreContent().getSpecTypes()) {
      for (AttributeDefinition ad : specType.getSpecAttributes()) {
        attributes.put(
            specType.getLongName() + "." + ad.getLongName() + "." + ad.getIdentifier(), ad);
      }
    }

    // Add them in alphabetical order.
    List<String> sortedKeys = new ArrayList<String>(attributes.keySet());
    Collections.sort(sortedKeys);
    for (String key : sortedKeys) {
      list.add(attributes.get(key));
    }

    return list;
  }
Exemplo n.º 2
0
 @Override
 public String getText(Object element) {
   if (element instanceof AttributeDefinition) {
     AttributeDefinition ad = (AttributeDefinition) element;
     SpecType specType = (SpecType) ad.eContainer();
     return ad.getLongName() + " (" + specType.getLongName() + ")";
   }
   return element.toString();
 }
Exemplo n.º 3
0
  /**
   * Finds the best labels, according to what is set in the preferences.
   *
   * @param specElement
   * @param adapterFactory
   * @param adapterFactory
   * @return
   */
  public static String getSpecElementLabel(
      SpecElementWithAttributes specElement, AdapterFactory adapterFactory) {

    List<String> labels = getDefaultLabels(ReqIF10Util.getReqIF(specElement));

    // Iterate over the list of labels requested
    for (String label : labels) {

      for (AttributeValue value : specElement.getValues()) {
        AttributeDefinition ad = ReqIF10Util.getAttributeDefinition(value);
        if (ad == null) continue;

        if (label.equals(ad.getLongName())) {
          ProrPresentationConfiguration config = getPresentationConfig(value);

          ItemProviderAdapter ip = ProrUtil.getItemProvider(adapterFactory, config);
          if (ip instanceof PresentationEditInterface) {
            String customLabel = ((PresentationEditInterface) ip).getLabel(value);
            if (customLabel != null) return customLabel;
          }

          Object result = ReqIF10Util.getTheValue(value);
          if (result != null) {

            // If we have an enumeration attribute
            if (value instanceof AttributeValueEnumeration && result instanceof EList) {
              EList<?> list = (EList<?>) result;
              if (!list.isEmpty()) return ((EnumValue) list.get(0)).getLongName();
              else return "";
            } else if (value instanceof AttributeValueXHTML && result instanceof XhtmlContent) {
              XhtmlContent content = (XhtmlContent) result;
              String text = ProrXhtmlSimplifiedHelper.xhtmlToSimplifiedString(content);

              // Ignore empty XHTML
              if (text.trim().length() == 0) {
                continue;
              }

              // Shorten long XHTML
              if (text.length() > 20) text = text.substring(0, 17) + "...";
              return text;
            }
            return result.toString();
          }
        }
      }
    }
    return specElement.getIdentifier();
  }
Exemplo n.º 4
0
  /**
   * Retrieves the {@link ProrSpecViewConfiguration} for the given {@link Specification}. If none
   * exists, it is built. The builder collects all attribute names of all SpecObjects and creates
   * corresponding columns.
   */
  public static ProrSpecViewConfiguration createSpecViewConfiguration(
      Specification specification, EditingDomain domain) {
    ProrToolExtension extension =
        createProrToolExtension(ReqIF10Util.getReqIF(specification), domain);

    EList<ProrSpecViewConfiguration> configs = extension.getSpecViewConfigurations();
    for (ProrSpecViewConfiguration config : configs) {
      if (config.getSpecification() != null && config.getSpecification().equals(specification)) {
        return config;
      }
    }

    // None found, let's build a new one that includes all attribute names.
    ProrSpecViewConfiguration specViewConfig =
        ConfigurationFactory.eINSTANCE.createProrSpecViewConfiguration();
    specViewConfig.setSpecification(specification);

    // Collect all Types

    final List<SpecType> types = new ArrayList<SpecType>();
    ReqIF10Switch<SpecHierarchy> visitor =
        new ReqIF10Switch<SpecHierarchy>() {
          @Override
          public SpecHierarchy caseSpecHierarchy(SpecHierarchy specHierarchy) {
            if (specHierarchy.getObject() != null) {
              SpecObjectType type = specHierarchy.getObject().getType();
              if (type != null && !types.contains(type)) {
                types.add(type);
              }
            }
            return specHierarchy;
          }
        };
    int counter = 0;
    for (Iterator<EObject> i = EcoreUtil.getAllContents(specification, true); i.hasNext(); ) {
      visitor.doSwitch(i.next());
      // we only explore the first 50 elements for performance.
      if (counter++ == 50) break;
    }

    // Collect all names from the types.  We use a list to maintain order.
    final List<String> colNames = new ArrayList<String>();
    for (SpecType type : types) {
      for (AttributeDefinition ad : type.getSpecAttributes()) {

        String colName = ad.getLongName();
        if (colName != null && !colNames.contains(colName)) {
          colNames.add(ad.getLongName());
        }
      }
    }

    // Build all Columns from the names
    boolean unifiedColumn = false;
    for (String colName : colNames) {
      Column column = ConfigurationFactory.eINSTANCE.createColumn();

      // See whether we need a unified column or not.
      if (colName.equals("ReqIF.Text") || colName.equals("ReqIF.ChapterName")) {
        if (unifiedColumn) continue;
        column = ConfigurationFactory.eINSTANCE.createUnifiedColumn();
        colName = "Main";
        unifiedColumn = true;
      }

      column.setWidth(100);
      column.setLabel(colName);
      specViewConfig.getColumns().add(column);
    }
    domain
        .getCommandStack()
        .execute(
            AddCommand.create(
                domain,
                extension,
                ConfigurationPackage.Literals.PROR_TOOL_EXTENSION__SPEC_VIEW_CONFIGURATIONS,
                specViewConfig));

    return specViewConfig;
  }