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;
}
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));
}
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));
}
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) };
}
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;
}
}
Aggregations