Search in sources :

Example 1 with ILocalResource

use of org.eclipse.team.svn.core.resource.ILocalResource 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)

Aggregations

Field (java.lang.reflect.Field)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 Path (org.eclipse.core.runtime.Path)1 CDOResource (org.eclipse.emf.cdo.eresource.CDOResource)1 Match (org.eclipse.emf.compare.Match)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