Search in sources :

Example 1 with ColoringService

use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.

the class AgeEditor method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    // 
    // Create the FX canvas which is an SWT widget for embedding JavaFX content.
    // 
    fxCanvas = new FXCanvas(parent, SWT.NONE);
    fxCanvas.addDisposeListener(e -> {
        fxCanvas.getScene().setRoot(new Group());
        fxCanvas.setScene(null);
    });
    fxCanvas.addPaintListener(paintListener);
    // Suppress SWT key press handling when interaction is active
    fxCanvas.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final org.eclipse.swt.events.KeyEvent e) {
            if (activeInteraction != null) {
                e.doit = false;
            }
        }
    });
    fxCanvas.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            deactivateInteraction();
        }
    });
    // Create the context menu
    contextMenuManager = new MenuManager(MENU_ID, MENU_ID);
    contextMenuManager.setRemoveAllWhenShown(true);
    final Menu contextMenu = contextMenuManager.createContextMenu(fxCanvas);
    fxCanvas.setMenu(contextMenu);
    getEditorSite().registerContextMenu(MENU_ID, contextMenuManager, selectionProvider, true);
    // Create the action executor. It will append an action to activate the editor when undoing and redoing actions.
    actionExecutor = (label, mode, action) -> {
        final boolean reverseActionWasSpecified = actionService.execute(label, mode, action);
        // This will ensure that when the action is undone, the editor will be switched to the one in which the action was performed.
        if (isEditorActive() && reverseActionWasSpecified && !actionService.isActionExecuting() && mode == ExecutionMode.NORMAL) {
            actionService.execute("Activate Editor", ExecutionMode.APPEND_ELSE_HIDE, new ActivateAgeEditorAction(AgeEditor.this));
        }
        fireDirtyPropertyChangeEvent();
        return reverseActionWasSpecified;
    };
    // Initialize the palette model
    final AgeEditorPaletteModel.ImageProvider imageProvider = id -> {
        final RegisteredImage img = extRegistry.getImageMap().get(id);
        if (img == null) {
            return Optional.empty();
        }
        final URI imageUri = URI.createPlatformPluginURI("/" + img.plugin + "/" + img.path, true);
        if (CommonPlugin.asLocalURI(imageUri).isFile()) {
            return Optional.of(new Image(imageUri.toString()));
        } else {
            return Optional.empty();
        }
    };
    Object diagramBo = AgeDiagramUtil.getConfigurationContextBusinessObject(diagram, projectReferenceService);
    if (diagramBo == null) {
        diagramBo = project;
    }
    this.paletteModel = new AgeEditorPaletteModel(extRegistry.getPaletteContributors(), diagramBo, imageProvider);
    // If the palette item changes while an interaction is active, deactivate the interaction.
    this.paletteModel.activeItemProperty().addListener((javafx.beans.value.ChangeListener<SimplePaletteItem>) (observable, oldValue, newValue) -> deactivateInteraction());
    // Initialize the JavaFX nodes based on the diagram
    canvas = new InfiniteCanvas();
    // Set show grid based on preferences
    canvas.setShowGrid(preferenceStore.getBoolean(Preferences.SHOW_GRID));
    final Scene scene = new Scene(new DiagramEditorNode(paletteModel, canvas));
    fxCanvas.setScene(scene);
    gefDiagram = new GefAgeDiagram(diagram, coloringService);
    // Create a wrapper around the diagram's scene node.
    final Group wrapper = new DiagramNodeWrapper(gefDiagram.getSceneNode());
    // Add the wrapper to the canvas
    canvas.getContentGroup().getChildren().add(wrapper);
    gefDiagram.updateDiagramFromSceneGraph(false);
    // Treat the current state of the diagram as clean.
    cleanDiagramChangeNumber = diagram.getCurrentChangeNumber();
    adapterMap.put(LayoutInfoProvider.class, gefDiagram);
    // Create overlays
    overlays = new Overlays(gefDiagram);
    selectionProvider.addSelectionChangedListener(overlays);
    canvas.getScrolledOverlayGroup().getChildren().add(overlays);
    // Perform the initial incremental layout
    diagram.modify("Incremental Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
    // Set action executor after initial load. This occurs after the incremental layout to prevent the loading and initial layout from being undoable
    diagram.setActionExecutor(actionExecutor);
    // Refresh the dirty state whenever an operation occurs
    final IOperationHistory history = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
    history.addOperationHistoryListener(operationHistoryListener);
    canvas.setOnScroll(e -> {
        if (e.isControlDown()) {
            // Adjust zoom
            if (e.getDeltaY() < 0.0) {
                zoomOut();
            } else {
                zoomIn();
            }
        } else {
            if (e.isShiftDown()) {
                // Scroll in X direction
                canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaY());
            } else {
                // Scroll
                canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaX());
                canvas.setVerticalScrollOffset(canvas.getVerticalScrollOffset() + e.getDeltaY());
            }
        }
    });
    // 
    // Listeners to handle tooltips
    // 
    canvas.addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, e -> {
        if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
            final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
            if (de != null) {
                tooltipManager.mouseEnter(de);
            }
        }
    });
    canvas.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, e -> {
        if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
            final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
            if (de != null) {
                tooltipManager.mouseExit(de);
            }
        }
    });
    // 
    // General input handlers
    // 
    // Event handler. Delegates to input event handlers or the active interaction as appropriate
    final EventHandler<? super InputEvent> handleInput = e -> {
        if (activeInteraction == null) {
            // Delegate processing of the event to the input event handlers
            for (final InputEventHandler inputEventHandler : inputEventHandlers) {
                final InputEventHandler.HandledEvent r = inputEventHandler.handleEvent(e);
                if (r != null) {
                    activeInteraction = r.newInteraction;
                    if (activeInteraction != null) {
                        canvas.setCursor(activeInteraction.getCursor());
                        if (tooltipManager != null) {
                            tooltipManager.hideTooltip();
                        }
                    }
                    break;
                }
            }
        } else {
            if (activeInteraction.handleEvent(e) == InteractionState.COMPLETE) {
                deactivateInteraction();
            }
            canvas.setCursor(activeInteraction == null ? null : activeInteraction.getCursor());
        }
    };
    // Handle mouse button presses
    canvas.addEventFilter(MouseEvent.MOUSE_PRESSED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_DRAGGED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_RELEASED, handleInput);
    scene.addEventFilter(KeyEvent.KEY_PRESSED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_MOVED, e -> {
        if (activeInteraction == null) {
            Cursor cursor = Cursor.DEFAULT;
            for (final InputEventHandler inputEventHandler : inputEventHandlers) {
                final Cursor overrideCursor = inputEventHandler.getCursor(e);
                if (overrideCursor != null) {
                    cursor = overrideCursor;
                    break;
                }
            }
            canvas.setCursor(cursor);
        }
        handleInput.handle(e);
    });
    // Create input event handlers
    inputEventHandlers.add(new OpenPropertiesViewInputEventHandler(this));
    inputEventHandlers.add(new ResizeInputEventHandler(this));
    inputEventHandlers.add(new MarqueeSelectInputEventHandler(this));
    inputEventHandlers.add(new MoveConnectionPointTool(this));
    inputEventHandlers.add(new RenameInputEventHandler(this));
    inputEventHandlers.add(new SelectInputEventHandler(this));
    inputEventHandlers.add(new MoveInputEventHandler(this));
    inputEventHandlers.add(new PaletteCommandInputEventHandler(this));
}
Also used : DiagramModifier(org.osate.ge.internal.diagram.runtime.DiagramModifier) Tool(org.osate.ge.internal.ui.tools.Tool) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) InteractionState(org.osate.ge.gef.ui.editor.Interaction.InteractionState) BusinessObjectContext(org.osate.ge.BusinessObjectContext) DefaultQueryService(org.osate.ge.services.impl.DefaultQueryService) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) CommonPlugin(org.eclipse.emf.common.CommonPlugin) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) StatusManager(org.eclipse.ui.statushandlers.StatusManager) ProjectProvider(org.osate.ge.internal.services.ProjectProvider) Transform(javafx.scene.transform.Transform) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Rectangle(javafx.scene.shape.Rectangle) AgeGefUiPlugin(org.osate.ge.gef.ui.AgeGefUiPlugin) KeyEvent(javafx.scene.input.KeyEvent) UiService(org.osate.ge.internal.services.UiService) Group(javafx.scene.Group) IContentOutlinePage(org.eclipse.ui.views.contentoutline.IContentOutlinePage) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IOperationHistoryListener(org.eclipse.core.commands.operations.IOperationHistoryListener) ReferenceService(org.osate.ge.internal.services.ReferenceService) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Overlays(org.osate.ge.gef.ui.editor.overlays.Overlays) SWT(org.eclipse.swt.SWT) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) EditorPart(org.eclipse.ui.part.EditorPart) AgeDiagramProvider(org.osate.ge.internal.AgeDiagramProvider) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Bounds(javafx.geometry.Bounds) PaintListener(org.eclipse.swt.events.PaintListener) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) URI(org.eclipse.emf.common.util.URI) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) ListenerList(org.eclipse.core.runtime.ListenerList) IEditorSite(org.eclipse.ui.IEditorSite) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPropertySheetPage(org.eclipse.ui.views.properties.IPropertySheetPage) ArrayList(java.util.ArrayList) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) AgeContentOutlinePage(org.osate.ge.internal.ui.editor.AgeContentOutlinePage) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ITabbedPropertySheetPageContributor(org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta) ReferenceResolutionService(org.osate.ge.services.ReferenceResolutionService) IFile(org.eclipse.core.resources.IFile) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) FXCanvas(javafx.embed.swt.FXCanvas) Color(javafx.scene.paint.Color) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SelectAllAction(org.osate.ge.internal.ui.editor.actions.SelectAllAction) Node(javafx.scene.Node) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) TabbedPropertySheetPage(org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) ProjectReferenceServiceProxy(org.osate.ge.internal.services.impl.ProjectReferenceServiceProxy) Cursor(javafx.scene.Cursor) QueryService(org.osate.ge.services.QueryService) IPartListener(org.eclipse.ui.IPartListener) IContextService(org.eclipse.ui.contexts.IContextService) InputEvent(javafx.scene.input.InputEvent) DiagramModificationAdapter(org.osate.ge.internal.diagram.runtime.DiagramModificationAdapter) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Preferences(org.osate.ge.gef.ui.preferences.Preferences) Image(javafx.scene.image.Image) EventHandler(javafx.event.EventHandler) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Affine(javafx.scene.transform.Affine) IAction(org.eclipse.jface.action.IAction) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) DefaultColoringService(org.osate.ge.internal.services.impl.DefaultColoringService) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException) ModificationsCompletedEvent(org.osate.ge.internal.diagram.runtime.ModificationsCompletedEvent) ActionService(org.osate.ge.internal.services.ActionService) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) ISelectionListener(org.eclipse.ui.ISelectionListener) DiagramModificationListener(org.osate.ge.internal.diagram.runtime.DiagramModificationListener) SimplePaletteItem(org.osate.ge.gef.palette.SimplePaletteItem) BusinessObjectNodeFactory(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNodeFactory) DefaultReferenceResolutionService(org.osate.ge.services.impl.DefaultReferenceResolutionService) Bundle(org.osgi.framework.Bundle) ActionExecutor(org.osate.ge.internal.services.ActionExecutor) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display) DiagramSerialization(org.osate.ge.internal.diagram.runtime.DiagramSerialization) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) DefaultActionService(org.osate.ge.internal.services.impl.DefaultActionService) List(java.util.List) DeactivatedEvent(org.osate.ge.internal.ui.tools.DeactivatedEvent) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) Optional(java.util.Optional) ISelection(org.eclipse.jface.viewers.ISelection) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) DefaultDiagramElementGraphicalConfigurationProvider(org.osate.ge.internal.diagram.runtime.updating.DefaultDiagramElementGraphicalConfigurationProvider) SystemInstanceLoadingService(org.osate.ge.internal.services.SystemInstanceLoadingService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CopyAction(org.osate.ge.internal.ui.editor.actions.CopyAction) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Scene(javafx.scene.Scene) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) DiagramContextChecker(org.osate.ge.internal.ui.editor.DiagramContextChecker) ColoringService(org.osate.ge.internal.services.ColoringService) ImmutableList(com.google.common.collect.ImmutableList) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) ActivatedEvent(org.osate.ge.internal.ui.tools.ActivatedEvent) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) ActivateAgeEditorAction(org.osate.ge.internal.ui.editor.ActivateAgeEditorAction) DefaultBusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.DefaultBusinessObjectTreeUpdater) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeDiagramUtil(org.osate.ge.internal.diagram.runtime.AgeDiagramUtil) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) IResource(org.eclipse.core.resources.IResource) Menu(org.eclipse.swt.widgets.Menu) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PasteAction(org.osate.ge.internal.ui.editor.actions.PasteAction) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) Group(javafx.scene.Group) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ActivateAgeEditorAction(org.osate.ge.internal.ui.editor.ActivateAgeEditorAction) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) Image(javafx.scene.image.Image) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) SimplePaletteItem(org.osate.ge.gef.palette.SimplePaletteItem) Cursor(javafx.scene.Cursor) FocusEvent(org.eclipse.swt.events.FocusEvent) URI(org.eclipse.emf.common.util.URI) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) Menu(org.eclipse.swt.widgets.Menu) FXCanvas(javafx.embed.swt.FXCanvas) Scene(javafx.scene.Scene) Overlays(org.osate.ge.gef.ui.editor.overlays.Overlays) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) MenuManager(org.eclipse.jface.action.MenuManager)

Example 2 with ColoringService

use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.

the class CreateEndToEndFlowSpecificationTool method activated.

@Override
public void activated(final ActivatedEvent ctx) {
    final UiService uiService = ctx.getUiService();
    try {
        ctx.getSelectedBoc().ifPresent(selectedBoc -> {
            final AadlModificationService aadlModService = ctx.getAadlModificatonService();
            final ColoringService coloringService = ctx.getColoringService();
            // Check for existing errors and warnings
            final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
            // Do not allow tool activation if there are errors in the models
            final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
            if (!errors.isEmpty()) {
                Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create End-To-End", errors).open());
            } else {
                // Create a coloring object that will allow adjustment of pictogram
                coloring = coloringService.adjustColors();
                // Create and update based on current selection
                createFlowDialog.create();
                if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
                    update(Collections.singletonList(selectedBoc));
                } else {
                    final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
                    while (segmentIt.hasNext()) {
                        final SegmentData segmentData = segmentIt.next();
                        setColor(segmentData, Color.MAGENTA.darker());
                    }
                    for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
                    }
                    update();
                }
                if (createFlowDialog.open() == Window.OK && createFlowDialog != null) {
                    createFlowDialog.getFlow().ifPresent(endToEndFlow -> {
                        if (createFlowDialog.eteFlowToEdit != null) {
                            // Editing end to end flow
                            final EndToEndFlow endToEndFlowToEdit = (EndToEndFlow) createFlowDialog.eteFlowToEdit;
                            aadlModService.modify(endToEndFlowToEdit, eTEFlowToEdit -> {
                                eTEFlowToEdit.getAllFlowSegments().clear();
                                eTEFlowToEdit.getAllFlowSegments().addAll(endToEndFlow.getAllFlowSegments());
                                eTEFlowToEdit.setName(endToEndFlow.getName());
                                eTEFlowToEdit.getInModeOrTransitions().clear();
                                eTEFlowToEdit.getInModeOrTransitions().addAll(endToEndFlow.getInModeOrTransitions());
                            });
                        } else {
                            // Creating end to end flow
                            createFlowDialog.getOwnerComponentImplementation().ifPresent(ownerCi -> {
                                aadlModService.modify(ownerCi, ci -> {
                                    ci.getOwnedEndToEndFlows().add(endToEndFlow);
                                    ci.setNoFlows(false);
                                });
                            });
                        }
                    });
                }
            }
        });
    } finally {
        uiService.deactivateActiveTool();
    }
}
Also used : EndToEndFlow(org.osate.aadl2.EndToEndFlow) UiService(org.osate.ge.internal.services.UiService) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ColoringService(org.osate.ge.internal.services.ColoringService)

Example 3 with ColoringService

use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.

the class CreateFlowImplementationTool method activated.

@Override
public void activated(final ActivatedEvent ctx) {
    final UiService uiService = ctx.getUiService();
    try {
        ctx.getSelectedBoc().ifPresent(selectedBoc -> {
            final AadlModificationService aadlModService = ctx.getAadlModificatonService();
            final ColoringService coloringService = ctx.getColoringService();
            // Check for existing errors and warnings
            final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
            // Do not allow tool activation if there are errors in the models
            final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
            if (!errors.isEmpty()) {
                Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create Flow Implementation", errors).open());
            } else {
                coloring = coloringService.adjustColors();
                // Create and update based on current selection
                createFlowImplDlg.create();
                if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
                    update(Collections.singletonList(selectedBoc), true);
                } else {
                    final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
                    if (segmentIt.hasNext()) {
                        // Set color for flow spec
                        setColor(segmentIt.next().getBoc(), Color.ORANGE.darker());
                        // Set color for flow segments
                        while (segmentIt.hasNext()) {
                            setColor(segmentIt.next().getBoc(), Color.MAGENTA.darker());
                        }
                    }
                    // Set color for in mode and mode transitions
                    for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
                    }
                }
                if (createFlowImplDlg.open() == Window.OK && createFlowImplDlg != null) {
                    final BusinessObjectContext ownerBoc = createFlowImplDlg.getOwnerBoc().orElse(null);
                    // Create a new flow impl based on selections
                    final FlowImplementation flowImpl = createFlowImplDlg.createFlow(ownerBoc);
                    createFlowImplDlg.getFlowComponentImplementation(ownerBoc).ifPresent(ownerCi -> {
                        // Modifications to perform
                        final List<AadlModificationService.Modification<? extends NamedElement, ? extends NamedElement>> modifications = new ArrayList<>();
                        if (createFlowImplDlg.flowImplToEdit != null) {
                            // Editing existing flow impl
                            final FlowImplementation flowImplToEdit = createFlowImplDlg.flowImplToEdit;
                            // Copy owned property associations from old flow impl to new flow impl and remove old flow impl
                            modifications.add(Modification.create(flowImplToEdit, fi -> {
                                flowImpl.getOwnedPropertyAssociations().addAll(EcoreUtil.copyAll(fi.getOwnedPropertyAssociations()));
                                EcoreUtil.remove(fi);
                            }));
                        }
                        // Add new flow impl
                        modifications.add(Modification.create(ownerCi, ci -> {
                            ci.getOwnedFlowImplementations().add(flowImpl);
                            ci.setNoFlows(false);
                        }));
                        // Perform modifications
                        aadlModService.modify(modifications);
                    });
                }
            }
        });
    } finally {
        uiService.deactivateActiveTool();
    }
}
Also used : TableViewer(org.eclipse.jface.viewers.TableViewer) StyledText(org.eclipse.swt.custom.StyledText) Tool(org.osate.ge.internal.ui.tools.Tool) Modification(org.osate.ge.internal.services.AadlModificationService.Modification) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) FlowKind(org.osate.aadl2.FlowKind) Point(org.eclipse.swt.graphics.Point) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData) SelectionChangedEvent(org.osate.ge.internal.ui.tools.SelectionChangedEvent) Aadl2Factory(org.osate.aadl2.Aadl2Factory) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Set(java.util.Set) Display(org.eclipse.swt.widgets.Display) UiService(org.osate.ge.internal.services.UiService) ContextHelpUtil(org.osate.ge.internal.ui.util.ContextHelpUtil) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ReferenceService(org.osate.ge.internal.services.ReferenceService) List(java.util.List) Window(org.eclipse.jface.window.Window) UiUtil(org.osate.ge.internal.ui.util.UiUtil) DeactivatedEvent(org.osate.ge.internal.ui.tools.DeactivatedEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) FlowSegment(org.osate.aadl2.FlowSegment) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Feature(org.osate.aadl2.Feature) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Function(java.util.function.Function) AgeAadlUtil(org.osate.ge.aadl2.internal.util.AgeAadlUtil) ArrayList(java.util.ArrayList) ColoringService(org.osate.ge.internal.services.ColoringService) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) GridData(org.eclipse.swt.layout.GridData) FlowEnd(org.osate.aadl2.FlowEnd) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) SimpleEntry(java.util.AbstractMap.SimpleEntry) RowData(org.eclipse.swt.layout.RowData) Context(org.osate.aadl2.Context) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator) Color(org.osate.ge.graphics.Color) ActivatedEvent(org.osate.ge.internal.ui.tools.ActivatedEvent) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) StyleRange(org.eclipse.swt.custom.StyleRange) ModeFeature(org.osate.aadl2.ModeFeature) ToolUtil(org.osate.ge.internal.ui.tools.ToolUtil) Adapters(org.eclipse.core.runtime.Adapters) TitleAreaDialog(org.eclipse.jface.dialogs.TitleAreaDialog) FlowImplementation(org.osate.aadl2.FlowImplementation) FlowElement(org.osate.aadl2.FlowElement) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) NamedElement(org.osate.aadl2.NamedElement) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Modification(org.osate.ge.internal.services.AadlModificationService.Modification) FlowImplementation(org.osate.aadl2.FlowImplementation) SegmentData(org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.common.util.Diagnostic) ColoringService(org.osate.ge.internal.services.ColoringService) UiService(org.osate.ge.internal.services.UiService) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) BusinessObjectContext(org.osate.ge.BusinessObjectContext) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Diagnostic (org.eclipse.emf.common.util.Diagnostic)2 BusinessObjectContext (org.osate.ge.BusinessObjectContext)2 SegmentData (org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData)2 AadlModificationService (org.osate.ge.internal.services.AadlModificationService)2 ColoringService (org.osate.ge.internal.services.ColoringService)2 UiService (org.osate.ge.internal.services.UiService)2 ImmutableList (com.google.common.collect.ImmutableList)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1