ckan-metadata-publisher-widget/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java

139 lines
3.8 KiB
Java

package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* A resource information form panel
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourceInfoForm extends Composite{
@UiField
TextBox resourceName;
@UiField
TextBox resourcePath;
@UiField
TextBox resourceFormat;
@UiField
TextArea resourceDescription;
@UiField
Button updateResourceButton;
// @UiField
// Button cancelButton;
@UiField
HorizontalPanel commandPanel;
@UiField
ControlGroup controlName;
private ResourceElementBean resourceBean;
private static ResourceInfoFormUiBinder uiBinder = GWT
.create(ResourceInfoFormUiBinder.class);
interface ResourceInfoFormUiBinder extends
UiBinder<Widget, ResourceInfoForm> {
}
public ResourceInfoForm() {
initWidget(uiBinder.createAndBindUi(this));
}
public ResourceInfoForm(final ResourceElementBean resource, final ValueUpdater<ResourceElementBean> valueUpdater) {
initWidget(uiBinder.createAndBindUi(this));
this.resourceBean = resource;
this.resourceDescription.setText(resource.getDescription());
this.resourceFormat.setText(resource.getMimeType() == null? "Unavailable" : resource.getMimeType());
this.resourceName.setText(resource.getName());
this.resourcePath.setText(resource.getFullPath());
commandPanel.setCellHorizontalAlignment(updateResourceButton, HasHorizontalAlignment.ALIGN_RIGHT);
// handlers
// cancelButton.addClickHandler(new ClickHandler() {
//
// @Override
// public void onClick(ClickEvent event) {
//
//
//
// }
// });
updateResourceButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeError(controlName);
// check description
resourceBean.setDescription(resourceDescription.getText());
// check name
String newName = resourceName.getText();
if(newName == null || newName.isEmpty()){
showError(controlName);
}else
resourceBean.setEditableName(newName);
valueUpdater.update(resourceBean);
}
});
}
public String getResourceName() {
return resourceName.getText();
}
public void setResourceName(String resourceName) {
this.resourceName.setText(resourceName);
}
public String getResourcePath() {
return resourcePath.getText();
}
public void setResourcePath(String resourcePath) {
this.resourcePath.setText(resourcePath);
}
public String getResourceFormat() {
return resourceFormat.getText();
}
public void setResourceFormat(String resourceFormat) {
this.resourceFormat.setText(resourceFormat);
}
public String getResourceDescription() {
return resourceDescription.getText();
}
public void setResourceDescription(String resourceDescription) {
this.resourceDescription.setText(resourceDescription);
}
public void removeError(ControlGroup control) {
control.setType(ControlGroupType.NONE);
}
public void showError(ControlGroup control) {
control.setType(ControlGroupType.ERROR);
}
}