Skip to content

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlasov committed May 29, 2024
1 parent 594ffde commit 3112d60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.nasdanika.html.model.app.gen.cli;

import java.io.File;
import java.io.IOException;

import org.eclipse.emf.common.util.DiagnosticException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.nasdanika.common.Context;
import org.nasdanika.common.ProgressMonitor;
import org.nasdanika.html.model.app.Action;
import org.nasdanika.html.model.app.AppFactory;

Expand Down Expand Up @@ -54,7 +58,7 @@ protected URI getModelURI(URI contextURI) {
private String rootActionLocation;

@Override
public Integer call() throws Exception {
protected int generate(Context context, ProgressMonitor progressMonitor) throws IOException, DiagnosticException {
Action rootAction = AppFactory.eINSTANCE.createAction();
rootAction.setIcon(rootActionIcon);
rootAction.setText(rootActionText);
Expand All @@ -71,7 +75,7 @@ public Integer call() throws Exception {
actionModelResource.getContents().add(rootAction);
actionModelResource.save(null);
modelURI = actionModelResourceURI.appendFragment("/");
return super.call();
return super.generate(context, progressMonitor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,23 @@ public void generateActionModel(
saveLabelMap(labelMap, actionModelResourceURI);
}

public static void saveLabelMap(Map<EObject, Collection<Label>> labelMap, URI actionModelResoureURI) throws IOException {
public static void saveLabels(Iterable<Label> labels, URI actionModelResoureURI) throws IOException {
ResourceSet actionModelsResourceSet = new ResourceSetImpl();
actionModelsResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());

Resource actionModelResource = actionModelsResourceSet.createResource(actionModelResoureURI);
labelMap
labels.forEach(actionModelResource.getContents()::add);

actionModelResource.save(null);
}

public static void saveLabelMap(Map<EObject, Collection<Label>> labelMap, URI actionModelResoureURI) throws IOException {
List<Label> labels = labelMap
.values()
.stream()
.flatMap(Collection::stream)
.forEach(actionModelResource.getContents()::add);

actionModelResource.save(null);
.toList();
saveLabels(labels, actionModelResoureURI);
}

/**
Expand Down

0 comments on commit 3112d60

Please sign in to comment.