Search in sources :

Example 1 with DiagramContextChecker

use of org.osate.ge.internal.ui.editor.DiagramContextChecker in project osate2 by osate.

the class AgeEditor method updateDiagram.

@Override
public void updateDiagram() {
    // Check the context
    Display.getCurrent().syncExec(() -> {
        final boolean promptToRelink = fxCanvas.isVisible() && diagramContextWasValid;
        final DiagramContextChecker contextChecker = new DiagramContextChecker(project, projectReferenceService, systemInstanceLoader);
        final DiagramContextChecker.Result result = contextChecker.checkContextIncrementalBuild(diagram, promptToRelink);
        // Store for next execution
        diagramContextWasValid = result.isContextValid();
        // Update editor with new state
        setDiagramContextIsValid(result.isContextValid());
    });
    // Updating the diagram should not be part of the undo stack. The layout portion is not included in the action because
    // layout needs to be undoable.
    actionService.execute("Update Diagram", ExecutionMode.APPEND_ELSE_HIDE, () -> {
        // Update the diagram
        diagramUpdater.updateDiagram(diagram);
        // Perform the layout as a separate operation because the sizes for the shapes will not be set until the JavaFX nodes are updated.
        diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
        return null;
    });
}
Also used : DiagramContextChecker(org.osate.ge.internal.ui.editor.DiagramContextChecker)

Example 2 with DiagramContextChecker

use of org.osate.ge.internal.ui.editor.DiagramContextChecker in project osate2 by osate.

the class AgeEditor method init.

@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
    setInput(input);
    setSite(site);
    // Register a resource change listener to handle moving and deleting the resource.
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
    site.getWorkbenchWindow().getSelectionService().addPostSelectionListener(toolPostSelectionListener);
    site.setSelectionProvider(selectionProvider);
    // Activate Context
    final IContextService contextService = site.getService(IContextService.class);
    if (contextService != null) {
        contextService.activateContext(CONTEXT_ID);
    }
    // Register actions for retargatable actions
    new UndoRedoActionGroup(site, DefaultActionService.CONTEXT, true).fillActionBars(site.getActionBars());
    registerAction(new CopyAction());
    registerAction(new PasteAction(this));
    registerAction(new SelectAllAction(this));
    // Load the diagram
    final org.osate.ge.diagram.Diagram mmDiagram = DiagramSerialization.readMetaModelDiagram(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
    diagram = DiagramSerialization.createAgeDiagram(project, mmDiagram, extRegistry);
    // Display warning if the diagram is stored with a newer version of the diagram file format.
    if (mmDiagram.getFormatVersion() > DiagramSerialization.FORMAT_VERSION) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Diagram Created with Newer Version of OSATE", "The diagram '" + diagramFile.getName() + "' was created with a newer version of the OSATE. The diagram may not be correctly displayed. Saving the diagram with this version of OSATE may result in the loss of diagram information.");
    }
    // Ensure the project is built. This prevents being unable to find the context due to the Xtext index not having completed.
    try {
        project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
    } catch (CoreException e) {
        throw new AgeGefRuntimeException(e);
    }
    // Update the diagram to finish initializing the diagram's fields
    actionService.execute("Update on Load", ExecutionMode.HIDE, () -> {
        diagram.modify("Update Diagram", m -> {
            // Check the diagram's context
            final DiagramContextChecker contextChecker = new DiagramContextChecker(project, projectReferenceService, systemInstanceLoader);
            final boolean workbenchIsVisible = isWorkbenchVisible();
            final DiagramContextChecker.Result result = contextChecker.checkContextFullBuild(diagram, workbenchIsVisible);
            if (!result.isContextValid()) {
                // we only prompts to relink if the workbench is visible.
                if (!workbenchIsVisible) {
                    closeEditor();
                }
                final String refContextLabel = projectReferenceService.getLabel(diagram.getConfiguration().getContextBoReference());
                throw new AgeGefRuntimeException("Unable to resolve context: " + refContextLabel);
            }
            diagramUpdater.updateDiagram(diagram);
        });
        return null;
    });
    this.modelChangeNotifier.addChangeListener(modelChangeListener);
    // Set the initial selection to the diagram
    selectionProvider.setSelection(new StructuredSelection(diagram));
    site.getWorkbenchWindow().getPartService().addPartListener(partListener);
    diagram.addModificationListener(diagramModificationListener);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DiagramContextChecker(org.osate.ge.internal.ui.editor.DiagramContextChecker) CopyAction(org.osate.ge.internal.ui.editor.actions.CopyAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) PasteAction(org.osate.ge.internal.ui.editor.actions.PasteAction) CoreException(org.eclipse.core.runtime.CoreException) SelectAllAction(org.osate.ge.internal.ui.editor.actions.SelectAllAction) IContextService(org.eclipse.ui.contexts.IContextService) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Aggregations

DiagramContextChecker (org.osate.ge.internal.ui.editor.DiagramContextChecker)2 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IContextService (org.eclipse.ui.contexts.IContextService)1 UndoRedoActionGroup (org.eclipse.ui.operations.UndoRedoActionGroup)1 AgeGefRuntimeException (org.osate.ge.gef.AgeGefRuntimeException)1 CopyAction (org.osate.ge.internal.ui.editor.actions.CopyAction)1 PasteAction (org.osate.ge.internal.ui.editor.actions.PasteAction)1 SelectAllAction (org.osate.ge.internal.ui.editor.actions.SelectAllAction)1