Search in sources :

Example 61 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-xtend by eclipse.

the class DerivedSourceDropDownAction method getMenu.

@Override
public Menu getMenu(Control parent) {
    if (menu != null) {
        menu.dispose();
    }
    menu = new Menu(parent);
    if (derivedSourceView.getSelectedSource() == null) {
        return menu;
    }
    List<IStorage> derivedSources = newArrayList(derivedSourceView.getDerivedSources());
    int min = min(derivedSources.size(), RESULTS_IN_DROP_DOWN);
    SelectDerivedSourceAction action = new SelectDerivedSourceAction(derivedSourceView.getSelectedSource());
    action.setChecked(true);
    addActionToMenu(menu, action);
    new MenuItem(menu, SWT.SEPARATOR);
    for (int i = 0; i < min; i++) {
        IStorage resource = derivedSources.get(i);
        if (!resource.equals(derivedSourceView.getSelectedSource())) {
            action = new SelectDerivedSourceAction(resource);
            addActionToMenu(menu, action);
        }
    }
    return menu;
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) IStorage(org.eclipse.core.resources.IStorage)

Example 62 with IStorage

use of org.eclipse.core.resources.IStorage in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenShortContentIsDifferent.

/**
 * Comparing two files that have same content length but having small
 * difference inside content should return false.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    // this typo should be here
    byte[] remoteContent = "very long lonk content".getBytes("UTF-8");
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 63 with IStorage

use of org.eclipse.core.resources.IStorage in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnTrueWhenShortContentIsDifferent.

/**
 * Comparing two files that have the same content and content length should
 * return true
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    byte[] remoteContent = "very long long content".getBytes("UTF-8");
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertTrue(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 64 with IStorage

use of org.eclipse.core.resources.IStorage in project egit by eclipse.

the class MockLogicalResourceMapping method getTraversals.

@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    SubMonitor sm = SubMonitor.convert(monitor, 3);
    Set<IFile> result = new LinkedHashSet<IFile>();
    result.add(file);
    try {
        List<IFile> dependencies = getDependencies(file, file.getParent());
        result.addAll(dependencies);
        sm.worked(1);
        if (context instanceof RemoteResourceMappingContext) {
            RemoteResourceMappingContext rmc = (RemoteResourceMappingContext) context;
            IStorage baseContents = rmc.fetchBaseContents(file, sm.newChild(1));
            if (baseContents != null) {
                result.addAll(getDependencies(baseContents, file.getParent()));
            }
            IStorage remoteContents = rmc.fetchRemoteContents(file, sm.newChild(1));
            if (remoteContents != null) {
                result.addAll(getDependencies(remoteContents, file.getParent()));
            }
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.egit.ui.test", "Exception while computing logical model", e));
    }
    final IResource[] resourceArray = result.toArray(new IResource[result.size()]);
    return new ResourceTraversal[] { new ResourceTraversal(resourceArray, IResource.DEPTH_ONE, IResource.NONE) };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) IFile(org.eclipse.core.resources.IFile) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) IStorage(org.eclipse.core.resources.IStorage) CoreException(org.eclipse.core.runtime.CoreException) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IResource(org.eclipse.core.resources.IResource)

Example 65 with IStorage

use of org.eclipse.core.resources.IStorage in project egit by eclipse.

the class EgitUiEditorUtils method openEditor.

/**
 * @param page
 * @param revision
 * @param monitor
 * @return the part
 * @throws CoreException
 */
public static IEditorPart openEditor(IWorkbenchPage page, IFileRevision revision, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    IStorage file = revision.getStorage(progress.newChild(1));
    if (file instanceof IFile) {
        // if this is the current workspace file, open it
        return IDE.openEditor(page, (IFile) file, OpenStrategy.activateOnOpen());
    } else {
        FileRevisionEditorInput fileRevEditorInput = FileRevisionEditorInput.createEditorInputFor(revision, progress.newChild(1));
        IEditorPart part = openEditor(page, fileRevEditorInput);
        return part;
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) SubMonitor(org.eclipse.core.runtime.SubMonitor) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IStorage(org.eclipse.core.resources.IStorage)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6