Search in sources :

Example 91 with Optional

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));
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation)

Example 92 with Optional

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));
//        }
}
Also used : Optional(com.google.common.base.Optional) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException) Notification(org.eclipse.che.ide.api.notification.Notification) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) NotificationListener(org.eclipse.che.ide.api.notification.NotificationListener)

Example 93 with Optional

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);
                    }
                });
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 94 with Optional

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));
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Document(org.eclipse.che.ide.api.editor.document.Document) EditorInput(org.eclipse.che.ide.api.editor.EditorInput) Before(org.junit.Before)

Example 95 with Optional

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));
}
Also used : Binding(com.google.inject.Binding) InstanceBinding(com.google.inject.spi.InstanceBinding) LinkedKeyBinding(com.google.inject.spi.LinkedKeyBinding) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) Optional(com.google.common.base.Optional) AbstractModule(com.google.inject.AbstractModule) Injector(com.google.inject.Injector) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Optional (com.google.common.base.Optional)159 RevFeature (org.locationtech.geogig.api.RevFeature)42 Test (org.junit.Test)38 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 ImmutableList (com.google.common.collect.ImmutableList)24 List (java.util.List)24 File (java.io.File)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)20 ArrayList (java.util.ArrayList)18 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)18 Function (com.google.common.base.Function)17 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)17 ObjectId (org.locationtech.geogig.api.ObjectId)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 Resource (org.eclipse.che.ide.api.resources.Resource)15 AddOp (org.locationtech.geogig.api.porcelain.AddOp)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 RevObject (org.locationtech.geogig.api.RevObject)13 NodeRef (org.locationtech.geogig.api.NodeRef)12 Feature (org.opengis.feature.Feature)12