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