use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class AddVoExtSourceTabItem method draw.
public Widget draw() {
titleWidget.setText("Add external source");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
final GetExtSources extSources = new GetExtSources();
// remove already assigned ext sources from offering
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// second callback
final GetVoExtSources alreadyAssigned = new GetVoExtSources(voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
JsArray<ExtSource> esToRemove = JsonUtils.jsoAsArray(jso);
for (int i = 0; i < esToRemove.length(); i++) {
extSources.removeFromTable(esToRemove.get(i));
}
}
});
alreadyAssigned.retrieveData();
}
};
extSources.setEvents(localEvents);
extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceX509");
extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceKerberos");
extSources.setExtSourceTypeFilter("cz.metacentrum.perun.core.impl.ExtSourceIdp");
final ExtendedSuggestBox box = new ExtendedSuggestBox(extSources.getOracle());
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedExtSource());
final TabItem tab = this;
assignButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<ExtSource> extSourcesToAdd = extSources.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(extSourcesToAdd)) {
// FIXME - Should have only one callback to core
for (int i = 0; i < extSourcesToAdd.size(); i++) {
final int n = i;
AddExtSource request = new AddExtSource(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// unselect added person
extSources.getSelectionModel().setSelected(extSourcesToAdd.get(n), false);
alreadyAddedList.add(extSourcesToAdd.get(n));
rebuildAlreadyAddedWidget();
// clear search
box.getSuggestBox().setText("");
}
}));
request.addExtSource(voId, extSourcesToAdd.get(i).getId());
}
}
}
});
menu.addFilterWidget(box, new PerunSearchEvent() {
@Override
public void searchFor(String text) {
extSources.filterTable(text);
}
}, "Filter by ext source name or type");
menu.addWidget(assignButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
vp.add(menu);
vp.setCellHeight(menu, "30px");
vp.add(alreadyAdded);
CellTable<ExtSource> table = extSources.getTable();
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(extSources, table, assignButton);
table.addStyleName("perun-table");
table.setWidth("100%");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
// do not use resizePerunTable() when tab is in overlay - wrong width is calculated
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class TestDataGridTabItem method draw.
public Widget draw() {
//contentWidget.setSize("100%", "100%");
DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
contentWidget.setWidget(ft);
final DataGrid gridTable = new DataGrid();
gridTable.setSize("100%", "100%");
final ArrayList<VirtualOrganization> vosList = new ArrayList<VirtualOrganization>();
final GetVos getVos = new GetVos(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
vosList.addAll(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
gridTable.setRowData(vosList);
gridTable.redraw();
}
});
getVos.retrieveData();
gridTable.setSelectionModel(new MultiSelectionModel<VirtualOrganization>(new GeneralKeyProvider<VirtualOrganization>()));
final SelectionModel<VirtualOrganization> selectionModel = gridTable.getSelectionModel();
Column<VirtualOrganization, Boolean> checkBoxColumn = new Column<VirtualOrganization, Boolean>(new CheckboxCell(true, true)) {
@Override
public Boolean getValue(VirtualOrganization object) {
// Get the value from the selection model.
return selectionModel.isSelected(object);
}
};
checkBoxColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, Boolean>() {
@Override
public void update(int i, VirtualOrganization virtualOrganization, Boolean aBoolean) {
selectionModel.setSelected(virtualOrganization, aBoolean);
}
});
// Checkbox column header
CheckboxCell cb = new CheckboxCell();
Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {
public Boolean getValue() {
//return true to see a checked checkbox.
return false;
}
};
checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {
public void update(Boolean value) {
// sets selected to all, if value = true, unselect otherwise
for (VirtualOrganization obj : vosList) {
selectionModel.setSelected(obj, value);
}
}
});
gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
TextColumn<VirtualOrganization> idColumn = new TextColumn<VirtualOrganization>() {
@Override
public String getValue(VirtualOrganization object) {
return String.valueOf(object.getId());
}
};
gridTable.addColumn(idColumn, "Id", "Id");
gridTable.setColumnWidth(idColumn, "90px");
Column<VirtualOrganization, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<VirtualOrganization, String>() {
public String getValue(VirtualOrganization object) {
return object.getName();
}
}, new FieldUpdater<VirtualOrganization, String>() {
@Override
public void update(int i, VirtualOrganization virtualOrganization, String s) {
session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
}
});
gridTable.addColumn(nameColumn, "Name", "Name");
TextColumn<VirtualOrganization> shortnameColumn = new TextColumn<VirtualOrganization>() {
@Override
public String getValue(VirtualOrganization object) {
return object.getShortName();
}
};
gridTable.addColumn(shortnameColumn, "Short name", "Short name");
shortnameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {
@Override
public void update(int i, VirtualOrganization virtualOrganization, String s) {
session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
}
});
idColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {
@Override
public void update(int i, VirtualOrganization virtualOrganization, String s) {
session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
}
});
nameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {
@Override
public void update(int i, VirtualOrganization virtualOrganization, String s) {
session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
}
});
TabMenu tabMenu = new TabMenu();
// CREATE & DELETE ONLY WITH PERUN ADMIN
if (session.isPerunAdmin()) {
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createVo(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateVoTabItem());
}
}));
final cz.metacentrum.perun.webgui.widgets.CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteVo());
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<VirtualOrganization> itemsToRemove = getVos.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(itemsToRemove)) {
VerticalPanel removePanel = new VerticalPanel();
removePanel.add(new Label("These VOs will be removed:"));
for (int i = 0; i < itemsToRemove.size(); i++) {
VirtualOrganization vo = itemsToRemove.get(i);
removePanel.add(new Label(" - " + vo.getName()));
}
// confirmation
Confirm c = new Confirm("Remove VOs", removePanel, new ClickHandler() {
public void onClick(ClickEvent event) {
for (int i = 0; i < itemsToRemove.size(); i++) {
DeleteVo request;
// if last, refresh
if (i == itemsToRemove.size() - 1) {
request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
} else {
request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteVo(itemsToRemove.get(i).getId(), false);
}
getVos.clearTableSelectedSet();
}
}, true);
c.show();
}
}
});
tabMenu.addWidget(removeButton);
}
// filter
tabMenu.addFilterWidget(new ExtendedSuggestBox(getVos.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
getVos.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterVo());
ft.addNorth(tabMenu, 50);
ft.add(gridTable);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class TestJSONParserTabItem method draw.
public Widget draw() {
Button sendMessageButton = new Button("Parse response");
final FlexTable ft = new FlexTable();
ft.setCellSpacing(15);
int row = 0;
ft.setText(row, 0, "Server response:");
ft.setWidget(row, 1, returnedValue);
row++;
ft.setText(row, 0, "Callback name:");
ft.setHTML(row, 1, "callbackPost");
row++;
ft.setWidget(row, 0, sendMessageButton);
row++;
sendMessageButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String resp = returnedValue.getText();
// trims the whitespace
resp = resp.trim();
// short comparing
if (("callbackPost(null);").equalsIgnoreCase(resp)) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
RegExp re = RegExp.compile("^" + "callbackPost" + "\\((.*)\\)|\\);$");
MatchResult result = re.exec(resp);
if (result != null) {
resp = result.getGroup(1);
}
UiElements.generateInfo("Unwrapped value", "Non-null unwrapped value is: " + resp);
// if response = null - return null
if (resp.equals("null")) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// normal object
JavaScriptObject jso = JsonUtils.parseJson(resp);
BasicOverlayType basic = jso.cast();
UiElements.generateInfo("Parser result", "Parsed result is: " + basic.getString());
}
});
this.contentWidget.setWidget(ft);
return getWidget();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class PerunWebSession method setActiveGroupId.
/**
* Sets currently active Group (refresh links in menu)
* when only ID is provided.
*
* @param groupId ID of groupwhich user is editing now
*/
public void setActiveGroupId(int groupId) {
new GetEntityById(PerunEntity.GROUP, groupId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Group group = jso.cast();
setActiveGroup(group);
}
}).retrieveData();
}
use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.
the class PerunWebSession method setActiveVoId.
/**
* Sets currently active VO (refresh links in menu)
* when only ID is provided.
*
* @param voId ID of VO which user is editing now
*/
public void setActiveVoId(final int voId) {
new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
VirtualOrganization vo = jso.cast();
setActiveVo(vo);
}
}).retrieveData();
}
Aggregations