Search in sources :

Example 16 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project Palladio-Editors-Sirius by PalladioSimulator.

the class AllocationCreationWizard method finish.

@Override
protected void finish() {
    Allocation allocation = (Allocation) modelObject;
    Session session = SessionManager.INSTANCE.getSession(modelObject);
    TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
    String fileString = modelURI.toPlatformString(true);
    IPath path = new Path(fileString);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    List<IFile> list = new ArrayList<IFile>();
    list.add(file);
    AbstractTransactionalCommand command = new AbstractTransactionalCommand(domain, "Save Allocation model.", list) {

        @Override
        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            allocation.setTargetResourceEnvironment_Allocation(resourceEnvironmentSelectorpage.getSelectedResourceEnvironment(session));
            allocation.setSystem_Allocation(systemSelectorPage.getSelectedSystem(session));
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        System.out.println("Unable to save allocation model.");
        e.printStackTrace();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ExecutionException(org.eclipse.core.commands.ExecutionException) Session(org.eclipse.sirius.business.api.session.Session)

Example 17 with TransactionalEditingDomain

use of org.eclipse.emf.transaction.TransactionalEditingDomain in project Palladio-Editors-Sirius by PalladioSimulator.

the class ResourceSelectorPage method resolveSelection.

/**
 * checks if the selected file is a valid resource.
 */
private void resolveSelection() {
    myResolvedObject = null;
    URI uri = URI.createURI(mySelectionText.getText(), true);
    TransactionalEditingDomain editingDomain = EditingDomainFactoryService.INSTANCE.getEditingDomainFactory().createEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    try {
        Resource resource = resourceSet.getResource(uri, true);
        myResolvedObject = (EObject) resource.getContents().get(0);
        path = mySelectionText.getText();
    } catch (WrappedException ex) {
    // do nothing
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)17 EObject (org.eclipse.emf.ecore.EObject)7 ArrayList (java.util.ArrayList)5 Resource (org.eclipse.emf.ecore.resource.Resource)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 WrappedException (org.eclipse.emf.common.util.WrappedException)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 List (java.util.List)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IFile (org.eclipse.core.resources.IFile)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 URI (org.eclipse.emf.common.util.URI)2 EReference (org.eclipse.emf.ecore.EReference)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