use of org.osate.ge.internal.services.DiagramService in project osate2 by osate.
the class GoToImplementationDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
// Get diagram and selected BOCs
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 0) {
throw new RuntimeException("No element selected");
}
final Object bo = selectedBusinessObjectContexts.get(0).getBusinessObject();
final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
final ComponentImplementation ci = Objects.requireNonNull(getComponentImplementation(bo), "Unable to retrieve component implementation");
diagramService.openOrCreateDiagramForBusinessObject(ci);
return null;
}
use of org.osate.ge.internal.services.DiagramService in project osate2 by osate.
the class GoToPackageDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
// Get diagram and selected BOCs
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 0) {
throw new RuntimeException("No element selected");
}
final Object bo = selectedBusinessObjectContexts.get(0).getBusinessObject();
final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
final AadlPackage pkg = Objects.requireNonNull(getPackage(bo), "Unable to retrieve package");
diagramService.openOrCreateDiagramForBusinessObject(pkg);
return null;
}
use of org.osate.ge.internal.services.DiagramService in project osate2 by osate.
the class OpenAssociatedDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
// Get diagram and selected BOCs
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 0) {
throw new RuntimeException("No element selected");
}
final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
final Object bo = selectedBusinessObjectContext.getBusinessObject();
final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
if (bo instanceof AadlPackage || bo instanceof Classifier) {
diagramService.openOrCreateDiagramForBusinessObject(bo);
} else if (bo instanceof Subcomponent) {
final ComponentClassifier cc = AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo);
if (cc != null) {
diagramService.openOrCreateDiagramForBusinessObject(cc);
}
}
return null;
}
use of org.osate.ge.internal.services.DiagramService in project osate2 by osate.
the class OpenBehaviorAnnexDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
final DefaultAnnexSubclause diagramContext = BehaviorAnnexSelectionUtil.getDefaultBehaviorAnnexSubclause(selection, HandlerUtil.getActiveEditor(event)).orElseThrow(() -> new RuntimeException("diagramContext cannot be null"));
final DiagramService diagramService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
diagramService.openOrCreateDiagramForBusinessObject(diagramContext);
return null;
}
use of org.osate.ge.internal.services.DiagramService in project osate2 by osate.
the class CreateDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
try {
Log.ok(getClass().getSimpleName() + " Started");
// Determine the context BO
final Object contextBo = SelectionUtil.getDiagramContext(AgeHandlerUtil.getCurrentSelection(), HandlerUtil.getActiveEditor(event));
if (contextBo == null) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Unable to Create Diagram", "Selection is not a valid diagram context.");
return null;
}
final DiagramService diagramService = (DiagramService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
final IFile diagramFile = diagramService.createDiagram(contextBo);
if (diagramFile != null) {
EditorUtil.openEditor(diagramFile, false);
}
Log.ok(getClass().getSimpleName() + " Finished");
} catch (RuntimeException e) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Activator.PLUGIN_ID, "Error creating diagram: " + e.getMessage());
Log.error("Error creating diagram", e);
throw e;
}
return null;
}
Aggregations