use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.
the class GroupResourceRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final Label facilityId = new Label();
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Facility fac = (Facility) jso;
facilityId.setText(String.valueOf(fac.getId()));
}
};
GetFacility facility = new GetFacility(resourceId, events);
facility.retrieveData();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groupId);
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
// local event fills the listBox
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
mems = new TableSorter<RichMember>().sortByName(mems);
listBox.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
listBox.addItem(mems.get(i));
}
listBox.addAllOption();
}
};
final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
getGroupRichMembers.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
// store for column with values
final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
listBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
// no member selected
if (selectedIndex == 0) {
// offer just group and group resource attributes
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get groups attributes
ids.put("group", groupId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// get group_resource attributes
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrs.sortTable();
// some member is selected
} else {
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get member, member-resource, user, user-facility attributes
ids.put("member", listBox.getSelectedObject().getId());
ids.put("resource", resourceId);
// to get user, user-facility attrs
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// all members are selected
if (selectedIndex == 1) {
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
// Value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
} else {
// member selected
// return original column
reqAttrsTable.removeColumn(columnId);
reqAttrsTable.insertColumn(columnId, columnStore, "Value");
}
}
}
});
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// send lists
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> memberList = new ArrayList<Attribute>();
ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> userList = new ArrayList<Attribute>();
ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
int selectedIndex = listBox.getSelectedIndex();
// if all selected
if (selectedIndex == 1) {
// TODO - USE NEW CONFIRM DESIGN
if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
return;
}
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member:")) {
memberList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
memberResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user:")) {
userList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
userFacilityList.add(attr);
}
}
// if not empty, send request
if (!(groupList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
request.setAttributes(ids, groupList);
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceId);
request.setAttributes(ids, groupResourceList);
}
if (!(memberList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberList);
}
} else {
// for one member
ids.clear();
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberList);
}
}
if (!(memberResourceList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("resource", resourceId);
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberResourceList);
}
} else {
// for one member
ids.clear();
ids.put("resource", resourceId);
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberResourceList);
}
}
if (!(userList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
request.setAttributes(ids, userList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
request.setAttributes(ids, userList);
}
}
if (!(userFacilityList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", listBox.getObjectAt(i).getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
menu.addWidget(new HTML("<strong>Group members:</strong>"));
menu.addWidget(listBox);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.
the class GroupRelationsTabItem method draw.
@Override
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": unions");
// main panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// if members group, hide
if (group.isCoreGroup()) {
vp.add(new HTML("<h2>Members group cannot have unions.</h2>"));
this.contentWidget.setWidget(vp);
return getWidget();
}
final GetGroupUnions unions = new GetGroupUnions(group, false);
// Events for reloading when group is created
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(unions);
// menu
TabMenu menu = new TabMenu();
final CheckBox subGroupsCheckBox = new CheckBox("Show sub-groups");
final ListBox reverseDropdown = new ListBox();
reverseDropdown.addItem("Normal");
reverseDropdown.addItem("Reverse");
reverseDropdown.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
switch(reverseDropdown.getSelectedIndex()) {
case 1:
unions.setReverseAndRefresh(true);
subGroupsCheckBox.setVisible(false);
break;
default:
unions.setReverseAndRefresh(false);
subGroupsCheckBox.setVisible(true);
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addGroupUnion(), new ClickHandler() {
public void onClick(ClickEvent event) {
// creates a new form
session.getTabManager().addTabToCurrentTab(new AddGroupUnionTabItem(group), true);
}
});
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) {
createButton.setEnabled(false);
unions.setCheckable(false);
}
menu.addWidget(createButton);
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupUnion());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Group> itemsToRemove = unions.getTableSelectedList();
String text = "Following group unions will be deleted.";
UiElements.showDeleteConfirm(itemsToRemove, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
RemoveGroupUnions request = new RemoveGroupUnions(JsonCallbackEvents.disableButtonEvents(removeButton, events));
if (unions.isReverse()) {
request.deleteGroupUnions(itemsToRemove, group);
} else {
request.deleteGroupUnions(group, itemsToRemove);
}
}
});
}
});
menu.addWidget(removeButton);
// filter box
final ExtendedSuggestBox box = new ExtendedSuggestBox(unions.getOracle());
menu.addFilterWidget(box, new PerunSearchEvent() {
public void searchFor(String text) {
unions.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterGroup());
subGroupsCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
unions.setShowSubgroupsAndRefresh(valueChangeEvent.getValue(), box.getSuggestBox().getText());
}
});
menu.addWidget(new HTML("<strong>Direction: </strong>"));
menu.addWidget(reverseDropdown);
menu.addWidget(subGroupsCheckBox);
// add menu to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
CellTable<Group> table = unions.getTable(new FieldUpdater<Group, String>() {
@Override
public void update(int arg0, Group group, String arg2) {
if (session.isGroupAdmin(group.getId()) || session.isVoAdmin(group.getId())) {
session.getTabManager().addTab(new GroupDetailTabItem(group.getId()));
} else {
UiElements.generateInfo("Not privileged", "You are not manager of selected group or its VO.");
}
}
});
removeButton.setEnabled(false);
if (session.isGroupAdmin(groupId) || session.isVoAdmin(group.getVoId()))
JsonUtils.addTableManagedButton(unions, table, removeButton);
// adds the table into the panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.
the class CreateFormItemTabItem method draw.
public Widget draw() {
// vertical panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("425px", "100%");
// flex table
final FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// select widget short name
final ExtendedTextBox shortNameTextBox = new ExtendedTextBox();
shortNameTextBox.setWidth("200px");
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (shortNameTextBox.getTextBox().getText().trim().isEmpty()) {
shortNameTextBox.setError("Short name can't be empty.");
return false;
} else {
shortNameTextBox.setOk();
return true;
}
}
};
shortNameTextBox.setValidator(validator);
// select widget type
final ListBox typeListBox = new ListBox();
for (String type : inputTypes.keySet()) {
typeListBox.addItem(inputTypes.get(type), type);
}
// insert after
final ListBox insertAfterListBox = new ListBox();
insertAfterListBox.addItem(" - insert to the beginning - ", 0 + "");
for (int i = 0; i < sourceList.size(); i++) {
ApplicationFormItem item = sourceList.get(i);
// with default en locale
RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, "");
String label = gen.getFormItem().getShortname();
// crop length
if (label.length() > CROP_LABEL_LENGTH) {
label = label.substring(0, CROP_LABEL_LENGTH);
}
// add to box
insertAfterListBox.addItem(label, (i + 1) + "");
}
layout.setHTML(0, 0, "Short name:");
layout.setWidget(0, 1, shortNameTextBox);
layout.setHTML(1, 0, "Input widget:");
layout.setWidget(1, 1, typeListBox);
layout.setHTML(2, 0, "Insert after:");
layout.setWidget(2, 1, insertAfterListBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setHTML(3, 0, "");
cellFormatter.setColSpan(3, 0, 2);
cellFormatter.setStyleName(3, 0, "inputFormInlineComment");
typeListBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
if (type.equals("TEXTFIELD")) {
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
} else if (type.equals("TEXTAREA")) {
layout.setHTML(3, 0, "Editable text area useful to gather longer text input with linebreaks, e.g. comments, SSH key");
} else if (type.equals("SELECTIONBOX")) {
layout.setHTML(3, 0, "Simple selection box with defined custom values that user can choose.");
} else if (type.equals("COMBOBOX")) {
layout.setHTML(3, 0, "Selection box with defined custom values and one special option: \"--custom value--\", which allows users to input own text (as simple text field).");
} else if (type.equals("CHECKBOX")) {
layout.setHTML(3, 0, "List of defined custom options with checkboxes. Selected values are gathered as comma separated string.");
} else if (type.equals("USERNAME")) {
layout.setHTML(3, 0, "Special text field to gather user`s login. It checks login availability on user input.");
} else if (type.equals("PASSWORD")) {
layout.setHTML(3, 0, "Two password fields to gather user`s new password. Input is never displayed. User must type same password in both fields.");
} else if (type.equals("VALIDATED_EMAIL")) {
layout.setHTML(3, 0, "Special text field to gather and verify user`s email address. Input is checked on email address format. If user enters new value, then validation email is sent. Application then can't be approved unless provided email address is validated.");
} else if (type.equals("SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to submit the form with custom label. All other form items are checked on valid input before submission. If it fails, form is not sent.");
} else if (type.equals("AUTO_SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to auto-submit the form with custom label. All other form items are checked on valid input before submission. If validation fail (at least once) user must submit form manually. If it's OK, then form is automatically submitted.");
} else if (type.equals("HTML_COMMENT")) {
layout.setHTML(3, 0, "Item is used to display custom HTML content anywhere on form. Useful for explanation descriptions, dividing parts of form etc.");
} else if (type.equals("HEADING")) {
layout.setHTML(3, 0, "Item is used to display customizable heading of form. Can have any HTML content.");
} else if (type.equals("TIMEZONE")) {
layout.setHTML(3, 0, "Selection box with pre-defined values of UTC timezones.");
} else if (type.equals("FROM_FEDERATION_HIDDEN")) {
layout.setHTML(3, 0, "Non-editable and hidden form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else if (type.equals("FROM_FEDERATION_SHOW")) {
layout.setHTML(3, 0, "Non-editable and visible form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else {
layout.setHTML(3, 0, "");
}
}
});
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
TabMenu menu = new TabMenu();
// create button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createFormItem(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox()) {
int positionToAdd = Integer.parseInt(insertAfterListBox.getValue(insertAfterListBox.getSelectedIndex()));
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
String shortName = shortNameTextBox.getTextBox().getText().trim();
createItem(shortName, type, positionToAdd);
}
}
}));
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.
the class AddFacilityManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(3, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.
the class AddPublicationsTabItem method loadCreateScreen.
/**
* Draw tab content for CREATE state.
*/
private void loadCreateScreen() {
// MAIN PANEL
final VerticalPanel mainPanel = new VerticalPanel();
mainPanel.setSize("100%", "100%");
// MAIN MENU
FlexTable header = new FlexTable();
header.setStyleName("wizardHeader");
mainPanel.add(header);
// splitter
HTML splitter = new HTML("<hr size=\"1\" width=\"100%\" />");
mainPanel.add(splitter);
int column = 0;
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookEditIcon()));
column++;
Label headerTitle = new Label();
headerTitle.getElement().setAttribute("style", "font-size: 1.35em;");
header.setWidget(0, column, headerTitle);
column++;
headerTitle.setText("Create publication");
// Widgets
final CustomButton backButton = TabMenu.getPredefinedButton(ButtonType.BACK, "Go back to start page - !! ALL UNSAVED CHANGES WILL BE LOST !!", new ClickHandler() {
public void onClick(ClickEvent event) {
importedPublications.clear();
hadError = false;
// go back to original state
state = State.START;
session.getTabManager().reloadTab(tab);
}
});
header.setWidget(0, column, backButton);
column++;
final ExtendedTextBox title = new ExtendedTextBox();
title.getTextBox().setMaxLength(1024);
final TextBox isbn = new TextBox();
isbn.setMaxLength(32);
final TextBox doi = new TextBox();
doi.setMaxLength(256);
final ExtendedTextArea cite = new ExtendedTextArea();
cite.getTextArea().setSize("380px", "75px");
cite.getTextArea().getElement().setAttribute("maxlength", "4000");
final ListBox year = new ListBox();
final CheckBox addAsAuthor = new CheckBox("Add me as author");
addAsAuthor.setValue(true);
addAsAuthor.setTitle("When checked, you will be automatically added as author of created publication");
final ExtendedTextBox.TextBoxValidator titleValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (title.getTextBox().getText().trim().isEmpty()) {
title.setError("Publication title can't be empty.");
return false;
} else {
title.setOk();
return true;
}
}
};
title.setValidator(titleValidator);
final ExtendedTextArea.TextAreaValidator citeValidator = new ExtendedTextArea.TextAreaValidator() {
@Override
public boolean validateTextArea() {
if (cite.getTextArea().getText().trim().isEmpty()) {
cite.setError("Publication citation can't be empty.");
return false;
} else {
cite.setOk();
return true;
}
}
};
cite.setValidator(citeValidator);
final CustomButton finishButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "Create publication in Perun");
// enable only after search for similar publications
finishButton.setEnabled(false);
finishButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// check
if (titleValidator.validateTextBox() && citeValidator.validateTextArea()) {
// create
CreatePublication request = new CreatePublication(JsonCallbackEvents.disableButtonEvents(finishButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Publication pub = jso.cast();
importedPublications.add(pub);
counter--;
if (addAsAuthor.getValue()) {
CreateAuthorship request = new CreateAuthorship();
request.createAuthorship(pub.getId(), userId);
previousState = State.CREATE;
state = State.REVIEW;
session.getTabManager().reloadTab(tab);
}
}
@Override
public void onError(PerunError error) {
hadError = true;
counter--;
}
}));
request.createPublication(title.getTextBox().getText().trim(), categoryId, Integer.parseInt(year.getValue(year.getSelectedIndex())), isbn.getText().trim(), doi.getText().trim(), cite.getTextArea().getText().trim());
counter++;
}
}
});
// checking
final Map<String, Object> ids = new HashMap<String, Object>();
ids.put("userId", session.getUser().getId());
ids.put("authors", 1);
final FindSimilarPublications filterCall = new FindSimilarPublications(ids);
filterCall.setCheckable(false);
CellTable<Publication> table = filterCall.getEmptyTable(new FieldUpdater<Publication, String>() {
public void update(int index, Publication object, String value) {
session.getTabManager().addTab(new PublicationDetailTabItem(object, true));
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
table.setWidth("100%");
table.removeColumn(0);
table.removeColumn(5);
table.removeColumn(4);
table.removeColumn(3);
// check layout
final FlexTable checkLayout = new FlexTable();
checkLayout.setSize("100%", "100%");
// form layout
final FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
layout.setWidth("600px");
final CustomButton checkButton = new CustomButton("Check", "Check if same publication exist in Perun", SmallIcons.INSTANCE.booksIcon());
filterCall.setEvents(JsonCallbackEvents.disableButtonEvents(checkButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
finishButton.setEnabled(true);
ArrayList<Publication> pubs = JsonUtils.jsoAsList(jso);
if (pubs == null || pubs.isEmpty()) {
UiElements.generateInfo("No similar publications", "No similar publications were found. You can continue reporting new publication.");
} else {
backButton.setEnabled(false);
checkButton.setEnabled(false);
mainPanel.remove(layout);
mainPanel.add(checkLayout);
}
}
@Override
public void onError(PerunError error) {
finishButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
}
}));
checkButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (titleValidator.validateTextBox() && citeValidator.validateTextArea()) {
ids.clear();
ids.put("authors", 1);
if (!title.getTextBox().getText().trim().equals("")) {
ids.put("title", title.getTextBox().getText().trim());
}
if (!isbn.getText().trim().equals("")) {
ids.put("isbn", isbn.getText().trim());
}
if (!doi.getText().equals("")) {
ids.put("doi", doi.getText());
}
filterCall.clearTable();
filterCall.retrieveData();
}
}
});
final ListBoxWithObjects<Category> category = new ListBoxWithObjects<Category>();
GetCategories request = new GetCategories(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
category.clear();
categories = JsonUtils.<Category>jsoAsList(jso);
if (categories != null && !categories.isEmpty()) {
for (Category c : categories) {
category.addItem(c);
if (c.getName().equalsIgnoreCase("Ke kontrole")) {
// set default
defaultCategoryId = c.getId();
categoryId = c.getId();
category.setSelected(c, true);
}
}
checkButton.setEnabled(true);
} else {
category.addItem("No category available");
}
}
@Override
public void onError(PerunError error) {
category.clear();
category.addItem("Error while loading");
// categories must be loaded !!
checkButton.setEnabled(false);
finishButton.setEnabled(false);
}
@Override
public void onLoadingStart() {
category.clear();
category.addItem("Loading...");
}
});
request.retrieveData();
category.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
// put new publication in right category
categoryId = category.getSelectedObject().getId();
}
});
// set year
for (int i = 2004; i <= JsonUtils.getCurrentYear(); i++) {
year.addItem(String.valueOf(i));
}
year.setSelectedIndex(year.getItemCount() - 1);
// form
layout.setHTML(0, 0, "Title:");
layout.setWidget(0, 1, title);
layout.setHTML(1, 0, "Year:");
layout.setWidget(1, 1, year);
layout.setHTML(2, 0, "ISBN / ISSN:");
layout.setWidget(2, 1, isbn);
layout.setHTML(3, 0, "DOI:");
layout.setWidget(3, 1, doi);
layout.setHTML(4, 0, "Category:");
layout.setWidget(4, 1, category);
layout.setHTML(5, 0, "Full cite:");
layout.setWidget(5, 1, cite);
layout.setHTML(6, 1, "Citation as close as possible to ČSN ISO 690 or ČSN ISO 690-2.");
layout.getFlexCellFormatter().setStyleName(6, 1, "inputFormInlineComment");
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
header.setWidget(0, column, checkButton);
column++;
header.setWidget(0, column, finishButton);
column++;
header.setWidget(0, column, addAsAuthor);
column++;
checkLayout.setWidget(0, 0, new CustomButton("Back to input form", "Back to Create publication form.", SmallIcons.INSTANCE.arrowLeftIcon(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
mainPanel.add(layout);
mainPanel.remove(checkLayout);
backButton.setEnabled(true);
checkButton.setEnabled(true);
}
}));
checkLayout.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
checkLayout.getFlexCellFormatter().setWidth(0, 0, "180px");
checkLayout.setHTML(0, 1, "<span class=\"input-status-error\">Please check if your publication is not already listed below.</span><ul><li>If NO, continue with Create button above.</br> </li><li>If YES, click on it to see details and add yourself between authors. If desired publication is locked for changes, notify administrators (meta@cesnet.cz) about your request.</li></ul>");
checkLayout.setWidget(1, 0, sp);
checkLayout.getFlexCellFormatter().setColSpan(1, 0, 2);
mainPanel.add(layout);
mainPanel.setCellHeight(layout, "100%");
this.contentWidget.setWidget(mainPanel);
}
Aggregations