Search in sources :

Example 1 with GenerateContextMapWizard

use of org.contextmapper.dsl.ui.handler.wizard.GenerateContextMapWizard 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)

Aggregations

ContextMapFormat (org.contextmapper.dsl.generator.contextmap.ContextMapFormat)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 GeneratorContext (org.eclipse.xtext.generator.GeneratorContext)1