use of org.osate.ge.palette.CreateConnectionPaletteCommand 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;
}
Aggregations