2017-11-09 22:11:10 +01:00
|
|
|
package org.gcube.datacatalogue.grsf_manage_widget.client.view.subwidgets;
|
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-12-07 12:37:21 +01:00
|
|
|
import org.gcube.datacatalogue.common.enums.Product_Type;
|
2017-12-12 18:54:45 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectedBean;
|
2017-11-23 20:04:47 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
|
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Paragraph;
|
|
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
2017-11-09 22:11:10 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2017-11-23 20:04:47 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Float;
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
|
|
|
import com.google.gwt.event.dom.client.KeyPressHandler;
|
2017-11-09 22:11:10 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
2017-11-23 20:04:47 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
2017-11-09 22:11:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
2017-11-23 20:04:47 +01:00
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2017-11-09 22:11:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class ConnectToWidget extends Composite{
|
|
|
|
|
|
|
|
private static ConnectToWidgetUiBinder uiBinder = GWT
|
|
|
|
.create(ConnectToWidgetUiBinder.class);
|
|
|
|
|
|
|
|
interface ConnectToWidgetUiBinder extends UiBinder<Widget, ConnectToWidget> {
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
@UiField
|
|
|
|
VerticalPanel connectPanel;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
Button suggestRecord;
|
|
|
|
|
2017-12-07 12:37:21 +01:00
|
|
|
//private GRSFManageWidgetServiceAsync service;
|
|
|
|
private List<Tuple> connectList = new ArrayList<Tuple>(0);
|
2017-11-23 20:04:47 +01:00
|
|
|
|
2017-12-07 12:37:21 +01:00
|
|
|
public ConnectToWidget(final ManageProductBean bean/*, GRSFManageWidgetServiceAsync service*/) {
|
2017-11-09 22:11:10 +01:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2017-12-07 12:37:21 +01:00
|
|
|
|
|
|
|
//this.service = service;
|
|
|
|
String acceptedDomain = bean.getGrsfDomain().equalsIgnoreCase(Product_Type.STOCK.getOrigName()) ? Product_Type.FISHERY.getOrigName() : Product_Type.STOCK.getOrigName(); // inverted
|
2017-11-23 20:04:47 +01:00
|
|
|
suggestRecord.setTitle("Connect this " + bean.getGrsfDomain() + " record to a " + acceptedDomain + " record ");
|
|
|
|
suggestRecord.setIcon(IconType.PLUS_SIGN);
|
|
|
|
suggestRecord.getElement().getStyle().setFloat(Float.RIGHT);
|
|
|
|
|
|
|
|
// add handler
|
|
|
|
suggestRecord.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent arg0) {
|
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
ConnectedBean cb = new ConnectedBean();
|
2017-11-23 20:04:47 +01:00
|
|
|
cb.setSourceDomain(bean.getGrsfDomain());
|
2017-12-07 12:37:21 +01:00
|
|
|
Tuple t = buildWidgetConnect(cb);
|
|
|
|
connectList.add(t);
|
|
|
|
connectPanel.add(t.getW());
|
2017-11-23 20:04:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-09 22:11:10 +01:00
|
|
|
}
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
/**
|
|
|
|
* Builds up a widget for connecting records.
|
|
|
|
* @param w the widget
|
|
|
|
* @param cb the connectBean.
|
|
|
|
*/
|
2017-12-12 18:54:45 +01:00
|
|
|
private Tuple buildWidgetConnect(final ConnectedBean cb){
|
2017-11-09 22:11:10 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
VerticalPanel main = new VerticalPanel();
|
|
|
|
main.setWidth("90%");
|
|
|
|
HorizontalPanel hp = new HorizontalPanel();
|
|
|
|
hp.setWidth("100%");
|
|
|
|
|
|
|
|
VerticalPanel vpLeft = new VerticalPanel();
|
|
|
|
vpLeft.getElement().getStyle().setMarginLeft(15, Unit.PX);
|
|
|
|
vpLeft.setWidth("80%");
|
2017-12-07 12:37:21 +01:00
|
|
|
Paragraph semanticIdentifier = new Paragraph("Record Identifier (UUID):");
|
2017-11-23 20:04:47 +01:00
|
|
|
final TextBox box = new TextBox();
|
2017-12-07 12:37:21 +01:00
|
|
|
box.setId("identifier-text");
|
2017-11-23 20:04:47 +01:00
|
|
|
box.addKeyPressHandler(new KeyPressHandler() {
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
@Override
|
|
|
|
public void onKeyPress(KeyPressEvent event) {
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
String currentText = box.getText().trim();
|
|
|
|
GWT.log("Text changed to " + currentText);
|
2017-12-07 12:37:21 +01:00
|
|
|
cb.setDestIdentifier(currentText);
|
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
box.addChangeHandler(new ChangeHandler() {
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
String currentText = box.getText().trim();
|
|
|
|
GWT.log("Text changed to " + currentText);
|
2017-12-07 12:37:21 +01:00
|
|
|
cb.setDestIdentifier(currentText);
|
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
box.setWidth("512px");
|
2017-12-07 12:37:21 +01:00
|
|
|
box.setPlaceholder("Insert the Identifier (UUID) of the record to connect");
|
2017-11-23 20:04:47 +01:00
|
|
|
|
|
|
|
vpLeft.add(semanticIdentifier);
|
|
|
|
vpLeft.add(box);
|
|
|
|
|
|
|
|
VerticalPanel vpRight = new VerticalPanel();
|
|
|
|
vpRight.setWidth("20%");
|
|
|
|
|
|
|
|
Button removeExtra = new Button();
|
|
|
|
removeExtra.setIcon(IconType.MINUS);
|
|
|
|
removeExtra.setTitle("Remove this connection");
|
|
|
|
removeExtra.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent arg0) {
|
|
|
|
|
|
|
|
// remove this object from the pairs list
|
2017-12-07 12:37:21 +01:00
|
|
|
Iterator<Tuple> iterator = connectList.iterator();
|
2017-11-23 20:04:47 +01:00
|
|
|
while (iterator.hasNext()) {
|
2017-12-07 12:37:21 +01:00
|
|
|
Tuple pair = (Tuple) iterator
|
2017-11-23 20:04:47 +01:00
|
|
|
.next();
|
|
|
|
if(pair.getO().equals(cb)){
|
|
|
|
pair.getW().removeFromParent();
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
vpRight.getElement().getStyle().setFloat(Float.RIGHT);
|
|
|
|
vpRight.add(removeExtra);
|
|
|
|
hp.add(vpLeft);
|
|
|
|
hp.add(vpRight);
|
|
|
|
HTML separator = new HTML("<hr style=\"width:100%;\"/>");
|
|
|
|
connectPanel.add(separator);
|
|
|
|
main.add(hp);
|
|
|
|
main.add(separator);
|
2017-12-07 12:37:21 +01:00
|
|
|
return new Tuple(cb, main, box);
|
2017-11-23 20:04:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-07 12:37:21 +01:00
|
|
|
/**
|
|
|
|
* Get the list of records to connect with this one
|
|
|
|
* @return
|
|
|
|
*/
|
2017-12-12 18:54:45 +01:00
|
|
|
public List<ConnectedBean> getConnectList() {
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
List<ConnectedBean> toReturn = new ArrayList<ConnectedBean>(0);
|
2017-12-07 12:37:21 +01:00
|
|
|
|
|
|
|
for (Tuple p : connectList) {
|
2017-12-12 18:54:45 +01:00
|
|
|
String suggestedIdentifier = ((ConnectedBean)p.getO()).getDestIdentifier();
|
2017-12-07 12:37:21 +01:00
|
|
|
if(suggestedIdentifier == null || suggestedIdentifier.isEmpty())
|
|
|
|
continue;
|
|
|
|
else
|
2017-12-12 18:54:45 +01:00
|
|
|
toReturn.add((ConnectedBean) p.getO());
|
2017-11-23 20:04:47 +01:00
|
|
|
}
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
2017-11-09 22:11:10 +01:00
|
|
|
|
|
|
|
}
|