Search in sources :

Example 1 with ContextMapperApplicationException

use of org.contextmapper.dsl.exception.ContextMapperApplicationException in project context-mapper-dsl by ContextMapper.

the class RefactoringActionGroup method fillRefactorMenu.

private int fillRefactorMenu(IMenuManager refactorSubmenu) {
    int added = 0;
    List<Command> allCommands = Lists.newArrayList(commandService.getDefinedCommands());
    for (Command command : allCommands.stream().filter(c -> c.getId().startsWith("org.contextmapper") && c.getId().endsWith("RefactoringCommand")).collect(Collectors.toList())) {
        Action action = new Action() {

            public void run() {
                try {
                    handlerService.executeCommand(command.getId(), null);
                } catch (Exception e) {
                    throw new ContextMapperApplicationException("Could not execute command with id '" + command.getId() + "'.", e);
                }
            }
        };
        try {
            action.setActionDefinitionId(command.getId());
            action.setText(command.getName());
            action.setEnabled(command.isEnabled());
            added += addAction(refactorSubmenu, action);
        } catch (NotDefinedException e) {
            throw new ContextMapperApplicationException("The command with the id '" + command.getId() + "' is not properly defined!", e);
        }
    }
    return added;
}
Also used : DslActivator(org.contextmapper.dsl.ui.internal.DslActivator) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) URL(java.net.URL) MenuManager(org.eclipse.jface.action.MenuManager) IHandler(org.eclipse.core.commands.IHandler) ICommandService(org.eclipse.ui.commands.ICommandService) Action(org.eclipse.jface.action.Action) Collectors(java.util.stream.Collectors) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ActionGroup(org.eclipse.ui.actions.ActionGroup) CMLQuickMenuCreator(org.contextmapper.dsl.ui.editor.CMLQuickMenuCreator) CMLImageDescriptionFactory(org.contextmapper.dsl.ui.images.CMLImageDescriptionFactory) IHandlerService(org.eclipse.ui.handlers.IHandlerService) List(java.util.List) Lists(com.google.common.collect.Lists) Command(org.eclipse.core.commands.Command) IMenuManager(org.eclipse.jface.action.IMenuManager) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Platform(org.eclipse.core.runtime.Platform) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Bundle(org.osgi.framework.Bundle) Action(org.eclipse.jface.action.Action) Command(org.eclipse.core.commands.Command) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException)

Example 2 with ContextMapperApplicationException

use of org.contextmapper.dsl.exception.ContextMapperApplicationException in project context-mapper-dsl by ContextMapper.

the class ExtractSuggestedServiceRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    BoundedContext bc = (BoundedContext) getSelectedElement();
    ChooseName4NewBoundedContextContext refactoringContext = new ChooseName4NewBoundedContextContext("NewBoundedContext");
    originalCMLResource = getAllResources().getResource(new ExtractSuggestedService(bc, "TempBC").constructOriginalModelUri(), false);
    if (originalCMLResource == null)
        throw new ContextMapperApplicationException("We were not able to find the original CML model. Please do not rename the models after generating service cut suggestions.");
    new WizardDialog(HandlerUtil.getActiveShell(event), new ChooseName4NewBoundedContextWizard(refactoringContext, executionContext -> {
        return finishRefactoring(new ExtractSuggestedService(bc, executionContext.getNewBoundedContextName()), new CMLResource(originalCMLResource), event);
    })).open();
}
Also used : ExtractSuggestedService(org.contextmapper.dsl.refactoring.ExtractSuggestedService) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) ChooseName4NewBoundedContextContext(org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextContext) ChooseName4NewBoundedContextWizard(org.contextmapper.dsl.ui.handler.wizard.ChooseName4NewBoundedContextWizard) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with ContextMapperApplicationException

use of org.contextmapper.dsl.exception.ContextMapperApplicationException in project context-mapper-dsl by ContextMapper.

the class CMLActionRegistry method createCommandQuickFix4ValidationMessage.

private List<Either<Command, CodeAction>> createCommandQuickFix4ValidationMessage(String validationId, Diagnostic diagnostic, ICodeActionService2.Options options) {
    List<Either<Command, CodeAction>> codeActions = Lists.newLinkedList();
    if (quickFixCommandRegistry.get(validationId) == null || quickFixCommandRegistry.get(validationId).isEmpty())
        return codeActions;
    CMLResource cmlResource = new CMLResource(options.getResource());
    List<EObject> objects = selectionResolver.resolveAllSelectedEObjects(cmlResource, options.getDocument().getOffSet(diagnostic.getRange().getStart()), options.getDocument().getOffSet(diagnostic.getRange().getEnd()));
    if (objects.isEmpty())
        throw new ContextMapperApplicationException("We could not find the selected object for the triggered quickfix.");
    for (QuickfixCommandMapper quickFixCommand : quickFixCommandRegistry.get(validationId)) {
        CodeAction action = quickFixCommand.getCodeAction(cmlResource, objects.get(0));
        List<Diagnostic> diagnostics = Lists.newLinkedList();
        diagnostics.add(diagnostic);
        action.setDiagnostics(diagnostics);
        codeActions.add(Either.forRight(action));
    }
    return codeActions;
}
Also used : ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) QuickfixCommandMapper(org.contextmapper.dsl.ide.quickfix.QuickfixCommandMapper) EObject(org.eclipse.emf.ecore.EObject) CodeAction(org.eclipse.lsp4j.CodeAction) CMLResource(org.contextmapper.dsl.cml.CMLResource) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 4 with ContextMapperApplicationException

use of org.contextmapper.dsl.exception.ContextMapperApplicationException in project context-mapper-dsl by ContextMapper.

the class CMLActionRegistry method createQuickFixCodeAction.

private CodeAction createQuickFixCodeAction(CMLQuickFix<? extends EObject> quickFix, Diagnostic diagnostic, ICodeActionService2.Options options, boolean useRootContext) {
    CodeAction action = new CodeAction(quickFix.getName());
    action.setDiagnostics(Arrays.asList(new Diagnostic[] { diagnostic }));
    action.setKind(CodeActionKind.QuickFix);
    action.setEdit(editRecorder.recordWorkspaceEdit(options.getLanguageServerAccess(), options.getResource().getURI(), options.getDocument(), (Resource resource) -> {
        CMLResource cmlResource = new CMLResource(resource);
        if (useRootContext) {
            quickFix.applyQuickfix2EObject(cmlResource.getContextMappingModel());
        } else {
            List<EObject> objects = selectionResolver.resolveAllSelectedEObjects(cmlResource, options.getDocument().getOffSet(diagnostic.getRange().getStart()), options.getDocument().getOffSet(diagnostic.getRange().getEnd()));
            if (objects.isEmpty())
                throw new ContextMapperApplicationException("Selected object for quick fix could not be found.");
            // we can assume that there is only one object per validation message
            quickFix.applyQuickfix2EObject(EcoreUtil.resolve(objects.get(0), resource));
        }
    }));
    return action;
}
Also used : ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CodeAction(org.eclipse.lsp4j.CodeAction) Resource(org.eclipse.emf.ecore.resource.Resource) CMLResource(org.contextmapper.dsl.cml.CMLResource) CMLResource(org.contextmapper.dsl.cml.CMLResource) Diagnostic(org.eclipse.lsp4j.Diagnostic) List(java.util.List)

Example 5 with ContextMapperApplicationException

use of org.contextmapper.dsl.exception.ContextMapperApplicationException in project context-mapper-dsl by ContextMapper.

the class NewCMLFileWizard method performFinish.

@Override
public boolean performFinish() {
    IFile file = mainPage.createNewFile();
    if (file == null) {
        return false;
    }
    selectAndReveal(file);
    // Open editor on new file.
    IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
    try {
        if (dw != null) {
            IWorkbenchPage page = dw.getActivePage();
            if (page != null) {
                IDE.openEditor(page, file, true);
            }
        }
    } catch (PartInitException e) {
        throw new ContextMapperApplicationException(e.getMessage(), e);
    }
    return true;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)27 List (java.util.List)7 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 CMLResource (org.contextmapper.dsl.cml.CMLResource)5 JsonArray (com.google.gson.JsonArray)4 Collectors (java.util.stream.Collectors)4 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)4 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)4 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)4 URI (org.eclipse.emf.common.util.URI)4 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)4 Lists (com.google.common.collect.Lists)3 File (java.io.File)3 IOException (java.io.IOException)3 Optional (java.util.Optional)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 SolverAlgorithm (ch.hsr.servicecutter.solver.SolverAlgorithm)2 Maps (com.google.common.collect.Maps)2