Search in sources :

Example 1 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project tdi-studio-se by Talend.

the class BusinessReferenceConnectionEditPolicy method createDeleteSemanticCommand.

/**
     * @generated
     */
protected Command createDeleteSemanticCommand(GroupRequest deleteRequest) {
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
    EditCommandRequestWrapper semReq = new EditCommandRequestWrapper(new DestroyElementRequest(editingDomain, false), deleteRequest.getExtendedData());
    Command semanticCmd = getHost().getCommand(semReq);
    if (semanticCmd != null && semanticCmd.canExecute()) {
        CompoundCommand cc = new CompoundCommand();
        cc.add(semanticCmd);
        return cc;
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) DestroyElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) DeleteCommand(org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) EditCommandRequestWrapper(org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project tdi-studio-se by Talend.

the class BusinessInitDiagramFileAction method run.

/**
     * @generated NOT
     */
public void run(IAction action) {
    TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    ResourceSet resourceSet = new ResourceSetImpl();
    EObject diagramRoot = null;
    try {
        Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(mySelectedModelFile.getFullPath().toString()), true);
        diagramRoot = (EObject) resource.getContents().get(0);
    } catch (WrappedException ex) {
        BusinessDiagramEditorPlugin.getInstance().logError(Messages.getString("BusinessInitDiagramFileAction.UnableToLoadResource") + mySelectedModelFile.getFullPath().toString(), //$NON-NLS-1$
        ex);
    }
    if (diagramRoot == null) {
        MessageDialog.openError(myPart.getSite().getShell(), Messages.getString("BusinessInitDiagramFileAction.Error"), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("BusinessInitDiagramFileAction.LoadFaild"));
        return;
    }
    Wizard wizard = new BusinessNewDiagramFileWizard(mySelectedModelFile, myPart.getSite().getPage(), mySelection, diagramRoot, editingDomain);
    IDialogSettings pluginDialogSettings = BusinessDiagramEditorPlugin.getInstance().getDialogSettings();
    //$NON-NLS-1$
    IDialogSettings initDiagramFileSettings = pluginDialogSettings.getSection("InisDiagramFile");
    if (initDiagramFileSettings == null) {
        //$NON-NLS-1$
        initDiagramFileSettings = pluginDialogSettings.addNewSection("InisDiagramFile");
    }
    wizard.setDialogSettings(initDiagramFileSettings);
    wizard.setForcePreviousAndNextButtons(false);
    wizard.setWindowTitle(//$NON-NLS-1$ //$NON-NLS-2$
    Messages.getString("BusinessInitDiagramFileAction.IntialNew") + BusinessProcessEditPart.MODEL_ID + Messages.getString("BusinessInitDiagramFileAction.DiagramFile"));
    WizardDialog dialog = new WizardDialog(myPart.getSite().getShell(), wizard);
    dialog.create();
    dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
    dialog.open();
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project tdi-studio-se by Talend.

the class BusinessDiagramEditor method createEditingDomain.

/**
     * @generated
     */
@Override
protected TransactionalEditingDomain createEditingDomain() {
    TransactionalEditingDomain domain = super.createEditingDomain();
    domain.setID(getEditingDomainID());
    return domain;
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain)

Example 4 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project tdi-studio-se by Talend.

the class BusinessDiagramEditorUtil method createNewDiagramFile.

/**
     * <p>
     * This method should be called within a workspace modify operation since it creates resources.
     * </p>
     * 
     * @generated
     * @return the created file resource, or <code>null</code> if the file was not created
     */
public static final IFile createNewDiagramFile(DiagramFileCreator diagramFileCreator, IPath containerFullPath, String fileName, InputStream initialContents, String kind, Shell shell, IProgressMonitor progressMonitor) {
    TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    //$NON-NLS-1$
    progressMonitor.beginTask("Creating diagram and model files", 4);
    final IProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor, 1);
    final IFile diagramFile = diagramFileCreator.createNewFile(containerFullPath, fileName, initialContents, shell, new IRunnableContext() {

        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
            runnable.run(subProgressMonitor);
        }
    });
    final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString()));
    List affectedFiles = new ArrayList();
    affectedFiles.add(diagramFile);
    final String kindParam = kind;
    AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, //$NON-NLS-1$
    "Creating diagram and model", //$NON-NLS-1$
    affectedFiles) {

        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            BusinessProcess model = createInitialModel();
            diagramResource.getContents().add(model);
            Diagram diagram = ViewService.createDiagram(model, kindParam, BusinessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            if (diagram != null) {
                diagramResource.getContents().add(diagram);
                diagram.setName(diagramFile.getName());
                diagram.setElement(model);
            }
            try {
                diagramResource.save(Collections.EMPTY_MAP);
            } catch (IOException e) {
                BusinessDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", //$NON-NLS-1$
                e);
            }
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
    } catch (ExecutionException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e);
    }
    try {
        //$NON-NLS-1$
        diagramFile.setCharset("UTF-8", new SubProgressMonitor(progressMonitor, 1));
    } catch (CoreException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to set charset for diagram file", e);
    }
    return diagramFile;
}
Also used : IRunnableContext(org.eclipse.jface.operation.IRunnableContext) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Diagram(org.eclipse.gmf.runtime.notation.Diagram) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 5 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain 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)

Aggregations

TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)9 EObject (org.eclipse.emf.ecore.EObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)3 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 Command (org.eclipse.gef.commands.Command)2 UnexecutableCommand (org.eclipse.gef.commands.UnexecutableCommand)2 ICommand (org.eclipse.gmf.runtime.common.core.command.ICommand)2 DeleteCommand (org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand)2 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1