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