Search in sources :

Example 1 with CompositeTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand in project tdi-studio-se by Talend.

the class BusinessBaseItemSemanticEditPolicy method getSemanticCommand.

/**
     * @generated
     */
protected Command getSemanticCommand(IEditCommandRequest request) {
    IEditCommandRequest completedRequest = completeRequest(request);
    Object editHelperContext = completedRequest.getEditHelperContext();
    if (editHelperContext instanceof View || (editHelperContext instanceof IEditHelperContext && ((IEditHelperContext) editHelperContext).getEObject() instanceof View)) {
        // no semantic commands are provided for pure design elements
        return null;
    }
    if (editHelperContext == null) {
        editHelperContext = ViewUtil.resolveSemanticElement((View) getHost().getModel());
    }
    IElementType elementType = ElementTypeRegistry.getInstance().getElementType(editHelperContext);
    if (elementType == ElementTypeRegistry.getInstance().getType("org.eclipse.gmf.runtime.emf.type.core.default")) {
        //$NON-NLS-1$ 
        elementType = null;
    }
    Command epCommand = getSemanticCommandSwitch(completedRequest);
    if (epCommand != null) {
        ICommand command = epCommand instanceof ICommandProxy ? ((ICommandProxy) epCommand).getICommand() : new CommandProxy(epCommand);
        completedRequest.setParameter(BusinessBaseEditHelper.EDIT_POLICY_COMMAND, command);
    }
    Command ehCommand = null;
    if (elementType != null) {
        ICommand command = elementType.getEditCommand(completedRequest);
        if (command != null) {
            if (!(command instanceof CompositeTransactionalCommand)) {
                TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
                command = new CompositeTransactionalCommand(editingDomain, null).compose(command);
            }
            ehCommand = new ICommandProxy(command);
        }
    }
    boolean shouldProceed = true;
    if (completedRequest instanceof DestroyRequest) {
        shouldProceed = shouldProceed((DestroyRequest) completedRequest);
    }
    if (shouldProceed) {
        if (completedRequest instanceof DestroyRequest) {
            TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
            Command deleteViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View) getHost().getModel()));
            ehCommand = ehCommand == null ? deleteViewCommand : ehCommand.chain(deleteViewCommand);
        }
        return ehCommand;
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) DestroyRequest(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest) IEditCommandRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest) View(org.eclipse.gmf.runtime.notation.View) IElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType) DeleteCommand(org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) CommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy) IEditHelperContext(org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) DeleteCommand(org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand) Command(org.eclipse.gef.commands.Command) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with CompositeTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand in project tdi-studio-se by Talend.

the class BusinessStructuralFeatureParser method getParseCommand.

/**
     * @generated
     */
public ICommand getParseCommand(IAdaptable adapter, Object[] values) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    if (element == null) {
        return UnexecutableCommand.INSTANCE;
    }
    TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
    if (editingDomain == null) {
        return UnexecutableCommand.INSTANCE;
    }
    Object value = values.length == 1 ? values[0] : null;
    ICommand command = getModificationCommand(element, feature, value);
    return new CompositeTransactionalCommand(editingDomain, command.getLabel(), Collections.singletonList(command));
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with CompositeTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand in project tdi-studio-se by Talend.

the class BusinessStructuralFeaturesParser method getParseCommand.

/**
     * @generated
     */
public ICommand getParseCommand(IAdaptable adapter, Object[] values) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    if (element == null) {
        return UnexecutableCommand.INSTANCE;
    }
    TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
    if (editingDomain == null) {
        return UnexecutableCommand.INSTANCE;
    }
    //$NON-NLS-1$
    CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values");
    for (int i = 0; i < values.length; i++) {
        EStructuralFeature feature = (EStructuralFeature) features.get(i);
        command.compose(getModificationCommand(element, feature, values[i]));
    }
    return command;
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)3 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)3 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)3 ICommand (org.eclipse.gmf.runtime.common.core.command.ICommand)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 Command (org.eclipse.gef.commands.Command)1 UnexecutableCommand (org.eclipse.gef.commands.UnexecutableCommand)1 DeleteCommand (org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand)1 CommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy)1 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 IEditHelperContext (org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext)1 IElementType (org.eclipse.gmf.runtime.emf.type.core.IElementType)1 DestroyRequest (org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest)1 IEditCommandRequest (org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)1 View (org.eclipse.gmf.runtime.notation.View)1