83 lines
2.0 KiB
Java
83 lines
2.0 KiB
Java
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.InputAddOn;
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
public class CustomFieldEntry extends Composite {
|
|
|
|
private static CustomFieldEntryUiBinder uiBinder = GWT
|
|
.create(CustomFieldEntryUiBinder.class);
|
|
|
|
interface CustomFieldEntryUiBinder extends
|
|
UiBinder<Widget, CustomFieldEntry> {
|
|
}
|
|
|
|
@UiField InputAddOn keyFieldPrepend;
|
|
@UiField InputAddOn valueFieldPrepend;
|
|
@UiField Button removeCustomField;
|
|
|
|
// event bus
|
|
private HandlerManager eventBus;
|
|
|
|
public CustomFieldEntry(HandlerManager eventBus) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
this.eventBus = eventBus;
|
|
}
|
|
|
|
/**
|
|
* Check if it has been added by the user during form creation or comes from the workspace
|
|
* @return
|
|
*/
|
|
private boolean isCreatedCustomField(){
|
|
|
|
return valueFieldPrepend.isAttached();
|
|
|
|
}
|
|
|
|
/**
|
|
* Retrieve the key value
|
|
* @return
|
|
*/
|
|
public String getKey(){
|
|
|
|
if(isCreatedCustomField())
|
|
return ((TextBox)keyFieldPrepend.getWidget(1)).getValue();
|
|
else
|
|
return valueFieldPrepend.get
|
|
|
|
}
|
|
|
|
/**
|
|
* Retrieve the value
|
|
* @return
|
|
*/
|
|
public String getValue(){
|
|
|
|
if(isCreatedCustomField())
|
|
return ((TextBox)valueFieldPrepend.getWidget(1)).getValue();
|
|
else
|
|
return valueFieldPrepend.getWidgetIndex(1).get
|
|
|
|
}
|
|
|
|
@UiHandler("removeCustomField")
|
|
void onRemoveCustomField(ClickEvent e){
|
|
|
|
// fire event
|
|
eventBus.fireEvent(new DeleteCustomFieldEvent(this));
|
|
|
|
}
|
|
|
|
}
|