geoportal-data-entry-app/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.java

95 lines
2.7 KiB
Java
Raw Normal View History

2022-05-26 17:43:48 +02:00
package org.gcube.portlets.user.geoportaldataentry.client.ui;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
2022-05-27 12:01:30 +02:00
import org.gcube.portlets.user.geoportaldataentry.client.events.CloneProjectEvent;
2022-05-26 17:43:48 +02:00
import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
2022-05-26 17:43:48 +02:00
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
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.event.shared.HandlerManager;
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.Widget;
public class CloneOperationPanel extends Composite {
@UiField
TextBox projectNameTextBox;
@UiField
AlertBlock infoBlock;
@UiField
AlertBlock infoProjectName;
@UiField
Button submitButton;
@UiField
CheckBox checkBoxPublish;
2022-05-26 17:43:48 +02:00
private static CloneOperationPanelUiBinder uiBinder = GWT.create(CloneOperationPanelUiBinder.class);
interface CloneOperationPanelUiBinder extends UiBinder<Widget, CloneOperationPanel> {
}
private HandlerManager appManagerBus;
2022-05-27 12:01:30 +02:00
public CloneOperationPanel(HandlerManager eventBus, ConcessioneDV concessione) {
2022-05-26 17:43:48 +02:00
initWidget(uiBinder.createAndBindUi(this));
2022-05-27 12:01:30 +02:00
GWT.log("Cloning the: " + concessione);
this.appManagerBus = eventBus;
2022-05-26 17:43:48 +02:00
this.selectedProject = concessione;
infoProjectName.setText(selectedProject.getNome());
projectNameTextBox.setText(selectedProject.getNome());
projectNameTextBox.setEnabled(false);
submitButton.addClickHandler(new ClickHandler() {
2022-05-26 17:43:48 +02:00
@Override
public void onClick(ClickEvent event) {
boolean isValid = checkIsValidForm();
if (isValid) {
appManagerBus.fireEvent(new CloneProjectEvent(selectedProject, projectNameTextBox.getText(), checkBoxPublish.getValue()));
submitButton.setEnabled(false);
2022-05-26 17:43:48 +02:00
}
}
});
checkBoxPublish.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if(checkBoxPublish.getValue()) {
submitButton.setText("Clone and Publish as New Project");
}else
submitButton.setText("Clone as New Project");
}
});
2022-05-26 17:43:48 +02:00
}
2022-05-27 12:01:30 +02:00
private ConcessioneDV selectedProject;
2022-05-26 17:43:48 +02:00
protected boolean checkIsValidForm() {
String text = projectNameTextBox.getText();
if (text == null || text.isEmpty()) {
infoBlock.setVisible(true);
infoBlock.setText("The Project's name cannot be empty!");
infoBlock.setType(AlertType.ERROR);
return false;
}
return true;
}
}