Search in sources :

Example 1 with Callback

use of com.google.gwt.core.client.Callback in project gwt-cs by iSergio.

the class ImageryLayersManipulation method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.baseLayerPicker = false;
    ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
    imageryLayers = csVPanel.getViewer().imageryLayers();
    setupLayers();
    updateLayerList();
    _callback.onSuccess(null);
    HorizontalPanel baseLayersHPanel = new HorizontalPanel();
    baseLayersHPanel.setSpacing(5);
    baseLayersHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    baseLayersHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    final ListBox baseLayersLBox = new ListBox();
    baseLayersHPanel.add(baseLayersLBox);
    Slider baseLayersSlider = new Slider("baseLayersAlpha", 0, 100, 100);
    baseLayersSlider.setWidth("200px");
    baseLayersSlider.addListener(new MSliderListener());
    baseLayersHPanel.add(baseLayersSlider);
    baseLayersLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            ImageryLayer baseLayer = baseLayers.get(source.getSelectedValue());
            int activeLayerIndex = 0;
            int numLayers = layers.size();
            for (int i = 0; i < numLayers; ++i) {
                if (baseLayers.containsValue(layers.get(i))) {
                    activeLayerIndex = i;
                }
            }
            ImageryLayer activeLayer = layers.get(activeLayerIndex);
            float alpha = activeLayer.alpha;
            boolean show = activeLayer.show;
            imageryLayers.remove(activeLayer, false);
            imageryLayers.add(baseLayer, numLayers - activeLayerIndex - 1);
            baseLayer.show = show;
            baseLayer.alpha = alpha;
            updateLayerList();
            selectedLayer = baseLayer;
        }
    });
    Callback<Void, Void> cesiumCreated = new Callback<Void, Void>() {

        @Override
        public void onFailure(Void aVoid) {
        // 
        }

        @Override
        public void onSuccess(Void aVoid) {
            for (Map.Entry<String, ImageryLayer> entry : baseLayers.entrySet()) {
                baseLayersLBox.addItem(entry.getKey(), entry.getKey());
            }
        }
    };
    addCallback(cesiumCreated);
    contentPanel.add(new HTML("<p>Layer imagery from multiple sources, including WMS servers, Bing Maps, ArcGIS Online, OpenStreetMaps, and more, and adjust the alpha of each independently.</p>"));
    contentPanel.add(baseLayersHPanel);
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Slider(org.cleanlogic.showcase.client.examples.slider.Slider) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) Callback(com.google.gwt.core.client.Callback) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ImageryLayer(org.cesiumjs.cs.scene.ImageryLayer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Callback

use of com.google.gwt.core.client.Callback in project che by eclipse.

the class OpenFileAction method promise.

@Override
public Promise<Void> promise(final ActionEvent actionEvent) {
    if (actionEvent.getParameters() == null) {
        return Promises.reject(JsPromiseError.create(localization.canNotOpenFileWithoutParams()));
    }
    final String pathToOpen = actionEvent.getParameters().get(FILE_PARAM_ID);
    if (pathToOpen == null) {
        return Promises.reject(JsPromiseError.create(localization.fileToOpenIsNotSpecified()));
    }
    final Call<Void, Throwable> call = new Call<Void, Throwable>() {

        HandlerRegistration handlerRegistration;

        @Override
        public void makeCall(final Callback<Void, Throwable> callback) {
            actionCompletedCallback = callback;
            handlerRegistration = eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {

                @Override
                public void onActivePartChanged(ActivePartChangedEvent event) {
                    if (event.getActivePart() instanceof EditorPartPresenter) {
                        EditorPartPresenter editor = (EditorPartPresenter) event.getActivePart();
                        handlerRegistration.removeHandler();
                        if (Path.valueOf(pathToOpen).equals(editor.getEditorInput().getFile().getLocation())) {
                            callback.onSuccess(null);
                        }
                    }
                }
            });
            actionPerformed(actionEvent);
        }
    };
    return createFromCallback(call);
}
Also used : HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) Call(org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.Call) CallbackPromiseHelper.createFromCallback(org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.createFromCallback) Callback(com.google.gwt.core.client.Callback) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 3 with Callback

use of com.google.gwt.core.client.Callback in project che by eclipse.

the class AppContextImpl method initResourceManager.

@Override
public void initResourceManager(final Callback<ResourceManager, Exception> callback) {
    if (runtime.getDevMachine() == null) {
        //should never happened, but anyway
        callback.onFailure(new NullPointerException("Dev machine is not initialized"));
    }
    if (projects != null) {
        for (Project project : projects) {
            eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, REMOVED)));
        }
        projects = null;
    }
    resourceManager = resourceManagerFactory.newResourceManager(runtime.getDevMachine());
    resourceManager.getWorkspaceProjects().then(projects -> {
        AppContextImpl.this.projects = projects;
        java.util.Arrays.sort(AppContextImpl.this.projects, ResourcePathComparator.getInstance());
        callback.onSuccess(resourceManager);
        eventBus.fireEvent(new WorkspaceReadyEvent(projects));
    }).catchError(error -> {
        callback.onFailure((Exception) error.getCause());
    });
}
Also used : ResourceDeltaImpl(org.eclipse.che.ide.resources.impl.ResourceDeltaImpl) WindowActionEvent(org.eclipse.che.ide.api.event.WindowActionEvent) Inject(com.google.inject.Inject) Arrays(org.eclipse.che.ide.util.Arrays) SelectionChangedEvent(org.eclipse.che.ide.api.event.SelectionChangedEvent) Arrays.sort(java.util.Arrays.sort) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ResourceDeltaImpl(org.eclipse.che.ide.resources.impl.ResourceDeltaImpl) StartUpAction(org.eclipse.che.ide.api.app.StartUpAction) UPDATED(org.eclipse.che.ide.api.resources.ResourceDelta.UPDATED) ResourceManagerInitializer(org.eclipse.che.ide.resources.ResourceManagerInitializer) Arrays.copyOf(java.util.Arrays.copyOf) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) ResourceChangedHandler(org.eclipse.che.ide.api.resources.ResourceChangedEvent.ResourceChangedHandler) Set(java.util.Set) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Callback(com.google.gwt.core.client.Callback) List(java.util.List) PROJECT(org.eclipse.che.ide.api.resources.Resource.PROJECT) MOVED_FROM(org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_FROM) ADDED(org.eclipse.che.ide.api.resources.ResourceDelta.ADDED) Singleton(com.google.inject.Singleton) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) Project(org.eclipse.che.ide.api.resources.Project) WindowActionHandler(org.eclipse.che.ide.api.event.WindowActionHandler) ResourcePathComparator(org.eclipse.che.ide.api.resources.ResourcePathComparator) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) AppContext(org.eclipse.che.ide.api.app.AppContext) SYNCHRONIZED(org.eclipse.che.ide.api.resources.ResourceDelta.SYNCHRONIZED) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) WorkspaceStoppedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent) Arrays.binarySearch(java.util.Arrays.binarySearch) ActiveRuntime(org.eclipse.che.ide.api.machine.ActiveRuntime) Selection(org.eclipse.che.ide.api.selection.Selection) EventBus(com.google.web.bindery.event.shared.EventBus) SelectionChangedHandler(org.eclipse.che.ide.api.event.SelectionChangedHandler) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode) ResourceManager(org.eclipse.che.ide.resources.impl.ResourceManager) Resource(org.eclipse.che.ide.api.resources.Resource) REMOVED(org.eclipse.che.ide.api.resources.ResourceDelta.REMOVED) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Provider(com.google.inject.Provider) Container(org.eclipse.che.ide.api.resources.Container) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) AppStateManager(org.eclipse.che.ide.statepersistance.AppStateManager) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 4 with Callback

use of com.google.gwt.core.client.Callback in project kie-wb-common by kiegroup.

the class NewResourcesMenuTest method testOnWorkspaceProjectContextChangedDisabled.

@Test
@SuppressWarnings("unchecked")
public void testOnWorkspaceProjectContextChangedDisabled() {
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) {
            final Object[] args = invocation.getArguments();
            final Callback callback = (Callback) args[0];
            callback.onSuccess(false);
            return null;
        }
    }).when(handler).acceptContext(any(Callback.class));
    // Arguments aren't actually used
    menu.onChange(null, null);
    verify(handler, times(1)).acceptContext(any(Callback.class));
    final List<MenuItem> menus = menu.getMenuItems();
    verify(handler, times(2)).acceptContext(any(Callback.class));
    final MenuItem mi = menus.get(0);
    assertFalse(mi.isEnabled());
}
Also used : Answer(org.mockito.stubbing.Answer) Callback(com.google.gwt.core.client.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Example 5 with Callback

use of com.google.gwt.core.client.Callback in project kie-wb-common by kiegroup.

the class NewResourcesMenuTest method testOnWorkspaceProjectContextChangedEnabled.

@Test
@SuppressWarnings("unchecked")
public void testOnWorkspaceProjectContextChangedEnabled() {
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) {
            final Object[] args = invocation.getArguments();
            final Callback callback = (Callback) args[0];
            callback.onSuccess(true);
            return null;
        }
    }).when(handler).acceptContext(any(Callback.class));
    // Arguments aren't actually used
    menu.onChange(null, null);
    verify(handler, times(1)).acceptContext(any(Callback.class));
    final List<MenuItem> menus = menu.getMenuItems();
    verify(handler, times(2)).acceptContext(any(Callback.class));
    final MenuItem mi = menus.get(0);
    assertTrue(mi.isEnabled());
}
Also used : Answer(org.mockito.stubbing.Answer) Callback(com.google.gwt.core.client.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Test(org.junit.Test)

Aggregations

Callback (com.google.gwt.core.client.Callback)6 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 MenuItem (org.uberfire.workbench.model.menu.MenuItem)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Sets (com.google.common.collect.Sets)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)1 ArrayList (java.util.ArrayList)1 Arrays.binarySearch (java.util.Arrays.binarySearch)1 Arrays.copyOf (java.util.Arrays.copyOf)1 Arrays.sort (java.util.Arrays.sort)1 HashMap (java.util.HashMap)1