Search in sources :

Example 6 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project tdi-studio-se by Talend.

the class DiagramResourceManager method updateResource.

public void updateResource(BusinessProcessItem businessProcessItem, IFile file) {
    Resource resource = createResource(file);
    // don't seems to be usefull
    // EcoreUtil.resolveAll(businessProcessItem.eResource());
    resource.getContents().clear();
    resource.getContents().add(EcoreUtil.copy(businessProcessItem.getSemantic()));
    resource.getContents().add(businessProcessItem.getNotation());
    try {
        resource.save(null);
    } catch (IOException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException)

Example 7 with Resource

use of org.eclipse.emf.ecore.resource.Resource 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 8 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project tdi-studio-se by Talend.

the class BusinessNewDiagramFileWizard method performFinish.

/**
     * @generated
     */
public boolean performFinish() {
    IFile diagramFile = myFileCreationPage.createNewFile();
    try {
        //$NON-NLS-1$
        diagramFile.setCharset("UTF-8", new NullProgressMonitor());
    } catch (CoreException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to set charset for diagram file", e);
    }
    ResourceSet resourceSet = myEditingDomain.getResourceSet();
    final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString()));
    List affectedFiles = new LinkedList();
    affectedFiles.add(mySelectedModelFile);
    affectedFiles.add(diagramFile);
    AbstractTransactionalCommand command = new AbstractTransactionalCommand(myEditingDomain, //$NON-NLS-1$
    "Initializing diagram contents", //$NON-NLS-1$
    affectedFiles) {

        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            int diagramVID = BusinessVisualIDRegistry.getDiagramVisualID(myDiagramRoot);
            if (diagramVID != BusinessProcessEditPart.VISUAL_ID) {
                //$NON-NLS-1$
                return CommandResult.newErrorCommandResult("Incorrect model object stored as a root resource object");
            }
            Diagram diagram = ViewService.createDiagram(myDiagramRoot, BusinessProcessEditPart.MODEL_ID, BusinessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            diagramResource.getContents().add(diagram);
            diagramResource.getContents().add(diagram.getElement());
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
        diagramResource.save(Collections.EMPTY_MAP);
        IDE.openEditor(myWorkbenchPage, diagramFile);
    } catch (ExecutionException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e);
    } catch (IOException ex) {
        BusinessDiagramEditorPlugin.getInstance().logError("Save operation failed for: " + diagramFile.getFullPath().toString(), //$NON-NLS-1$
        ex);
    } catch (PartInitException ex) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to open editor", ex);
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Diagram(org.eclipse.gmf.runtime.notation.Diagram) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LinkedList(java.util.LinkedList) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 9 with Resource

use of org.eclipse.emf.ecore.resource.Resource 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 10 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project tdi-studio-se by Talend.

the class AutoUpdateRelationsMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    try {
        RelationshipItemBuilder.getInstance().addOrUpdateItem(item, true);
        // release the memory when gc
        if (item instanceof ProcessItem) {
            Resource processResource = ((ProcessItem) item).getProcess().eResource();
            Resource propertyResource = item.eResource();
            if (processResource != null && processResource.isLoaded() && (processResource instanceof XMIResource)) {
                propertyResource.unload();
                processResource.unload();
                rM.resourceSet.getResources().remove(propertyResource);
                rM.resourceSet.getResources().remove(processResource);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(new Exception("Error in item:" + item.getProperty().getLabel(), e));
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)58 URI (org.eclipse.emf.common.util.URI)23 IOException (java.io.IOException)18 IResource (org.eclipse.core.resources.IResource)11 EObject (org.eclipse.emf.ecore.EObject)10 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)9 PersistenceException (org.talend.commons.exception.PersistenceException)8 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)8 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)7 List (java.util.List)6 IProject (org.eclipse.core.resources.IProject)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IFile (org.eclipse.core.resources.IFile)5 TalendXMIResource (org.talend.commons.runtime.model.emf.TalendXMIResource)5 ByteArrayResource (org.talend.core.model.properties.helper.ByteArrayResource)5 CwmResource (org.talend.model.emf.CwmResource)5