use of com.google.common.base.Optional in project che by eclipse.
the class ProjectWizard method complete.
/** {@inheritDoc} */
@Override
public void complete(@NotNull final CompleteCallback callback) {
if (mode == CREATE) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (mode == UPDATE) {
appContext.getWorkspaceRoot().getContainer(Path.valueOf(dataObject.getPath())).then(new Operation<Optional<Container>>() {
@Override
public void apply(Optional<Container> optContainer) throws OperationException {
checkState(optContainer.isPresent(), "Failed to update non existed path");
final Container container = optContainer.get();
if (container.getResourceType() == PROJECT) {
((Project) container).update().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (container.getResourceType() == FOLDER) {
((Folder) container).toProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
}
}
});
} else if (mode == IMPORT) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().thenPromise(new Function<Project, Promise<Project>>() {
@Override
public Promise<Project> apply(Project project) throws FunctionException {
return project.update().withBody(dataObject).send();
}
}).then(addCommands(callback)).catchError(onFailure(callback));
}
}
use of com.google.common.base.Optional in project che by eclipse.
the class UploadFilePresenter method onSubmitComplete.
/** {@inheritDoc} */
@Override
public void onSubmitComplete(String result) {
if (!isNullOrEmpty(result)) {
view.closeDialog();
notificationManager.notify(locale.failedToUploadFiles(), parseMessage(result), StatusNotification.Status.FAIL, FLOAT_MODE);
return;
}
container.getFile(Path.valueOf(view.getFileName())).then(new Operation<Optional<File>>() {
@Override
public void apply(final Optional<File> file) throws OperationException {
if (file.isPresent()) {
eventBus.fireEvent(new RevealResourceEvent(file.get()));
final NotificationListener notificationListener = new NotificationListener() {
boolean clicked = false;
@Override
public void onClick(Notification notification) {
if (!clicked) {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
clicked = true;
notification.setListener(null);
notification.setContent("");
}
}
@Override
public void onDoubleClick(Notification notification) {
//stub
}
@Override
public void onClose(Notification notification) {
//stub
}
};
notificationManager.notify("File '" + view.getFileName() + "' has uploaded successfully", "Click here to open it", StatusNotification.Status.SUCCESS, FLOAT_MODE, notificationListener);
view.closeDialog();
}
}
});
//TODO this should process editor agent
// if (view.isOverwriteFileSelected()) {
// String path = ((HasStorablePath)getResourceBasedNode()).getStorablePath() + "/" + view.getFileName();
// eventBus.fireEvent(new FileContentUpdateEvent(path));
// }
}
use of com.google.common.base.Optional in project che by eclipse.
the class MatchNode method actionPerformed.
@Override
public void actionPerformed() {
if (compilationUnit != null) {
final EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(compilationUnit.getPath()));
if (editorPartPresenter != null) {
selectRange(editorPartPresenter);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
editorAgent.activateEditor(editorPartPresenter);
}
});
return;
}
appContext.getWorkspaceRoot().getFile(compilationUnit.getPath()).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
selectRange(editor);
}
});
}
}
});
} else if (classFile != null) {
final String className = classFile.getElementName();
final Resource resource = appContext.getResource();
if (resource == null) {
return;
}
final Project project = resource.getRelatedProject().get();
service.getContent(project.getLocation(), className).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final VirtualFile file = new SyntheticFile(Path.valueOf(className.replace('.', '/')).lastSegment(), content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
selectRange(editor);
}
});
}
});
}
}
use of com.google.common.base.Optional in project che by eclipse.
the class JavaReconcilerStrategyTest method setUp.
@Before
public void setUp() throws Exception {
EditorInput editorInput = mock(EditorInput.class);
Optional project = mock(Optional.class);
Project projectConfig = mock(Project.class);
Optional<Resource> srcFolder = mock(Optional.class);
Container startPoint = mock(Container.class);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editorInput.getFile()).thenReturn(file);
when(file.getName()).thenReturn(FILE_NAME);
when(file.getRelatedProject()).thenReturn(project);
when(file.getLocation()).thenReturn(Path.valueOf("some/path/to/file"));
when(project.get()).thenReturn(projectConfig);
when(projectConfig.getLocation()).thenReturn(Path.valueOf("some/path/to/project"));
when(project.isPresent()).thenReturn(true);
when(file.getParentWithMarker(any())).thenReturn(srcFolder);
when(srcFolder.isPresent()).thenReturn(true);
when(srcFolder.get()).thenReturn(startPoint);
when(startPoint.getLocation()).thenReturn(Path.valueOf("some/path"));
when(resolvingProjectStateHolderRegistry.getResolvingProjectStateHolder(anyString())).thenReturn(resolvingProjectStateHolder);
when(localizationConstant.codeAssistErrorMessageResolvingProject()).thenReturn("error");
javaReconcilerStrategy.setDocument(mock(Document.class));
}
use of com.google.common.base.Optional in project guice by google.
the class MultibinderTest method testSetAndMapValueAreDistinctInSpi.
// See issue 670
public void testSetAndMapValueAreDistinctInSpi() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), String.class).addBinding().toInstance("A");
MapBinder.newMapBinder(binder(), String.class, String.class).addBinding("B").toInstance("b");
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("C");
}
});
Collector collector = new Collector();
Binding<Map<String, String>> mapbinding = injector.getBinding(Key.get(mapOfStringString));
mapbinding.acceptTargetVisitor(collector);
assertNotNull(collector.mapbinding);
Binding<Set<String>> setbinding = injector.getBinding(Key.get(setOfString));
setbinding.acceptTargetVisitor(collector);
assertNotNull(collector.setbinding);
Binding<Optional<String>> optionalbinding = injector.getBinding(Key.get(optionalOfString));
optionalbinding.acceptTargetVisitor(collector);
assertNotNull(collector.optionalbinding);
// There should only be three instance bindings for string types
// (but because of the OptionalBinder, there's 2 ProviderInstanceBindings also).
// We also know the InstanceBindings will be in the order: A, b, C because that's
// how we bound them, and binding order is preserved.
List<Binding<String>> bindings = FluentIterable.from(injector.findBindingsByType(stringType)).filter(Predicates.instanceOf(InstanceBinding.class)).toList();
assertEquals(bindings.toString(), 3, bindings.size());
Binding<String> a = bindings.get(0);
Binding<String> b = bindings.get(1);
Binding<String> c = bindings.get(2);
assertEquals("A", ((InstanceBinding<String>) a).getInstance());
assertEquals("b", ((InstanceBinding<String>) b).getInstance());
assertEquals("C", ((InstanceBinding<String>) c).getInstance());
// Make sure the correct elements belong to their own sets.
assertFalse(collector.mapbinding.containsElement(a));
assertTrue(collector.mapbinding.containsElement(b));
assertFalse(collector.mapbinding.containsElement(c));
assertTrue(collector.setbinding.containsElement(a));
assertFalse(collector.setbinding.containsElement(b));
assertFalse(collector.setbinding.containsElement(c));
assertFalse(collector.optionalbinding.containsElement(a));
assertFalse(collector.optionalbinding.containsElement(b));
assertTrue(collector.optionalbinding.containsElement(c));
}
Aggregations