use of com.google.gwt.json.client.JSONArray in project perun by CESNET.
the class EditFormItemTabItem method saveItem.
/**
* Saves the values back to the item
*/
protected void saveItem() {
// TODO set only when actual change happens
item.setEdited(true);
// shortName is required item !!
if (shortNameTextBox.getText() == null || (shortNameTextBox.getText().isEmpty())) {
UiElements.generateAlert("Empty shortName", "'shortName' is required parameter and can't be empty !");
return;
}
item.setFederationAttribute(federationAttributes.getValue(federationAttributes.getSelectedIndex()));
if (perunDestinationAttributeListBox.getSelectedIndex() > 0) {
// some value set
item.setPerunDestinationAttribute(perunDestinationAttributeListBox.getValue(perunDestinationAttributeListBox.getSelectedIndex()));
} else {
// empty value set
item.setPerunDestinationAttribute(null);
}
item.setRegex(regexTextBox.getText().trim());
item.setRequired(requiredCheckBox.getValue());
item.setShortname(shortNameTextBox.getText().trim());
JSONArray newApplicationTypesJson = new JSONArray();
int pointer = 0;
int i = 0;
for (Application.ApplicationType type : Application.ApplicationType.values()) {
CheckBox cb = applicationTypesCheckBoxes.get(i);
if (cb.getValue()) {
newApplicationTypesJson.set(pointer, new JSONString(type.toString()));
pointer++;
}
i++;
}
item.setApplicationTypes(newApplicationTypesJson.getJavaScriptObject());
/* LANGUAGE */
// item texts
Map<String, ItemTexts> itemTextsMap = new HashMap<String, ItemTexts>();
// help
for (Map.Entry<String, TextArea> entry : helpTextBoxes.entrySet()) {
String locale = entry.getKey();
ItemTexts itemTexts;
// if already
if (itemTextsMap.containsKey(locale)) {
itemTexts = itemTextsMap.get(locale);
} else {
itemTexts = new JSONObject().getJavaScriptObject().cast();
}
// set help
itemTexts.setHelp(entry.getValue().getValue().trim());
// update
itemTextsMap.put(locale, itemTexts);
}
// label
for (Map.Entry<String, TextArea> entry : labelTextBoxes.entrySet()) {
String locale = entry.getKey();
ItemTexts itemTexts;
// if already
if (itemTextsMap.containsKey(locale)) {
itemTexts = itemTextsMap.get(locale);
} else {
itemTexts = new JSONObject().getJavaScriptObject().cast();
}
// set help
itemTexts.setLabel(entry.getValue().getValue().trim());
// update
itemTextsMap.put(locale, itemTexts);
}
// error
for (Map.Entry<String, TextArea> entry : errorTextBoxes.entrySet()) {
String locale = entry.getKey();
ItemTexts itemTexts;
// if already
if (itemTextsMap.containsKey(locale)) {
itemTexts = itemTextsMap.get(locale);
} else {
itemTexts = new JSONObject().getJavaScriptObject().cast();
}
// set help
itemTexts.setErrorMessage(entry.getValue().getValue().trim());
// update
itemTextsMap.put(locale, itemTexts);
}
// OPTIONS
for (Map.Entry<String, Map<TextBox, TextBox>> localeTextboxes : optionsBoxes.entrySet()) {
String locale = localeTextboxes.getKey();
Map<String, String> keyValue = new HashMap<String, String>();
// iterate over textboxes
for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.getValue().entrySet()) {
String key = textBoxes.getKey().getText();
String value = textBoxes.getValue().getText();
if (!key.equals("") && !value.equals("")) {
keyValue.put(key.trim(), value.trim());
}
}
// serialize key-value
String options = RegistrarFormItemGenerator.serializeSelectionBox(keyValue);
ItemTexts itemTexts;
// if already
if (itemTextsMap.containsKey(locale)) {
itemTexts = itemTextsMap.get(locale);
} else {
itemTexts = new JSONObject().getJavaScriptObject().cast();
}
// set options
itemTexts.setOptions(options);
// update
itemTextsMap.put(locale, itemTexts);
}
// FOR EACH ITEM TEXT, save it
for (Map.Entry<String, ItemTexts> entry : itemTextsMap.entrySet()) {
String locale = entry.getKey();
ItemTexts itemTexts = entry.getValue();
session.getUiElements().setLogText(itemTexts.toSource());
// save it
this.item.setItemTexts(locale, itemTexts);
}
}
use of com.google.gwt.json.client.JSONArray in project perun by CESNET.
the class CreateFormItemTabItem method createItem.
/**
* Creates the item
*
* @param shortname
* @param type
* @param positionToAdd
*/
protected void createItem(String shortname, String type, int positionToAdd) {
ApplicationFormItem item = RegistrarFormItemGenerator.generateFormItem(shortname, type);
// set both app types checked for new item
JSONArray array = new JSONArray();
array.set(0, new JSONString("INITIAL"));
array.set(1, new JSONString("EXTENSION"));
item.setApplicationTypes(array.getJavaScriptObject());
// set also position
item.setOrdnum(positionToAdd);
sourceList.add(positionToAdd, item);
session.getTabManager().addTabToCurrentTab(new EditFormItemTabItem(item, events));
events.onFinished(item);
}
use of com.google.gwt.json.client.JSONArray in project perun by CESNET.
the class SetAttributes method prepareJSONObject.
/**
* Prepares a JSON object.
* @return JSONObject the whole query
*/
private JSONObject prepareJSONObject() {
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
// create attrs field
JSONArray array = new JSONArray();
// create attributes
for (int i = 0; i < attributes.size(); i++) {
// skip attribute with empty or null value
if (attributes.get(i).getValue() == null || attributes.get(i).getValue().equalsIgnoreCase("")) {
continue;
}
// create Json object from attribute
JSONObject attr = new JSONObject(attributes.get(i));
// get only interested in properties
JSONValue id = attr.get("id");
JSONValue friendlyName = attr.get("friendlyName");
JSONValue namespace = attr.get("namespace");
JSONValue type = attr.get("type");
JSONValue description = attr.get("description");
JSONValue value = attr.get("value");
JSONValue displayName = attr.get("displayName");
// create new Attribute jsonObject
JSONObject newAttr = new JSONObject();
newAttr.put("value", value);
newAttr.put("id", id);
newAttr.put("type", type);
newAttr.put("description", description);
newAttr.put("namespace", namespace);
newAttr.put("friendlyName", friendlyName);
newAttr.put("displayName", displayName);
// put attribute into array
array.set(array.size(), newAttr);
}
for (Map.Entry<String, Integer> attrIds : this.ids.entrySet()) {
jsonQuery.put(attrIds.getKey(), new JSONNumber(attrIds.getValue()));
}
jsonQuery.put("attributes", array);
return jsonQuery;
}
use of com.google.gwt.json.client.JSONArray in project perun by CESNET.
the class CreateApplication method prepareJSONObject.
/**
* Prepares a JSON object.
* @return JSONObject - the whole query
*/
private JSONObject prepareJSONObject() {
// data to JSON array
JSONArray data = new JSONArray();
for (int i = 0; i < formData.size(); i++) {
data.set(i, new JSONObject(formData.get(i)));
}
// query
JSONObject query = new JSONObject();
query.put("app", new JSONObject(application));
query.put("data", data);
return query;
}
use of com.google.gwt.json.client.JSONArray in project opentsdb by OpenTSDB.
the class QueryUi method refreshLogs.
private void refreshLogs() {
asyncGetJson(LOGS_URL, new GotJsonCallback() {
public void got(final JSONValue json) {
final JSONArray logmsgs = json.isArray();
final int nmsgs = logmsgs.size();
final FlexTable.FlexCellFormatter fcf = logs.getFlexCellFormatter();
final FlexTable.RowFormatter rf = logs.getRowFormatter();
for (int i = 0; i < nmsgs; i++) {
final String msg = logmsgs.get(i).isString().stringValue();
String part = msg.substring(0, msg.indexOf('\t'));
logs.setText(i * 2, 0, new Date(Integer.valueOf(part) * 1000L).toString());
// So we can change the style ahead.
logs.setText(i * 2 + 1, 0, "");
int pos = part.length() + 1;
part = msg.substring(pos, msg.indexOf('\t', pos));
if ("WARN".equals(part)) {
rf.getElement(i * 2).getStyle().setBackgroundColor("#FCC");
rf.getElement(i * 2 + 1).getStyle().setBackgroundColor("#FCC");
} else if ("ERROR".equals(part)) {
rf.getElement(i * 2).getStyle().setBackgroundColor("#F99");
rf.getElement(i * 2 + 1).getStyle().setBackgroundColor("#F99");
} else {
rf.getElement(i * 2).getStyle().clearBackgroundColor();
rf.getElement(i * 2 + 1).getStyle().clearBackgroundColor();
if ((i % 2) == 0) {
rf.addStyleName(i * 2, "subg");
rf.addStyleName(i * 2 + 1, "subg");
}
}
pos += part.length() + 1;
// level
logs.setText(i * 2, 1, part);
part = msg.substring(pos, msg.indexOf('\t', pos));
pos += part.length() + 1;
// thread
logs.setText(i * 2, 2, part);
part = msg.substring(pos, msg.indexOf('\t', pos));
pos += part.length() + 1;
if (part.startsWith("net.opentsdb.")) {
part = part.substring(13);
} else if (part.startsWith("org.hbase.")) {
part = part.substring(10);
}
// logger
logs.setText(i * 2, 3, part);
// message
logs.setText(i * 2 + 1, 0, msg.substring(pos));
fcf.setColSpan(i * 2 + 1, 0, 4);
rf.addStyleName(i * 2, "fwf");
rf.addStyleName(i * 2 + 1, "fwf");
}
}
});
}
Aggregations