Search in sources :

Example 1 with CDOResource

use of org.eclipse.emf.cdo.eresource.CDOResource in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method getContainingFolder.

private IResource getContainingFolder(Comparison comparison) {
    if (comparison.getMatches() != null && comparison.getMatches().isEmpty() == false) {
        Match match = comparison.getMatches().get(0);
        Resource resource = match.getLeft().eResource();
        if (resource instanceof CDOResource) {
            return getModelingProject(resource);
        } else if (resource.getURI().isPlatformResource()) {
            String uri = resource.getURI().toPlatformString(true);
            Path path = new Path(uri);
            return ResourcesPlugin.getWorkspace().getRoot().getFile(path).getParent();
        } else if (activeEditor.getEditorInput() instanceof ThreeWayResourceCompareInput) {
            // The resource is a SVN resource
            try {
                IEditorInput editorInput = activeEditor.getEditorInput();
                Field localField = editorInput.getClass().getDeclaredField("local");
                localField.setAccessible(true);
                ILocalResource local = (ILocalResource) localField.get(editorInput);
                return local.getResource().getParent();
            } catch (ReflectiveOperationException e) {
            // The fallback case below will apply
            } catch (SecurityException e) {
            // The fallback case below will apply
            } catch (IllegalArgumentException e) {
            // The fallback case below will apply
            }
        }
        // Fallback case
        ContainerSelectionDialog projectSelectionDialog = new ContainerSelectionDialog(activeEditor.getSite().getShell(), null, false, "Sélectionner le projet de destination :");
        projectSelectionDialog.setTitle("Sélection de projet");
        if (projectSelectionDialog.open() == ContainerSelectionDialog.OK && projectSelectionDialog.getResult().length == 1) {
            Path projectPath = (Path) projectSelectionDialog.getResult()[0];
            IResource selectedResource = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath);
            if (selectedResource instanceof IProject) {
                return selectedResource;
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) ThreeWayResourceCompareInput(org.eclipse.team.svn.ui.compare.ThreeWayResourceCompareInput) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) Resource(org.eclipse.emf.ecore.resource.Resource) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) Match(org.eclipse.emf.compare.Match) Field(java.lang.reflect.Field) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 2 with CDOResource

use of org.eclipse.emf.cdo.eresource.CDOResource in project InformationSystem by ObeoNetwork.

the class CollaborativeBusinessProjectImporter method getTargetRemoteResource.

private CDOResource getTargetRemoteResource(String targetResourcePath) {
    CDOResource targetResource = null;
    CDOTransaction transaction = getTransactionOnSession(getTargetSession());
    if (transaction != null && transaction.hasResource(targetResourcePath)) {
        try {
            targetResource = transaction.getResource(targetResourcePath);
        } catch (Exception e) {
        // unable to get resource, it probably doesn't exist
        }
    }
    return targetResource;
}
Also used : CDOTransaction(org.eclipse.emf.cdo.transaction.CDOTransaction) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) RepositoryConnectionException(fr.obeo.dsl.viewpoint.collab.api.RepositoryConnectionException)

Example 3 with CDOResource

use of org.eclipse.emf.cdo.eresource.CDOResource in project InformationSystem by ObeoNetwork.

the class EmbeddedCDOServer method getRemoteProjectsURIs.

private Collection<URI> getRemoteProjectsURIs(CDOTransaction transaction) {
    Collection<URI> remoteProjectsURIs = new ArrayList<URI>();
    CDOResource rootResource = transaction.getRootResource();
    for (EObject object : rootResource.getContents()) {
        // CDOResourceNode
        if (object instanceof CDOResourceFolder) {
            // Search in folder
            remoteProjectsURIs.addAll(getRemoteProjectsURIs((CDOResourceFolder) object));
        } else if (object instanceof CDOResourceNode) {
            CDOResourceNode node = (CDOResourceNode) object;
            if (isSessionResource(node)) {
                remoteProjectsURIs.add(node.getURI());
            }
        }
    }
    return remoteProjectsURIs;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) CDOResourceFolder(org.eclipse.emf.cdo.eresource.CDOResourceFolder) CDOResourceNode(org.eclipse.emf.cdo.eresource.CDOResourceNode) URI(org.eclipse.emf.common.util.URI) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource)

Example 4 with CDOResource

use of org.eclipse.emf.cdo.eresource.CDOResource in project InformationSystem by ObeoNetwork.

the class ScaffoldingOperation method createScaffoldResourceForSharedProject.

private Resource createScaffoldResourceForSharedProject(CDOView cdoView) {
    CDOTransaction transaction = (CDOTransaction) cdoView;
    String name = getScaffoldModelName();
    int count = 0;
    while (count < 10) {
        String path = SCAFFOLD_FOLDER + "/" + getFilenameForScaffoldModel(name, count);
        // Create resource
        CDOResource resource = transaction.getOrCreateResource(path);
        // Check if it is empty
        if (resource.getContents().isEmpty()) {
            resource.getContents().add(scaffoldInfo);
            return resource;
        } else {
            // try with another name
            count++;
        }
    }
    return null;
}
Also used : CDOTransaction(org.eclipse.emf.cdo.transaction.CDOTransaction) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource)

Example 5 with CDOResource

use of org.eclipse.emf.cdo.eresource.CDOResource in project InformationSystem by ObeoNetwork.

the class CollaborativeBusinessProjectImporter method addToRemoteSemanticResource.

private void addToRemoteSemanticResource(final EObject copyObject, final String targetPath) {
    CDOTransaction transaction = getTransactionOnSession(getTargetSession());
    if (transaction != null) {
        CDOResource targetResource = transaction.getOrCreateResource(targetPath);
        targetResource.getContents().add(copyObject);
        if (!existsTargetSemanticResource(targetResource.getURI())) {
            addToSemanticResources(getTargetSession(), targetResource.getURI(), new NullProgressMonitor());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CDOTransaction(org.eclipse.emf.cdo.transaction.CDOTransaction) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource)

Aggregations

CDOResource (org.eclipse.emf.cdo.eresource.CDOResource)5 CDOTransaction (org.eclipse.emf.cdo.transaction.CDOTransaction)3 RepositoryConnectionException (fr.obeo.dsl.viewpoint.collab.api.RepositoryConnectionException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 CDOResourceFolder (org.eclipse.emf.cdo.eresource.CDOResourceFolder)1 CDOResourceNode (org.eclipse.emf.cdo.eresource.CDOResourceNode)1 URI (org.eclipse.emf.common.util.URI)1 Match (org.eclipse.emf.compare.Match)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ILocalResource (org.eclipse.team.svn.core.resource.ILocalResource)1 ThreeWayResourceCompareInput (org.eclipse.team.svn.ui.compare.ThreeWayResourceCompareInput)1 IEditorInput (org.eclipse.ui.IEditorInput)1 ContainerSelectionDialog (org.eclipse.ui.dialogs.ContainerSelectionDialog)1