001package org.nasdanika.html.ecore; 002 003import org.eclipse.emf.common.util.EList; 004import org.eclipse.emf.ecore.EAttribute; 005import org.eclipse.emf.ecore.EClass; 006import org.eclipse.emf.ecore.EPackage; 007import org.eclipse.emf.ecore.EReference; 008import org.nasdanika.common.Context; 009import org.nasdanika.common.ProgressMonitor; 010import org.nasdanika.common.Util; 011import org.nasdanika.html.bootstrap.Table; 012import org.nasdanika.ncore.util.NcoreUtil; 013 014public class EReferenceActionSupplier extends EStructuralFeatureActionSupplier<EReference> { 015 016 public EReferenceActionSupplier(EReference value, Context context, java.util.function.Function<EPackage,String> ePackagePathComputer) { 017 super(value, context, ePackagePathComputer); 018 } 019 020 @Override 021 protected Table propertiesTable(EClass contextEClass, ProgressMonitor monitor) throws Exception { 022 Table propertiesTable = super.propertiesTable(contextEClass, monitor); 023 EReference opposite = NcoreUtil.getOpposite(eObject); 024 if (opposite != null) { 025 String oPath = path(opposite.getEContainingClass(), contextEClass); 026 if (Util.isBlank(oPath)) { 027 addRow(propertiesTable, "Opposite").add(opposite.getName()); 028 } else { 029 addRow(propertiesTable, "Opposite").add("<a href=\"" + oPath + "#EReference-" + opposite.getName() +"\">" + opposite.getName() + "</a>"); 030 } 031 } 032 EList<EAttribute> eKeys = eObject.getEKeys(); 033 if (!eKeys.isEmpty()) { 034 if (eKeys.size() == 1) { 035 addRow(propertiesTable, "Key").add(eKeys.get(0).getName()); 036 } else { 037 StringBuilder vb = new StringBuilder("<ol>"); 038 eKeys.forEach(eKey -> vb.append("<li>").append(eKey.getName()).append("</li>")); 039 vb.append("</ol>"); 040 addRow(propertiesTable, "Key").add(vb.toString()); 041 } 042 } 043 return propertiesTable; 044 } 045 046}