use of org.osate.ge.internal.services.ActionService 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;
}
use of org.osate.ge.internal.services.ActionService in project osate2 by osate.
the class EmbeddedTextEditor method createControls.
private void createControls(final GridData styledTextLayoutData) {
// Create styled text
styledText = new StyledText(this, styledTextStyle);
styledText.setEditable(false);
// Set empty caret so that the caret will not show.
// Makes sure users know it is not editable.
// Note: If caret is set to null, exception may occur
// when used with the StyledTextXtextAdapter.
final Caret emptyCaret = new Caret(getShell(), SWT.NONE);
styledText.setCaret(emptyCaret);
styledText.setLayoutData(styledTextLayoutData);
styledText.addDisposeListener(e -> emptyCaret.dispose());
editBtn = new Button(this, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
final EditableEmbeddedTextValue embeddedTextValue = xtextAdapter.getEmbeddedTextValue();
final NamedElement ne = embeddedTextValue.getElementToModify();
final EditEmbeddedTextDialog dlg = new EditEmbeddedTextDialog(Display.getCurrent().getActiveShell(), embeddedTextValue, styledTextStyle, styledTextLayoutData);
if (dlg.open() == Window.OK) {
// Edit condition
BehaviorAnnexSelectionUtil.getActiveEditor().ifPresent(editorPart -> {
final ActionService actionService = Adapters.adapt(editorPart, ActionService.class);
final ModelChangeNotifier modelChangeNotifier = Objects.requireNonNull(editorPart.getAdapter(ModelChangeNotifier.class), "Unable to get model change notifier");
final IXtextDocument xtextDocument = getXtextDocument(ne).orElse(null);
if (xtextDocument != null) {
// Execute modification with xtext document
actionService.execute(embeddedTextValue.getModificationLabel(), ExecutionMode.NORMAL, new EmbeddedTextModificationAction(xtextDocument, modelChangeNotifier, dlg.getResult().getFullSource()));
} else {
final XtextResource xtextResource = getXtextResource(ne).orElseThrow();
embeddedTextValue.setEditableText(dlg.getResult().getPartialSource());
// Execute modification with xtext resource
actionService.execute(embeddedTextValue.getModificationLabel(), ExecutionMode.NORMAL, new EmbeddedTextModificationAction(xtextResource, modelChangeNotifier, embeddedTextValue));
}
});
}
}));
}
Aggregations