ckan2zenodo-publisher-widget/src/main/java/org/gcube/portlets/widgets/ckan2zenodopublisher/client/ui/authors/CreatorView.java

281 lines
6.8 KiB
Java
Raw Normal View History

2019-12-17 11:37:56 +01:00
package org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.authors;
2019-12-16 17:51:37 +01:00
2020-01-15 17:51:22 +01:00
import java.util.Arrays;
2019-12-18 11:58:49 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.events.RemoveCreatorEvent;
2020-01-15 17:51:22 +01:00
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.utils.InfoTextAndLabels;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.view.FieldUtil;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoAuthor;
2019-12-18 11:58:49 +01:00
import com.github.gwtbootstrap.client.ui.Button;
2020-01-13 17:48:41 +01:00
import com.github.gwtbootstrap.client.ui.ControlGroup;
2020-01-15 17:51:22 +01:00
import com.github.gwtbootstrap.client.ui.ControlLabel;
import com.github.gwtbootstrap.client.ui.ListBox;
2019-12-16 17:51:37 +01:00
import com.github.gwtbootstrap.client.ui.TextBox;
import com.google.gwt.core.client.GWT;
2019-12-18 11:58:49 +01:00
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
2019-12-16 17:51:37 +01:00
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
2020-01-15 17:51:22 +01:00
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
2019-12-16 17:51:37 +01:00
import com.google.gwt.user.client.ui.Widget;
2019-12-18 11:58:49 +01:00
// TODO: Auto-generated Javadoc
2020-01-15 17:51:22 +01:00
/**
* The Class CreatorView.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 15, 2020
*/
2019-12-16 17:51:37 +01:00
public class CreatorView extends Composite {
private static CreatorViewUiBinder uiBinder = GWT.create(CreatorViewUiBinder.class);
2020-01-15 17:51:22 +01:00
/**
* The Interface CreatorViewUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 15, 2020
*/
2019-12-16 17:51:37 +01:00
interface CreatorViewUiBinder extends UiBinder<Widget, CreatorView> {
}
2019-12-18 11:58:49 +01:00
2019-12-16 17:51:37 +01:00
@UiField
TextBox field_name;
@UiField
TextBox field_affiliation;
@UiField
TextBox field_orcid;
2019-12-18 11:58:49 +01:00
@UiField
Button remove_author;
2020-01-13 17:48:41 +01:00
@UiField
ControlGroup cg_authors;
2020-01-15 17:51:22 +01:00
@UiField
ListBox field_author_type;
@UiField
HorizontalPanel controls_author_type;
@UiField
ControlLabel field_cl_author;
2019-12-18 11:58:49 +01:00
private HandlerManager eventBus;
2020-01-15 17:51:22 +01:00
private String userRole; //Can be: Creator, Contributor etc..
private ZenodoAuthor author;
private boolean isMandatoryField;
2019-12-18 11:58:49 +01:00
2020-01-15 17:51:22 +01:00
/**
* Instantiates a new creator view.
*
* @param author the author
* @param userRole the user role
* @param isMandatoryField the is mandatory field
2020-01-15 17:51:22 +01:00
*/
public CreatorView(ZenodoAuthor author, String userRole, Boolean isMandatoryField) {
2019-12-18 11:58:49 +01:00
initWidget(uiBinder.createAndBindUi(this));
GWT.log("Creating CreatorView for author: "+author+", userRole: "+userRole);
2020-01-15 17:51:22 +01:00
this.userRole = userRole;
this.author = author;
this.isMandatoryField = isMandatoryField == null? false:isMandatoryField;
2020-01-15 17:51:22 +01:00
String fieldLabel = isMandatoryField?"<font color='red'>*</font>":"";
2020-01-15 17:51:22 +01:00
if(this.userRole!=null) {
field_cl_author.add(new HTML(fieldLabel+"&nbsp;"+userRole));
remove_author.setText("Remove "+userRole);
2020-01-15 17:51:22 +01:00
}else { //default role is Author
field_cl_author.add(new HTML(fieldLabel+"&nbsp;Author"));
remove_author.setText("Remove Author");
2020-01-15 17:51:22 +01:00
}
if(this.author!=null) {
setField_name(InfoTextAndLabels.validValue(this.author.getName()));
setField_affiliation(InfoTextAndLabels.validValue(this.author.getAffiliation()));
setField_orcid(InfoTextAndLabels.validValue(this.author.getOrcid()));
2020-01-15 17:51:22 +01:00
if(this.author.getType()!=null) {
controls_author_type.setVisible(true);
FieldUtil.addValuesToListBox(field_author_type, this.author.getType().getSelectableValues());
FieldUtil.selectValueToListBox(field_author_type, Arrays.asList(this.author.getType().getSelectedValues().get(0)));
}
}
if(this.userRole!=null) {
String userRoleToLowerCase = userRole.toLowerCase();
if(userRoleToLowerCase.startsWith("creator")) {
InfoTextAndLabels.addTooltipForFieldKey("creators", field_cl_author);
}else if(userRoleToLowerCase.startsWith("contributor")) {
InfoTextAndLabels.addTooltipForFieldKey("contributors", field_cl_author);
}else {
InfoTextAndLabels.addTooltipForFieldKey("authors", field_cl_author);
}
2020-01-17 12:46:32 +01:00
}
GWT.log("Created creator view with author: "+this.author);
2019-12-18 11:58:49 +01:00
}
2020-01-15 17:51:22 +01:00
/**
* Instantiates a new creator view.
*
* @param author the author
* @param userRole the user role
* @param eventBus the event bus
* @param isFieldMandatory the is field mandatory
2020-01-15 17:51:22 +01:00
*/
public CreatorView(ZenodoAuthor author, String userRole, HandlerManager eventBus, Boolean isFieldMandatory) {
this(author, userRole, isFieldMandatory);
2019-12-18 11:58:49 +01:00
this.eventBus = eventBus;
remove_author.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
CreatorView.this.eventBus.fireEvent(new RemoveCreatorEvent(CreatorView.this));
}
});
}
/**
* Sets the visible remove creator.
*
* @param visible the new visible remove creator
*/
public void setVisibleRemoveCreator(boolean visible) {
remove_author.setVisible(visible);
}
/**
* Checks if is mandatory field.
*
* @return true, if is mandatory field
*/
public boolean isMandatoryField() {
return isMandatoryField;
}
2019-12-16 17:51:37 +01:00
2020-01-15 17:51:22 +01:00
/**
* Gets the field name.
*
* @return the field name
*/
2019-12-16 17:51:37 +01:00
public TextBox getField_name() {
return field_name;
}
2020-01-15 17:51:22 +01:00
/**
* Sets the field name.
*
* @param field_name the new field name
*/
2019-12-18 11:58:49 +01:00
public void setField_name(String field_name) {
this.field_name.setValue(field_name);
2019-12-16 17:51:37 +01:00
}
2020-01-15 17:51:22 +01:00
/**
* Gets the field affiliation.
*
* @return the field affiliation
*/
2019-12-16 17:51:37 +01:00
public TextBox getField_affiliation() {
return field_affiliation;
}
2020-01-15 17:51:22 +01:00
/**
* Sets the field affiliation.
*
* @param field_affiliation the new field affiliation
*/
2019-12-18 11:58:49 +01:00
public void setField_affiliation(String field_affiliation) {
this.field_affiliation.setValue(field_affiliation);
2019-12-16 17:51:37 +01:00
}
2020-01-15 17:51:22 +01:00
/**
* Gets the field orcid.
*
* @return the field orcid
*/
2019-12-16 17:51:37 +01:00
public TextBox getField_orcid() {
return field_orcid;
}
2020-01-15 17:51:22 +01:00
/**
* Sets the field orcid.
*
* @param field_orcid the new field orcid
*/
2019-12-18 11:58:49 +01:00
public void setField_orcid(String field_orcid) {
this.field_orcid.setValue(field_orcid);
2019-12-16 17:51:37 +01:00
}
2020-01-13 17:48:41 +01:00
2020-01-15 17:51:22 +01:00
/**
* Gets the control group author.
*
* @return the control group author
*/
2020-01-13 17:48:41 +01:00
public ControlGroup getControlGroup_Author() {
return cg_authors;
}
2020-01-15 17:51:22 +01:00
/**
* Gets the user role.
*
* @return the user role
*/
public String getUserRole() {
return userRole;
}
/**
* Gets the author.
*
* @return the author
*/
public ZenodoAuthor getAuthor() {
return author;
}
/**
* Gets the field author type.
*
* @return the field author type
*/
public ListBox getField_author_type() {
return field_author_type;
}
/**
* Gets the author type value.
*
* @return the author type value
*/
public String getAuthorTypeValue(){
String authorTypeSelected = null;
if(controls_author_type.isVisible()) {
authorTypeSelected = field_author_type.getValue();
}
return authorTypeSelected;
}
2019-12-18 11:58:49 +01:00
2019-12-16 17:51:37 +01:00
}