Search in sources :

Example 1 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class ShowElementsInModeHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InternalDiagramEditor editor = getDiagramEditor(event);
    referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
    final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(editor, ExtensionRegistryService.class), "Unable to retrieve extension service");
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
    final BusinessObjectNode boTree = getBoTree(editor, boTreeUpdater);
    final List<BusinessObjectContext> selectedModes = AgeHandlerUtil.getSelectedBusinessObjectContexts().stream().filter(de -> isModal(de.getBusinessObject())).collect(Collectors.toList());
    for (final BusinessObjectContext selectedMode : selectedModes) {
        enableInModeNodes(bopHelper, boTree, selectedMode);
    }
    final AgeDiagram diagram = editor.getDiagram();
    final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
    editor.getActionExecutor().execute("Show Elements In Mode", ExecutionMode.NORMAL, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram, boTree);
        // Update layout
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
        return null;
    });
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ModalElement(org.osate.aadl2.ModalElement) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ModeTransition(org.osate.aadl2.ModeTransition) LinkedList(java.util.LinkedList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) IEditorPart(org.eclipse.ui.IEditorPart) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) FeatureGroup(org.osate.aadl2.FeatureGroup) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) ModeFeature(org.osate.aadl2.ModeFeature) UUID(java.util.UUID) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ModeInstance(org.osate.aadl2.instance.ModeInstance) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) Queue(java.util.Queue) AbstractHandler(org.eclipse.core.commands.AbstractHandler) NamedElement(org.osate.aadl2.NamedElement) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)

Example 2 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class ShowAllContentsHandler method getContentFilterProvider.

private ContentFilterProvider getContentFilterProvider() {
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    return extService;
}
Also used : Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService)

Example 3 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class ShowContentFilterHandler method getContentFilterProvider.

private ContentFilterProvider getContentFilterProvider() {
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final ExtensionRegistryService extService = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    return extService;
}
Also used : Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService)

Example 4 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class GefDiagramExportService method loadDiagram.

private GefAgeDiagram loadDiagram(final IFile diagramFile) {
    final URI uri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
    final IProject project = ProjectUtil.getProjectOrNull(uri);
    final org.osate.ge.diagram.Diagram mmDiagram = DiagramSerialization.readMetaModelDiagram(uri);
    final IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(GefDiagramExportService.class).getBundleContext());
    final ExtensionRegistryService extensionRegistry = Objects.requireNonNull(eclipseContext.get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
    final ReferenceService referenceService = Objects.requireNonNull(eclipseContext.get(ReferenceService.class), "unable to retrieve reference service");
    final ActionService actionService = Objects.requireNonNull(eclipseContext.get(ActionService.class), "unable to retrieve action service");
    final AgeDiagram diagram = DiagramSerialization.createAgeDiagram(project, mmDiagram, extensionRegistry);
    // Update the diagram
    final QueryService queryService = new DefaultQueryService(referenceService);
    final ProjectProvider projectProvider = diagramFile::getProject;
    final ProjectReferenceService projectReferenceService = new ProjectReferenceServiceProxy(referenceService, projectProvider);
    final BusinessObjectNodeFactory nodeFactory = new BusinessObjectNodeFactory(projectReferenceService);
    final DefaultBusinessObjectTreeUpdater boTreeUpdater = new DefaultBusinessObjectTreeUpdater(projectProvider, extensionRegistry, projectReferenceService, queryService, nodeFactory);
    final DefaultDiagramElementGraphicalConfigurationProvider deInfoProvider = new DefaultDiagramElementGraphicalConfigurationProvider(queryService, () -> diagram, extensionRegistry);
    final DiagramUpdater diagramUpdater = new DiagramUpdater(boTreeUpdater, deInfoProvider, actionService, projectReferenceService, projectReferenceService);
    diagramUpdater.updateDiagram(diagram);
    // Create the GEF Diagram
    final GefAgeDiagram gefDiagram = new GefAgeDiagram(diagram, new DefaultColoringService(new org.osate.ge.internal.services.impl.DefaultColoringService.StyleRefresher() {

        @Override
        public void refreshDiagramColoring() {
        // No-op. Handling coloring service refresh requests is not required.
        }

        @Override
        public void refreshColoring(final Collection<DiagramElement> diagramElements) {
        // No-op. Handling coloring service refresh requests is not required.
        }
    }));
    // Add to scene. This is required for text rendering
    new Scene(gefDiagram.getSceneNode());
    // Update the diagram to reflect the scene graph and perform incremental layout
    gefDiagram.updateDiagramFromSceneGraph(false);
    diagram.modify("Incremental Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
    return gefDiagram;
}
Also used : ReferenceService(org.osate.ge.internal.services.ReferenceService) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) DefaultColoringService(org.osate.ge.internal.services.impl.DefaultColoringService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) URI(org.eclipse.emf.common.util.URI) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ProjectReferenceServiceProxy(org.osate.ge.internal.services.impl.ProjectReferenceServiceProxy) DefaultQueryService(org.osate.ge.services.impl.DefaultQueryService) BusinessObjectNodeFactory(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNodeFactory) ActionService(org.osate.ge.internal.services.ActionService) ProjectProvider(org.osate.ge.internal.services.ProjectProvider) DefaultDiagramElementGraphicalConfigurationProvider(org.osate.ge.internal.diagram.runtime.updating.DefaultDiagramElementGraphicalConfigurationProvider) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) Scene(javafx.scene.Scene) IProject(org.eclipse.core.resources.IProject) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) DefaultQueryService(org.osate.ge.services.impl.DefaultQueryService) QueryService(org.osate.ge.services.QueryService) DefaultBusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.DefaultBusinessObjectTreeUpdater) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Collection(java.util.Collection)

Example 5 with ExtensionRegistryService

use of org.osate.ge.internal.services.ExtensionRegistryService in project osate2 by osate.

the class ConfigureDiagramHandler 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 elements
    final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = diagramEditor.getDiagram();
    if (diagram == null) {
        throw new RuntimeException("Unable to get diagram");
    }
    // Get services
    final BusinessObjectTreeUpdater boTreeUpdater = diagramEditor.getBoTreeUpdater();
    final DiagramUpdater diagramUpdater = diagramEditor.getDiagramUpdater();
    final ProjectProvider projectProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectProvider.class), "Unable to retrieve project provider");
    final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, LayoutInfoProvider.class), "Unable to retrieve layout information provider");
    final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ExtensionRegistryService.class), "Unable to retrieve extension service");
    final ProjectReferenceService referenceService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectReferenceService.class), "Unable to retrieve reference service");
    BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(diagram);
    // Update the tree so that it's business objects are refreshed
    boTree = boTreeUpdater.updateTree(diagram.getConfiguration(), boTree);
    final DefaultDiagramConfigurationDialogModel model = new DefaultDiagramConfigurationDialogModel(referenceService, extService, projectProvider, diagram.getConfiguration().getDiagramType());
    // Create a BO path for the initial selection. The initial selection will be the first diagram element which will be included in the BO tree.
    Object[] initialSelectionBoPath = null;
    for (final DiagramElement selectedDiagramElement : selectedDiagramElements) {
        if (model.shouldShowBusinessObject(selectedDiagramElement.getBusinessObject())) {
            // Only build a selection path if the BO will be shown
            DiagramNode tmp = selectedDiagramElement;
            final LinkedList<Object> boList = new LinkedList<>();
            while (tmp instanceof DiagramElement) {
                boList.addFirst(tmp.getBusinessObject());
                tmp = tmp.getParent();
            }
            initialSelectionBoPath = boList.toArray();
            break;
        }
    }
    // Show the dialog
    final DiagramConfigurationDialog.Result result = DiagramConfigurationDialog.show(null, model, diagram.getConfiguration(), boTree, initialSelectionBoPath);
    if (result != null) {
        // Update the diagram
        diagramEditor.getActionExecutor().execute("Set Diagram Configuration", ExecutionMode.NORMAL, () -> {
            diagram.modify("Set Diagram Configuration", m -> {
                m.setDiagramConfiguration(result.getDiagramConfiguration());
                diagramUpdater.updateDiagram(diagram, result.getBusinessObjectTree());
            });
            // Clear ghosts triggered by this update to prevent them from being unghosted during the next update.
            diagramUpdater.clearGhosts();
            diagram.modify("Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
            return null;
        });
    }
    return null;
}
Also used : BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) DefaultDiagramConfigurationDialogModel(org.osate.ge.internal.ui.dialogs.DefaultDiagramConfigurationDialogModel) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) IEditorPart(org.eclipse.ui.IEditorPart) LinkedList(java.util.LinkedList) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) DiagramConfigurationDialog(org.osate.ge.internal.ui.dialogs.DiagramConfigurationDialog) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) ProjectProvider(org.osate.ge.internal.services.ProjectProvider)

Aggregations

ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)12 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)8 IEditorPart (org.eclipse.ui.IEditorPart)7 Bundle (org.osgi.framework.Bundle)7 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)6 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)5 List (java.util.List)3 Objects (java.util.Objects)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)3 LayoutInfoProvider (org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider)3 ProjectProvider (org.osate.ge.internal.services.ProjectProvider)3 ProjectReferenceService (org.osate.ge.internal.services.ProjectReferenceService)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2