use of elemental.json.JsonArray in project che by eclipse.
the class AbstractPerspective method restorePartController.
private void restorePartController(PartStack partStack, WorkBenchPartController controller, JsonObject partStackJSON) {
if (partStackJSON.hasKey("PARTS")) {
JsonArray parts = partStackJSON.get("PARTS");
for (int i = 0; i < parts.length(); i++) {
JsonObject value = parts.get(i);
if (value.hasKey("CLASS")) {
String className = value.getString("CLASS");
Provider<PartPresenter> provider = dynaProvider.getProvider(className);
if (provider != null) {
PartPresenter partPresenter = provider.get();
if (!partStack.containsPart(partPresenter)) {
partStack.addPart(partPresenter);
}
}
}
}
}
//hide part stack if it has no parts
if (partStack.getParts().isEmpty()) {
controller.setHidden(true);
return;
}
if (partStackJSON.hasKey("HIDDEN") && partStackJSON.getBoolean("HIDDEN")) {
partStack.minimize();
return;
}
if (partStackJSON.hasKey("SIZE")) {
double size = partStackJSON.getNumber("SIZE");
// Size of the part must not be less 100 pixels.
if (size < MIN_PART_SIZE) {
size = DEFAULT_PART_SIZE;
}
controller.setSize(size);
}
}
use of elemental.json.JsonArray in project che by eclipse.
the class AbstractPerspectivePersistenceTest method shouldRestorePartStackSize.
@Test
public void shouldRestorePartStackSize() throws Exception {
JsonObject state = Json.createObject();
JsonObject parts = Json.createObject();
state.put("PART_STACKS", parts);
JsonObject partStack = Json.createObject();
parts.put("INFORMATION", partStack);
JsonArray partsArray = Json.createArray();
partStack.put("PARTS", partsArray);
JsonObject part = Json.createObject();
partsArray.set(0, part);
part.put("CLASS", "foo.Bar");
partStack.put("SIZE", 142);
// partStackPresenter.getParts() must return non empty list
final List<PartPresenter> partPresenters = new ArrayList<>();
partPresenters.add(partPresenter);
when(partStackPresenter.getParts()).thenAnswer(new Answer<List<? extends PartPresenter>>() {
@Override
public List<? extends PartPresenter> answer(InvocationOnMock invocationOnMock) throws Throwable {
return partPresenters;
}
});
perspective.loadState(state);
verify(workBenchController).setSize(142d);
}
use of elemental.json.JsonArray in project che by eclipse.
the class JsonRpcListTest method shouldToJsonArrayCreatedDoubleArray.
@Test
public void shouldToJsonArrayCreatedDoubleArray() throws Exception {
JsonArray expected = jsonFactory.createArray();
expected.set(0, 0D);
JsonRpcList jsonRpcList = new JsonRpcList(singletonList(0D), jsonFactory, dtoFactory);
JsonArray actual = jsonRpcList.toJsonArray();
assertTrue(expected.jsEquals(actual));
}
use of elemental.json.JsonArray in project che by eclipse.
the class JsonRpcListTest method shouldToJsonArrayCreatedStringArray.
@Test
public void shouldToJsonArrayCreatedStringArray() throws Exception {
JsonArray expected = jsonFactory.createArray();
expected.set(0, "a");
JsonRpcList jsonRpcList = new JsonRpcList(singletonList("a"), jsonFactory, dtoFactory);
JsonArray actual = jsonRpcList.toJsonArray();
assertTrue(expected.jsEquals(actual));
}
use of elemental.json.JsonArray in project che by eclipse.
the class JsonRpcListTest method shouldToStringArrayParsedStringArray.
@Test
public void shouldToStringArrayParsedStringArray() throws Exception {
String expected = "a";
JsonArray array = jsonFactory.createArray();
array.set(0, expected);
String message = array.toJson();
JsonRpcList jsonRpcList = new JsonRpcList(message, jsonFactory, dtoFactory);
String actual = jsonRpcList.toString();
assertEquals(message, actual);
}
Aggregations