/** * 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; }