Search in sources :

Example 1 with Storage

use of com.google.gwt.storage.client.Storage in project che by eclipse.

the class BreakpointManagerImpl method restoreBreakpoints.

private void restoreBreakpoints() {
    Storage localStorage = Storage.getLocalStorageIfSupported();
    if (localStorage == null) {
        return;
    }
    String data = localStorage.getItem(LOCAL_STORAGE_BREAKPOINTS_KEY);
    if (data == null || data.isEmpty()) {
        return;
    }
    List<StorableBreakpointDto> allDtoBreakpoints = dtoFactory.createListDtoFromJson(data, StorableBreakpointDto.class);
    Promise<Void> bpPromise = promises.resolve(null);
    for (final StorableBreakpointDto dto : allDtoBreakpoints) {
        bpPromise.thenPromise(new Function<Void, Promise<Void>>() {

            @Override
            public Promise<Void> apply(Void ignored) throws FunctionException {
                return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {

                    @Override
                    public Void apply(Optional<File> file) throws FunctionException {
                        if (!file.isPresent()) {
                            return null;
                        }
                        if (dto.getType() == Type.CURRENT) {
                            doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
                        } else {
                            addBreakpoint(new Breakpoint(dto.getType(), dto.getLineNumber(), dto.getPath(), file.get(), dto.isActive()));
                        }
                        return null;
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError arg) throws OperationException {
                        Log.error(getClass(), "Failed to restore breakpoint. ", arg.getCause());
                    }
                });
            }
        });
    }
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) StorableBreakpointDto(org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto) Promise(org.eclipse.che.api.promises.client.Promise) Storage(com.google.gwt.storage.client.Storage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 2 with Storage

use of com.google.gwt.storage.client.Storage in project actor-platform by actorapp.

the class IdentityUtils method getUniqueId.

public static String getUniqueId() {
    Storage storage = Storage.getLocalStorageIfSupported();
    String id = storage.getItem("tech_unique_id");
    if (id != null) {
        return id;
    }
    Random rnd = new Random();
    id = "";
    for (int i = 0; i < 128; i++) {
        id += ((char) ('a' + rnd.nextInt('z' - 'a')));
    }
    storage.setItem("tech_unique_id", id);
    return id;
}
Also used : Storage(com.google.gwt.storage.client.Storage) Random(java.util.Random)

Example 3 with Storage

use of com.google.gwt.storage.client.Storage in project perun by CESNET.

the class MainMenu method getAdvancedStateFromBrowser.

/**
 * Safely retrieve "advanced view" state from browser memory
 * for selected menu section
 *
 * @param menu menu to get advanced view state for
 * @return advanced view state if stored / JsonUtils.isExtendedInfoVisible() otherwise
 */
public boolean getAdvancedStateFromBrowser(String menu, MainMenuSection section) {
    try {
        Storage storage = Storage.getLocalStorageIfSupported();
        if (storage != null) {
            // we must also write so we could get an error if storage is supported but size set to 0.
            storage.setItem("urn:perun:gui:preferences:localStorageCheck", "checked");
            String value = storage.getItem("urn:perun:gui:preferences:menu-" + menu);
            if (value != null && !value.isEmpty()) {
                return Boolean.parseBoolean(value);
            } else {
                return JsonUtils.isExtendedInfoVisible();
            }
        }
    } catch (Exception ex) {
    // storage is blocked but supported
    }
    return section.isDisplayAdvanced();
}
Also used : Storage(com.google.gwt.storage.client.Storage)

Example 4 with Storage

use of com.google.gwt.storage.client.Storage in project perun by CESNET.

the class UiElements method getToggleLanguageButton.

/**
 * Setup and return button with "change language" ability
 *
 * @return button widget
 */
public ToggleButton getToggleLanguageButton() {
    // translation not supported
    if (Utils.getNativeLanguage().isEmpty()) {
        languageButton.setVisible(false);
        languageButton.setEnabled(false);
        return languageButton;
    }
    // display for perun admin only in WebGui.class
    languageButton.setVisible(true);
    if (!LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(1)));
    } else {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
    }
    languageButton.setPixelSize(16, 16);
    languageButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Confirm conf = new Confirm(languageButton.getTitle(), new HTML(WidgetTranslation.INSTANCE.changeLanguageConfirmText()), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // on OK
                    // set proper locale
                    String localeName = LocaleInfo.getCurrentLocale().getLocaleName();
                    if (!localeName.equals(Utils.getNativeLanguage().get(0))) {
                        localeName = Utils.getNativeLanguage().get(0);
                        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
                    } else {
                        localeName = "en";
                        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(1)));
                    }
                    // set locale param to URL or local storage
                    try {
                        Storage localStorage;
                        localStorage = Storage.getLocalStorageIfSupported();
                        if (localStorage != null) {
                            localStorage.setItem("urn:perun:gui:preferences:language", localeName);
                            Window.Location.reload();
                        } else {
                            UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", localeName);
                            Window.Location.replace(builder.buildString());
                        }
                    } catch (Exception ex) {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", localeName);
                        Window.Location.replace(builder.buildString());
                    }
                    // unclick button
                    languageButton.setDown(false);
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // on CANCEL
                    languageButton.setDown(false);
                }
            }, true);
            conf.setNonScrollable(true);
            conf.show();
        }
    });
    return languageButton;
}
Also used : Storage(com.google.gwt.storage.client.Storage) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Example 5 with Storage

use of com.google.gwt.storage.client.Storage in project gwt-test-utils by gwt-test-utils.

the class StorageTest method itemSessionStorage.

@Test
public void itemSessionStorage() {
    // Given
    Storage session = Storage.getSessionStorageIfSupported();
    // When
    session.setItem("test", "my test");
    // Then
    assertThat(session.getItem("test")).isEqualTo("my test");
}
Also used : Storage(com.google.gwt.storage.client.Storage) Test(org.junit.Test)

Aggregations

Storage (com.google.gwt.storage.client.Storage)14 Test (org.junit.Test)8 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)2 StorableBreakpointDto (org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto)2 Optional (com.google.common.base.Optional)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 UrlBuilder (com.google.gwt.http.client.UrlBuilder)1 GetGuiConfiguration (cz.metacentrum.perun.webgui.json.GetGuiConfiguration)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetPerunPrincipal (cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal)1 KeepAlive (cz.metacentrum.perun.webgui.json.authzResolver.KeepAlive)1 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 PerunPrincipal (cz.metacentrum.perun.webgui.model.PerunPrincipal)1 TabManager (cz.metacentrum.perun.webgui.tabs.TabManager)1 UrlMapper (cz.metacentrum.perun.webgui.tabs.UrlMapper)1 CantLogAsServiceUserWidget (cz.metacentrum.perun.webgui.widgets.CantLogAsServiceUserWidget)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1