use of org.contextmapper.dsl.generator.contextmap.ContextMapFormat in project context-mapper-dsl by ContextMapper.
the class ContextMapGenerationHandler method runGeneration.
@Override
protected void runGeneration(Resource resource, ExecutionEvent event, IFileSystemAccess2 fsa) {
try {
if (!generator.isGraphvizInstalled()) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Graphviz installation not found", "Graphviz has not been found on your system. Ensure it is installed and the binaries are part of your PATH environment variable.");
return;
}
} catch (Exception e) {
String message = e.getMessage() != null && !"".equals(e.getMessage()) ? e.getMessage() : e.getClass().getName() + " occurred in " + this.getClass().getName();
Status status = new Status(IStatus.ERROR, DslActivator.PLUGIN_ID, message, e);
StatusManager.getManager().handle(status);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Graphviz installation check", "Your PATH variable could not be parsed to check if Graphviz is installed. The generator may not work if Graphviz is not available.");
}
GenerateContextMapContext context = createContext(event);
new WizardDialog(HandlerUtil.getActiveShell(event), new GenerateContextMapWizard(context, executionContext -> {
persistContext(event, executionContext);
generator.setContextMapFormats(context.getFormats().toArray(new ContextMapFormat[context.getFormats().size()]));
generator.setLabelSpacingFactor(context.getLabelSpacingFactor());
generator.clusterTeams(context.clusterTeams());
if (context.isFixWidth())
generator.setWidth(context.getWidth());
else if (context.isFixHeight())
generator.setHeight(context.getHeight());
generator.printAdditionalLabels(context.generateAdditionalLabels());
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
getGenerator().doGenerate(resource, fsa, new GeneratorContext());
} catch (GeneratorInputException e) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Model Input", e.getMessage());
}
}
});
return true;
})).open();
}
use of org.contextmapper.dsl.generator.contextmap.ContextMapFormat in project context-mapper-dsl by ContextMapper.
the class GenerateContextMapWizardPage method createControl.
@Override
public void createControl(Composite parent) {
container = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.verticalSpacing = 10;
container.setLayout(layout);
// name label
Label formatSelectionLabel = new Label(container, SWT.NONE);
formatSelectionLabel.setText("Generated formats:");
// format selection checkboxes
Group formatSelectionGroup = new Group(container, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
formatSelectionGroup.setLayout(gridLayout);
formatSelectionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
SelectionListener formatSelectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Button button = ((Button) event.widget);
ContextMapFormat format = ContextMapFormat.valueOf(button.getText());
if (button.getSelection())
selectedFormats.add(format);
else if (selectedFormats.contains(format))
selectedFormats.remove(format);
setPageComplete(isPageComplete());
}
};
for (ContextMapFormat format : ContextMapFormat.values()) {
Button button = new Button(formatSelectionGroup, SWT.CHECK);
button.setText(format.toString());
button.setSelection(true);
button.addSelectionListener(formatSelectionListener);
}
// fix width to custom value
widthCheckBox = new Button(container, SWT.CHECK);
widthCheckBox.setText("Fix image width: ");
widthCheckBox.setSelection(context.isFixWidth());
widthCheckBox.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
widthSpinner.setEnabled(widthCheckBox.getSelection());
if (widthCheckBox.getSelection()) {
heightCheckBox.setSelection(false);
heightSpinner.setEnabled(false);
}
}
});
widthSpinner = new Spinner(container, SWT.NONE);
widthSpinner.setMinimum(1);
widthSpinner.setMaximum(20000);
widthSpinner.setSelection(width);
widthSpinner.setIncrement(100);
widthSpinner.setEnabled(context.isFixWidth());
widthSpinner.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
width = widthSpinner.getSelection();
}
});
// fix height to custom value
heightCheckBox = new Button(container, SWT.CHECK);
heightCheckBox.setText("Fix image height:");
heightCheckBox.setSelection(context.isFixHeight());
heightCheckBox.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
heightSpinner.setEnabled(heightCheckBox.getSelection());
if (heightCheckBox.getSelection()) {
widthCheckBox.setSelection(false);
widthSpinner.setEnabled(false);
}
}
});
heightSpinner = new Spinner(container, SWT.NONE);
heightSpinner.setMinimum(1);
heightSpinner.setMaximum(20000);
heightSpinner.setSelection(height);
heightSpinner.setIncrement(100);
heightSpinner.setEnabled(context.isFixHeight());
heightSpinner.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
height = heightSpinner.getSelection();
}
});
// generate labels checkbox
Label generateLabelsLabel = new Label(container, SWT.NONE);
generateLabelsLabel.setText("Generate labels:");
generateLabelsCheckBox = new Button(container, SWT.CHECK);
generateLabelsCheckBox.setText("Labels for relationship names and implementation technologies");
generateLabelsCheckBox.setSelection(context.generateAdditionalLabels());
// cluster teams checkbox
Label clusterTeamsLabel = new Label(container, SWT.NONE);
clusterTeamsLabel.setText("Cluster team contexts:");
clusterTeamsCheckBox = new Button(container, SWT.CHECK);
clusterTeamsCheckBox.setText("Separate team/generic Bounded Contexts into clusters (team maps only)");
clusterTeamsCheckBox.setSelection(context.clusterTeams());
// spacing factor label
Label labelSpacingFactorLabel = new Label(container, SWT.NONE);
labelSpacingFactorLabel.setText("Spacing factor:");
// spacing factor selection
Scale scale = new Scale(container, SWT.HORIZONTAL);
scale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
scale.setSelection(labelSpacingFactor);
scale.setMinimum(1);
scale.setMaximum(20);
scale.setIncrement(1);
scale.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
labelSpacingFactor = scale.getSelection();
}
});
// spacing factor hint
new Label(container, SWT.NONE);
Label spacingHintLabel1 = new Label(container, SWT.NONE);
spacingHintLabel1.setText(" Hint: Increasing the spacing factor may improve the generated");
new Label(container, SWT.NONE);
Label spacingHintLabel2 = new Label(container, SWT.NONE);
spacingHintLabel2.setText(" image in case it contains overlapping labels.");
setControl(container);
setPageComplete(false);
}
use of org.contextmapper.dsl.generator.contextmap.ContextMapFormat in project context-mapper-dsl by ContextMapper.
the class ContextMapGenerator method generateFromContextMap.
@Override
protected void generateFromContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap cmlContextMap, IFileSystemAccess2 fsa, URI inputFileURI) {
String fileName = inputFileURI.trimFileExtension().lastSegment();
ContextMap contextMap = new ContextMapModelConverter().convert(cmlContextMap, printAdditionalLabels);
org.contextmapper.contextmap.generator.ContextMapGenerator generator = createContextMapGenerator();
generator.setLabelSpacingFactor(labelSpacingFactor);
generator.clusterTeams(clusterTeams);
if (this.width > 0 && useWidth)
generator.setWidth(width);
else if (this.height > 0)
generator.setHeight(height);
for (ContextMapFormat format : formats) {
try (ByteArrayOutputStream outputstream = new ByteArrayOutputStream()) {
generator.generateContextMapGraphic(contextMap, getGraphvizLibFormat(format), outputstream);
try (InputStream inputstream = new ByteArrayInputStream(outputstream.toByteArray())) {
fsa.generateFile(fileName + "_ContextMap." + format.getFileExtension(), inputstream);
}
} catch (IOException e) {
throw new RuntimeException("An error occured while generating the Context Map!", e);
}
}
}
use of org.contextmapper.dsl.generator.contextmap.ContextMapFormat in project context-mapper-dsl by ContextMapper.
the class ContextMapGenerationCommand method executeCommand.
@Override
public void executeCommand(CMLResource cmlResource, Document document, ILanguageServerAccess access, ExecuteCommandParams params) {
if (params.getArguments().size() != 2 || params.getArguments().get(1).getClass() != JsonArray.class)
throw new ContextMapperApplicationException("This command expects a JSON array with the generator parameters as a second parameter.");
JsonArray paramArray = (JsonArray) params.getArguments().get(1);
JsonObject paramObject = paramArray.get(0).getAsJsonObject();
ContextMapFormat[] formats = getFormatsFromInputArray(paramObject.get("formats").getAsJsonArray());
boolean fixWidth = paramObject.get("fixWidth").getAsBoolean();
boolean fixHeight = paramObject.get("fixHeight").getAsBoolean();
boolean generateLabels = paramObject.get("generateLabels").getAsBoolean();
int labelSpacingFactor = paramObject.get("labelSpacingFactor").getAsInt();
boolean clusterTeams = paramObject.get("clusterTeams").getAsBoolean();
generator.setContextMapFormats(formats);
generator.setLabelSpacingFactor(labelSpacingFactor);
generator.printAdditionalLabels(generateLabels);
generator.clusterTeams(clusterTeams);
if (fixWidth)
generator.setWidth(paramObject.get("width").getAsInt());
else if (fixHeight)
generator.setHeight(paramObject.get("height").getAsInt());
super.executeCommand(cmlResource, document, access, params);
}
Aggregations