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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations