Search in sources :

Example 1 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class ModeContributionItem method refresh.

void refresh() {
    final ComboViewer comboViewer = getComboViewer();
    final SortedSet<ModeFeatureReference> modeFeatureReferences = new TreeSet<>((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    if (comboViewer != null) {
        final ModeFeatureReference nullValue = AadlModalElementUtil.createModeFeatureReference(getNullValueString(), null, null);
        modeFeatureReferences.add(nullValue);
        Object selectedValue = nullValue;
        final String selectedModeName = editor == null ? null : editor.getPartProperty(SELECTED_MODE_PROPERTY_KEY);
        // Clear the combo box
        comboViewer.setInput(null);
        if (editor == null) {
            return;
        }
        final AgeDiagram diagram = editor.getDiagram();
        if (diagram != null) {
            final QueryService queryService = ContributionUtil.getQueryService(editor);
            if (queryService != null) {
                queryService.getResults(MODE_CONTAINER_QUERY, diagram, null).stream().flatMap(modeContainer -> {
                    // If container contains a modal element
                    if (AadlModalElementUtil.getModalElement(modeContainer.getBusinessObjectContext()) != null) {
                        // Get qualified modes to add to the drop-down
                        return Stream.concat(getModeBindingFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()), getModeFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()));
                    }
                    return Stream.empty();
                }).forEach(modeFeatureRef -> {
                    modeFeatureReferences.add(modeFeatureRef);
                });
                // Find ComboViewer selection
                final Optional<ModeFeatureReference> tmpSelectedValue = modeFeatureReferences.stream().filter(tmpKey -> tmpKey.getName().equalsIgnoreCase(selectedModeName)).findAny();
                if (tmpSelectedValue.isPresent()) {
                    selectedValue = tmpSelectedValue.get();
                }
                comboViewer.setLabelProvider(new LabelProvider() {

                    @Override
                    public String getText(final Object element) {
                        final ModeFeatureReference mf = (ModeFeatureReference) element;
                        return mf.getName();
                    }
                });
                comboViewer.setInput(modeFeatureReferences);
            }
        }
        final StructuredSelection newSelection = new StructuredSelection(selectedValue);
        if (!Objects.equal(newSelection, comboViewer.getSelection())) {
            comboViewer.setSelection(newSelection);
            onSelection(newSelection.getFirstElement());
        }
    }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SortedSet(java.util.SortedSet) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeSet(java.util.TreeSet) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Composite(org.eclipse.swt.widgets.Composite) ComboContributionItem(org.osate.ge.internal.ui.editor.ComboContributionItem) Subcomponent(org.osate.aadl2.Subcomponent) Objects(com.google.common.base.Objects) IEditorPart(org.eclipse.ui.IEditorPart) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) Stream(java.util.stream.Stream) UiUtil(org.osate.ge.internal.ui.util.UiUtil) QueryService(org.osate.ge.services.QueryService) AadlModalElementUtil(org.osate.ge.aadl2.internal.util.AadlModalElementUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) ExecutableQuery(org.osate.ge.query.ExecutableQuery) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ModeFeatureReference(org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) QueryService(org.osate.ge.services.QueryService) TreeSet(java.util.TreeSet) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class ConnectionHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final QueryService queryService = ctx.getQueryService();
    final Connection c = boc.getBusinessObject(Connection.class).orElseThrow();
    final QueryResult src = queryService.getFirstResult(SRC_QUERY, boc, c).orElse(null);
    final QueryResult dst = queryService.getFirstResult(DST_QUERY, boc, c).orElse(null);
    final boolean partial = (src != null && src.isPartial()) || (dst != null && dst.isPartial());
    final StyleBuilder sb = StyleBuilder.create(AadlInheritanceUtil.isInherited(boc) ? Styles.INHERITED_ELEMENT : Style.EMPTY);
    if (partial) {
        sb.dotted();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(GRAPHIC).style(sb.build()).source(src == null ? null : src.getBusinessObjectContext()).destination(dst == null ? null : dst.getBusinessObjectContext()).build());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) Connection(org.osate.aadl2.Connection) StyleBuilder(org.osate.ge.graphics.StyleBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 3 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class FlowSpecificationInstanceHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final FlowSpecificationInstance fsi = boc.getBusinessObject(FlowSpecificationInstance.class).get();
    final QueryService queryService = ctx.getQueryService();
    final QueryResult srcResult = queryService.getFirstResult(SRC_QUERY, boc, fsi).orElse(null);
    final BusinessObjectContext src = srcResult == null ? null : srcResult.getBusinessObjectContext();
    boolean partial = (srcResult != null && srcResult.isPartial());
    BusinessObjectContext dst = null;
    if (fsi.getFlowSpecification().getKind() == FlowKind.PATH) {
        final QueryResult dstResult = queryService.getFirstResult(DST_QUERY, boc, fsi).orElse(null);
        dst = dstResult == null ? null : dstResult.getBusinessObjectContext();
        partial |= (dstResult != null && dstResult.isPartial());
    }
    final StyleBuilder sb = StyleBuilder.create(AadlInheritanceUtil.isInherited(boc) ? Styles.INHERITED_ELEMENT : Style.EMPTY);
    if (fsi.getFlowSpecification().getKind() == FlowKind.PATH) {
        sb.lineWidth(4.0);
    }
    if (partial) {
        sb.dotted();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(AadlGraphics.getFlowSpecificationGraphic(fsi.getFlowSpecification())).style(sb.build()).source(src).destination(dst).build());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) StyleBuilder(org.osate.ge.graphics.StyleBuilder) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 4 with QueryService

use of org.osate.ge.services.QueryService in project osate2 by osate.

the class GeneralizatonHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final Object bo = boc.getBusinessObject();
    final QueryService queryService = ctx.getQueryService();
    final BusinessObjectContext destination = getDestination(boc, queryService);
    if (destination == null) {
        return Optional.of(GraphicalConfigurationBuilder.create().graphic(LABEL_GRAPHIC).build());
    } else {
        return Optional.of(GraphicalConfigurationBuilder.create().graphic(getConnectionGraphicalRepresentation(bo)).style(getStyle(bo)).source(boc.getParent()).destination(getDestination(boc, queryService)).build());
    }
}
Also used : QueryService(org.osate.ge.services.QueryService) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 5 with QueryService

use of org.osate.ge.services.QueryService 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)

Aggregations

QueryService (org.osate.ge.services.QueryService)18 BusinessObjectContext (org.osate.ge.BusinessObjectContext)16 Collectors (java.util.stream.Collectors)4 Subcomponent (org.osate.aadl2.Subcomponent)4 QueryResult (org.osate.ge.query.QueryResult)4 List (java.util.List)3 Optional (java.util.Optional)3 ExecutableQuery (org.osate.ge.query.ExecutableQuery)3 Objects (com.google.common.base.Objects)2 Collections (java.util.Collections)2 Stream (java.util.stream.Stream)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 ComponentImplementation (org.osate.aadl2.ComponentImplementation)2 Element (org.osate.aadl2.Element)2