use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupToResources in project perun by CESNET.
the class AssignGroupTabItem method draw.
public Widget draw() {
// set tab name
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": assign to resource");
// main content
VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
// menu
TabMenu menu = new TabMenu();
menu.addWidget(UiElements.getRefreshButton(this));
// callback
final GetRichResources callback = new GetRichResources(group.getVoId());
callback.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
for (RichResource rr : resources) {
callback.removeFromTable(rr);
}
ArrayList<RichResource> temp = new ArrayList<RichResource>();
temp.addAll(callback.getList());
callback.setList(temp);
}
});
CellTable<RichResource> table = callback.getTable();
// close tab event
final TabItem tab = this;
// filter box
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
public void searchFor(String text) {
callback.filterTable(text);
// if single group, select
if (callback.getList().size() == 1) {
callback.getSelectionModel().setSelected(callback.getList().get(0), true);
}
}
}, ButtonTranslation.INSTANCE.filterResources());
// button
final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignGroupToSelectedResources());
assignButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<RichResource> toAssign = callback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(toAssign)) {
AssignGroupToResources request = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
alreadyAddedList.addAll(toAssign);
for (RichResource r : toAssign) {
callback.getSelectionModel().setSelected(r, false);
}
rebuildAlreadyAddedWidget();
}
}));
request.assignGroupToResources(group, toAssign);
}
}
});
menu.addWidget(assignButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// fixme - probably should be button for finish and close
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
assignButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, assignButton);
// add menu and the table to the main panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// do not use resizePerunTable() in overlay mode - calculated width is wrong
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
mainTab.add(menu);
mainTab.setCellHeight(menu, "30px");
rebuildAlreadyAddedWidget();
mainTab.add(alreadyAdded);
mainTab.add(sp);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupToResources in project perun by CESNET.
the class ManageGroupsBeforeAssigning method draw.
public Widget draw() {
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final ListBoxWithObjects<Group> groupsDropDown = new ListBoxWithObjects<Group>();
for (Group grp : groupsToAssign) {
groupsDropDown.addItem(grp);
}
final ListBoxWithObjects<Group> subgroupsDropDown = new ListBoxWithObjects<Group>();
subgroupsDropDown.addNotSelectedOption();
final CustomButton finishAssigningButton = TabMenu.getPredefinedButton(ButtonType.FINISH, ButtonTranslation.INSTANCE.finishGroupAssigning());
final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(finishAssigningButton, this, true);
final JsonCallbackEvents disableButtonEvents = JsonCallbackEvents.disableButtonEvents(finishAssigningButton);
finishAssigningButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// assign all
if (groupsDropDown.getSelectedIndex() == 0) {
AssignGroupsToResource request = new AssignGroupsToResource(closeTabEvents);
request.assignGroupsToResource(groupsToAssign, resource);
} else {
// assign selected
if (groupsDropDown.getSelectedObject() == null) {
Window.alert("No group selected");
return;
}
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// call previus events
closeTabEvents.onFinished(null);
// removed finished group
groupsDropDown.removeSelectedItem();
if (groupsDropDown.isEmpty()) {
// if no group left - close windows
closeTabEvents.onFinished(null);
}
}
};
AssignGroupToResources request = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(finishAssigningButton, localEvents));
request.assignGroupToResources(groupsDropDown.getSelectedObject(), JsonUtils.<RichResource>toList(resource));
}
}
});
menu.addWidget(finishAssigningButton);
menu.addWidget(new HTML("<strong>Selected group: </strong>"));
menu.addWidget(groupsDropDown);
// TODO - get subgroups correctly too
// menu.addWidget(new HTML("<strong>Configure sub-groups: </strong>"));
// menu.addWidget(subgroupsDropDown);
vp.add(menu);
vp.setCellHeight(menu, "30px");
groupsDropDown.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// removes previous table
if (vp.getWidgetCount() == 2) {
vp.remove(1);
}
if (groupsDropDown.getSelectedIndex() > 0) {
/*
// fill subgroups listbox with groups
subgroupsDropDown.removeAllOption();
subgroupsDropDown.removeNotSelectedOption();
subgroupsDropDown.clear();
subgroupsDropDown.addNotSelectedOption();
for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
subgroupsDropDown.addItem(grp);
}
subgroupsDropDown.addAllOption();
*/
// some group selected
TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else {
/*
//clear listbox
subgroupsDropDown.removeAllOption();
subgroupsDropDown.removeNotSelectedOption();
subgroupsDropDown.clear();
subgroupsDropDown.addNotSelectedOption();
subgroupsDropDown.addItem("All");
*/
// all groups tab
TabItem ti = new GroupsResourceRequiredAttributesTabItem(resourceId, groupsToAssign);
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
}
}
});
/*
subgroupsDropDown.addChangeHandler(new ChangeHandler(){
public void onChange(ChangeEvent event) {
if (vp.getWidgetCount() == 2) { vp.remove(1); } // removes previous table
if (subgroupsDropDown.getSelectedIndex() > 1){
// sub-group selected
TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else if (subgroupsDropDown.getSelectedIndex() == 1){
// all selected
if (groupsDropDown.getSelectedIndex() > 0) {
// all subgroups of selected group
TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getAllObjects());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else {
// all groups and subgroups
TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, allGroups);
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
}
} else {
// parent-group selected / subgroup not selected
TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, groupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
}
}
});
*/
TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
groupsDropDown.addAllOption();
/*
// if some group selected
if (groupsDropDown.getSelectedObject() != null){
// fill subgroups listbox with groups
subgroupsDropDown.addNotSelectedOption();
for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
subgroupsDropDown.addItem(grp);
}
subgroupsDropDown.addAllOption();
}
*/
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations