Search in sources :

Example 1 with DiagramService

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;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ComponentImplementation(org.osate.aadl2.ComponentImplementation) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with DiagramService

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;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) AadlPackage(org.osate.aadl2.AadlPackage) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 3 with DiagramService

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;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 4 with DiagramService

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;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) DiagramService(org.osate.ge.internal.services.DiagramService) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause)

Example 5 with DiagramService

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) DiagramService(org.osate.ge.internal.services.DiagramService)

Aggregations

DiagramService (org.osate.ge.internal.services.DiagramService)10 IEditorPart (org.eclipse.ui.IEditorPart)5 BusinessObjectContext (org.osate.ge.BusinessObjectContext)5 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)4 IFile (org.eclipse.core.resources.IFile)3 ISelection (org.eclipse.jface.viewers.ISelection)2 AadlPackage (org.osate.aadl2.AadlPackage)2 DefaultAnnexSubclause (org.osate.aadl2.DefaultAnnexSubclause)2 IProject (org.eclipse.core.resources.IProject)1 EObject (org.eclipse.emf.ecore.EObject)1 Classifier (org.osate.aadl2.Classifier)1 ComponentClassifier (org.osate.aadl2.ComponentClassifier)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 ComponentType (org.osate.aadl2.ComponentType)1 Subcomponent (org.osate.aadl2.Subcomponent)1 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)1 GraphicalEditor (org.osate.ge.GraphicalEditor)1 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)1 BusinessObjectHandler (org.osate.ge.businessobjecthandling.BusinessObjectHandler)1 AadlModificationService (org.osate.ge.internal.services.AadlModificationService)1