167 lines
4.9 KiB
Java
167 lines
4.9 KiB
Java
package org.gcube.datacatalogue.grsf_manage_widget.client.view.subwidgets;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync;
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectBean;
|
|
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;
|
|
import com.google.gwt.core.client.GWT;
|
|
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;
|
|
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.HTML;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
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> {
|
|
}
|
|
|
|
@UiField
|
|
VerticalPanel connectPanel;
|
|
|
|
@UiField
|
|
Button suggestRecord;
|
|
|
|
private GRSFManageWidgetServiceAsync service;
|
|
private List<Pair> connectList = new ArrayList<Pair>(0);
|
|
|
|
public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
this.service = service;
|
|
|
|
String acceptedDomain = bean.getGrsfDomain().equalsIgnoreCase("stock") ? "Fishery" : "Stock";
|
|
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) {
|
|
|
|
ConnectBean cb = new ConnectBean();
|
|
cb.setSourceDomain(bean.getGrsfDomain());
|
|
Widget w = buildWidgetConnect(cb);
|
|
connectList.add(new Pair(cb, w));
|
|
connectPanel.add(w);
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* Builds up a widget for connecting records.
|
|
* @param w the widget
|
|
* @param cb the connectBean.
|
|
*/
|
|
private Widget buildWidgetConnect(final ConnectBean cb){
|
|
|
|
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%");
|
|
Paragraph semanticIdentifier = new Paragraph("Semantic Identifier:");
|
|
final TextBox box = new TextBox();
|
|
box.addKeyPressHandler(new KeyPressHandler() {
|
|
|
|
@Override
|
|
public void onKeyPress(KeyPressEvent event) {
|
|
|
|
String currentText = box.getText().trim();
|
|
GWT.log("Text changed to " + currentText);
|
|
cb.setDestSemanticIdentifier(currentText);
|
|
|
|
}
|
|
});
|
|
box.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
String currentText = box.getText().trim();
|
|
GWT.log("Text changed to " + currentText);
|
|
cb.setDestSemanticIdentifier(currentText);
|
|
|
|
}
|
|
});
|
|
box.setWidth("512px");
|
|
box.setPlaceholder("Insert the Semantic Identifier of the record to connect");
|
|
|
|
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
|
|
Iterator<Pair> iterator = connectList.iterator();
|
|
while (iterator.hasNext()) {
|
|
Pair pair = (Pair) iterator
|
|
.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);
|
|
return main;
|
|
}
|
|
|
|
public List<ConnectBean> getConnectList() {
|
|
|
|
List<ConnectBean> toReturn = new ArrayList<ConnectBean>(0);
|
|
|
|
for (Pair p : connectList) {
|
|
toReturn.add((ConnectBean) p.getO());
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
}
|