Search in sources :

Example 1 with ContextMapFormat

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();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) GeneratorContext(org.eclipse.xtext.generator.GeneratorContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) GenerateContextMapContext(org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapContext) GenerateContextMapWizard(org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapWizard)

Example 2 with ContextMapFormat

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);
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Scale(org.eclipse.swt.widgets.Scale) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with ContextMapFormat

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);
        }
    }
}
Also used : ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap)

Example 4 with ContextMapFormat

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);
}
Also used : JsonArray(com.google.gson.JsonArray) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) JsonObject(com.google.gson.JsonObject)

Aggregations

ContextMapFormat (org.contextmapper.dsl.generator.contextmap.ContextMapFormat)4 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ContextMap (org.contextmapper.contextmap.generator.model.ContextMap)1 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)1 ContextMapModelConverter (org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter)1 GeneratorInputException (org.contextmapper.dsl.generator.exception.GeneratorInputException)1 GenerateContextMapContext (org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapContext)1 GenerateContextMapWizard (org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapWizard)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1