added popup panel close event

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@130349 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-07-14 10:14:33 +00:00
parent 65491b7b9f
commit a1800eacbb
4 changed files with 137 additions and 15 deletions

View File

@ -0,0 +1,27 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
import com.google.gwt.event.shared.GwtEvent;
/**
* Called on close form.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CloseCreationFormEvent extends GwtEvent<CloseCreationFormEventHandler>{
public static Type<CloseCreationFormEventHandler> TYPE = new Type<CloseCreationFormEventHandler>();
public CloseCreationFormEvent() {
super();
}
@Override
public Type<CloseCreationFormEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(CloseCreationFormEventHandler handler) {
handler.onClose(this);
}
}

View File

@ -0,0 +1,13 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* Close event handler interface
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public interface CloseCreationFormEventHandler extends EventHandler {
void onClose(CloseCreationFormEvent event);
}

View File

@ -11,6 +11,8 @@ import java.util.Map.Entry;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEvent;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended;
@ -168,7 +170,7 @@ public class CreateDatasetForm extends Composite{
private LicensesBean licenseBean;
// event bus
private final HandlerManager eventBus = new HandlerManager(null);
private final HandlerManager eventBus;
// added custom field entries
List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
@ -187,15 +189,21 @@ public class CreateDatasetForm extends Composite{
// resource table
private ResourcesTable resourcesTable;
// List of opened popup'ids
List<String> popupOpenedIds = new ArrayList<String>();
/**
* Invoked in the most general case
* @param owner
*/
public CreateDatasetForm(String owner) {
public CreateDatasetForm(String owner, HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.owner = owner;
// save event bus
this.eventBus = eventBus;
// bind on events
bind();
@ -300,10 +308,13 @@ public class CreateDatasetForm extends Composite{
* @param idFolderWorkspace
* @param owner
*/
public CreateDatasetForm(String idFolderWorkspace, String owner) {
public CreateDatasetForm(String idFolderWorkspace, String owner, final HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.owner = owner;
// save event bus
this.eventBus = eventBus;
// prepare info icons
prepareInfoIcons();
@ -494,7 +505,7 @@ public class CreateDatasetForm extends Composite{
listOfMetadataFields.clear();
for (MetadataFieldWrapper field : fields) {
MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(field);
MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
metadataFieldsPanel.add(fieldWidget);
listOfMetadataFields.add(fieldWidget);
}
@ -520,6 +531,18 @@ public class CreateDatasetForm extends Composite{
}
});
// on close form
eventBus.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() {
@Override
public void onClose(CloseCreationFormEvent event) {
closeDialogBox();
}
});
}
@ -1143,8 +1166,6 @@ public class CreateDatasetForm extends Composite{
*/
private void addTagElement(TextBox itemBox){
GWT.log("value is " + itemBox.getValue());
if (itemBox.getValue() != null && !"".equals(itemBox.getValue().trim())) {
if(tagsList.contains(itemBox.getValue())){
@ -1154,12 +1175,17 @@ public class CreateDatasetForm extends Composite{
// ckan accepts only alphanumeric values
String[] subTags = itemBox.getValue().split(" ");
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$"))
return;
if(subTag.length() <= 1)
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
return;
}
}
final String value = itemBox.getValue();
@ -1195,12 +1221,17 @@ public class CreateDatasetForm extends Composite{
// ckan accepts only alphanumeric values
String[] subTags = tag.split(" ");
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$"))
return;
if(subTag.length() <= 1)
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
return;
}
}
final ListItem displayItem = new ListItem();
@ -1242,6 +1273,23 @@ public class CreateDatasetForm extends Composite{
tagsPanel.clear();
}
/**
* Close any dialog box opened
*/
private void closeDialogBox() {
for (String popupid : popupOpenedIds) {
GcubeDialogExtended popup = null;
try{
Element element = DOM.getElementById(popupid);
popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element));
popup.hide();
}catch(Exception e){
GWT.log("ERROR", e);
}
}
}
/**
* Prepare the popover and the gcube popup panel for information.
@ -1287,6 +1335,9 @@ public class CreateDatasetForm extends Composite{
popup = new GcubeDialogExtended(captionText, text);
popup.getElement().setId(popupId);
popup.setModal(false);
// add its id
popupOpenedIds.add(popupId);
}

View File

@ -2,6 +2,8 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEvent;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
@ -20,6 +22,7 @@ import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
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;
@ -58,12 +61,21 @@ public class MetaDataFieldSkeleton extends Composite{
// the dialog box for this metadata
private GcubeDialogExtended dialog;
// save event bus referene
private HandlerManager eventBus;
public MetaDataFieldSkeleton(MetadataFieldWrapper field) {
public MetaDataFieldSkeleton(MetadataFieldWrapper field, HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
// prepare information
this.field = field;
// event bus
this.eventBus = eventBus;
// bind
bind();
// add custom css properties
controls.addStyleName("form-controls-custom");
@ -163,6 +175,25 @@ public class MetaDataFieldSkeleton extends Composite{
}
/**
* Bind on events
*/
private void bind() {
// on close form
eventBus.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() {
@Override
public void onClose(CloseCreationFormEvent event) {
if(dialog != null)
dialog.hide();
}
});
}
@UiHandler("focusPanelIconContainer")
void onInfoIconClick(ClickEvent c){