Search in sources :

Example 1 with ActionService

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;
}
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 2 with ActionService

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));
                }
            });
        }
    }));
}
Also used : SwtUtil(org.osate.ge.swt.SwtUtil) StyledText(org.eclipse.swt.custom.StyledText) ActionService(org.osate.ge.internal.services.ActionService) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) Composite(org.eclipse.swt.widgets.Composite) AgeXtextUtil(org.osate.ge.internal.ui.xtext.AgeXtextUtil) GridData(org.eclipse.swt.layout.GridData) BehaviorAnnexSelectionUtil(org.osate.ge.ba.util.BehaviorAnnexSelectionUtil) XtextResource(org.eclipse.xtext.resource.XtextResource) Button(org.eclipse.swt.widgets.Button) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Caret(org.eclipse.swt.widgets.Caret) Display(org.eclipse.swt.widgets.Display) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) Objects(java.util.Objects) Adapters(org.eclipse.core.runtime.Adapters) Window(org.eclipse.jface.window.Window) EditableEmbeddedTextValue(org.osate.ge.ba.ui.properties.EditableEmbeddedTextValue) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) SWT(org.eclipse.swt.SWT) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) NamedElement(org.osate.aadl2.NamedElement) SelectionListener(org.eclipse.swt.events.SelectionListener) StyledText(org.eclipse.swt.custom.StyledText) Button(org.eclipse.swt.widgets.Button) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) XtextResource(org.eclipse.xtext.resource.XtextResource) EditableEmbeddedTextValue(org.osate.ge.ba.ui.properties.EditableEmbeddedTextValue) NamedElement(org.osate.aadl2.NamedElement) Caret(org.eclipse.swt.widgets.Caret) ActionService(org.osate.ge.internal.services.ActionService) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

ActionService (org.osate.ge.internal.services.ActionService)2 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Scene (javafx.scene.Scene)1 IProject (org.eclipse.core.resources.IProject)1 Adapters (org.eclipse.core.runtime.Adapters)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 Window (org.eclipse.jface.window.Window)1 SWT (org.eclipse.swt.SWT)1 StyledText (org.eclipse.swt.custom.StyledText)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Caret (org.eclipse.swt.widgets.Caret)1 Composite (org.eclipse.swt.widgets.Composite)1