Search in sources :

Example 1 with TargetedPaletteCommand

use of org.osate.ge.palette.TargetedPaletteCommand in project osate2 by osate.

the class CreateConnectionInteraction method handleEvent.

@Override
public HandledEvent handleEvent(final InputEvent e) {
    if (e.getEventType() != MouseEvent.MOUSE_PRESSED) {
        return null;
    }
    // Retrieve the active palette command
    final PaletteCommand cmd = editor.getPaletteModel().getActivePaletteCommand();
    if (cmd == null) {
        return null;
    }
    final MouseEvent me = (MouseEvent) e;
    if (me.getButton() == MouseButton.PRIMARY) {
        if (cmd instanceof TargetedPaletteCommand) {
            final TargetedPaletteCommand tc = (TargetedPaletteCommand) cmd;
            createGetTargetedOperationContext((MouseEvent) e).ifPresent(c -> {
                final Node sceneNode = editor.getSceneNode((DiagramNode) c.getTarget());
                final Point2D p = getTargetPosition(sceneNode, me.getSceneX(), me.getSceneY());
                class CreateAction implements AgeAction {

                    @Override
                    public AgeAction execute() {
                        final DiagramNode targetNode = (DiagramNode) c.getTarget();
                        tc.getOperation(c).ifPresent(operation -> {
                            // Perform modification
                            final OperationExecutor opExecutor = new OperationExecutor(editor.getAadlModificationService(), editor.getReferenceService());
                            OperationResultsProcessor.processResults(editor, targetNode, GefAgeDiagramUtil.toAgePoint(p), opExecutor.execute(operation));
                        });
                        return null;
                    }
                }
                final CreateAction createAction = new CreateAction();
                editor.getActionExecutor().execute("Create " + cmd.getLabel(), ExecutionMode.NORMAL, createAction);
                // Deactivate the current palette item and select the "Select" item
                editor.getPaletteModel().deactivateNonSelectItem();
            });
            return HandledEvent.consumed();
        } else if (cmd instanceof CreateConnectionPaletteCommand) {
            final CreateConnectionPaletteCommand createCmd = (CreateConnectionPaletteCommand) cmd;
            final CanStartConnectionContext ctx = createCanStartConnectionContext(me).orElse(null);
            if (ctx == null || !createCmd.canStartConnection(ctx)) {
                return null;
            }
            return HandledEvent.newInteraction(new CreateConnectionInteraction(createCmd, (DiagramElement) ctx.getSource(), editor, me));
        }
    } else if (me.getButton() == MouseButton.SECONDARY) {
        editor.getPaletteModel().deactivateNonSelectItem();
    }
    return null;
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) MouseEvent(javafx.scene.input.MouseEvent) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) Point2D(javafx.geometry.Point2D) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) AgeAction(org.osate.ge.internal.services.AgeAction) GeometryNode(org.eclipse.gef.fx.nodes.GeometryNode) Node(javafx.scene.Node) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) OperationExecutor(org.osate.ge.internal.operations.OperationExecutor) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) PaletteCommand(org.osate.ge.palette.PaletteCommand) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand)

Example 2 with TargetedPaletteCommand

use of org.osate.ge.palette.TargetedPaletteCommand in project osate2 by osate.

the class AadlPaletteContributor method getTargetedCommands.

@Override
public Stream<TargetedPaletteCommand> getTargetedCommands(final PaletteCommandProviderContext ctx) {
    final List<TargetedPaletteCommand> commands = new ArrayList<>();
    if (PaletteCommandUtil.diagramMayContainPackageOrClassifiers(ctx)) {
        if (PaletteCommandUtil.diagramMayContainPackage(ctx)) {
            commands.add(new CreateAnnexLibraryPaletteCommand());
        }
        commands.add(new CreateAnnexSubclausePaletteCommand());
        commands.add(CreateFlowSourceSinkSpecificationPaletteCommand.createFlowSourceCommand());
        commands.add(CreateFlowSourceSinkSpecificationPaletteCommand.createFlowSinkCommand());
        for (EClass featureType : AadlFeatureUtil.getFeatureTypes()) {
            commands.add(new CreateFeaturePaletteCommand(featureType));
        }
    }
    if (PaletteCommandUtil.diagramMayContainPackageOrComponentClassifiers(ctx)) {
        commands.add(new CreateModePaletteCommand());
    }
    if (PaletteCommandUtil.diagramMayContainPackageOrComponentImplementations(ctx)) {
        // Create palette entries for each subcomponent EClass
        for (final EClass subcomponentType : AadlSubcomponentUtil.getSubcomponentTypes()) {
            commands.add(new CreateSubcomponentPaletteCommand(subcomponentType));
        }
        commands.add(new CreateSubprogramCallSequencePaletteCommand());
        commands.add(new CreateSubprogramCallCommand());
    }
    if (PaletteCommandUtil.diagramMayContainPackage(ctx)) {
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.ABSTRACT, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.ABSTRACT, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.BUS, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.BUS, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.DATA, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.DATA, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.DEVICE, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.DEVICE, true));
        commands.add(CreateClassifierPaletteCommand.createFeatureGroupTypeCommand());
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.MEMORY, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.MEMORY, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.PROCESS, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.PROCESS, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.PROCESSOR, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.PROCESSOR, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SUBPROGRAM, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SUBPROGRAM, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SUBPROGRAM_GROUP, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SUBPROGRAM_GROUP, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SYSTEM, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.SYSTEM, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.THREAD, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.THREAD, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.THREAD_GROUP, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.THREAD_GROUP, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.VIRTUAL_BUS, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.VIRTUAL_BUS, true));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.VIRTUAL_PROCESSOR, false));
        commands.add(new CreateClassifierPaletteCommand(ComponentCategory.VIRTUAL_PROCESSOR, true));
    }
    return commands.stream();
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ArrayList(java.util.ArrayList) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand)

Aggregations

TargetedPaletteCommand (org.osate.ge.palette.TargetedPaletteCommand)2 ArrayList (java.util.ArrayList)1 Point2D (javafx.geometry.Point2D)1 Node (javafx.scene.Node)1 MouseEvent (javafx.scene.input.MouseEvent)1 EClass (org.eclipse.emf.ecore.EClass)1 GeometryNode (org.eclipse.gef.fx.nodes.GeometryNode)1 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)1 OperationExecutor (org.osate.ge.internal.operations.OperationExecutor)1 AgeAction (org.osate.ge.internal.services.AgeAction)1 CanStartConnectionContext (org.osate.ge.palette.CanStartConnectionContext)1 CreateConnectionPaletteCommand (org.osate.ge.palette.CreateConnectionPaletteCommand)1 PaletteCommand (org.osate.ge.palette.PaletteCommand)1