Пример #1
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();
  }
Пример #2
0
  /**
   * In addition to the regular functionality (creating a SpecHierarchy child object), this method
   * allows a SpecObject or a SpecType as an argument: Note that this is almost the same as {@link
   * SpecificationItemProvider#createCreateChildCommand(EditingDomain, EObject, EStructuralFeature,
   * Object, int, Collection)} .
   *
   * @param value instanceof {@link SpecType}: A new SpecObject with the given SpecType is created,
   *     and a SpecHierarchy is added that is associated with the newly created SpecObject.
   * @param value instanceof {@link SpecObject}: The SpecObject is added to a new SpecHierarchy,
   *     which is then added.
   */
  @Override
  protected Command createCreateChildCommand(
      EditingDomain domain,
      EObject owner,
      EStructuralFeature feature,
      Object value,
      int index,
      Collection<?> collection) {

    if (value instanceof SpecType) {
      ReqIFContent content = ReqIF10Util.getReqIF(owner).getCoreContent();
      SpecObject specObject = ReqIF10Factory.eINSTANCE.createSpecObject();
      SpecHierarchy specHierarchy = ReqIF10Factory.eINSTANCE.createSpecHierarchy();

      CompoundCommand cmd =
          ProrUtil.createAddTypedElementCommand(
              content,
              REQ_IF_CONTENT__SPEC_OBJECTS,
              specObject,
              SPEC_OBJECT__TYPE,
              (SpecType) value,
              -1,
              3,
              domain,
              adapterFactory);
      cmd.append(AddCommand.create(domain, owner, SPEC_HIERARCHY__CHILDREN, specHierarchy, index));
      cmd.append(SetCommand.create(domain, specHierarchy, SPEC_HIERARCHY__OBJECT, specObject));
      return cmd;
    }
    if (value instanceof SpecObject) {
      Object icon = ProrUtil.getItemProvider(adapterFactory, value).getImage(value);
      CompoundCommand cmd = ProrUtil.createCompoundCommandWithAddIcon(icon, 0);
      cmd.setLabel("Adding SpecObject");
      cmd.setDescription("Adding SpecObject");
      SpecHierarchy specHierarchy = ReqIF10Factory.eINSTANCE.createSpecHierarchy();
      cmd.append(AddCommand.create(domain, owner, SPEC_HIERARCHY__CHILDREN, specHierarchy, index));
      cmd.append(
          AddCommand.create(
              domain,
              ReqIF10Util.getReqIF(owner).getCoreContent(),
              REQ_IF_CONTENT__SPEC_OBJECTS,
              value));
      cmd.append(SetCommand.create(domain, specHierarchy, SPEC_HIERARCHY__OBJECT, value));
      return cmd;
    }

    return super.createCreateChildCommand(domain, owner, feature, value, index, collection);
  }
Пример #3
0
 /**
  * Returns the {@link ProrPresentationConfiguration} that is associated with the {@link
  * DatatypeDefinition} of the given {@link AttributeValue}. If either intermediate element is
  * null, null is returned.
  */
 public static ProrPresentationConfiguration getPresentationConfiguration(AttributeValue av) {
   DatatypeDefinition dd = ReqIF10Util.getDatatypeDefinition(av);
   if (av != null) {
     return getPresentationConfiguration(dd);
   }
   return null;
 }
Пример #4
0
  private static String getDefaultValue(AttributeValue av, String indent) {
    Object value = av == null ? null : ReqIF10Util.getTheValue(av);
    String textValue;
    if (value == null) {
      textValue = "";
    } else if (value instanceof List<?>) {
      textValue = "";
      for (Iterator<EnumValue> i = ((List<EnumValue>) value).iterator(); i.hasNext(); ) {
        textValue += i.next().getLongName();

        if (i.hasNext()) {
          textValue += ", ";
        }
      }
    } else if (value instanceof XhtmlContent) {
      textValue = ProrXhtmlSimplifiedHelper.xhtmlToSimplifiedString((XhtmlContent) value);

      try {
        String xhtmlString = ReqIF10XhtmlUtil.getXhtmlString((XhtmlContent) value);
        System.out.println("xhtmlString" + xhtmlString);
        xhtmlString = xhtmlString.replace("<xhtml:", "<");
        xhtmlString = xhtmlString.replace("</xhtml:", "</");
        textValue = xhtmlString;
      } catch (IOException e) {
      }
    } else {
      textValue = value.toString();
    }

    return indent + textValue;
  }
Пример #5
0
 /**
  * @return The Configuration element for the given {@link DatatypeDefinition} or null if none is
  *     configured.
  */
 public static ProrPresentationConfiguration getPresentationConfiguration(DatatypeDefinition dd) {
   ReqIF reqif = ReqIF10Util.getReqIF(dd);
   if (reqif == null) return null;
   ProrToolExtension prorToolExtension = getProrToolExtension(reqif);
   if (prorToolExtension == null) return null;
   ProrPresentationConfigurations extensions = prorToolExtension.getPresentationConfigurations();
   if (extensions == null) return null;
   for (ProrPresentationConfiguration config : extensions.getPresentationConfigurations()) {
     if (dd.equals(config.getDatatype())) return config;
   }
   return null;
 }
Пример #6
0
  /** Ensures that added items have a unique ID */
  @Override
  protected Command createAddCommand(
      EditingDomain domain,
      EObject owner,
      EStructuralFeature feature,
      Collection<?> collection,
      int index) {

    // Ensure that the ID is unique if it's a copy operation.
    collection = ReqIF10Util.ensureIdIsUnique(owner.eResource(), collection);
    return super.createAddCommand(domain, owner, feature, collection, index);
  }
Пример #7
0
 /**
  * Retrieves all active {@link PresentationEditInterface} instances for the given object (which
  * assumes to be part of a ReqIF model). If none is found, an empty set is returned.
  */
 public static Set<PresentationEditInterface> getPresentationEditInterfaces(
     Object obj, AdapterFactory adapterFactory) {
   ReqIF reqif = ReqIF10Util.getReqIF(obj);
   ProrPresentationConfigurations configs = getPresentationConfigurations(reqif);
   if (configs != null) {
     Set<PresentationEditInterface> result = new HashSet<PresentationEditInterface>();
     for (ProrPresentationConfiguration config : configs.getPresentationConfigurations()) {
       ItemProviderAdapter ip = ProrUtil.getItemProvider(adapterFactory, config);
       if (ip instanceof PresentationEditInterface) {
         result.add((PresentationEditInterface) ip);
       }
     }
     return result;
   }
   return Collections.emptySet();
 }
Пример #8
0
  private static ArrayList<Map<String, ?>> fillRecursive(
      EList<SpecHierarchy> children,
      ProrSpecViewConfiguration config,
      ArrayList<Map<String, ?>> specMapList) {
    for (SpecHierarchy child : children) {
      if (child.getObject() != null) {
        SpecObject specObj = child.getObject();
        HashMap<String, String> specMap = new HashMap<String, String>();

        for (Column col : config.getColumns()) {

          AttributeValue av = ReqIF10Util.getAttributeValueForLabel(specObj, col.getLabel());

          specMap.put(col.getLabel(), getDefaultValue(av));
        }

        specMapList.add(specMap);
      }
      fillRecursive(child.getChildren(), config, specMapList);
    }
    return specMapList;
  }
Пример #9
0
  /**
   * We extended the command in order to append an additional command for setting the lastChanged
   * attribute of the {@link SpecHierarchy} whenever it is moved (the order is changed).
   */
  @Override
  protected Command createMoveCommand(
      EditingDomain domain, EObject owner, EStructuralFeature feature, Object value, int index) {

    List<Command> commandList = new ArrayList<Command>();
    commandList.add(super.createMoveCommand(domain, owner, feature, value, index));

    XMLGregorianCalendar lastChange = ReqIF10Util.getReqIFLastChange();
    if (value instanceof SpecHierarchy) {
      SetCommand sc =
          new SetCommand(
              domain,
              (SpecHierarchy) value,
              ReqIF10Package.eINSTANCE.getIdentifiable_LastChange(),
              lastChange);
      commandList.add(sc);
    }

    CompoundCommand cc = new CompoundCommand(commandList);

    return cc;
  }
Пример #10
0
 public void unregisterReqIF() {
   if (reqifAdapter != null) {
     ReqIF10Util.getReqIF(this).getCoreContent().eAdapters().remove(reqifAdapter);
   }
 }
Пример #11
0
 /**
  * Two listeners must be registered:
  *
  * <ul>
  *   <li>An adapter on the {@link ReqIF}, reacting to relevant SpecObject changes that require the
  *       creation of new IDs
  *   <li>An adapter to the {@link IdConfiguration}, reacting to changes of its attributes.
  * </ul>
  */
 public void registerReqIF() {
   reqifAdapter = buildReqifListener();
   ReqIF10Util.getReqIF(this).getCoreContent().eAdapters().add(reqifAdapter);
 }
Пример #12
0
 public static ProrPresentationConfiguration getPresentationConfig(AttributeValue value) {
   DatatypeDefinition dd = ReqIF10Util.getDatatypeDefinition(value);
   ProrPresentationConfiguration config = getPresentationConfiguration(dd);
   return config;
 }
Пример #13
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;
  }
Пример #14
0
  /**
   * Create a new model.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  protected EObject createInitialModel() {
    ReqIF root = reqif10Factory.createReqIF();

    ReqIFHeader header = reqif10Factory.createReqIFHeader();
    root.setTheHeader(header);

    XMLGregorianCalendar reqIFLastChange = ReqIF10Util.getReqIFLastChange();

    header.setCreationTime(reqIFLastChange);
    header.setSourceToolId("ProR (http://pror.org)");
    header.setIdentifier("rmf-" + UUID.randomUUID());
    header.setReqIFVersion("1.0.1");
    header.setReqIFToolId("ProR (http://pror.org)");
    header.setComment("Created by: " + System.getProperty("user.name"));

    ReqIFContent content = reqif10Factory.createReqIFContent();
    root.setCoreContent(content);

    // Add a DatatypeDefinition
    DatatypeDefinitionString ddString = reqif10Factory.createDatatypeDefinitionString();
    ddString.setLongName("T_String32k");
    ddString.setMaxLength(new BigInteger("32000"));
    ddString.setLastChange(reqIFLastChange);
    content.getDatatypes().add(ddString);

    // Add a SpecObjectType
    SpecObjectType specObjectType = reqif10Factory.createSpecObjectType();
    specObjectType.setLongName("Requirement Type");
    specObjectType.setLastChange(reqIFLastChange);
    content.getSpecTypes().add(specObjectType);

    // Add an AttributeDefinition
    AttributeDefinitionString ad1 = reqif10Factory.createAttributeDefinitionString();
    ad1.setType(ddString);
    ad1.setLongName("Description");
    ad1.setLastChange(reqIFLastChange);
    specObjectType.getSpecAttributes().add(ad1);

    // Add a SpecificationType
    SpecificationType specificationType = reqif10Factory.createSpecificationType();
    specificationType.setLongName("Specification Type");
    specificationType.setLastChange(reqIFLastChange);
    content.getSpecTypes().add(specificationType);

    // Add an AttributeDefinition
    AttributeDefinitionString ad2 = reqif10Factory.createAttributeDefinitionString();
    ad2.setType(ddString);
    ad2.setLongName("Description");
    ad2.setLastChange(reqIFLastChange);
    specificationType.getSpecAttributes().add(ad2);

    // Add a Specification
    Specification spec = reqif10Factory.createSpecification();
    spec.setLongName("Specification Document");
    spec.setType(specificationType);
    spec.setLastChange(reqIFLastChange);
    AttributeValueString value1 = reqif10Factory.createAttributeValueString();
    value1.setTheValue("Requirements Document");
    value1.setDefinition(ad2);
    spec.getValues().add(value1);

    content.getSpecifications().add(spec);

    // Configure the Specification View
    ProrToolExtension extension = ConfigurationFactory.eINSTANCE.createProrToolExtension();
    ReqIFToolExtensionUtil.addToolExtension(root, extension);
    ProrSpecViewConfiguration prorSpecViewConfiguration =
        ConfigurationFactory.eINSTANCE.createProrSpecViewConfiguration();
    extension.getSpecViewConfigurations().add(prorSpecViewConfiguration);
    prorSpecViewConfiguration.setSpecification(spec);
    Column col = ConfigurationFactory.eINSTANCE.createColumn();
    col.setLabel("Description");
    col.setWidth(400);
    prorSpecViewConfiguration.getColumns().add(col);

    Column leftHeaderColumn = ConfigurationFactory.eINSTANCE.createColumn();
    leftHeaderColumn.setWidth(ConfigurationUtil.DEFAULT_LEFT_HEADER_COLUMN_WIDTH);
    leftHeaderColumn.setLabel(ConfigurationUtil.DEFAULT_LEFT_HEADER_COLUMN_NAME);
    prorSpecViewConfiguration.setLeftHeaderColumn(leftHeaderColumn);

    // Configure the Label configuration
    ProrGeneralConfiguration generalConfig =
        ConfigurationFactory.eINSTANCE.createProrGeneralConfiguration();
    LabelConfiguration labelConfig = ConfigurationFactory.eINSTANCE.createLabelConfiguration();
    labelConfig.getDefaultLabel().add("Description");
    generalConfig.setLabelConfiguration(labelConfig);
    extension.setGeneralConfiguration(generalConfig);

    // Create one Requirement
    SpecObject specObject = reqif10Factory.createSpecObject();
    specObject.setType(specObjectType);
    specObject.setLastChange(reqIFLastChange);
    content.getSpecObjects().add(specObject);
    AttributeValueString value2 = reqif10Factory.createAttributeValueString();
    value2.setTheValue("Start editing here.");
    value2.setDefinition(ad1);
    specObject.getValues().add(value2);

    // Add the requirement to the Specification
    SpecHierarchy specHierarchy = reqif10Factory.createSpecHierarchy();
    specHierarchy.setLastChange(reqIFLastChange);
    spec.getChildren().add(specHierarchy);
    specHierarchy.setObject(specObject);
    return root;
  }