starting the implementation

This commit is contained in:
Francesco Mangiacrapa 2020-10-01 15:56:27 +02:00
parent 45bd3c10b2
commit 4e87e23d3e
67 changed files with 8340 additions and 252 deletions

View File

@ -32,6 +32,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -20,10 +20,29 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.gwtplugins.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.gwtplugins.gwt.eclipse.core.gwtProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>com.gwtplugins.gwt.eclipse.core.gwtNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

13
.settings/.jsdtscope Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
lastWarOutDir=/home/francesco-mangiacrapa/git/metadata-profile-form-builder-widget/target/metadata-profile-form-builder-widget-0.1.0-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -1,6 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="metadata-profile-form-builder-widget-0.1.0-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="metadata-profile-discovery-0.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-discovery/metadata-profile-discovery">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="metadata-profile-form-builder-widget"/>
<property name="java-output-path" value="/metadata-profile-form-builder-widget/target/classes"/>
</wb-module>
</project-modules>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="com.gwtplugins.gwt.facet" version="1.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

View File

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@ -0,0 +1 @@
Window

View File

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>metadata-profile-form-builder-widget</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>
<version>0.1.0-SNAPSHOT</version>
<name>Metadata Profile Form Builder</name>
<description>
@ -67,6 +67,12 @@
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>

View File

@ -3,18 +3,25 @@
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Responsive design -->
<set-property name="bootstrap.responsiveDesign" value="true" />
<inherits name='com.github.gwtbootstrap.datetimepicker.Datetimepicker' />
<inherits name='com.github.gwtbootstrap.datepicker.Datepicker' />
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='com.google.gwt.json.JSON'/>
<inherits
name='org.gcube.portlets.widgets.openlayerbasicwidgets.olbasicwidgets' />
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<!--<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />-->
<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />
<!-- Specify the paths for translatable code -->
<source path='client' />

View File

@ -2,8 +2,6 @@ package org.gcube.portlets.widgets.mpformbuilder.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@ -19,23 +17,12 @@ public class MetadataProfileFormBuilder implements EntryPoint {
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final MetadataProfileFormBuilderAsync greetingService = GWT.create(MetadataProfileFormBuilderService.class);
private final MetadataProfileFormBuilderServiceAsync formBuilderService = GWT.create(MetadataProfileFormBuilderService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
greetingService.greetServer("Hello World", new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
Window.alert(result);
}
@Override
public void onFailure(Throwable caught) {
}
});
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.portlets.widgets.mpformbuilder.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MetadataProfileFormBuilderAsync {
/**
* GWT-RPC service asynchronous (client-side) interface
*
* @see org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService
*/
void greetServer(java.lang.String name, AsyncCallback<java.lang.String> callback);
/**
* Utility class to get the RPC Async interface from client-side code
*/
public static final class Util {
private static MetadataProfileFormBuilderAsync instance;
public static final MetadataProfileFormBuilderAsync getInstance() {
if (instance == null) {
instance = (MetadataProfileFormBuilderAsync) GWT.create(MetadataProfileFormBuilderService.class);
}
return instance;
}
private Util() {
// Utility class should not be instantiated
}
}
}

View File

@ -1,12 +1,19 @@
package org.gcube.portlets.widgets.mpformbuilder.client;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
@RemoteServiceRelativePath("greet")
@RemoteServiceRelativePath("mpformbuilderservice")
public interface MetadataProfileFormBuilderService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
List<MetaDataProfileBean> getProfilesInTheScope(String scope, String genericResourceSecondaryType) throws Exception;
MetaDataProfileBean getProfileForMetadata(String metadata) throws Exception;
}

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.widgets.mpformbuilder.client;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MetadataProfileFormBuilderServiceAsync {
/**
* GWT-RPC service asynchronous (client-side) interface
*
* @see org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService
*/
void getProfilesInTheScope(String scope, String genericResourceSecondaryType, AsyncCallback<List<MetaDataProfileBean>> callback);
void getProfileForMetadata(String metadata,
AsyncCallback<MetaDataProfileBean> callback);
/**
* Utility class to get the RPC Async interface from client-side code
*/
public static final class Util {
private static MetadataProfileFormBuilderServiceAsync instance;
public static final MetadataProfileFormBuilderServiceAsync getInstance() {
if (instance == null) {
instance = (MetadataProfileFormBuilderServiceAsync) GWT.create(MetadataProfileFormBuilderService.class);
}
return instance;
}
private Util() {
// Utility class should not be instantiated
}
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.google.gwt.event.shared.GwtEvent;
/**
* Added resource event
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AddResourceEvent extends GwtEvent<AddResourceEventHandler> {
public static Type<AddResourceEventHandler> TYPE = new Type<AddResourceEventHandler>();
private ResourceElementBean resource;
public AddResourceEvent(ResourceElementBean resource) {
this.resource = resource;
}
public ResourceElementBean getResource() {
return resource;
}
@Override
public Type<AddResourceEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(AddResourceEventHandler handler) {
handler.onAddedResource(this);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* Added resource handler interface
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public interface AddResourceEventHandler extends EventHandler {
void onAddedResource(AddResourceEvent addResourceEvent);
}

View File

@ -0,0 +1,27 @@
package org.gcube.portlets.widgets.mpformbuilder.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.mpformbuilder.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

@ -0,0 +1,32 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CustomFieldEntry;
import com.google.gwt.event.shared.GwtEvent;
/**
* Delete custom field event.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class DeleteCustomFieldEvent extends GwtEvent<DeleteCustomFieldEventHandler> {
public static Type<DeleteCustomFieldEventHandler> TYPE = new Type<DeleteCustomFieldEventHandler>();
private CustomFieldEntry removedEntry;
public DeleteCustomFieldEvent(CustomFieldEntry removedEntry) {
this.removedEntry = removedEntry;
}
public CustomFieldEntry getRemovedEntry() {
return removedEntry;
}
@Override
public Type<DeleteCustomFieldEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(DeleteCustomFieldEventHandler handler) {
handler.onRemoveEntry(this);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* Handler associated to the DeleteCustomFieldEvent
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public interface DeleteCustomFieldEventHandler extends EventHandler {
void onRemoveEntry(DeleteCustomFieldEvent event);
}

View File

@ -0,0 +1,34 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.google.gwt.event.shared.GwtEvent;
/**
* Deleted resource event.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
private ResourceElementBean resource;
public DeleteResourceEvent(ResourceElementBean resource) {
this.resource = resource;
}
public ResourceElementBean getResource() {
return resource;
}
@Override
public Type<DeleteResourceEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(DeleteResourceEventHandler handler) {
handler.onDeletedResource(this);
}
}

View File

@ -0,0 +1,11 @@
package org.gcube.portlets.widgets.mpformbuilder.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* The delete event handler
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public interface DeleteResourceEventHandler extends EventHandler{
void onDeletedResource(DeleteResourceEvent deleteResourceEvent);
}

View File

@ -0,0 +1,162 @@
package org.gcube.portlets.widgets.mpformbuilder.client.form;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.constants.LabelType;
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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class MetaDataField.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jun 10, 2019
*/
public class MetaDataField extends Composite {
private static MetaDataFieldUiBinder uiBinder = GWT.create(MetaDataFieldUiBinder.class);
@UiField VerticalPanel panelMetaDataFieldsSkeleton;
@UiField Label repeatabilityLabel;
//@UiField ControlGroup cgMetaDataFieldSkeletonFields;
@UiField Button addFieldButton;
@UiField Button removeFieldButton;
private List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
private MetadataFieldWrapper fieldWrapper;
private HandlerManager eventBus;
/**
* The Interface MetaDataFieldUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jun 10, 2019
*/
interface MetaDataFieldUiBinder extends UiBinder<Widget, MetaDataField> {
}
/**
* Instantiates a new meta data field.
*
* @param field the field
* @param eventBus the event bus
* @throws Exception the exception
*/
public MetaDataField(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception {
initWidget(uiBinder.createAndBindUi(this));
this.fieldWrapper = field;
this.eventBus = eventBus;
addNewOccurrenceOfField();
checkAllowedAddField();
checkAllowedRemoveField();
addFieldButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addNewOccurrenceOfField();
checkAllowedAddField();
checkAllowedRemoveField();
}
});
removeFieldButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeLatestOccurrenceOfFiled();
checkAllowedAddField();
checkAllowedRemoveField();
}
});
//The field is repeatable
if(field.getMaxOccurs()>1) {
repeatabilityLabel.setVisible(true);
repeatabilityLabel.setType(LabelType.INFO);
addFieldButton.setTitle("Add another "+field.getFieldName());
removeFieldButton.setTitle("Remove latest "+field.getFieldName());
// String maxTxt = field.getMaxOccurs()==Integer.MAX_VALUE?"":"(max occurs declared are "+field.getMaxOccurs()+" times)";
}
}
/**
* Check allowed remove field.
*/
private void checkAllowedRemoveField() {
boolean removeCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size()>1;
removeFieldButton.setVisible(removeCond);
}
/**
* Checks if is allowed add occurrence.
*/
private void checkAllowedAddField() {
boolean repeatibilityCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size()<fieldWrapper.getMaxOccurs();
addFieldButton.setVisible(repeatibilityCond);
}
/**
* Removes the latest occurrence of filed.
*/
private void removeLatestOccurrenceOfFiled() {
int size = listOfMetadataFields.size();
MetaDataFieldSkeleton skeleton = listOfMetadataFields.get(size-1);
try {
panelMetaDataFieldsSkeleton.remove(skeleton);
listOfMetadataFields.remove(size-1);
}catch (Exception e) {
GWT.log("Error: ",e);
}
}
/**
* Adds the new occurrence of field.
*/
private void addNewOccurrenceOfField() {
try {
MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(fieldWrapper, eventBus);
listOfMetadataFields.add(fieldWidget);
panelMetaDataFieldsSkeleton.add(fieldWidget);
} catch (Exception e) {
GWT.log("Error: ",e);
}
}
/**
* Gets the list of metadata fields.
*
* @return the list of metadata fields
*/
public List<MetaDataFieldSkeleton> getListOfMetadataFields() {
return listOfMetadataFields;
}
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.margin-left-max-occurrs {
padding-left: 50px;
}
</ui:style>
<g:HTMLPanel>
<g:VerticalPanel
ui:field="panelMetaDataFieldsSkeleton" width="100%">
</g:VerticalPanel>
<b:ControlGroup>
<b:Controls addStyleNames="{style.margin-left-max-occurrs}">
<b:Label ui:field="repeatabilityLabel" visible="false">Repeatable field</b:Label>
<b:Button icon="MINUS_SIGN" title="Remove Latest Field"
ui:field="removeFieldButton" visible="false"></b:Button>
<b:Button icon="PLUS_SIGN" title="Add Another Field"
ui:field="addFieldButton" visible="false"></b:Button>
</b:Controls>
</b:ControlGroup>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,410 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:m="urn:import:org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.tags">
<ui:style>
.form-main-style {
margin-left: 10px;
}
.fieldset-border-style {
border: 1px groove #444;
-webkit-box-shadow: 0px 0px 0px 0px #000;
box-shadow: 0px 0px 0px 0px #000;
padding: 10px;
}
.legend-style {
width: auto;
padding: 10px;
margin-bottom: 0px;
}
@external .form-horizontal .input-large;
.form-horizontal .input-large .input-prepend {
width: 95%;
}
.block-alert-style {
margin-top: 10px;
padding: 10px;
margin-bottom: 10px;
}
.tagsPanelStyle {
display: inline-block;
}
.selected-profile {
font-weight: bold;
}
.label-go-to-product {
display: inline-block;
vertical-align: middle;
font-weight: bold;
}
.the-margin-left{
margin-left: 5px;
}
</ui:style>
<g:HTMLPanel ui:field="createDatasetMainPanel">
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formFirstStep" visible="true">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Insert Item Information
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<!-- Alert blocks for info/errors -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="infoBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
<b:ControlGroup ui:field="productTitleGroup">
<b:ControlLabel for="title" title="Item title">
<font color="red">*</font>
Title :
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="Item title"
width="90%" b:id="title" title="Item title" ui:field="titleTextBox" />
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverTitle" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelTitle">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTitle" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="description" title="Item description">
Description:
</b:ControlLabel>
<b:Controls>
<b:TextArea placeholder="eg. Some useful notes about the item"
width="90%" alternateSize="LARGE" b:id="description" title="Item description"
ui:field="descriptionTextarea"></b:TextArea>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverDescription" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelDescription">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconDescription" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<!-- TAGS Panel -->
<m:TagsPanel ui:field="tagsPanel"></m:TagsPanel>
<b:ControlGroup>
<b:ControlLabel for="licenses" title="License">License:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="licenses" title="Item license"
width="91%" ui:field="licenseListbox">
</b:ListBox>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverLicenses" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelLicenses">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconLicenses" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="licenseUrl" title="Selected License'url">Selected
License Url:</b:ControlLabel>
<b:Controls>
<b:Paragraph ui:field="unavailableUrl" visible="true">
<b>Unavailable</b>
</b:Paragraph>
<g:Anchor ui:field="licenseUrlAnchor" target="_blank"
visible="false"></g:Anchor>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="visibility" title="Visibility of the item">Visibility:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="visibility" title="Item visibility"
width="91%" ui:field="visibilityListbox">
<g:item title="restricted">Restricted</g:item>
<g:item enabled="true" title="public">Public</g:item>
</b:ListBox>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverVisibility" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelVisibility">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconVisibility" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="organizationsGroup">
<b:ControlLabel for="organization"
title="Select the organizations in which you want
to publish the item">Publish in:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="organization" alternateSize="LARGE"
width="91%" title="Publish in this organization" ui:field="organizationsListbox">
</b:ListBox>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="versionControlGroup">
<b:ControlLabel for="version"
title="Item version expressed as positive integer number">
Version:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="1.0" b:id="version"
width="90%" title="Item version" ui:field="versionTextbox" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="author" title="Item author">
<font color="red">*</font>
Author:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" width="90%"
placeholder="Joe Bloggs" enabled="false" b:id="author" title="Item author"
ui:field="authorTextbox" />
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverAuthor" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelAuthor">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconAuthor" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="authorEmailControlGroup">
<b:ControlLabel for="email" title="Item author's email">
<font color="red">*</font>
Author Email:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" width="90%"
placeholder="joe.bloggs@example.com" enabled="false" b:id="email"
title="Item author" ui:field="authorEmailTextbox" />
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverAuthorEmail" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelAuthorEmail">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconAuthorEmail" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="maintainer" title="Item maintainer">
Maintainer:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="Joe Bloggs"
width="90%" b:id="maintainer" title="Item maintainer"
ui:field="maintainerTextbox" />
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverMaintainer" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelMaintainer">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconMaintainer" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="maintainerControlGroup">
<b:ControlLabel for="emailMaintaner" title="Item author's email">
Maintainer Email:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="maintainer@example.com"
width="90%" b:id="emailMaintaner" title="Item author"
ui:field="maintainerEmailTextbox" />
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverMaintainerEmail" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelMaintainerEmail">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconMaintainerEmail" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="metadataTypesControlGroup">
<b:ControlLabel for="metadataTypes" title="Item profile types">Types:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="metadataTypes" alternateSize="LARGE"
width="91%" title="The item type to be used"
ui:field="metadataTypeListbox">
<g:item enabled="true" title="None">none</g:item>
</b:ListBox>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverTypes" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelTypes">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTypes" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="groupsControlGroup"
visible="false">
<b:ControlLabel for="groups" title="The groups for this item">Item Groups:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="groups" alternateSize="LARGE" width="91%"
multipleSelect="true"
title="The groups for this item (Hold CTRL or Command button for multiple selection)"
ui:field="groupsListbox">
</b:ListBox>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverGroups" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelGroups">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconGroups" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on continue -->
<b:AlertBlock animation="true" visible="false"
ui:field="alertNoResources"
text="Please note that the item you are going to publish will not have resources.">
</b:AlertBlock>
<!-- Alert block on continue -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onContinueAlertBlock">
</b:AlertBlock>
<b:Button title="Continue" ui:field="continueButton" type="PRIMARY"
block="true">Continue</b:Button>
<b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button>
</b:Fieldset>
</b:Form>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formSecondStep" visible="false">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Manage Resources
</b:Legend>
<b:ControlGroup>
<b:Controls>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverResources" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelResources">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconResources" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<g:SimplePanel ui:field="workspaceResourcesContainer"
width="100%" visible="true">
</g:SimplePanel>
<b:Button title="Continue" ui:field="continueThirdStep"
type="PRIMARY" block="true">Continue</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonFirstStep"
block="true">Go
Back</b:Button>
</b:Fieldset>
</b:Form>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formThirdStep" visible="false">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Insert Item Profile Information
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<b:Paragraph ui:field="selectedProfile" styleName="{style.selected-profile}"></b:Paragraph>
<!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="metadataFieldsPanel"
visible="false" width="100%"></g:VerticalPanel>
<!-- Custom fields can be dinamically added -->
<b:ControlGroup ui:field="customFields">
<b:ControlLabel>Custom Field(s):</b:ControlLabel>
</b:ControlGroup>
<b:ControlGroup>
<b:Controls>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverCustomFields" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelCustomFields">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconCustomFields" />
</g:FocusPanel>
</b:Popover>
</span>
<b:Button icon="PLUS_SIGN" title="Add Custom Field"
ui:field="addCustomFieldButton"></b:Button>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on create -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onCreateAlertBlock" styleName="{style.block-alert-style}">
</b:AlertBlock>
<g:HorizontalPanel ui:field="goToDatasetButtonPanel" visible="false">
<g:Label>Go to the Item</g:Label>
<b:Button title="Go to the Item" ui:field="goToDatasetButton"
type="LINK" visible="false" styleName="{style.the-margin-left}"></b:Button>
</g:HorizontalPanel>
<b:Button title="Add resources to the just created item"
block="true" type="PRIMARY" visible="false" ui:field="addResourcesButton">Add Resources</b:Button>
<b:Button title="Create Item" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonSecondStep"
block="true">Go
Back</b:Button>
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,861 @@
package org.gcube.portlets.widgets.mpformbuilder.client.form.generic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEvent;
import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEventHandler;
import org.gcube.portlets.widgets.mpformbuilder.client.events.DeleteCustomFieldEvent;
import org.gcube.portlets.widgets.mpformbuilder.client.events.DeleteCustomFieldEventHandler;
import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CategoryPanel;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CustomFieldEntry;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.resources.AddResourceToDataset;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection.TwinColumnSelectionMainPanel;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.InfoIconsLabels;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.OrganizationBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.Form;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Paragraph;
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
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.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.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Create metadata form for ckan product.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CreateMetadataForm extends Composite{
private static EditMetadataFormUiBinder uiBinder = GWT
.create(EditMetadataFormUiBinder.class);
/**
* The Interface EditMetadataFormUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Oct 1, 2020
*/
interface EditMetadataFormUiBinder extends
UiBinder<Widget, CreateMetadataForm> {
}
@UiField HTMLPanel createDatasetMainPanel;
@UiField ControlGroup customFields;
@UiField Button addCustomFieldButton;
@UiField Button createButton;
@UiField Button resetButton;
@UiField AlertBlock infoBlock;
@UiField AlertBlock onContinueAlertBlock;
@UiField AlertBlock onCreateAlertBlock;
@UiField VerticalPanel metadataFieldsPanel;
@UiField ListBox metadataTypeListbox;
@UiField Form formFirstStep;
@UiField Button continueButton;
@UiField Paragraph selectedProfile;
@UiField TagsPanel tagsPanel;
// info panels
@UiField Icon infoIconTypes;
@UiField FocusPanel focusPanelTypes;
@UiField Popover popoverTypes;
@UiField Icon infoIconCustomFields;
@UiField FocusPanel focusPanelCustomFields;
@UiField Popover popoverCustomFields;
@UiField ControlGroup metadataTypesControlGroup;
@UiField ControlGroup productTitleGroup;
@UiField ControlGroup maintainerControlGroup;
@UiField ControlGroup versionControlGroup;
@UiField ControlGroup organizationsGroup;
@UiField ControlGroup groupsControlGroup;
private final MetadataProfileFormBuilderServiceAsync formBuilderService = GWT.create(MetadataProfileFormBuilderService.class);
private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]";
private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
private static final String NONE_PROFILE = "none";
// error/info messages
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your item.";
protected static final String PRODUCT_CREATED_OK = "Item correctly published!";
private static final String TRYING_TO_CREATE_PRODUCT = "Trying to publish the item, please wait...";
protected static final String MISSING_PUBLISH_RIGHTS = "It seems you are not authorized to publish on catalogue. Request it to the VRE manager or the portal administrator.";
// tab panel
private TabPanel tabPanel;
// add resource form
private AddResourceToDataset resourceForm;
// the licenses
private List<LicenseBean> licenseBean;
// event bus
private HandlerManager eventBus;
// added custom field entries (by the user)
private List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
// the list of MetaDataField added
private List<MetaDataField> listOfMetadataFields = new ArrayList<MetaDataField>();
// dataset metadata bean
//private DatasetBean receivedBean;
// the owner
private String owner;
// resource table
private TwinColumnSelectionMainPanel resourcesTwinPanel;
// List of opened popup'ids
private List<String> popupOpenedIds = new ArrayList<String>();
// map of organization name title
private Map<String, String> nameTitleOrganizationMap = new HashMap<String, String>();
private String scope;
private String genericResourceSecondaryType;
/**
* Invoked in the most general case.
*
* @param scope the scope
* @param genericResourceSecondaryType the generic resource secondary type
* @param eventBus the event bus
*/
public CreateMetadataForm(String scope, String genericResourceSecondaryType, HandlerManager eventBus) {
this(eventBus);
this.scope = scope;
this.genericResourceSecondaryType = genericResourceSecondaryType;
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getProfilesInTheScope(scope, genericResourceSecondaryType, new AsyncCallback<List<MetaDataProfileBean>>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(List<MetaDataProfileBean> profiles) {
createDatasetFormBody(profiles);
}
});
}
/**
* Instantiates a new creates the dataset form.
*
* @param profiles the profiles
* @param eventBus the event bus
*/
public CreateMetadataForm(List<MetaDataProfileBean> profiles, HandlerManager eventBus) {
this(eventBus);
createDatasetFormBody(profiles);
}
/**
* Instantiates a new creates the dataset form.
*
* @param eventBus the event bus
*/
private CreateMetadataForm(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
bind();
prepareInfoIcons();
}
/**
* Bind on events.
*/
private void bind() {
// when a custom field is removed, remove it from the list
eventBus.addHandler(DeleteCustomFieldEvent.TYPE, new DeleteCustomFieldEventHandler() {
@Override
public void onRemoveEntry(DeleteCustomFieldEvent event) {
customFieldEntriesList.remove(event.getRemovedEntry());
customFields.remove(event.getRemovedEntry());
}
});
// on close form
eventBus.addHandler(CloseCreationFormEvent.TYPE, new CloseCreationFormEventHandler() {
@Override
public void onClose(CloseCreationFormEvent event) {
InfoIconsLabels.closeDialogBox(popupOpenedIds);
}
});
}
/**
* Creates the dataset form body.
*
* @param profiles the profiles
*/
private void createDatasetFormBody(final List<MetaDataProfileBean> profiles){
if(profiles == null){
setAlertBlock("An unknow error occurred while retrieving types, sorry", AlertType.ERROR, true);
}
else{
prepareMetadataList(profiles);
metadataTypeListbox.setEnabled(true);
}
}
/**
* Add the items to the listbox and put data into the metadataPanel.
*
* @param profiles the profiles
*/
private void prepareMetadataList(final List<MetaDataProfileBean> profiles) {
if(profiles != null && !profiles.isEmpty()){
for(MetaDataProfileBean metadataBean: profiles){
metadataTypeListbox.addItem(metadataBean.getType());
// add handler on select
metadataTypeListbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String selectedItemText = metadataTypeListbox.getSelectedItemText();
metadataFieldsPanel.clear();
if(selectedItemText.equals(NONE_PROFILE)){
metadataFieldsPanel.setVisible(false);
//receivedBean.setChosenType(null);
}else{
//receivedBean.setChosenType(selectedItemText);
addFields(selectedItemText, profiles);
}
}
});
}
// // hide elements or show them if needed (groups in profiles cannot be present again in groups listbox)
// if(groupsControlGroup.isVisible()){
// List<String> groupsToHide = new ArrayList<String>();
// for(MetaDataProfileBean profile: profiles)
// groupsToHide.add(profile.getType().toString());
//
// SelectElement se = groupsListbox.getElement().cast();
//
// for (int i = 0; i < groupsListbox.getItemCount(); i++) {
// if(groupsToHide.contains(groupsListbox.getItemText(i))){
// se.getOptions().getItem(i).getStyle().setProperty("display", "none");
// }else
// se.getOptions().getItem(i).getStyle().setProperty("display", "");
// }
// }
//
// metadataTypesControlGroup.setVisible(true);
}else{
// just hide this listbox
metadataTypesControlGroup.setVisible(false);
metadataFieldsPanel.clear();
listOfMetadataFields.clear();
//receivedBean.setChosenType(null);
}
}
/**
* Add fields of the selected metadata profile to the widget.
*
* @param selectedItem the selected item
* @param listProfiles the list profiles
*/
protected void addFields(String selectedItem, List<MetaDataProfileBean> listProfiles) {
for(MetaDataProfileBean bean: listProfiles){
if(bean.getType().equals(selectedItem)){
// clear old data
listOfMetadataFields.clear();
// prepare the data
List<MetadataFieldWrapper> fields = bean.getMetadataFields();
List<CategoryWrapper> categories = bean.getCategories();
GWT.log("There are " + categories.size() + " categories for profile " + bean.getTitle());
if(categories == null || categories.isEmpty()){
for (MetadataFieldWrapper field : fields) {
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
metadataFieldsPanel.add(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(field, eventBus);
metadataFieldsPanel.add(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
}else{
// create the categories, then parse the fields. Fields do not belonging to a category are put at the end
for (CategoryWrapper categoryWrapper : categories) {
if(categoryWrapper.getFieldsForThisCategory() != null && categoryWrapper.getFieldsForThisCategory().size() > 0){
CategoryPanel cp = new CategoryPanel(categoryWrapper.getTitle(), categoryWrapper.getDescription());
List<MetadataFieldWrapper> fieldsForThisCategory = categoryWrapper.getFieldsForThisCategory();
fields.removeAll(fieldsForThisCategory);
for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) {
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(metadataFieldWrapper, eventBus);
cp.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus);
cp.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
metadataFieldsPanel.add(cp);
}
}
// add the remaining one at the end of the categories
CategoryPanel extrasCategory = new CategoryPanel("Other", null);
for (MetadataFieldWrapper field : fields) {
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
extrasCategory.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(field, eventBus);
extrasCategory.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
metadataFieldsPanel.add(extrasCategory);
}
metadataFieldsPanel.setVisible(true);
}
}
}
/**
* Adds the custom field event.
*
* @param e the e
*/
@UiHandler("addCustomFieldButton")
void addCustomFieldEvent(ClickEvent e){
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, "", "", true);
customFieldEntriesList.add(toAdd);
customFields.add(toAdd);
}
/**
* On continue button.
*
* @param e the e
*/
@UiHandler("continueButton")
void onContinueButton(ClickEvent e){
// validate data
final String errorMsg = validateDataOnContinue();
if(errorMsg != null){
alertOnContinue("Please check inserted data [" + errorMsg + "]", AlertType.ERROR);
return;
}else{
Window.alert("Called onContinueButton");
}
}
/**
* After onContinue ...
*/
private void actionsAfterOnContinue(){
Window.alert("Called actionsAfterOnContinue");
if(metadataTypeListbox.getSelectedItemText().equals(NONE_PROFILE))
selectedProfile.setText("");
else
selectedProfile.setText("Selected Type is " + metadataTypeListbox.getSelectedItemText());
}
/**
* On go back button first step.
*
* @param e the e
*/
@UiHandler("goBackButtonFirstStep")
void onGoBackButtonFirstStep(ClickEvent e){
Window.alert("Called onGoBackButtonFirstStep");
// // swap forms
// formFirstStep.setVisible(true);
// formSecondStep.setVisible(false);
// formThirdStep.setVisible(false);
}
/**
* On go back button.
*
* @param e the e
*/
@UiHandler("goBackButtonSecondStep")
void onGoBackButton(ClickEvent e){
Window.alert("Called onGoBackButton");
// // swap forms
// if(isWorkspaceRequest){
// formFirstStep.setVisible(hideManageResources());
// formSecondStep.setVisible(!hideManageResources());
// }else{
// formFirstStep.setVisible(true);
// formSecondStep.setVisible(false);
// }
// formThirdStep.setVisible(false);
}
/**
* On continue third step.
*
* @param e the e
*/
@UiHandler("continueThirdStep")
void onContinueThirdStep(ClickEvent e){
Window.alert("Called onGoBackButton");
// swap forms
// formSecondStep.setVisible(false);
// formThirdStep.setVisible(true);
}
/**
* Creates the dataset event.
*
* @param e the e
*/
@UiHandler("createButton")
void createDatasetEvent(ClickEvent e){
String errorMessage = areProfileDataValid();
if(errorMessage != null){
alertOnCreate("Please check the inserted values and the mandatory fields [" + errorMessage +"]", AlertType.ERROR, true);
}
else{
Set<String> tags = new HashSet<String>(tagsPanel.getTags());
List<OrganizationBean> groups = new ArrayList<OrganizationBean>();
List<OrganizationBean> groupsToForceCreation = new ArrayList<OrganizationBean>();
Map<String, List<String>> customFieldsMap = new HashMap<String, List<String>>();
// prepare custom fields
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
List<String> valuesForField = field.getFieldCurrentValue();
if(!valuesForField.isEmpty()){
String key = field.getFieldNameQualified();
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.addAll(valuesForField);
customFieldsMap.put(key, valuesForThisField);
// get also tag/group if it is the case for this field
List<String> tagsField = field.getTagFromThisField();
if(tagsField != null)
tags.addAll(tagsField);
List<String> groupsTitle = field.getGroupTitleFromThisGroup();
if(groupsTitle != null){
for (String groupTitle : groupsTitle) {
if(field.isGroupToForce())
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
else
groups.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
}
}
}
}
}
for(CustomFieldEntry customEntry : customFieldEntriesList){
String key = customEntry.getKey();
String value = customEntry.getValue();
if(value != null && !value.isEmpty()){
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.add(value);
customFieldsMap.put(key, valuesForThisField);
}
}
// alert
alertOnCreate(TRYING_TO_CREATE_PRODUCT, AlertType.INFO, false);
// invoke the create method
createButton.setEnabled(false);
}
}
/**
* Prepare the info icons of all core metadata info.
*/
private void prepareInfoIcons() {
// tags
tagsPanel.prepareIcon(popupOpenedIds);
// profiles (or types)
InfoIconsLabels.preparePopupPanelAndPopover(
InfoIconsLabels.PROFILES_INFO_ID_POPUP,
InfoIconsLabels.PROFILES_INFO_TEXT,
InfoIconsLabels.PROFILES_INFO_CAPTION,
infoIconTypes,
popoverTypes,
focusPanelTypes,
popupOpenedIds
);
// custom fields
InfoIconsLabels.preparePopupPanelAndPopover(
InfoIconsLabels.CUSTOM_FIELDS_INFO_ID_POPUP,
InfoIconsLabels.CUSTOM_FIELDS_INFO_TEXT,
InfoIconsLabels.CUSTOM_FIELDS_INFO_CAPTION,
infoIconCustomFields,
popoverCustomFields,
focusPanelCustomFields,
popupOpenedIds
);
}
/**
* Test if profile data are valid.
*
* @return the string
*/
private String areProfileDataValid() {
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
field.removeError();
String error = field.isFieldValueValid();
if(error != null){
field.showError();
return field.getFieldNameOriginal() + " is not valid. Suggestion: " + error;
}
}
}
return null;
}
/**
* On continue show alert box and enable buttons.
*
* @param text the text
* @param type the type
*/
private void alertOnContinue(String text, AlertType type){
onContinueAlertBlock.setText(text);
onContinueAlertBlock.setType(type);
onContinueAlertBlock.setVisible(true);
continueButton.setEnabled(true);
resetButton.setEnabled(true);
// hide after some seconds
Timer t = new Timer() {
@Override
public void run() {
onContinueAlertBlock.setVisible(false);
}
};
t.schedule(4000);
}
/**
* On continue show alert box and enable buttons.
*
* @param text the text
* @param type the type
* @param hideAfterAWhile the hide after A while
*/
private void alertOnCreate(String text, AlertType type, boolean hideAfterAWhile){
Window.alert("Called alertOnCreate");
// onCreateAlertBlock.setText(text);
// onCreateAlertBlock.setType(type);
// onCreateAlertBlock.setVisible(true);
// createButton.setEnabled(true);
// goBackButtonSecondStep.setEnabled(true);
//
// if(hideAfterAWhile){
// // hide after some seconds
// Timer t = new Timer() {
//
// @Override
// public void run() {
//
// onCreateAlertBlock.setVisible(false);
//
// }
// };
// t.schedule(10000);
// }
}
/**
* Validate data.
*
* @return true on success, false otherwise
*/
private String validateDataOnContinue() {
// // remove errors
// productTitleGroup.setType(ControlGroupType.NONE);
// maintainerControlGroup.setType(ControlGroupType.NONE);
// versionControlGroup.setType(ControlGroupType.NONE);
// metadataTypesControlGroup.setType(ControlGroupType.NONE);
// organizationsGroup.setType(ControlGroupType.NONE);
// tagsPanel.setGroupPanelType(ControlGroupType.NONE);
//
// String title = titleTextBox.getText().trim();
// if(title.isEmpty()){
// productTitleGroup.setType(ControlGroupType.ERROR);
// return "Missing title";
// }
//
// // better check for the title
// String[] splittedTitle = title.split(" ");
//
// for (String word : splittedTitle) {
// String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, "");
// if(!replaced.equals(word)){
// productTitleGroup.setType(ControlGroupType.ERROR);
// return "Please note not all characters are allowed for the title";
// }
// }
//
// // email reg expression
// String maintainerMail = maintainerEmailTextbox.getText();
// if(!maintainerMail.isEmpty() && !maintainerMail.matches(REGEX_MAIL)){
// maintainerControlGroup.setType(ControlGroupType.ERROR);
// return "Not valid maintainer email";
// }
//
// // check if version is a number
// try{
// int number = Integer.valueOf(versionTextbox.getText().trim());
// if(number <= 0)
// throw new Exception();
// }catch(Exception e){
// versionControlGroup.setType(ControlGroupType.ERROR);
// return "Version must be a natural number greater than zero";
// }
//
// // check if metadata profile is different from none and its mandatory fields have been fulfilled
// if(checkSelectedMetaDataProfile()){
// metadataTypesControlGroup.setType(ControlGroupType.ERROR);
// return "You must select a Type different frome none";
// }
//
// if(organizationsListbox.getSelectedItemText() == null){
// organizationsGroup.setType(ControlGroupType.ERROR);
// return "You must select an organization in which you want to publish";
// }
//
// // at least one tag..
// if(tagsPanel.getTags().isEmpty()){
// tagsPanel.setGroupPanelType(ControlGroupType.ERROR);
// return "Please add at least one meaningful tag for the item";
// }
return null;
}
/**
* Checks if a metadata profile has been chosen and its fields have been fulfilled.
*
* @return true, if successful
*/
private boolean checkSelectedMetaDataProfile() {
return metadataTypeListbox.getSelectedItemText().equals(NONE_PROFILE) && metadataTypeListbox.getItemCount() != 1;
}
/**
* Reset form event.
*
* @param e the e
*/
@UiHandler("resetButton")
void resetFormEvent(ClickEvent e){
// delete custom fields
for (CustomFieldEntry customField : customFieldEntriesList) {
customField.removeFromParent();
}
customFieldEntriesList.clear();
}
/**
* Disable dataset editable fields once the dataset has been successfully created.
*/
protected void disableDatasetFields() {
tagsPanel.freeze();
addCustomFieldButton.setEnabled(false);
metadataTypeListbox.setEnabled(false);
for(CustomFieldEntry ce: customFieldEntriesList)
ce.freeze();
// disable profile fields
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
field.freeze();
}
}
// freeze table of resources
if(resourcesTwinPanel != null)
resourcesTwinPanel.freeze();
}
/**
* change alert block behavior.
*
* @param textToShow the text to show
* @param type the type
* @param visible the visible
*/
private void setAlertBlock(String textToShow, AlertType type, boolean visible){
infoBlock.setText(textToShow);
infoBlock.setType(type);
infoBlock.setVisible(visible);
}
/**
* On selected license change.
*
* @param c the c
*/
@UiHandler("licenseListbox")
void onSelectedLicenseChange(ChangeEvent c){
showLicenseUrl();
}
/**
* The body of the onSelectedLicenseChange.
*/
private void showLicenseUrl(){
Window.alert("Called showLicenseUrl");
}
}

View File

@ -0,0 +1,410 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:m="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.tags">
<ui:style>
.form-main-style {
margin-left: 10px;
}
.fieldset-border-style {
border: 1px groove #444;
-webkit-box-shadow: 0px 0px 0px 0px #000;
box-shadow: 0px 0px 0px 0px #000;
padding: 10px;
}
.legend-style {
width: auto;
padding: 10px;
margin-bottom: 0px;
}
@external .form-horizontal .input-large;
.form-horizontal .input-large .input-prepend {
width: 95%;
}
.block-alert-style {
margin-top: 10px;
padding: 10px;
margin-bottom: 10px;
}
.tagsPanelStyle {
display: inline-block;
}
.selected-profile {
font-weight: bold;
}
.label-go-to-product {
display: inline-block;
vertical-align: middle;
font-weight: bold;
}
.the-margin-left{
margin-left: 5px;
}
</ui:style>
<g:HTMLPanel ui:field="createDatasetMainPanel">
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formFirstStep" visible="true">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Insert Item Information
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<!-- Alert blocks for info/errors -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="infoBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
<!-- <b:ControlGroup ui:field="productTitleGroup"> -->
<!-- <b:ControlLabel for="title" title="Item title"> -->
<!-- <font color="red">*</font> -->
<!-- Title : -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" placeholder="Item title" -->
<!-- width="90%" b:id="title" title="Item title" ui:field="titleTextBox" /> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverTitle" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelTitle"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTitle" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="description" title="Item description"> -->
<!-- Description: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextArea placeholder="eg. Some useful notes about the item" -->
<!-- width="90%" alternateSize="LARGE" b:id="description" title="Item description" -->
<!-- ui:field="descriptionTextarea"></b:TextArea> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverDescription" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelDescription"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconDescription" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="licenses" title="License">License:</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:ListBox b:id="licenses" title="Item license" -->
<!-- width="91%" ui:field="licenseListbox"> -->
<!-- </b:ListBox> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverLicenses" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelLicenses"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconLicenses" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="licenseUrl" title="Selected License'url">Selected -->
<!-- License Url:</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:Paragraph ui:field="unavailableUrl" visible="true"> -->
<!-- <b>Unavailable</b> -->
<!-- </b:Paragraph> -->
<!-- <g:Anchor ui:field="licenseUrlAnchor" target="_blank" -->
<!-- visible="false"></g:Anchor> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="visibility" title="Visibility of the item">Visibility:</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:ListBox b:id="visibility" title="Item visibility" -->
<!-- width="91%" ui:field="visibilityListbox"> -->
<!-- <g:item title="restricted">Restricted</g:item> -->
<!-- <g:item enabled="true" title="public">Public</g:item> -->
<!-- </b:ListBox> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverVisibility" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelVisibility"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconVisibility" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup ui:field="organizationsGroup"> -->
<!-- <b:ControlLabel for="organization" -->
<!-- title="Select the organizations in which you want -->
<!-- to publish the item">Publish in:</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:ListBox b:id="organization" alternateSize="LARGE" -->
<!-- width="91%" title="Publish in this organization" ui:field="organizationsListbox"> -->
<!-- </b:ListBox> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup ui:field="versionControlGroup"> -->
<!-- <b:ControlLabel for="version" -->
<!-- title="Item version expressed as positive integer number"> -->
<!-- Version: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" placeholder="1.0" b:id="version" -->
<!-- width="90%" title="Item version" ui:field="versionTextbox" /> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="author" title="Item author"> -->
<!-- <font color="red">*</font> -->
<!-- Author: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" width="90%" -->
<!-- placeholder="Joe Bloggs" enabled="false" b:id="author" title="Item author" -->
<!-- ui:field="authorTextbox" /> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverAuthor" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelAuthor"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconAuthor" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup ui:field="authorEmailControlGroup"> -->
<!-- <b:ControlLabel for="email" title="Item author's email"> -->
<!-- <font color="red">*</font> -->
<!-- Author Email: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" width="90%" -->
<!-- placeholder="joe.bloggs@example.com" enabled="false" b:id="email" -->
<!-- title="Item author" ui:field="authorEmailTextbox" /> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverAuthorEmail" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelAuthorEmail"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconAuthorEmail" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup> -->
<!-- <b:ControlLabel for="maintainer" title="Item maintainer"> -->
<!-- Maintainer: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" placeholder="Joe Bloggs" -->
<!-- width="90%" b:id="maintainer" title="Item maintainer" -->
<!-- ui:field="maintainerTextbox" /> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverMaintainer" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelMaintainer"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconMaintainer" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <b:ControlGroup ui:field="maintainerControlGroup"> -->
<!-- <b:ControlLabel for="emailMaintaner" title="Item author's email"> -->
<!-- Maintainer Email: -->
<!-- </b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:TextBox alternateSize="LARGE" placeholder="maintainer@example.com" -->
<!-- width="90%" b:id="emailMaintaner" title="Item author" -->
<!-- ui:field="maintainerEmailTextbox" /> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverMaintainerEmail" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelMaintainerEmail"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconMaintainerEmail" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<b:ControlGroup ui:field="metadataTypesControlGroup">
<b:ControlLabel for="metadataTypes" title="Item profile types">Types:</b:ControlLabel>
<b:Controls>
<b:ListBox b:id="metadataTypes" alternateSize="LARGE"
width="91%" title="The item type to be used"
ui:field="metadataTypeListbox">
<g:item enabled="true" title="None">none</g:item>
</b:ListBox>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverTypes" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelTypes">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTypes" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<!-- TAGS Panel -->
<m:TagsPanel ui:field="tagsPanel"></m:TagsPanel>
<!-- <b:ControlGroup ui:field="groupsControlGroup" -->
<!-- visible="false"> -->
<!-- <b:ControlLabel for="groups" title="The groups for this item">Item Groups:</b:ControlLabel> -->
<!-- <b:Controls> -->
<!-- <b:ListBox b:id="groups" alternateSize="LARGE" width="91%" -->
<!-- multipleSelect="true" -->
<!-- title="The groups for this item (Hold CTRL or Command button for multiple selection)" -->
<!-- ui:field="groupsListbox"> -->
<!-- </b:ListBox> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverGroups" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelGroups"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconGroups" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- Alert block on continue -->
<!-- <b:AlertBlock animation="true" visible="false" -->
<!-- ui:field="alertNoResources" -->
<!-- text="Please note that the item you are going to publish will not have resources."> -->
<!-- </b:AlertBlock> -->
<!-- Alert block on continue -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onContinueAlertBlock">
</b:AlertBlock>
<b:Button title="Continue" ui:field="continueButton" type="PRIMARY"
block="true">Continue</b:Button>
<b:Button title="Reset" ui:field="resetButton" block="true">Reset</b:Button>
</b:Fieldset>
</b:Form>
<!-- <b:Form type="HORIZONTAL" styleName="{style.form-main-style}" -->
<!-- ui:field="formSecondStep" visible="false"> -->
<!-- <b:Fieldset styleName="{style.fieldset-border-style}"> -->
<!-- <b:Legend styleName="{style.legend-style}"> -->
<!-- Manage Resources -->
<!-- </b:Legend> -->
<!-- <b:ControlGroup> -->
<!-- <b:Controls> -->
<!-- <span style="float:right; width:5%; color: #aaaaaa;"> -->
<!-- <b:Popover ui:field="popoverResources" html="true" -->
<!-- animation="true" placement="LEFT"> -->
<!-- <g:FocusPanel ui:field="focusPanelResources"> -->
<!-- <b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconResources" /> -->
<!-- </g:FocusPanel> -->
<!-- </b:Popover> -->
<!-- </span> -->
<!-- </b:Controls> -->
<!-- </b:ControlGroup> -->
<!-- <g:SimplePanel ui:field="workspaceResourcesContainer" -->
<!-- width="100%" visible="true"> -->
<!-- </g:SimplePanel> -->
<!-- <b:Button title="Continue" ui:field="continueThirdStep" -->
<!-- type="PRIMARY" block="true">Continue</b:Button> -->
<!-- <b:Button title="Go Back" ui:field="goBackButtonFirstStep" -->
<!-- block="true">Go -->
<!-- Back</b:Button> -->
<!-- </b:Fieldset> -->
<!-- </b:Form> -->
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="formThirdStep" visible="false">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Insert Item Profile Information
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<b:Paragraph ui:field="selectedProfile" styleName="{style.selected-profile}"></b:Paragraph>
<!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="metadataFieldsPanel"
visible="false" width="100%"></g:VerticalPanel>
<!-- Custom fields can be dinamically added -->
<b:ControlGroup ui:field="customFields">
<b:ControlLabel>Custom Field(s):</b:ControlLabel>
</b:ControlGroup>
<b:ControlGroup>
<b:Controls>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverCustomFields" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelCustomFields">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconCustomFields" />
</g:FocusPanel>
</b:Popover>
</span>
<b:Button icon="PLUS_SIGN" title="Add Custom Field"
ui:field="addCustomFieldButton"></b:Button>
</b:Controls>
</b:ControlGroup>
<!-- Alert block on create -->
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="onCreateAlertBlock" styleName="{style.block-alert-style}">
</b:AlertBlock>
<g:HorizontalPanel ui:field="goToDatasetButtonPanel" visible="false">
<g:Label>Go to the Item</g:Label>
<b:Button title="Go to the Item" ui:field="goToDatasetButton"
type="LINK" visible="false" styleName="{style.the-margin-left}"></b:Button>
</g:HorizontalPanel>
<b:Button title="Add resources to the just created item"
block="true" type="PRIMARY" visible="false" ui:field="addResourcesButton">Add Resources</b:Button>
<b:Button title="Create Item" ui:field="createButton"
type="PRIMARY" block="true">Create</b:Button>
<b:Button title="Go Back" ui:field="goBackButtonSecondStep"
block="true">Go
Back</b:Button>
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,208 @@
/**
*
*/
package org.gcube.portlets.widgets.mpformbuilder.client.openlayerwidget;
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEvent;
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEvent.SelectAreaDialogEventHandler;
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEventType;
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.widgets.AreaSelectionDialog;
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.widgets.GeometryType;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsonUtils;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Command;
/**
* The Class GeoJsonAreaSelectionDialog.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 20, 2019
*/
public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{
private String wktArea;
private Command onResponseCommand;
private ListBox geometries;
/**
* Instantiates a new geo json area selection dialog.
*
* @param geometry the geometry
*/
public GeoJsonAreaSelectionDialog(GeometryType geometry) {
super(geometry);
//THE HANDLER
SelectAreaDialogEventHandler handler = new SelectAreaDialogEventHandler() {
@Override
public void onResponse(SelectAreaDialogEvent event) {
print("SelectAreaDialog Response: "+event);
if(event==null)
return;
SelectAreaDialogEventType closedType = event.getSelectAreaDialogEventType();
if(closedType==null)
return;
wktArea = null;
if(closedType.equals(SelectAreaDialogEventType.Completed)){
wktArea = event.getArea();
onResponseCommand.execute();
}
}
};
addSelectAreaDialogEventHandler(handler);
this.getElement().addClassName("GeoJson-DialogBox");
setZIndex(10000);
}
/**
* Fire command on response.
*
* @param command the command
*/
public void fireCommandOnResponse(Command command){
this.onResponseCommand = command;
}
/**
* Convert wkt to geo json.
*
* @param wktData the wkt data
* @return the string
*/
private static native String convertWKTToGeoJSON(String wktData) /*-{
try {
var ol = $wnd.ol;
var geojson_options = {};
var wkt_format = new ol.format.WKT();
var wktFeature = wkt_format.readFeature(wktData);
//console.log('WKT feature: '+wktFeature);
var wkt_options = {};
var geojson_format = new ol.format.GeoJSON(wkt_options);
console.log('geojson_format: '+geojson_format);
var geoJsonFeature = geojson_format.writeFeature(wktFeature);
//console.log('GeoJSON Feature: '+geoJsnameonFeature);
return geoJsonFeature;
}catch(err) {
console.log(err.message);
return null;
}
}-*/;
/**
* Prints the.
*
* @param txt the txt
* @return the string
*/
public static native String print(String txt) /*-{
console.log(txt)
}-*/;
/**
* Wkt to geo json.
*
* @param wktTxt the wkt txt
* @return the string
* @throws Exception the exception
*/
public String wktToGeoJSON(String wktTxt) throws Exception{
try {
String geoJSON = convertWKTToGeoJSON(wktTxt);
//Window.alert("geoJSON: "+geoJSON);
print("geoJSON: "+geoJSON);
if(geoJSON==null)
throw new Exception();
JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON);
JSONObject objJson = new JSONObject(toJSON);
return objJson.get("geometry").toString();
}catch(Exception e) {
//silent
throw new Exception("Sorry, an error occurred while getting GeoJSON format for the drawn Geometry");
}
}
/**
* Gets the WKT to geo json.
*
* @return the WKT to geo json
* @throws Exception the exception
*/
public String getWKTToGeoJSON() throws Exception{
if(wktArea==null){
print("wktArea is null");
throw new Exception("Sorry, an error occurred while reading the drawn Geometry");
}
//print("wktArea is: "+wktArea);
return wktToGeoJSON(wktArea);
}
/**
* Gets the wkt area.
*
* @return the wktArea
*/
public String getWktArea() {
return wktArea;
}
/**
* Gets the geometries.
*
* @return the geometries
*/
public static ListBox getGeometries() {
ListBox geometries = new ListBox();
//see Feature #13074
// for (GeometryType geometry : GeometryType.values()) {
// geometries.addItem(geometry.name(),geometry.name());
// }
geometries.addItem(GeometryType.Point.name(), GeometryType.Point.name());
geometries.addItem(GeometryType.LineString.name(), GeometryType.LineString.name());
geometries.addItem(GeometryType.Triangle.name(), GeometryType.Triangle.name());
geometries.addItem(GeometryType.Square.name(), GeometryType.Square.name());
geometries.addItem(GeometryType.Box.name(), GeometryType.Box.name());
return geometries;
}
/**
* To geometry.
*
* @param name the name
* @return the geometry type
*/
public static GeometryType toGeometry(String name){
GeometryType theGeom = null;
try {
theGeom = GeometryType.valueOf(name);
}catch (Exception e) {
//silent
}
return theGeom;
}
}

View File

@ -0,0 +1,13 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.icons;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
public interface Images extends ClientBundle {
@Source("file.png")
ImageResource fileIcon();
@Source("folder.png")
ImageResource folderIcon();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

View File

@ -0,0 +1,80 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField;
import com.github.gwtbootstrap.client.ui.PageHeader;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Float;
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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
public class CategoryPanel extends Composite{
private static CategoryPanelUiBinder uiBinder = GWT
.create(CategoryPanelUiBinder.class);
interface CategoryPanelUiBinder extends UiBinder<Widget, CategoryPanel> {
}
@UiField VerticalPanel fieldsPanel;
@UiField PageHeader categoryHeader;
//private List<MetaDataFieldSkeleton> fieldsForThisCategory;
private List<MetaDataField> fieldsForThisCategory;
public CategoryPanel() {
initWidget(uiBinder.createAndBindUi(this));
}
/**
*
* @param fieldsForThisCategory
* @param title
* @param description
*/
public CategoryPanel(String title, String description) {
initWidget(uiBinder.createAndBindUi(this));
title = title == null ? "" : title;
description = description == null ? "" : description;
categoryHeader.setTitle(title);
categoryHeader.setText(title);
categoryHeader.setSubtext(description);
categoryHeader.getElement().getStyle().setFloat(Float.LEFT);
}
/**
* Add a field to this widget
* @param fieldWidget
*/
/*public void addField(MetaDataFieldSkeleton fieldWidget) {
if(fieldsForThisCategory == null){
fieldsForThisCategory = new ArrayList<MetaDataFieldSkeleton>();
fieldWidget.setVisible(true);
fieldsPanel.setVisible(true);
}
fieldsForThisCategory.add(fieldWidget);
fieldsPanel.add(fieldWidget);
}*/
/**
* Add a field to this widget
* @param fieldWidget
*/
public void addField(MetaDataField fieldWidget) {
if(fieldsForThisCategory == null){
fieldsForThisCategory = new ArrayList<MetaDataField>();
fieldWidget.setVisible(true);
fieldsPanel.setVisible(true);
}
fieldsForThisCategory.add(fieldWidget);
fieldsPanel.add(fieldWidget);
}
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<g:VerticalPanel width="100%">
<b:PageHeader ui:field="categoryHeader"></b:PageHeader>
<!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="fieldsPanel" visible="false"
width="100%"></g:VerticalPanel>
</g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,107 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata;
import org.gcube.portlets.widgets.mpformbuilder.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;
/**
* A custom field entry that has two textboxes, one for the key value and the other for the value.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
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;
//inserted values
private String value;
private String key;
private boolean isCustomCreatedByUser;
// event bus
private HandlerManager eventBus;
public CustomFieldEntry(HandlerManager eventBus, String key, String value, boolean isCustomCreatedByUser) {
initWidget(uiBinder.createAndBindUi(this));
// save information
this.eventBus = eventBus;
this.value = value;
this.key = key;
this.isCustomCreatedByUser = isCustomCreatedByUser;
// remove the first appendbox
if(!isCustomCreatedByUser){
this.valueFieldPrepend.removeFromParent();
this.keyFieldPrepend.setPrependText(key + ":");
((TextBox)this.keyFieldPrepend.getWidget(1)).setText(value);
}
}
/**
* Retrieve the key value
* @return
*/
public String getKey(){
if(isCustomCreatedByUser){
return ((TextBox)this.keyFieldPrepend.getWidget(1)).getText();
}
return key;
}
/**
* Retrieve the value
* @return
*/
public String getValue(){
if(isCustomCreatedByUser){
return ((TextBox)this.valueFieldPrepend.getWidget(1)).getText();
}
return value;
}
@UiHandler("removeCustomField")
void onRemoveCustomField(ClickEvent e){
// fire event
eventBus.fireEvent(new DeleteCustomFieldEvent(this));
}
/**
* Remove delete button
*/
public void freeze() {
removeCustomField.setEnabled(false);
}
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<b:Controls>
<b:InputAddOn prependText="Key:" ui:field="keyFieldPrepend">
<b:TextBox />
</b:InputAddOn>
<b:InputAddOn prependText="Value:" ui:field="valueFieldPrepend">
<b:TextBox />
</b:InputAddOn>
<b:Button icon="REMOVE_SIGN" title="Remove field" ui:field="removeCustomField"></b:Button>
</b:Controls>
</ui:UiBinder>

View File

@ -0,0 +1,926 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEvent;
import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEventHandler;
import org.gcube.portlets.widgets.mpformbuilder.client.openlayerwidget.GeoJsonAreaSelectionDialog;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.timeandranges.DataTimeBox;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.GcubeDialogExtended;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.FieldAsGroup;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.FieldAsTag;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.TaggingGroupingValue;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ControlLabel;
import com.github.gwtbootstrap.client.ui.Controls;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
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;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
public class MetaDataFieldSkeleton extends Composite {
private static MetaDataFieldSkeletonUiBinder uiBinder = GWT.create(MetaDataFieldSkeletonUiBinder.class);
interface MetaDataFieldSkeletonUiBinder extends UiBinder<Widget, MetaDataFieldSkeleton> {
}
@UiField
Element mandatorySymbol;
@UiField
SpanElement name;
@UiField
SimplePanel elementPanel;
@UiField
FlowPanel noteFieldContainer;
@UiField
Popover noteFieldPopover;
@UiField
ControlLabel controlLabel;
@UiField
Controls controls;
@UiField
Icon infoIcon;
@UiField
FocusPanel focusPanelIconContainer;
@UiField
ControlGroup metafieldControlGroup;
// private static final String REGEX_IS_NUMBER = "[0-9]+[.]?[0-9]+";
// the element that holds the value (it could be a checkbox, textbox or listbox,
// textarea, calendar, two calendars, more calendars)
private Widget holder;
// the field this object represents
private MetadataFieldWrapper field;
// the dialog box for this metadata
private GcubeDialogExtended dialog;
// range list
private List<DataTimeBox> rangesList = new ArrayList<DataTimeBox>();
private List<TextArea> geoJsonList = new ArrayList<TextArea>();
// save event bus reference
private HandlerManager eventBus;
// errors
private static final String MANDATORY_ATTRIBUTE_MISSING = "a mandatory attribute cannot be empty";
private static final String MALFORMED_ATTRIBUTE = " the inserted value has a wrong format";
private static final String ADD_NEW_TIME_RANGE = "Add a new Time Range";
private static final String DELETE_TIME_RANGE = "Delete the last Time Range";
// missing range value
private static final String INSERT_MISSING_VALUE = " you cannot specify an end date without a start one";
private static final String INSERT_MISSING_VALUE_MANDATORY = " one or more range value missing in mandatory attribute";
private static final String UPPER_RANGE_NOT_SPECIFIED = "Not specified";
// time range separator
public static final String RANGE_SEPARATOR = ",";
private static final String TOOLTIP_MULTISELECTION = "Hold down the Control (CTRL) or Command (CMD) button to select multiple options";
public MetaDataFieldSkeleton(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception {
initWidget(uiBinder.createAndBindUi(this));
// prepare information
this.field = field;
// event bus
this.eventBus = eventBus;
// bind
bind();
switch (field.getType()) {
case Boolean:
// its a checkbox
holder = new CheckBox();
if (field.getDefaultValue() != null)
((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue()));
break;
case GeoJSON:
// MANAGED By FRANCESCO
final VerticalPanel containerGeoJSON = new VerticalPanel();
// containerGeoJSON.setWidth("100%");
final TextArea textArea = new TextArea();
textArea.setWidth("100%");
if (field.getDefaultValue() != null)
textArea.setText(field.getDefaultValue());
containerGeoJSON.add(textArea);
HorizontalPanel hp = new HorizontalPanel();
hp.getElement().getStyle().setMarginTop(10, Unit.PX);
final ListBox geometries = GeoJsonAreaSelectionDialog.getGeometries();
Button butt = new Button();
butt.setIcon(IconType.MAP_MARKER);
butt.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String geometrySelected = geometries.getSelectedItemText();
if (geometrySelected == null) {
containerGeoJSON.add(new Alert("Please, select one geometry", AlertType.WARNING, true));
}
final GeoJsonAreaSelectionDialog dialog = new GeoJsonAreaSelectionDialog(
GeoJsonAreaSelectionDialog.toGeometry(geometrySelected));
Command fillGeoJSONArea = new Command() {
public void execute() {
try {
String geoJsonGeom = dialog.getWKTToGeoJSON();
if (geoJsonGeom != null)
textArea.setText(geoJsonGeom);
else {
textArea.setText("");
containerGeoJSON.add(new Alert("Sorry, an error occurred by reading the Geometry",
AlertType.ERROR, true));
}
} catch (Exception e) {
containerGeoJSON.add(new Alert(e.getMessage(), AlertType.ERROR, true));
}
}
};
dialog.fireCommandOnResponse(fillGeoJSONArea);
dialog.center();
}
});
geoJsonList.add(textArea);
Label label = new Label("Draw a");
label.getElement().getStyle().setMarginRight(5, Unit.PX);
hp.add(label);
geometries.getElement().getStyle().setMarginRight(5, Unit.PX);
hp.add(geometries);
hp.add(butt);
geometries.setItemSelected(0, true);
containerGeoJSON.add(hp);
holder = containerGeoJSON;
break;
case Text:
holder = new TextArea();
if (field.getDefaultValue() != null)
((TextArea) holder).setText(field.getDefaultValue());
break;
case Time:
DataTimeBox ref;
holder = ref = new DataTimeBox(false);
// set time, if present
if (field.getDefaultValue() != null && !field.getDefaultValue().isEmpty()) {
String[] dateAndTime = field.getDefaultValue().split(" ");
if (dateAndTime.length > 0) {
ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null);
}
}
break;
case Time_Interval:
DataTimeBox rangeBox;
holder = rangeBox = new DataTimeBox(true);
setRangeTimeInTimeBox(field.getDefaultValue(), rangeBox);
rangesList.add(rangeBox);
break;
case Times_ListOf:
holder = new FlowPanel();
// start and end range date
final VerticalPanel containerRanges = new VerticalPanel();
containerRanges.setWidth("100%");
SimplePanel panelFirstRange = new SimplePanel();
DataTimeBox rangeBoxFirst = new DataTimeBox(true);
setRangeTimeInTimeBox(field.getDefaultValue(), rangeBoxFirst);
panelFirstRange.add(rangeBoxFirst);
rangesList.add(rangeBoxFirst);
// Add more button
Button addRangeButton = new Button();
addRangeButton.setIcon(IconType.PLUS_SIGN);
addRangeButton.setTitle(ADD_NEW_TIME_RANGE);
addRangeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final FlowPanel newRange = new FlowPanel();
final DataTimeBox newRangeBox = new DataTimeBox(true);
setRangeTimeInTimeBox(field.getDefaultValue(), newRangeBox);
rangesList.add(newRangeBox);
// delete button
Button deleteRangeButton = new Button("", IconType.MINUS_SIGN, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
newRange.removeFromParent();
rangesList.remove(newRangeBox);
}
});
deleteRangeButton.setTitle(DELETE_TIME_RANGE);
newRange.add(newRangeBox);
newRange.add(deleteRangeButton);
containerRanges.add(newRange);
}
});
// add calendars and plus sign
containerRanges.add(panelFirstRange);
// add the vertical panel first, then the button
((FlowPanel) holder).add(containerRanges);
((FlowPanel) holder).add(addRangeButton);
break;
case Number:
holder = new TextBox();
if (field.getDefaultValue() != null)
((TextBox) holder).setText(field.getDefaultValue());
break;
case String:
// it could be a listbox or a textbox according to the vocabulary fields
if (field.getVocabulary() == null || field.getVocabulary().isEmpty()) {
// textbox
holder = new TextBox();
if (field.getDefaultValue() != null)
((TextBox) holder).setText(field.getDefaultValue());
} else {
// listbox
ListBox tempListBox;
holder = tempListBox = new ListBox(field.isMultiSelection());
if (field.isMultiSelection())
tempListBox.setTitle(TOOLTIP_MULTISELECTION);
// if it is not mandatory, add a disabled option
if (!field.getMandatory()) {
tempListBox.addItem("Select " + field.getFieldName());
tempListBox.setSelectedValue("Select " + field.getFieldName());
tempListBox.getElement().getElementsByTagName("option").getItem(0).setAttribute("disabled",
"disabled");
}
// get vocabulary fields
List<String> vocabulary = field.getVocabulary();
for (String term : vocabulary) {
tempListBox.addItem(term);
}
// set default value
if (field.getDefaultValue() != null)
tempListBox.setSelectedValue(field.getDefaultValue());
}
break;
default:
return;
}
// add custom css properties
controls.addStyleName("form-controls-custom");
controlLabel.addStyleName("form-control-label-custom");
// save the name
name.setInnerText(field.getFieldName() + ":");
// check if it is mandatory
if (!field.getMandatory())
mandatorySymbol.getStyle().setDisplay(Display.NONE);
// add to the elementPanel
elementPanel.add(holder);
// set holder width
if (holder.getClass().equals(ListBox.class))
holder.setWidth("96%");
else
holder.setWidth("95%");
// set the notes, if any, and the popover
if (field.getNote() != null && !field.getNote().isEmpty()) {
noteFieldPopover.setText(new HTML("<p style='color:initial'>" + field.getNote() + "</p>").getHTML());
noteFieldPopover.setHeading(new HTML("<b>" + field.getFieldName() + "</b>").getHTML());
infoIcon.getElement().getStyle().setCursor(Cursor.HELP);
noteFieldPopover.setHtml(true);
noteFieldContainer.setVisible(true);
} else {
noteFieldContainer.setVisible(false);
}
// add a resize handler to center the dialog box if it's not null
Window.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
if (dialog != null)
dialog.center();
}
});
}
/**
* 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) {
if (dialog == null) {
// create the dialog box
dialog = new GcubeDialogExtended(field.getFieldName(), field.getNote());
// set as non modal
dialog.setModal(false);
}
// else just show and center
dialog.center();
dialog.show();
}
/**
* Check if this field has valid values
*
* @return a string with the occurred error on error, null otherwise
*/
public String isFieldValueValid() {
switch (field.getType()) {
case Boolean:
// nothing to validate
return null;
case Text:
case GeoJSON:
String textAreaValue = getFieldCurrentValue().get(0);
if (field.getMandatory()) {
if (!textAreaValue.trim().isEmpty())
if (field.getValidator() == null || field.getValidator().isEmpty())
return null; // no further check
else
return checkValidator(textAreaValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
else
return MANDATORY_ATTRIBUTE_MISSING;
} else {
if (textAreaValue.trim().isEmpty())
return null;
else
return checkValidator(textAreaValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
}
case Time:
String dateValue = getFieldCurrentValue().get(0);
if (field.getMandatory()) {
if (dateValue.isEmpty())
return MANDATORY_ATTRIBUTE_MISSING;
}
return null;
case Time_Interval:
String rangeValue = rangesList.get(0).getCurrentValue();
if (field.getMandatory()) {
if (rangeValue.contains(DataTimeBox.MISSING_RANGE_VALUE_START)
|| rangeValue.contains(DataTimeBox.MISSING_RANGE_VALUE_END))
return INSERT_MISSING_VALUE_MANDATORY;
}
if (rangeValue.contains(DataTimeBox.MISSING_RANGE_VALUE_START)
&& !rangeValue.equals(DataTimeBox.MISSING_RANGE_VALUE_START + DataTimeBox.RANGE_SEPARATOR_START_END
+ DataTimeBox.MISSING_RANGE_VALUE_END))
return INSERT_MISSING_VALUE;
return null;
case Times_ListOf:
for (DataTimeBox el : rangesList) {
String currentValue = el.getCurrentValue();
if (field.getMandatory()) {
if (currentValue.contains(DataTimeBox.MISSING_RANGE_VALUE_START)
|| currentValue.contains(DataTimeBox.MISSING_RANGE_VALUE_END))
return INSERT_MISSING_VALUE_MANDATORY;
}
GWT.log("Printing " + currentValue);
if (currentValue.contains(DataTimeBox.MISSING_RANGE_VALUE_START)
&& !currentValue.equals(DataTimeBox.MISSING_RANGE_VALUE_START
+ DataTimeBox.RANGE_SEPARATOR_START_END + DataTimeBox.MISSING_RANGE_VALUE_END))
return INSERT_MISSING_VALUE;
}
return null;
case Number:
String numberValue = ((TextBox) holder).getValue();
if (field.getMandatory()) {
if (!numberValue.trim().isEmpty())
if (field.getValidator() == null || field.getValidator().isEmpty())
return isANumber(numberValue) ? null : MALFORMED_ATTRIBUTE;
else
return checkValidator(numberValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
else
return " a mandatory attribute cannot be empty";
} else {
if (numberValue.trim().isEmpty())
return null;
else {
String validatorToUse = field.getValidator();
if (validatorToUse != null && !validatorToUse.isEmpty())
return checkValidator(numberValue, validatorToUse) ? null : MALFORMED_ATTRIBUTE;
else
return isANumber(numberValue) ? null : MALFORMED_ATTRIBUTE;
}
}
case String:
// just handle the case of textbox
if (holder.getClass().equals(TextBox.class)) {
String textBoxValue = getFieldCurrentValue().get(0);
if (field.getMandatory()) {
if (!textBoxValue.trim().isEmpty())
if (field.getValidator() == null || field.getValidator().isEmpty())
return null; // no further check
else
return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
else
return MANDATORY_ATTRIBUTE_MISSING;
} else {
if (textBoxValue.trim().isEmpty())
return null;
else
return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
}
} else {
List<String> listboxValues = getFieldCurrentValue();
if (listboxValues.isEmpty() && field.getMandatory())
return MANDATORY_ATTRIBUTE_MISSING;
for (String value : listboxValues) {
if (!field.getMandatory()) {
if (field.getValidator() == null || field.getValidator().isEmpty())
continue;
else if (checkValidator(value, field.getValidator()))
continue;
else
return MALFORMED_ATTRIBUTE;
} else {
if (value == null || value.isEmpty())
return MANDATORY_ATTRIBUTE_MISSING;
else
continue;
}
}
}
return null;
default:
return null;
}
}
/**
* Check if this string is a number
*
* @param numberValue
* @return
*/
private boolean isANumber(String numberValue) {
return numberValue.matches("-?\\d+(\\.\\d+)?");
}
/**
* Check if value matches validator (regex). In case validator is null, true is
* returned.
*
* @param value
* @param validator
* @return true if validator is null OR value.matches(reges), false otherwise
*/
private boolean checkValidator(String value, String validator) {
GWT.log("Value is " + value);
GWT.log("Validator is " + validator);
if (validator == null || validator.isEmpty())
return true;
else
return value.matches(validator);
}
/**
* Returns the current value of the field. In case of TimeInterval or TimeList
* see getTimeIntervalOrTimeListWithoutMissing()
*
* @return
*/
public List<String> getFieldCurrentValue() {
List<String> toReturn = new ArrayList<String>();
String manipulatedTemp = "";
switch (field.getType()) {
case Boolean:
toReturn.add(((CheckBox) holder).getValue().toString());
break;
case Text:
toReturn.add(((TextArea) holder).getText());
break;
case GeoJSON:
toReturn.add(geoJsonList.get(0).getText());
break;
case Time:
toReturn.add(
((DataTimeBox) holder).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "")); // it
// was
// a
// noRange
// metadata
break;
case Time_Interval:
manipulatedTemp = rangesList.get(0).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "")
.replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED);
if (toReturn.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED))
manipulatedTemp = "";
// split to check if the extreme are equals
String[] temp = manipulatedTemp.split(DataTimeBox.RANGE_SEPARATOR_START_END);
if (temp[0].equals(temp[1]))
manipulatedTemp = temp[0];
toReturn.add(manipulatedTemp);
break;
case Times_ListOf:
manipulatedTemp = "";
for (DataTimeBox elem : rangesList) {
String currentRange = elem.getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "")
.replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED);
if (currentRange.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED))
continue;
String[] splitted = currentRange.split(DataTimeBox.RANGE_SEPARATOR_START_END);
if (splitted[0].equals(splitted[1]))
manipulatedTemp += manipulatedTemp.isEmpty() ? splitted[0] : RANGE_SEPARATOR + splitted[0];
else
manipulatedTemp += manipulatedTemp.isEmpty()
? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1]
: RANGE_SEPARATOR + splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1];
}
if (manipulatedTemp.endsWith(RANGE_SEPARATOR))
manipulatedTemp = manipulatedTemp.substring(0, manipulatedTemp.length() - 1);
toReturn.add(manipulatedTemp);
break;
case Number:
case String:
if (holder.getClass().equals(TextBox.class))
toReturn.add(((TextBox) holder).getText());
else {
// handle multiselected case
for (int i = 0; i < ((ListBox) holder).getItemCount(); i++) {
if (((ListBox) holder).isItemSelected(i)) {
toReturn.add(((ListBox) holder).getItemText(i));
}
}
// if it was not mandatory but there was no choice, returning empty string
if (!field.getMandatory())
if (toReturn.equals("Select " + field.getFieldName())) {
toReturn.clear();
toReturn.add("");
}
}
break;
default:
break;
}
return toReturn;
}
/**
* Returns the current name of the field
*
* @return
*/
public String getFieldNameOriginal() {
return field.getFieldName();
}
/**
* Returns the current name of the field
*
* @return
*/
public String getFieldNameQualified() {
if (field.getFieldNameFromCategory() != null)
return field.getFieldNameFromCategory();
return field.getFieldName();
}
/**
* Freeze this widget (after on create)
*/
public void freeze() {
switch (field.getType()) {
case Boolean:
((CheckBox) holder).setEnabled(false);
break;
case GeoJSON:
case Text:
((TextArea) holder).setEnabled(false);
break;
case Time:
((DataTimeBox) holder).freeze();
break;
case Time_Interval:
rangesList.get(0).freeze();
break;
case Times_ListOf:
for (DataTimeBox el : rangesList)
el.freeze();
break;
case Number:
((TextBox) holder).setEnabled(false);
break;
case String:
if (holder.getClass().equals(ListBox.class))
((ListBox) holder).setEnabled(false);
else
((TextBox) holder).setEnabled(false);
break;
default:
break;
}
}
/**
* Get the original MetadataFieldWrapper object
*
* @return
*/
public MetadataFieldWrapper getField() {
return field;
}
public void removeError() {
metafieldControlGroup.setType(ControlGroupType.NONE);
}
public void showError() {
metafieldControlGroup.setType(ControlGroupType.ERROR);
}
/**
* Build the range interval
*
* @param rangeValues
* @param tb
*/
private void setRangeTimeInTimeBox(String rangeValues, DataTimeBox tb) {
// set time, if present
if (rangeValues != null && !rangeValues.isEmpty()) {
if (!rangeValues.contains(DataTimeBox.RANGE_SEPARATOR_START_END))
rangeValues += "/" + rangeValues;
String[] dateAndTimeRanges = rangeValues.split(DataTimeBox.RANGE_SEPARATOR_START_END);
if (dateAndTimeRanges.length > 0) {
String[] firstRangeDate = dateAndTimeRanges[0].split(" ");
tb.setStartDate(firstRangeDate[0], firstRangeDate.length > 1 ? firstRangeDate[1] : null);
if (dateAndTimeRanges.length > 1) {
String[] secondRangeDate = dateAndTimeRanges[1].split(" ");
tb.setEndDate(secondRangeDate[0], secondRangeDate.length > 1 ? secondRangeDate[1] : null);
}
}
}
}
/**
* Given the name and the value of this field, return a tag if it is the case.
*
* @return a tag as string
*/
public List<String> getTagFromThisField() {
FieldAsTag asTag = field.getAsTag();
List<String> generatedTags = new ArrayList<String>();
if (asTag != null && asTag.isCreate()) {
List<String> values = getFieldCurrentValue();
for (String value : values) {
generatedTags.add(TaggingGroupingValue.getComposedValueTag(field.getFieldName(), value,
asTag.getSeparator(), asTag.getTaggingValue()));
}
return generatedTags;
}
return null;
}
/**
* Given the name and the value of this field, return a group title if it is the
* case.
*
* @return a tag as string
*/
public List<String> getGroupTitleFromThisGroup() {
FieldAsGroup asGroup = field.getAsGroup();
List<String> generatedGroups = new ArrayList<String>();
if (asGroup != null) {
List<String> values = getFieldCurrentValue();
for (String value : values) {
generatedGroups.addAll(TaggingGroupingValue.getComposedValueGroup(field.getFieldName(), value,
asGroup.getGroupingValue()));
}
return generatedGroups;
}
return null;
}
/**
* Check if the group associated (if it exists) should be forced
*
* @return
*/
public boolean isGroupToForce() {
FieldAsGroup asGroup = field.getAsGroup();
if (asGroup != null) {
return asGroup.getCreate();
}
return false;
}
/**
* Check if the propagateUp is set
*
* @return
*/
public boolean isPropagateUp() {
FieldAsGroup asGroup = field.getAsGroup();
if (asGroup != null) {
return asGroup.isPropagateUp();
}
return false;
}
}

View File

@ -0,0 +1,50 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:b2="urn:import:com.github.gwtbootstrap.datetimepicker.client.ui"
xmlns:b3="urn:import:com.github.gwtbootstrap.datepicker.client.ui">
<ui:style>
.note-container {
display: inline-block;
float: right;
width: 5%;
color: #aaaaaa;
}
.note-field-text {
display: inline;
text-align: justify;
margin-left: 5px;
word-wrap: break-word;
}
.element-panel {
display: inline-block;
}
</ui:style>
<g:HTMLPanel width="100%">
<b:ControlGroup ui:field="metafieldControlGroup">
<b:ControlLabel ui:field="controlLabel">
<font color="red" ui:field="mandatorySymbol">*</font>
<span ui:field="name"></span>
</b:ControlLabel>
<b:Controls ui:field="controls">
<g:FlowPanel width="95%">
<g:SimplePanel ui:field="elementPanel" styleName="{style.element-panel}"
width="95%">
<!-- Listbox, Checkbox, Textbox, Calendar etc -->
</g:SimplePanel>
<g:FlowPanel ui:field="noteFieldContainer" styleName="{style.note-container}">
<b:Popover ui:field="noteFieldPopover" html="true"
animation="true" placement="LEFT">
<g:FocusPanel ui:field="focusPanelIconContainer">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIcon" />
</g:FocusPanel>
</b:Popover>
</g:FlowPanel>
</g:FlowPanel>
</b:Controls>
</b:ControlGroup>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.resources;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT;
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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Container for the third phase (add resource to dataset)
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AddResourceContainer extends Composite{
private static AddResourceContainerUiBinder uiBinder = GWT
.create(AddResourceContainerUiBinder.class);
interface AddResourceContainerUiBinder extends
UiBinder<Widget, AddResourceContainer> {
}
@UiField VerticalPanel resourcesPanel;
public AddResourceContainer(final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this));
}
/**
* Add the form to this panel
* @param w
*/
public void add(TabPanel w){
resourcesPanel.add(w);
}
}

View File

@ -0,0 +1,8 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel>
<!-- Here will be placed the form for the resources -->
<g:VerticalPanel ui:field="resourcesPanel" width="100%"></g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,189 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.resources;
import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.TextArea;
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.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class AddResourceToDataset.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Oct 1, 2020
*/
public class AddResourceToDataset extends Composite{
private static AddResourceToDatasetUiBinder uiBinder = GWT
.create(AddResourceToDatasetUiBinder.class);
/**
* The Interface AddResourceToDatasetUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Oct 1, 2020
*/
interface AddResourceToDatasetUiBinder extends
UiBinder<Widget, AddResourceToDataset> {
}
// bus to alert the dataset form about this new resource
private HandlerManager eventBus;
// the dataset id
private String datasetId;
// the dataset organization
private String datasetOrg;
@UiField TextBox resourceUrlTextBox;
@UiField TextBox resourceNameTextBox;
@UiField TextArea resourceDescriptionTextArea;
@UiField Button addResourceButton;
@UiField AlertBlock infoBlock;
@UiField Button goToDatasetButton;
/**
* Instantiates a new adds the resource to dataset.
*
* @param eventBus the event bus
* @param datasetId the dataset id
* @param datasetOrg the dataset org
* @param owner the owner
* @param datasetUrl the dataset url
*/
public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetOrg, String owner, final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this));
// save bus
this.eventBus = eventBus;
// save dataset id (it is needed when we will add resources)
this.datasetId = datasetId;
this.datasetOrg = datasetOrg;
goToDatasetButton.setText(
(datasetUrl.length() > 100 ?
datasetUrl.substring(0, 100) + "..." : datasetUrl)
);
// goToDatasetButton.setHref(datasetUrl);
goToDatasetButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open(datasetUrl, "_blank", "");
}
});
}
/**
* On add button click.
*
* @param e the e
*/
@UiHandler("addResourceButton")
void onAddButtonClick(ClickEvent e){
infoBlock.setVisible(false);
// validation
if(resourceUrlTextBox.getText().isEmpty() || resourceNameTextBox.getText().isEmpty()){
showAlert("Url and name fields cannot be empty", AlertType.ERROR);
return;
}
// collect data and build up the bean
/*//TODO MUST BE DONE IN ANOTHER POINT
*
* final ResourceElementBean resource =
new ResourceElementBean(
resourceNameTextBox.getText(),
true,
false,
null,
null,
null,
null,
null,
resourceUrlTextBox.getText(),
resourceDescriptionTextArea.getText(),
datasetOrg);
// disable add button
addResourceButton.setEnabled(false);
// try to create
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() {
@Override
public void onSuccess(ResourceElementBean result) {
if(result != null){
showAlert("Resource created correctly", AlertType.SUCCESS);
eventBus.fireEvent(new AddResourceEvent(result));
// remove data
resourceUrlTextBox.setText("");
resourceNameTextBox.setText("");
resourceDescriptionTextArea.setText("");
}
else
showAlert("Unable to add this resource. Check that the url is correct", AlertType.ERROR);
}
@Override
public void onFailure(Throwable caught) {
showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), AlertType.ERROR);
}
});*/
}
/**
* Show error/success after resource creation attempt.
*
* @param text the text
* @param type the type
*/
protected void showAlert(String text, AlertType type) {
infoBlock.setText(text);
infoBlock.setType(type);
infoBlock.setVisible(true);
addResourceButton.setEnabled(true);
// hide after some seconds
Timer t = new Timer() {
@Override
public void run() {
infoBlock.setVisible(false);
}
};
t.schedule(4000);
}
}

View File

@ -0,0 +1,110 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.form-main-style {
margin-left: 10px;
}
.fieldset-border-style {
border: 1px groove #444;
-webkit-box-shadow: 0px 0px 0px 0px #000;
box-shadow: 0px 0px 0px 0px #000;
padding: 10px;
}
.legend-style {
width: auto;
padding: 10px;
margin-bottom: 0px;
}
@external .form-horizontal .input-large;
.form-horizontal .input-large {
width: 95%;
}
.block-alert-style {
margin-top: 10px;
padding: 10px;
margin-bottom: 10px;
}
.tagsPanelStyle {
display: inline-block;
}
.add-resource-button {
float: right;
}
.label-go-to-product {
display: inline-block;
vertical-align: middle;
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<b:Form type="HORIZONTAL" styleName="{style.form-main-style}"
ui:field="form">
<b:Fieldset styleName="{style.fieldset-border-style}">
<b:Legend styleName="{style.legend-style}">
Add Resource
<small>
<span style="color:red;">*</span>
is required
</small>
</b:Legend>
<b:ControlGroup>
<b:ControlLabel for="url" title="File url">
<font color="red">*</font>
URL:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="http://example.com/image.jpg"
b:id="url" title="Product's title" ui:field="resourceUrlTextBox" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="name" title="Resource name">
<font color="red">*</font>
Name:
</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="my-image"
b:id="name" title="Resource name" ui:field="resourceNameTextBox" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="description" title="Resource description">
Description:
</b:ControlLabel>
<b:Controls>
<b:TextArea alternateSize="LARGE"
placeholder="Some useful notes about data" b:id="description"
title="Resource description" ui:field="resourceDescriptionTextArea" />
</b:Controls>
</b:ControlGroup>
<!-- Alert blocks for info/errors -->
<b:AlertBlock type="INFO" animation="true" visible="false"
close="false" ui:field="infoBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
<!-- Add resource button -->
<b:Button title="Add resource" ui:field="addResourceButton"
type="PRIMARY">Add</b:Button>
</b:Fieldset>
</b:Form>
<g:FlowPanel>
<g:Label styleName="{style.label-go-to-product}">Go to the Item</g:Label>
<b:Button title="Go to Item" ui:field="goToDatasetButton"
type="LINK" visible="true"></b:Button>
</g:FlowPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,159 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.resources;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.client.events.AddResourceEvent;
import org.gcube.portlets.widgets.mpformbuilder.client.events.AddResourceEventHandler;
import org.gcube.portlets.widgets.mpformbuilder.client.events.DeleteResourceEvent;
import org.gcube.portlets.widgets.mpformbuilder.client.events.DeleteResourceEventHandler;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.Accordion;
import com.github.gwtbootstrap.client.ui.AccordionGroup;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Paragraph;
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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* A summary of the resources added by the user.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class AddedResourcesSummary extends Composite{
private static AddedResourcesSummaryUiBinder uiBinder = GWT
.create(AddedResourcesSummaryUiBinder.class);
interface AddedResourcesSummaryUiBinder extends
UiBinder<Widget, AddedResourcesSummary> {
}
// Event bus
private HandlerManager eventBus;
// list of added resources (beans)
List<ResourceElementBean> addedResources;
@UiField VerticalPanel addResourcesPanel;
public AddedResourcesSummary(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
// save bus
this.eventBus = eventBus;
// bind on add resource event
bind();
// init list
addedResources = new ArrayList<ResourceElementBean>();
}
/**
* Bind on add/delete resource event
*/
private void bind() {
// when a new resource is added
eventBus.addHandler(AddResourceEvent.TYPE, new AddResourceEventHandler() {
@Override
public void onAddedResource(AddResourceEvent addResourceEvent) {
// get the resource
final ResourceElementBean justAddedResource = addResourceEvent.getResource();
// Build an accordion to show resource info
Accordion accordion = new Accordion();
AccordionGroup accordionGroup = new AccordionGroup();
accordionGroup.setHeading("- " + justAddedResource.getName());
accordion.add(accordionGroup);
// add sub-info such as url and description
Paragraph pUrl = new Paragraph();
pUrl.setText("Url : " + justAddedResource.getUrl());
Paragraph pDescription = new Paragraph();
pDescription.setText("Description : " + justAddedResource.getDescription());
// button to delete the resource
Button deleteButton = new Button();
deleteButton.setText("Delete");
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
eventBus.fireEvent(new DeleteResourceEvent(justAddedResource));
}
});
// fill accordion
accordionGroup.add(pUrl);
accordionGroup.add(pDescription);
accordionGroup.add(deleteButton);
// add to the list
addedResources.add(justAddedResource);
// add to the panel
addResourcesPanel.add(accordion);
}
});
// when the user wants to delete a resource
eventBus.addHandler(DeleteResourceEvent.TYPE, new DeleteResourceEventHandler() {
@Override
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) {
// to delete
ResourceElementBean toDelete = deleteResourceEvent.getResource();
// find it
/*
* MUST ME MANAGED IN ANOTHER POINT
*
* for(int i = 0; i < addedResources.size(); i++){
if(addedResources.get(i).getOriginalIdInWorkspace().equals(toDelete.getOriginalIdInWorkspace())){
// get the associated widget and remove it
final Widget widget = addResourcesPanel.getWidget(i);
// remote call to remove it from the dataset
ckanServices.deleteResourceFromDataset(toDelete, new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if(result)
widget.removeFromParent();
}
@Override
public void onFailure(Throwable caught) {
}
});
break;
}
}*/
// remove from the list
addedResources.remove(toDelete);
}
});
}
}

View File

@ -0,0 +1,8 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel>
<h3>Added Resources</h3>
<g:VerticalPanel ui:field="addResourcesPanel" width="100%"></g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,279 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.tags;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.InfoIconsLabels;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.base.ListItem;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
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.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
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.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Panel for tags.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class TagsPanel extends Composite{
private static TagsPanelUiBinder uiBinder = GWT
.create(TagsPanelUiBinder.class);
interface TagsPanelUiBinder extends UiBinder<Widget, TagsPanel> {
}
@UiField TextBox tagsEnterTextBox;
@UiField FlowPanel tagsPanel;
@UiField Icon infoIconTags;
@UiField FocusPanel focusPanelTags;
@UiField Popover popoverTags;
@UiField ControlGroup tagsInsertGroup;
@UiField ListBox tagsEnterListBox;
// regular expression for tags
private static final String REGEX_TAG = "^[a-zA-Z0-9]*$";
// tags list
private List<String> tagsList = new ArrayList<String>();
// vocabulary
private List<String> vocabulary;
public TagsPanel() {
initWidget(uiBinder.createAndBindUi(this));
tagsEnterListBox.setVisible(false);
tagsList.clear();
tagsPanel.clear();
}
/**
* Since we have a controlled vocabulary, we swap to a listbox with multiple selection
* @param vocabularyTags
*/
public void setVocabulary(List<String> vocabularyTags) {
GWT.log("Vocabulary of tags is " + vocabularyTags);
if(vocabularyTags == null || vocabularyTags.isEmpty()){
vocabulary = null;
tagsEnterListBox.setVisible(false);
tagsPanel.setVisible(true);
tagsEnterTextBox.setVisible(true);
}else{
vocabulary = vocabularyTags;
tagsEnterListBox.clear();
tagsPanel.clear();
tagsList.clear();
for (String vocabularyTag : vocabularyTags) {
tagsEnterListBox.addItem(vocabularyTag, vocabularyTag);
}
tagsPanel.setVisible(false);
tagsEnterTextBox.setVisible(false);
tagsEnterListBox.setVisible(true);
}
}
/**
* Prepare icons
* @param popupOpenedIds
*/
public void prepareIcon(List<String> popupOpenedIds) {
InfoIconsLabels.preparePopupPanelAndPopover(
InfoIconsLabels.TAGS_INFO_ID_POPUP,
InfoIconsLabels.TAGS_INFO_TEXT,
InfoIconsLabels.TAGS_INFO_CAPTION,
infoIconTags,
popoverTags,
focusPanelTags,
popupOpenedIds
);
}
@UiHandler("tagsEnterTextBox")
void onAddTag(KeyDownEvent event){
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox);
}
}
}
/**
* Add the tag as an element (inserted by the user)
*/
private void addTagElement(TextBox itemBox){
if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) {
if(tagsList.contains(itemBox.getValue().trim())){
itemBox.setValue("");
return;
}
// ckan accepts only alphanumeric values
String[] subTags = itemBox.getValue().trim().split(" ");
if(subTags.length == 1){
if(!subTags[0].matches(REGEX_TAG))
return;
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches(REGEX_TAG))
return;
}
}
final String value = itemBox.getValue().trim();
final ListItem displayItem = new ListItem();
displayItem.setStyleName("tag-style");
Span tagText = new Span(itemBox.getValue());
Span tagRemove = new Span("x");
tagRemove.setTitle("Remove this tag");
tagRemove.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeTag(displayItem, value);
}
});
tagRemove.setStyleName("tag-style-x");
displayItem.add(tagText);
displayItem.add(tagRemove);
itemBox.setValue("");
itemBox.setFocus(true);
tagsPanel.add(displayItem);
tagsList.add(value);
}
}
/**
* Add the tag as an element (when publishing from workspace)
*/
public void addTagElement(final String tag){
if(tagsList.contains(tag))
return;
// ckan accepts only alphanumeric values
String[] subTags = tag.trim().split(" ");
if(subTags.length == 1){
if(!subTags[0].matches(REGEX_TAG))
return;
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches(REGEX_TAG))
return;
}
}
final ListItem displayItem = new ListItem();
displayItem.setStyleName("tag-style");
Span p = new Span(tag);
Span span = new Span("x");
span.setTitle("Remove this tag");
span.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
removeTag(displayItem, tag);
}
});
span.setStyleName("tag-style-x");
displayItem.add(p);
displayItem.add(span);
tagsPanel.add(displayItem);
tagsList.add(tag);
}
/**
* Remove a tag from the list
* @param displayItem
*/
private void removeTag(ListItem displayItem, String value) {
tagsList.remove(value.trim());
tagsPanel.remove(displayItem);
}
/**
* Remove all inserted tags
*/
public void removeTags(){
tagsList.clear();
tagsPanel.clear();
}
/**
* Return the tag list
* @return
*/
public List<String> getTags() {
if(vocabulary == null){
return tagsList;
}else{
List<String> selected = new ArrayList<String>();
for(int i = 0; i < tagsEnterListBox.getItemCount(); i++){
if(tagsEnterListBox.isItemSelected(i))
selected.add(tagsEnterListBox.getItemText(i));
}
return selected;
}
}
/**
* Freeze tags
*/
public void freeze() {
tagsEnterTextBox.setEnabled(false);
tagsEnterListBox.setEnabled(false);
for(int i = 0; i < tagsList.size(); i++){
// get tag widget
ListItem tagWidget = (ListItem)tagsPanel.getWidget(i);
// get the "x" span
tagWidget.getWidget(1).removeFromParent();
}
}
/**
* Set the tag group panel type
* @param none
*/
public void setGroupPanelType(ControlGroupType type) {
tagsInsertGroup.setType(type);
}
}

View File

@ -0,0 +1,36 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.tagsPanelStyle {
display: inline-block;
}
</ui:style>
<g:HTMLPanel>
<b:ControlGroup ui:field="tagsInsertGroup">
<b:ControlLabel for="tags" title="Item tag">
<font color="red">*</font>
Tag:
</b:ControlLabel>
<b:Controls ui:field="controlAsTextBox">
<b:TextBox width="90%" placeholder="Write a tag here (push ENTER to attach it to the Item)"
b:id="tags" ui:field="tagsEnterTextBox" maxLength="100"/>
<b:ListBox width="91%" title="HOLD CTRL or CMD for multiple selection"
b:id="tags" ui:field="tagsEnterListBox" multipleSelect="true"/>
<span style="float:right; width:5%; color: #aaaaaa;">
<b:Popover ui:field="popoverTags" html="true" animation="true"
placement="LEFT">
<g:FocusPanel ui:field="focusPanelTags">
<b:Icon type="INFO_SIGN" size="TWO_TIMES" ui:field="infoIconTags" />
</g:FocusPanel>
</b:Popover>
</span>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:Controls>
<g:FlowPanel ui:field="tagsPanel" styleName="{style.tagsPanelStyle}"></g:FlowPanel>
</b:Controls>
</b:ControlGroup>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,138 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.timeandranges;
import java.util.Date;
import com.github.gwtbootstrap.datepicker.client.ui.DateBox;
import com.github.gwtbootstrap.datetimepicker.client.ui.DateTimeBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
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.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Widget for handling date-like fields.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class DataTimeBox extends Composite{
private static DataTimeBoxUiBinder uiBinder = GWT
.create(DataTimeBoxUiBinder.class);
interface DataTimeBoxUiBinder extends UiBinder<Widget, DataTimeBox> {
}
public static final String RANGE_SEPARATOR_START_END = "/";
public static final String MISSING_RANGE_VALUE_START = "MISSING_RANGE_PART_START";
public static final String MISSING_RANGE_VALUE_END = "MISSING_RANGE_PART_END";
private static final String COLON = ":";
private static final String INSERT_DATE_INSTANT_LABEL = "Insert a date";
private static final String INSERT_TIME_INSTANT_LABEL = "Hour and minutes";
private static final String INSERT_DATE_START_LABEL = "Insert a start date";
private static final String INSERT_DATE_END_LABEL = "Insert an end date";
private static final DateTimeFormat formatDate = DateTimeFormat.getFormat("yyyy-MM-dd");
private static final DateTimeFormat formatTime = DateTimeFormat.getFormat("HH:mm");
private boolean isRange;
@UiField
DateBox startRangeDate;
@UiField
DateTimeBox startRangeTime;
@UiField
DateBox endRangeDate;
@UiField
DateTimeBox endRangeTime;
@UiField
FlowPanel singleDataEnd;
@UiField
FlowPanel singleDataStart;
public DataTimeBox(boolean isRange) {
initWidget(uiBinder.createAndBindUi(this));
this.isRange = isRange;
startRangeDate.setPlaceholder(INSERT_DATE_INSTANT_LABEL);
startRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);
if(isRange){
singleDataEnd.setVisible(true);
singleDataEnd.setWidth("50%");
singleDataStart.setWidth("50%");
startRangeTime.setWidth("30%");
endRangeTime.setWidth("30%");
startRangeDate.setWidth("60%");
endRangeDate.setWidth("60%");
startRangeDate.setPlaceholder(INSERT_DATE_START_LABEL);
endRangeDate.setPlaceholder(INSERT_DATE_END_LABEL);
endRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);
}
startRangeDate.setValue(null);
startRangeTime.setValue(null);
endRangeDate.setValue(null);
endRangeTime.setValue(null);
}
public boolean getIsRange(){
return isRange;
}
public void setStartDate(String date, String time){
GWT.log("Date is " + date + " and time is " + time);
startRangeDate.setValue(new Date(date));
if(time != null && !time.isEmpty()){
Date completeDate = new Date();
completeDate.setHours(Integer.parseInt(time.split(COLON)[0]));
completeDate.setMinutes(Integer.parseInt(time.split(COLON)[1]));
startRangeTime.setValue(completeDate);
}
}
public void setEndDate(String date, String time){
GWT.log("Date is " + date + " and time is " + time);
endRangeDate.setValue(new Date(date));
if(time != null && !time.isEmpty()){
Date completeDate = new Date();
completeDate.setHours(Integer.parseInt(time.split(COLON)[0]));
completeDate.setMinutes(Integer.parseInt(time.split(COLON)[1]));
endRangeTime.setValue(completeDate);
}
}
/**
* Return the current value, with MISSING_RANGE_VALUE in case of missing entry
* @return
*/
public String getCurrentValue(){
String firstRange = MISSING_RANGE_VALUE_START;
String secondRange = MISSING_RANGE_VALUE_END;
if(startRangeDate.getValue() != null){
firstRange = formatDate.format(startRangeDate.getValue()) + " " + (startRangeTime.getValue() != null ? formatTime.format(startRangeTime.getValue()) : "");;
}
if(isRange && endRangeDate.getValue() != null){
secondRange = formatDate.format(endRangeDate.getValue()) + " " + (endRangeTime.getValue() != null ? formatTime.format(endRangeTime.getValue()) : "");
}
if(isRange){
GWT.log("Returning " + firstRange + RANGE_SEPARATOR_START_END + secondRange);
return firstRange + RANGE_SEPARATOR_START_END + secondRange;
}else {
GWT.log("Returning " + firstRange);
return firstRange;
}
}
/**
* Freeze the inputs
*/
public void freeze(){
startRangeDate.setEnabled(false);
startRangeTime.setEnabled(false);
endRangeDate.setEnabled(false);
endRangeTime.setEnabled(false);
}
}

View File

@ -0,0 +1,30 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b2="urn:import:com.github.gwtbootstrap.datetimepicker.client.ui"
xmlns:b3="urn:import:com.github.gwtbootstrap.datepicker.client.ui">
<ui:style>
.flow-panel-style {
display: inline-block;
}
</ui:style>
<g:HTMLPanel width="100%">
<g:FlowPanel width="100%">
<g:FlowPanel width="100%" ui:field="singleDataStart" styleName="{style.flow-panel-style}"
visible="true">
<b3:DateBox format="yyyy-mm-dd" autoClose="true"
language="en" ui:field="startRangeDate" width="70%" />
<b2:DateTimeBox format="hh:ii" autoClose="true"
maxView="HOUR" startView="HOUR" language="en"
width="20%" ui:field="startRangeTime" />
</g:FlowPanel>
<g:FlowPanel width="100%" ui:field="singleDataEnd" visible="false"
styleName="{style.flow-panel-style}">
<b3:DateBox format="yyyy-mm-dd" autoClose="true" width="70%"
language="en" ui:field="endRangeDate" />
<b2:DateTimeBox format="hh:ii" autoClose="true"
maxView="HOUR" startView="HOUR" language="en"
width="20%" ui:field="endRangeTime" />
</g:FlowPanel>
</g:FlowPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.icons.Images;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Image;
/**
* Cell that renders left side panel objects
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
private static final Images image = GWT.create(Images.class);
private static final String tipFile = "Hold down the Control (ctrl) or Command button to select multiple options";
private static final String tipFolder = "Click on the folder to navigate it";
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
ResourceElementBean value, SafeHtmlBuilder sb) {
if (value == null || value.isToBeAdded()) {
return;
}
Image file = new Image(image.fileIcon());
Image folder = new Image(image.folderIcon());
file.setWidth("15px");
file.setHeight("15px");
folder.setWidth("15px");
folder.setHeight("15px");
String whichTip = value.isFolder() ? tipFolder : tipFile;
sb.appendHtmlConstant("<div title='" + value.getName() + "( " + whichTip + " )" + "' style='overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis;max-width:240px; min-height:30px; padding-top:5px;'>");
sb.appendHtmlConstant("<span style='margin-left:5px;'>");
sb.appendHtmlConstant(value.isFolder() ? folder.toString() : file.toString());
sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("<span style='margin-left:10px;'>");
sb.appendHtmlConstant("<b>");
sb.appendEscaped(value.getName());
sb.appendHtmlConstant("</b>");
sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("</div>");
}
}

View File

@ -0,0 +1,65 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.icons.Images;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Image;
/**
* Cell that renders right side panel objects
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
private static final Images image = GWT.create(Images.class);
private static final String tip = "Hold down the Control (CTRL) or Command button to select multiple options. Double click to access "
+ "this resource information";
public ResourceCellRight() {
super("keydown", "dblclick");
}
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
ResourceElementBean value, SafeHtmlBuilder sb) {
if (value == null || !value.isToBeAdded() || value.isFolder()) {
return;
}
Image file = new Image(image.fileIcon());
file.setWidth("15px");
file.setHeight("15px");
sb.appendHtmlConstant("<div title='" + value.getName() + "( " + tip + " )" + "' style='overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis;max-width:240px; min-height:30px; padding-top:5px;'>");
sb.appendHtmlConstant("<span style='margin-left:5px'>");
sb.appendHtmlConstant(file.toString());
sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("<span style='margin-left:10px'>");
sb.appendHtmlConstant("<b>");
sb.appendEscaped(value.getEditableName());
sb.appendHtmlConstant("</b>");
sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("</div>");
}
@Override
public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,
Element parent, ResourceElementBean value, NativeEvent event,
ValueUpdater<ResourceElementBean> valueUpdater) {
if(value == null || TwinColumnSelectionMainPanel.isFroozen())
return;
super.onBrowserEvent(context, parent, value, event, valueUpdater);
ResourceInfoForm info = new ResourceInfoForm(value, valueUpdater);
if(TwinColumnSelectionMainPanel.detailContainer.getWidget() != null)
TwinColumnSelectionMainPanel.detailContainer.clear();
TwinColumnSelectionMainPanel.detailContainer.add(info);
TwinColumnSelectionMainPanel.detailContainer.setVisible(true);
}
}

View File

@ -0,0 +1,143 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.cell.client.ValueUpdater;
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.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
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.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* A resource information form panel
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourceInfoForm extends Composite{
@UiField
public TextBox resourceName;
@UiField
public TextBox resourcePath;
@UiField
public TextBox resourceFormat;
@UiField
public TextArea resourceDescription;
@UiField
public Button updateResourceButton;
@UiField
Button closeButton;
@UiField
HorizontalPanel commandPanel;
@UiField
ControlGroup controlName;
private ResourceElementBean resourceBean;
private static ResourceInfoFormUiBinder uiBinder = GWT
.create(ResourceInfoFormUiBinder.class);
interface ResourceInfoFormUiBinder extends
UiBinder<Widget, ResourceInfoForm> {
}
public ResourceInfoForm() {
initWidget(uiBinder.createAndBindUi(this));
}
public ResourceInfoForm(final ResourceElementBean resource, final ValueUpdater<ResourceElementBean> valueUpdater) {
initWidget(uiBinder.createAndBindUi(this));
resourceBean = resource;
resourceDescription.setText(resource.getDescription());
resourceFormat.setText(resource.getMimeType() == null? "Unavailable" : resource.getMimeType());
resourceName.setText(resource.getEditableName());
resourcePath.setText(resource.getFullPath());
closeButton.getElement().getStyle().setFloat(Float.RIGHT);
closeButton.setIcon(IconType.REMOVE_CIRCLE);
commandPanel.setCellHorizontalAlignment(updateResourceButton, HasHorizontalAlignment.ALIGN_RIGHT);
commandPanel.getElement().getStyle().setMarginTop(10, Unit.PX);
updateResourceButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
resourceBean.setDescription(resourceDescription.getText());
removeError(controlName);
String newName = resourceName.getText();
if(newName == null || newName.isEmpty()){
showError(controlName);
}else{
resourceBean.setEditableName(newName);
valueUpdater.update(resourceBean);
}
}
});
closeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
clearPanel();
}
});
}
public String getResourceName() {
return resourceName.getText();
}
public void setResourceName(String resourceName) {
this.resourceName.setText(resourceName);
}
public String getResourcePath() {
return resourcePath.getText();
}
public void setResourcePath(String resourcePath) {
this.resourcePath.setText(resourcePath);
}
public String getResourceFormat() {
return resourceFormat.getText();
}
public void setResourceFormat(String resourceFormat) {
this.resourceFormat.setText(resourceFormat);
}
public String getResourceDescription() {
return resourceDescription.getText();
}
public void setResourceDescription(String resourceDescription) {
this.resourceDescription.setText(resourceDescription);
}
public void removeError(ControlGroup control) {
control.setType(ControlGroupType.NONE);
}
public void showError(ControlGroup control) {
control.setType(ControlGroupType.ERROR);
}
protected void clearPanel() {
this.removeFromParent();
}
}

View File

@ -0,0 +1,88 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.legend-style {
width: 100%;
padding: 10px;
margin-bottom: 0px;
font-size: 14px;
}
.panel-style {
padding: 5px;
border: 1px solid #bbb;
border-radius: 5px;
height: 400px;
width: 95%;
}
.labels-style {
color: #999;
}
.controls-style {
margin-left: 10px !important;
}
.control-group {
margin-bottom: 0px !important;
}
</ui:style>
<g:HTMLPanel styleName="{style.panel-style}">
<b:Form type="VERTICAL" width="100%">
<!-- <b:Fieldset styleName="{style.fieldset-border-style}"> -->
<b:Legend styleName="{style.legend-style}">
<b>Resource Information</b>
<b:Button ui:field="closeButton" type="LINK" title="Close details"></b:Button>
</b:Legend>
<b:ControlGroup ui:field="controlName" styleName="{style.control-group}">
<b:ControlLabel for="name" styleName="{style.labels-style}"
title="The name the resource will have on the catalogue">
<b>Name:</b>
</b:ControlLabel>
<b:Controls styleName="{style.controls-style}">
<b:TextBox placeholder="Resource name" b:id="name"
enabled="true" title="The name the resource will have on the catalogue"
ui:field="resourceName" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup styleName="{style.control-group}">
<b:ControlLabel for="path" title="Resource path"
styleName="{style.labels-style}">
<b>Path:</b>
</b:ControlLabel>
<b:Controls styleName="{style.controls-style}">
<b:TextBox placeholder="Resource path" b:id="path"
readOnly="true" title="Resource path" ui:field="resourcePath" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup styleName="{style.control-group}">
<b:ControlLabel for="description" styleName="{style.labels-style}"
title="The description the resource will have on the catalogue">
<b>Description:</b>
</b:ControlLabel>
<b:Controls styleName="{style.controls-style}">
<b:TextArea placeholder="Resource description" b:id="description"
title="The description the resource will have on the catalogue"
ui:field="resourceDescription"></b:TextArea>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup styleName="{style.control-group}">
<b:ControlLabel for="format" styleName="{style.labels-style}"
title="The MIME type">
<b>Format:</b>
</b:ControlLabel>
<b:Controls styleName="{style.controls-style}">
<b:TextBox placeholder="Resource format" b:id="format"
title="The MIME type" ui:field="resourceFormat" readOnly="true" />
</b:Controls>
</b:ControlGroup>
<g:HorizontalPanel width="100%" ui:field="commandPanel">
<!-- <b:Button ui:field="cancelButton">Cancel</b:Button> -->
<b:Button ui:field="updateResourceButton" type="PRIMARY">Update</b:Button>
</g:HorizontalPanel>
<!-- </b:Fieldset> -->
</b:Form>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,101 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.user.cellview.client.AbstractPager;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasRows;
/**
* Basically a scroll panel
* Partially changed from the code at http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellList
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ShowMorePagerPanel extends AbstractPager{
/**
* The default increment size.
*/
public static final int DEFAULT_INCREMENT = 10;
/**
* The increment size.
*/
private int incrementSize = DEFAULT_INCREMENT;
/**
* The last scroll position.
*/
private int lastScrollPos = 0;
/**
* The scrollable panel.
*/
private final ScrollPanel scrollable = new ScrollPanel();
/**
* Construct a new {@link ShowMorePagerPanel}.
*/
public ShowMorePagerPanel() {
initWidget(scrollable);
// Do not let the scrollable take tab focus.
scrollable.getElement().setTabIndex(-1);
// Handle scroll events.
scrollable.addScrollHandler(new ScrollHandler() {
public void onScroll(ScrollEvent event) {
// If scrolling up, ignore the event.
int oldScrollPos = lastScrollPos;
lastScrollPos = scrollable.getVerticalScrollPosition();
if (oldScrollPos >= lastScrollPos) {
return;
}
HasRows display = getDisplay();
if (display == null) {
return;
}
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
- scrollable.getOffsetHeight();
if (lastScrollPos >= maxScrollTop) {
// We are near the end, so increase the page size.
int newPageSize = Math.min(
display.getVisibleRange().getLength() + incrementSize,
display.getRowCount());
display.setVisibleRange(0, newPageSize);
}
}
});
}
/**
* Get the number of rows by which the range is increased when the scrollbar
* reaches the bottom.
* @return the increment size
*/
public int getIncrementSize() {
return incrementSize;
}
@Override
public void setDisplay(HasRows display) {
assert display instanceof Widget : "display must extend Widget";
scrollable.setWidget((Widget) display);
super.setDisplay(display);
}
/**
* Set the number of rows by which the range is increased when the scrollbar
* reaches the bottom.
* @param incrementSize the incremental number of rows
*/
public void setIncrementSize(int incrementSize) {
this.incrementSize = incrementSize;
}
@Override
protected void onRangeOrRowCountChanged() {
}
}

View File

@ -0,0 +1,571 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.Breadcrumbs;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.FluidContainer;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.FontWeight;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
/**
* The twin column panels for selection of the files to attach to the catalague product.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
* @author Francesco Mangiacrapa at ISTI-CNR
*/
public class TwinColumnSelectionMainPanel extends Composite{
@UiField
VerticalPanel leftContainer;
@UiField
VerticalPanel rightContainer;
@UiField
VerticalPanel buttonsPanel;
@UiField
Button allToRightButton;
@UiField
Button toRightButton;
@UiField
Button toLeftButton;
@UiField
Button allToLeftButton;
// @UiField
// Popover popoverResourceSelection;
// @UiField
// Button resourceInfoButton;
@UiField
Breadcrumbs breadcrumbs;
@UiField
FluidContainer mainContainerResourcesSelection;
// @UiField
// Button getResources;
@UiField
public static SimplePanel detailContainer;
/**
* The breadcrumb subpath with the linked folder
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
private class PathBean{
NavLink link;
ResourceElementBean resourceFolder;
PathBean(NavLink link, ResourceElementBean resourceFolder){
this.link = link;
this.resourceFolder = resourceFolder;
}
}
private static boolean frozen = false;
private List<PathBean> pathListBeans = new ArrayList<PathBean>();
private static final String PANEL_BORDER_COLOR = "#8899a6";
private static final String PANEL_HEIGHT = "400px";
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel();
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel();
private CellList<ResourceElementBean> cellListLeft;
private CellList<ResourceElementBean> cellListRight;
private ListDataProvider<ResourceElementBean> dataProviderLeft = new ListDataProvider<ResourceElementBean>();
private ListDataProvider<ResourceElementBean> dataProviderRight = new ListDataProvider<ResourceElementBean>();
private MultiSelectionModel<ResourceElementBean> selectionModelRight;
private MultiSelectionModel<ResourceElementBean> selectionModelLeft;
private final ResourceElementBean initialBean;
// private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>");
// private final static HTML aboutBody = new HTML("<p style='text-align:justify;'>Move the files you want to attach to the product on the right panel below."
// + " Please consider that any complex hierarchy structure you may have will be flatten.</p>");
// private static final short PATH_THRESHOLD = 1; // TODO
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
.create(TwinColumnSelectionMainPanelUiBinder.class);
interface TwinColumnSelectionMainPanelUiBinder extends
UiBinder<Widget, TwinColumnSelectionMainPanel> {
}
public TwinColumnSelectionMainPanel(ResourceElementBean initialBean) {
initWidget(uiBinder.createAndBindUi(this));
frozen = false;
GWT.log(initialBean.toString());
this.initialBean = initialBean;
buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT);
allToRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
buttonsPanel.getElement().setAttribute("align", "center");
// popoverResourceSelection.setPlacement(Placement.LEFT);
// popoverResourceSelection.setHeading(aboutHeader.getHTML());
// popoverResourceSelection.setText(aboutBody.getHTML());
// resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT);
// resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX);
mainContainerResourcesSelection.getElement().getStyle().setPadding(10, Unit.PX);
breadcrumbs.getElement().getStyle().setBackgroundColor("white");
breadcrumbs.getElement().getStyle().setFontWeight(FontWeight.BOLD);
breadcrumbs.getElement().getStyle().setMarginLeft(0, Unit.PX);
mainContainerResourcesSelection.getElement().getStyle().setMarginLeft(10, Unit.PX);
mainContainerResourcesSelection.getElement().getStyle().setMarginBottom(20, Unit.PX);
mainContainerResourcesSelection.getElement().getStyle().setMarginTop(0, Unit.PX);
prepareHandlers();
initLeftSidePanel(initialBean);
initRightSidePanel();
}
/**
* Initialize the left side panel
*/
private void initLeftSidePanel(final ResourceElementBean initialBean) {
// initialize the left side list
ResourceCellLeft cell = new ResourceCellLeft();
// Set a key provider that provides a unique key for each object.
cellListLeft = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER);
cellListLeft.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
// set page size
int size = initialBean.isFolder() ? initialBean.getChildren().size() : 1;
cellListLeft.setPageSize(size);
// Add a selection model so we can select cells.
selectionModelLeft = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
cellListLeft.setSelectionModel(selectionModelLeft);
// perform an action on selection
selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
if(frozen)
return;
Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator();
while (selectedObjectsIterator.hasNext()) {
ResourceElementBean selectedBean = selectedObjectsIterator.next();
if(selectedBean.isFolder()){
// a single folder selected
if(selectionModelLeft.getSelectedSet().size() == 1){
// update path
final NavLink navElem = new NavLink(selectedBean.getName());
navElem.getElement().getStyle().setFontWeight(FontWeight.BOLD);
final PathBean pathBean = new PathBean(navElem, selectedBean);
navElem.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeStartingFromBreadcrumbs(navElem, pathBean);
GWT.log("Clicked on element " + pathBean.resourceFolder.getName());
//breadcrumbsUpdater();
ResourceElementBean folder = pathBean.resourceFolder;
Collections.sort(folder.getChildren());
dataProviderLeft.setList(folder.getChildren());
dataProviderLeft.refresh();
}
});
pathListBeans.add(pathBean);
breadcrumbs.add(navElem);
//breadcrumbsUpdater();
Collections.sort(selectedBean.getChildren());
GWT.log("Children " + selectedBean.getChildren());
dataProviderLeft.setList(selectedBean.getChildren());
cellListLeft.setPageSize(selectedBean.getChildren().size());
dataProviderLeft.refresh();
}
selectionModelLeft.setSelected(selectedBean, false);
}
}
// enable the buttons that allows to move the objects to the right
enableMoveToRightButtons(selectionModelLeft.getSelectedSet());
}
});
// set the list into the provider
if(initialBean.isFolder()){
Collections.sort(this.initialBean.getChildren());
dataProviderLeft.setList(this.initialBean.getChildren());
}else
dataProviderLeft.setList(Arrays.asList(this.initialBean));
// add root to breadcrumb
final NavLink root = new NavLink(initialBean.getName());
final PathBean pathBean = new PathBean(root, initialBean);
root.getElement().getStyle().setFontWeight(FontWeight.BOLD);
pathListBeans.add(pathBean);
breadcrumbs.add(root);
root.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeStartingFromBreadcrumbs(root, pathBean);
//breadcrumbsUpdater();
// set back the root content list
dataProviderLeft.setList(initialBean.getChildren());
cellListLeft.setPageSize(initialBean.getChildren().size());
dataProviderLeft.refresh();
}
});
// set the cell list into the provider
dataProviderLeft.addDataDisplay(cellListLeft);
// manage showMorePanelLeft
showMorePanelLeft.setDisplay(cellListLeft);
showMorePanelLeft.setHeight(PANEL_HEIGHT);
showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
showMorePanelLeft.getElement().getStyle().setBorderWidth(2, Unit.PX);
showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
// add the list to the leftContainerPanel
leftContainer.add(showMorePanelLeft);
}
/**
* Update the path
* @param navElem
* @param pathBean
*/
public void removeStartingFromBreadcrumbs(NavLink navElem, PathBean pathBean){
// remove data after
Iterator<Widget> iteratorBreadcrumb = breadcrumbs.iterator();
Iterator<PathBean> iteratorListPath = pathListBeans.iterator();
boolean delete = false;
while(iteratorBreadcrumb.hasNext()){
Widget current = iteratorBreadcrumb.next();
if(delete){
current.removeFromParent();
iteratorBreadcrumb.remove();
}
if(!delete && navElem.equals(current))
delete = true;
}
delete = false;
while(iteratorListPath.hasNext()){
PathBean current = iteratorListPath.next();
if(delete)
iteratorListPath.remove();
if(!delete && pathBean.equals(current))
delete = true;
}
}
/**
* Initialize the left side panel
*/
private void initRightSidePanel() {
// initialize the left side list
ResourceCellRight cell = new ResourceCellRight();
// Set a key provider that provides a unique key for each object.
cellListRight = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER);
cellListRight.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
cellListRight.setValueUpdater(new ValueUpdater<ResourceElementBean>() {
@Override
public void update(ResourceElementBean value) {
// just redraw the list
cellListRight.redraw();
}
});
// Add a selection model so we can select cells.
selectionModelRight = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
cellListRight.setSelectionModel(selectionModelRight);
// perform an action on selection
selectionModelRight.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
if(frozen)
return;
enableMoveToLeftButtons(selectionModelRight.getSelectedSet());
}
});
// set the cell list into the provider
dataProviderRight.addDataDisplay(cellListRight);
// manage showMorePanelRight
showMorePanelRight.setDisplay(cellListRight);
showMorePanelRight.setHeight(PANEL_HEIGHT);
showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
showMorePanelRight.getElement().getStyle().setBorderWidth(2, Unit.PX);
showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
// add the list to the leftContainerPanel
rightContainer.add(showMorePanelRight);
}
/**
* Enable/disable the buttons to move objects from left to right properly.
* @param setselectedItemsLeft
*/
private void enableMoveToRightButtons(Set<ResourceElementBean> setselectedItemsLeft){
if(setselectedItemsLeft == null || setselectedItemsLeft.isEmpty()){
allToRightButton.setEnabled(false);
toRightButton.setEnabled(false);
}
else if(setselectedItemsLeft.size() > 1){
allToRightButton.setEnabled(true);
toRightButton.setEnabled(false);
}
else{
allToRightButton.setEnabled(false);
toRightButton.setEnabled(true);
}
}
/**
* Enable/disable the buttons to move objects from right to left properly.
* @param setselectedItemsRight
*/
private void enableMoveToLeftButtons(Set<ResourceElementBean> setselectedItemsRight){
if(setselectedItemsRight == null || setselectedItemsRight.isEmpty()){
allToLeftButton.setEnabled(false);
allToLeftButton.setEnabled(false);
}
else if(setselectedItemsRight.size() > 1){
allToLeftButton.setEnabled(true);
toLeftButton.setEnabled(false);
}
else{
allToLeftButton.setEnabled(false);
toLeftButton.setEnabled(true);
}
}
/**
* Prepare the buttons' handlers
*/
private void prepareHandlers() {
allToRightButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
moveToRight(selectionModelLeft.getSelectedSet());
}
});
toRightButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
moveToRight(selectionModelLeft.getSelectedSet());
}
});
allToLeftButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
moveToLeft(selectionModelRight.getSelectedSet());
}
});
toLeftButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
moveToLeft(selectionModelRight.getSelectedSet());
}
});
}
/**
* Move to right elements
* @param set the elements to move
*/
private void moveToRight(Set<ResourceElementBean> setSelected){
if(setSelected == null || setSelected.isEmpty())
return;
Iterator<ResourceElementBean> iterator = setSelected.iterator();
while (iterator.hasNext()) {
ResourceElementBean resourceElementBean = iterator
.next();
resourceElementBean.setToBeAdded(true);
int indexRight = dataProviderRight.getList().indexOf(resourceElementBean);
if(indexRight >= 0)
dataProviderRight.getList().set(indexRight, resourceElementBean);
else{
dataProviderRight.getList().add(resourceElementBean);
Collections.sort(dataProviderRight.getList());
dataProviderRight.refresh();
}
int indexLeft = dataProviderLeft.getList().indexOf(resourceElementBean);
dataProviderLeft.getList().set(indexLeft, resourceElementBean);
}
}
/**
* Move to left elements
* @param setSelected the elements to move
*/
private void moveToLeft(Set<ResourceElementBean> setSelected){
if(setSelected == null || setSelected.isEmpty())
return;
Iterator<ResourceElementBean> iterator = setSelected.iterator();
while (iterator.hasNext()) {
ResourceElementBean resourceElementBean = iterator.next();
resourceElementBean.setToBeAdded(false);
}
Collections.sort(dataProviderLeft.getList());
dataProviderLeft.refresh();
dataProviderRight.refresh();
}
/**
* Freeze the panel
*/
public void freeze() {
frozen = true;
Iterator<Widget> iteratorOverPath = breadcrumbs.iterator();
while (iteratorOverPath.hasNext()) {
Widget widget = iteratorOverPath.next();
if(widget instanceof NavLink)
((NavLink)widget).setActive(false);
}
allToRightButton.setEnabled(false);
toRightButton.setEnabled(false);
allToLeftButton.setEnabled(false);
toLeftButton.setEnabled(false);
}
/**
* Returns the root parent with the children as files to save
* @return the resources to save
*/
public ResourceElementBean getResourcesToPublish(){
List<ResourceElementBean> current = dataProviderRight.getList();
ResourceElementBean toReturn = new ResourceElementBean();
List<ResourceElementBean> children = new ArrayList<ResourceElementBean>();
for (ResourceElementBean resource : current) {
if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ...
ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource);
beanWithoutChildren.setName(resource.getEditableName());
children.add(beanWithoutChildren);
}
}
toReturn.setChildren(children);
return toReturn;
}
/**
* @return the freezed
*/
public static boolean isFroozen() {
return frozen;
}
// @UiHandler("getResources")
// void getResources(ClickEvent ce){
// getResourcesToPublish();
// }
//
// /**
// * Short the current path if needed
// */
// private void breadcrumbsUpdater(){
//
// // ignore first and last elem
// boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD;
//
// GWT.log("Is to reduce? " + reduce);
//
// GWT.log("Full size is " + pathListBeans.size());
//
// if(!reduce){
// GWT.log("Restore");
// for(int i = 0; i < pathListBeans.size(); i++){
// PathBean bean = pathListBeans.get(i);
// GWT.log("Elem is " + bean.resourceFolder);
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true);
// }
// }else{
// for(int i = 1; i < pathListBeans.size(); i++){
// PathBean bean = pathListBeans.get(i);
//
// if(i == (pathListBeans.size() - 1)){
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true);
// }else if(i == (pathListBeans.size() - 2)){
// GWT.log("The last to modify ****" + bean.resourceFolder.getName());
// bean.link.setText("...");
// bean.link.setVisible(true);
// }else{
// bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(false);
// }
// }
// }
// GWT.log("Updated list is " + pathListBeans.toString());
// }
}

View File

@ -0,0 +1,58 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:m="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection">
<ui:style>
</ui:style>
<g:HTMLPanel>
<b:FluidContainer ui:field="mainContainerResourcesSelection">
<!-- <b:FluidRow> -->
<!-- <b:Column offset="6" size="1"> -->
<!-- <b:Popover ui:field="popoverResourceSelection" html="true"> -->
<!-- <b:Button ui:field="resourceInfoButton" type="LINK" icon="INFO_SIGN" -->
<!-- size="LARGE"></b:Button> -->
<!-- </b:Popover> -->
<!-- </b:Column> -->
<!-- </b:FluidRow> -->
<b:FluidRow>
<b:Column size="11">
<b:Breadcrumbs ui:field="breadcrumbs" divider=">"
title="Current path">
</b:Breadcrumbs>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="3" ui:field="leftColumn">
<!-- <b:Button enabled="true" type="LINK" ui:field="goRootButton">Root
level</b:Button> -->
<!-- <b:Button enabled="true" type="LINK" ui:field="goUpButton">Go up</b:Button> -->
<g:VerticalPanel ui:field="leftContainer" width="100%">
</g:VerticalPanel>
</b:Column>
<b:Column size="1" ui:field="centralPanel">
<g:VerticalPanel ui:field="buttonsPanel">
<b:Button ui:field="allToRightButton" name="toRight"
enabled="false" title="Add selected files" text=">>" />
<b:Button ui:field="toRightButton" name="toRight"
enabled="false" title="Add selected file" text=">" />
<b:Button ui:field="toLeftButton" name="toLeft" enabled="false"
title="Remove selected file" text="&lt;" />
<b:Button ui:field="allToLeftButton" name="toRight"
enabled="false" title="Remove selected files" text="&lt;&lt;" />
</g:VerticalPanel>
</b:Column>
<b:Column size="3" ui:field="rightColumn">
<g:VerticalPanel ui:field="rightContainer" width="100%"></g:VerticalPanel>
</b:Column>
<b:Column size="3" ui:field="detailColumn">
<g:SimplePanel ui:field="detailContainer" width="100%"></g:SimplePanel>
</b:Column>
<!-- <b:Column size="2"> -->
<!-- <m:ResourceInfoForm ui:field="resourceInfoForm"></m:ResourceInfoForm> -->
<!-- </b:Column> -->
</b:FluidRow>
</b:FluidContainer>
<!-- <b:Button ui:field="getResources">Get Resources</b:Button> -->
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,155 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.utils;
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
import org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection.ResourceInfoForm;
import com.github.gwtbootstrap.client.ui.Paragraph;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Widget;
/**
* Extended version of the GcubeDialog with close symbol on the caption
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class GcubeDialogExtended extends GCubeDialog {
/**
* For simple information
* @param captionText
* @param text
*/
public GcubeDialogExtended(String captionText, String text){
// add custom style
addStyleName("metadata-popup-panel");
// create an anchor to close the dialogbox
final Anchor closeAnchor = new Anchor("x");
closeAnchor.setTitle("Close");
// create a panel that will be put into the caption
FlexTable captionLayoutTable = new FlexTable();
captionLayoutTable.setText(0, 0, captionText);
captionLayoutTable.setWidget(0, 3, closeAnchor);
captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_RIGHT);
captionLayoutTable.setWidth("100%");
HTML caption = (HTML) getCaption();
caption.getElement().getStyle().setCursor(Cursor.MOVE);
caption.getElement().appendChild(captionLayoutTable.getElement());
caption.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// get the event
EventTarget target = event.getNativeEvent().getEventTarget();
Element targetElement = (Element) target.cast();
// fire the event to the anchor
if (targetElement == closeAnchor.getElement()) {
closeAnchor.fireEvent(event);
}
}
});
closeAnchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hide();
}
});
add(new Paragraph(text));
}
/**
* For simple information
* @param captionText
* @param text
*/
public GcubeDialogExtended(final ResourceInfoForm form){
// add custom style
addStyleName("metadata-popup-panel");
// create an anchor to close the dialogbox
final Anchor closeAnchor = new Anchor("x");
closeAnchor.setTitle("Close");
closeAnchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hide();
}
});
// create a panel that will be put into the caption
FlexTable captionLayoutTable = new FlexTable();
captionLayoutTable.setText(0, 0, "About Resource");
captionLayoutTable.setWidget(0, 3, closeAnchor);
captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_RIGHT);
captionLayoutTable.setWidth("100%");
HTML caption = (HTML) getCaption();
caption.getElement().getStyle().setCursor(Cursor.MOVE);
caption.getElement().appendChild(captionLayoutTable.getElement());
caption.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
EventTarget target = event.getNativeEvent().getEventTarget();
Element targetElement = (Element) target.cast();
if (targetElement == closeAnchor.getElement()) {
closeAnchor.fireEvent(event);
}
}
});
setWidget(form);
Widget widget = getWidget();
ClickHandler click = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
EventTarget target = event.getNativeEvent().getEventTarget();
Element targetElement = (Element) target.cast();
GWT.log("Target elem is " + targetElement);
if (targetElement == form.resourceDescription.getElement()) {
GWT.log("Fired click");
form.resourceDescription.fireEvent(event);
}else if (targetElement == form.resourceName.getElement()) {
GWT.log("Fired click");
form.resourceName.fireEvent(event);
}else if(targetElement == form.getElement()){
form.fireEvent(event);
}
}
};
widget.addDomHandler(click, ClickEvent.getType());
widget.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(DoubleClickEvent event) {
EventTarget target = event.getNativeEvent().getEventTarget();
Element targetElement = (Element) target.cast();
GWT.log("Target elem is " + targetElement);
if (targetElement == form.resourceDescription.getElement()) {
GWT.log("Fired click");
form.resourceDescription.fireEvent(event);
}else if (targetElement == form.resourceName.getElement()) {
GWT.log("Fired click");
form.resourceName.fireEvent(event);
}else if(targetElement == form.getElement()){
form.fireEvent(event);
}
}
}, DoubleClickEvent.getType());
}
}

View File

@ -0,0 +1,198 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.utils;
import java.util.List;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.Popover;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
/**
* Labels and texts for core ckan information
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class InfoIconsLabels {
// TAGS
public static final String TAGS_INFO_ID_POPUP = "tags-popup-panel-info";
public static final String TAGS_INFO_CAPTION = "Tags";
public static final String TAGS_INFO_TEXT = "Tags are meaningful information that can be associated to the "
+ "item and by means of them it can be retrieved. A tag can contain only alphanumeric characters. "
+ "If the tag is composed by a single word it must have a size of at least two characters."
+ "Examples of good tags: \"This is a sample tag\", \"tagY\". Example of bad tag: \"c\"."
+ " You must push ENTER for attaching a tag, or use the provided list of predefined tags. In the latter case"
+ " hold down the CTRL or CMD button to select multiple options.";
// LICENSES
public static final String LICENSES_INFO_ID_POPUP = "licenses-popup-panel-info";
public static final String LICENSES_INFO_CAPTION = "Licenses";
public static final String LICENSES_INFO_TEXT = "License definitions and additional information can be found at <a href=\"http://opendefinition.org/licenses/\" target=\"_blank\">opendefinition.org</a>";
// VISIBILITY
public static final String VISIBILITY_INFO_ID_POPUP = "visibility-popup-panel-info";
public static final String VISIBILITY_INFO_CAPTION = "Visibility";
public static final String VISIBILITY_INFO_TEXT = "Restricted items can only be accessed by certain users, while public items can be accessed by anyone.";
// AUTHOR
public static final String AUTHOR_INFO_ID_POPUP = "author-popup-panel-info";
public static final String AUTHOR_INFO_CAPTION = "Author's fullname";
public static final String AUTHOR_INFO_TEXT = "The author of this item. Example: Joe Bloggs.";
// AUTHOR EMAIL
public static final String AUTHOR_EMAIL_INFO_ID_POPUP = "author-email-popup-panel-info";
public static final String AUTHOR_EMAIL_INFO_CAPTION = "Author's email";
public static final String AUTHOR_EMAIL_INFO_TEXT = "The author's email. Example: joe.bloggs@catalogue.com";
// MAINTAINER
public static final String MAINTAINER_INFO_ID_POPUP = "maintainer-popup-panel-info";
public static final String MAINTAINER_INFO_CAPTION = "Maintainer";
public static final String MAINTAINER_INFO_TEXT = "The maintainer of this item (a person or an organization). Examples: Joe Bloggs, D4Science";
// MAINTAINER EMAIL
public static final String MAINTAINER_EMAIL_INFO_ID_POPUP = "maintainer-email-popup-panel-info";
public static final String MAINTAINER_EMAIL_INFO_CAPTION = "Maintainer's email";
public static final String MAINTAINER_EMAIL_INFO_TEXT = "The maintainer's email. Example: joe.bloggs@catalogue.com";
// PROFILES
public static final String PROFILES_INFO_ID_POPUP = "product-profiles-popup-panel-info";
public static final String PROFILES_INFO_CAPTION = "Item Types";
public static final String PROFILES_INFO_TEXT = "Select a type, different from none, for your item among the ones available";
// RESOURCES
public static final String RESOURCES_INFO_ID_POPUP = "resouces-popup-panel-info";
public static final String RESOURCES_INFO_CAPTION = "Manage resource items";
public static final String RESOURCES_INFO_TEXT = "Move the files you want to attach to the item on the right panel below. Double click on the item for changing resource's name or description."
+ " Please consider that any complex hierarchy structure you may have will be flatten.";
// CUSTOM FIELDS
public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info";
public static final String CUSTOM_FIELDS_INFO_CAPTION = "Item Custom Fields";
public static final String CUSTOM_FIELDS_INFO_TEXT = "Custom fields are customable metadata that will be added to the item. You can remove them at any time until you create the item.";
// TITLE
public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info";
public static final String TITLE_INFO_TEXT = "Item Title must contain only alphanumer characters, dots, underscore or hyphen minus. No others symbols are allowed. Please note that this field will be always visible, despite the item's visibility.";
public static final String TITLE_INFO_CAPTION = "Item Title";
// DESCRIPTION
public static final String DESCRIPTION_INFO_ID_POPUP = "description-popup-panel-info";
public static final String DESCRIPTION_INFO_TEXT = "Description of a few sentences, written in plain language. Should provide a sufficiently comprehensive overview of the resource for anyone, "
+ "to understand its content, origins, and any continuing work on it. The description can be written at the end, since it summarizes key, information from the other metadata fields. Please note that this field will be always visible, despite the item's visibility.";
public static final String DESCRIPTION_INFO_CAPTION = "Item Description";
// GROUPS
public static final String GROUPS_INFO_ID_POPUP = "groups-popup-panel-info";
public static final String GROUPS_INFO_TEXT = "Associate this item to groups. A group is a view of items belonging to one or more organization.";
public static final String GROUPS_INFO_CAPTION = "Item Groups";
/**
* Prepare the popover and the gcube popup panel for information.
* @param text
* @param captionText
* @param iconElement
* @param popover
* @param focusPanel
*/
public static void preparePopupPanelAndPopover(
final String popupId,
final String text,
final String captionText,
Icon iconElement,
Popover popover,
FocusPanel focusPanel,
final List<String> popupOpenedIds
){
// prepare the popover
popover.setText(new HTML("<p style='color:initial'>" + text +"</p>").getHTML());
popover.setHeading(new HTML("<b>" + captionText +"</b>").getHTML());
// set icon cursor
iconElement.getElement().getStyle().setCursor(Cursor.HELP);
// prepare the gcube dialog
focusPanel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// Retrieve elemnt that should have this id
GcubeDialogExtended popup = null;
try{
Element element = DOM.getElementById(popupId);
popup = (GcubeDialogExtended) Widget.asWidgetOrNull(getWidget(element));
}catch(Exception e){
GWT.log("ERROR", e);
}
// if it doesn't exist, create it
if(popup == null){
popup = new GcubeDialogExtended(captionText, text);
popup.getElement().setId(popupId);
popup.setModal(false);
// add its id
popupOpenedIds.add(popupId);
}
// then center and show
popup.center();
popup.show();
}
});
}
/**
* Check if an element of such type is actually a widget
* @param element
* @return
*/
public static IsWidget getWidget(Element element) {
EventListener listener = DOM
.getEventListener(element);
// No listener attached to the element, so no widget exist for this
// element
if (listener == null) {
GWT.log("Widget is NULL");
return null;
}
if (listener instanceof Widget) {
// GWT uses the widget as event listener
GWT.log("Widget is " + listener);
return (Widget) listener;
}
return null;
}
/**
* Close any dialog box opened
*/
public static void closeDialogBox(List<String> popupOpenedIds) {
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);
}
}
}
}

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
*/
public class MetadataDiscovery {
private static final Logger logger = LoggerFactory.getLogger(MetadataDiscovery.class);
private static final Logger LOG = LoggerFactory.getLogger(MetadataDiscovery.class);
/**
* Gets the profiles names.
@ -67,7 +67,7 @@ public class MetadataDiscovery {
return toReturn;
} catch (Exception e) {
logger.error("Failed to fetch profiles", e);
LOG.error("Failed to fetch profiles", e);
} finally {
ScopeProvider.instance.set(currentContext);
}
@ -88,7 +88,7 @@ public class MetadataDiscovery {
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
logger.debug("Discovering into scope " + scope);
LOG.debug("Discovering into scope " + scope);
String currentContext = ScopeProvider.instance.get();
try {
@ -100,155 +100,29 @@ public class MetadataDiscovery {
MetadataProfileReader reader = new MetadataProfileReader(gRSecondaryType);
List<MetadataProfile> profiles = reader.getListOfMetadataProfiles();
logger.debug("Profiles are " + profiles);
LOG.debug("Profiles are " + profiles);
List<NamespaceCategory> categories = reader.getListOfNamespaceCategories();
if (categories == null)
categories = new ArrayList<NamespaceCategory>();
logger.debug("All Categories are " + categories);
LOG.debug("All Categories are " + categories);
for (MetadataProfile profile : profiles) {
logger.debug(
LOG.debug(
"Wrapping profile with name " + profile.getName() + " and type " + profile.getMetadataType());
MetadataFormat metadata = reader.getMetadataFormatForMetadataProfile(profile);
MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName());
beans.add(bean);
/*
String type = metadata.getType();
String title = profile.getName();
List<MetadataField> fields = metadata.getMetadataFields();
// we need to wrap the list of metadata and categories
List<MetadataFieldWrapper> fieldsWrapper = new ArrayList<MetadataFieldWrapper>(
fields != null ? fields.size() : 0);
List<CategoryWrapper> categoriesWrapper = new ArrayList<CategoryWrapper>(categories.size());
Map<String, CategoryWrapper> idToCategory = new HashMap<String, CategoryWrapper>(categories.size());
// manage the categories
for (NamespaceCategory category : categories) {
CategoryWrapper categoryWrapped = new CategoryWrapper(category.getId(), category.getTitle(),
category.getDescription());
categoriesWrapper.add(categoryWrapped);
idToCategory.put(category.getId(), categoryWrapped);
}
// also evaluate the fields for each category
Map<String, List<MetadataFieldWrapper>> fieldsPerCategory = new HashMap<String, List<MetadataFieldWrapper>>(
categoriesWrapper.size());
// manage the fields
if (fields != null)
for (MetadataField metadataField : fields) {
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
wrapperObj.setFieldNameFromCategory(metadataField.getCategoryFieldQName());
wrapperObj.setType(DataTypeWrapper.valueOf(metadataField.getDataType().toString()));
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
wrapperObj.setFieldName(metadataField.getFieldName());
wrapperObj.setMandatory(metadataField.getMandatory());
wrapperObj.setNote(metadataField.getNote());
MetadataValidator validator = metadataField.getValidator();
if (validator != null)
wrapperObj.setValidator(validator.getRegularExpression());
MetadataVocabulary vocabulary = metadataField.getVocabulary();
if (vocabulary != null) {
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
}
MetadataTagging tagging = metadataField.getTagging();
if (tagging != null) {
FieldAsTag tag = new FieldAsTag();
tag.setCreate(tagging.getCreate());
tag.setSeparator(tagging.getSeparator());
tag.setTaggingValue(TaggingGroupingValue.valueOf(tagging.getTaggingValue().toString()));
wrapperObj.setAsTag(tag);
}
MetadataGrouping grouping = metadataField.getGrouping();
if (grouping != null) {
FieldAsGroup group = new FieldAsGroup();
group.setCreate(grouping.getCreate());
group.setPropagateUp(grouping.getPropagateUp());
group.setGroupingValue(
TaggingGroupingValue.valueOf(grouping.getGroupingValue().toString()));
wrapperObj.setAsGroup(group);
}
// set to which category this field belongs to and vice-versa
if (metadataField.getCategoryRef() != null) {
CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef());
if (ownerCategory == null) {
logger.warn("A field with categoryref " + metadataField.getCategoryRef()
+ " has been found, but"
+ " such category is not defined within the namespaces");
} else {
wrapperObj.setOwnerCategory(ownerCategory);
List<MetadataFieldWrapper> fieldsPerCategoryN = fieldsPerCategory
.get(metadataField.getCategoryRef());
if (fieldsPerCategoryN == null)
fieldsPerCategoryN = new ArrayList<MetadataFieldWrapper>();
fieldsPerCategoryN.add(wrapperObj);
fieldsPerCategory.put(metadataField.getCategoryRef(), fieldsPerCategoryN);
// instead of re-looping on the fieldsPerCategory map later, just set this
// potentially partial list
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN);
}
}
// Added by Francesco
int maxOccurs = 1; // Default value is 1. A field should occur once.
if (metadataField.getMaxOccurs() != null) {
try {
// the field can appear an unlimited number of times.
if (metadataField.getMaxOccurs().equals("*")) {
maxOccurs = Integer.MAX_VALUE;
} else {
// the field must appear N times;
maxOccurs = Integer.parseInt(metadataField.getMaxOccurs());
}
} catch (Exception e) {
// silent
}
wrapperObj.setMaxOccurs(maxOccurs);
}
fieldsWrapper.add(wrapperObj);
}
// filter the categories without children here
Iterator<CategoryWrapper> categoryToRemoveIT = categoriesWrapper.iterator();
while (categoryToRemoveIT.hasNext()) {
CategoryWrapper categoryWrapper = (CategoryWrapper) categoryToRemoveIT.next();
if (categoryWrapper.getFieldsForThisCategory() == null)
categoryToRemoveIT.remove();
}
MetaDataProfileBean bean = new MetaDataProfileBean(type, title, fieldsWrapper, categoriesWrapper);
beans.add(bean);
*/
}
logger.debug("List of beans is " + beans);
LOG.debug("List of beans is " + beans);
} catch (Exception e) {
logger.error("Error while retrieving metadata beans ", e);
LOG.error("Error while retrieving metadata beans ", e);
throw new Exception("Failed to parse Types: " + e.getMessage());
} finally {
ScopeProvider.instance.set(currentContext);
@ -258,19 +132,28 @@ public class MetadataDiscovery {
}
/**
* Gets the metadata profiles.
* Gets the metadata profile.
*
* @param metadataProfileStream the metadata profile stream
* @return the metadata profiles
* @return the metadata profile
* @throws JAXBException the JAXB exception
*/
public MetaDataProfileBean getMetadataProfiles(InputStream metadataProfileStream) throws JAXBException {
public static MetaDataProfileBean getMetadataProfile(InputStream metadataProfileStream) throws JAXBException {
MetadataFormat metadata = MetadataProfileReader.toMetadataFormat(metadataProfileStream);
return toMetaDataProfileBean(metadata, null, null);
}
/**
* To meta data profile bean.
*
* @param metadata the metadata
* @param categories the categories
* @param profileName the profile name
* @return the meta data profile bean
*/
private static MetaDataProfileBean toMetaDataProfileBean(MetadataFormat metadata, List<NamespaceCategory> categories, String profileName){
String type = metadata.getType();
@ -345,7 +228,7 @@ public class MetadataDiscovery {
CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef());
if (ownerCategory == null) {
logger.warn("A field with categoryref " + metadataField.getCategoryRef()
LOG.warn("A field with categoryref " + metadataField.getCategoryRef()
+ " has been found, but"
+ " such category is not defined within the namespaces");
} else {

View File

@ -1,7 +1,15 @@
package org.gcube.portlets.widgets.mpformbuilder.server;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService;
import org.gcube.portlets.widgets.mpformbuilder.shared.FieldVerifier;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@ -9,41 +17,58 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet implements
MetadataProfileFormBuilderService {
public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet
implements MetadataProfileFormBuilderService {
public String greetServer(String input) throws IllegalArgumentException {
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
private static final Logger LOG = LoggerFactory.getLogger(MetadataProfileFormBuilderServiceImpl.class);
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
}
// Escape data from the client to avoid cross-site script vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
@Override
public List<MetaDataProfileBean> getProfilesInTheScope(String scope,String genericResourceSecondaryType) throws Exception {
LOG.info("Called getProfilesInTheScope with parameter scope: " +scope+ ", genericResourceSecondaryType: "+genericResourceSecondaryType);
if(genericResourceSecondaryType==null || genericResourceSecondaryType.isEmpty())
throw new Exception("The input parameter 'genericResourceSecondaryType' is not valid");
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
try {
String evaluatedScope = scope == null || scope.isEmpty()?ScopeProvider.instance.get():scope;
LOG.debug("Evaluated scope is " + scope);
toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, genericResourceSecondaryType);
} catch (Exception e) {
LOG.error("Failed to retrieve profiles for scope " +scope, e);
throw e;
}
return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;
}
return toReturn;
}
@Override
public MetaDataProfileBean getProfileForMetadata(String metadata) throws Exception {
LOG.info("Called getProfileForMetadata with parameter metadata: " + metadata);
MetaDataProfileBean toReturn = null;
try {
InputStream targetStream = new ByteArrayInputStream(metadata.getBytes());
toReturn = MetadataDiscovery.getMetadataProfile(targetStream);
} catch (Exception e) {
LOG.error("Failed to retrieve profile for metadata " +metadata, e);
throw e;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(
">", "&gt;");
}
return toReturn;
}
}

View File

@ -0,0 +1,335 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.catalogue;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
/**
* This bean will contain during ckan metadata creation information related to the future build.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
@SuppressWarnings("serial")
public class DatasetBean implements Serializable {
private String id;
private String title;
private String description;
private String license; // chosen by the user
private String source; // url of the folder in the workspace
private String authorName; // author name
private String authorSurname; // author surname
private String authorFullName;
private String authorEmail; // owner's email
private String maintainer;
private String maintainerEmail;
private String ownerIdentifier; // owner of the folder into the workspace (e.g., andrea.rossi)
private String chosenType; // the name of the MetaDataType chosen
private String selectedOrganization;
private long version; // version 1, 2 ...
private boolean visible; // Private (false) or Public(true)
private List<OrganizationBean> organizationList; // list of organization in which the user is present and could create the dataset
private ResourceElementBean resourceRoot; // in case of workspace, this is the directory root or the single file information
private List<MetaDataProfileBean> metadataList;
private List<String> tags; // on retrieve, they are the keys of the product
private List<String> tagsVocabulary; // when available
private Map<String, List<String>> customFields;
private List<OrganizationBean> groups;
private List<OrganizationBean> groupsForceCreation;
public DatasetBean(){
super();
}
/** Create a metadata bean object.
* @param id
* @param title
* @param description
* @param customFields
* @param tags
* @param license
* @param visibility
* @param source
* @param version
* @param author
* @param authorEmail
* @param maintainer
* @param maintainerEmail
* @param ownerIdentifier
* @param organizationList
* @param selectedOrganization
* @param resourcesIds
* @param addResources
* @param metadataList
*/
public DatasetBean(String id, String title, String description,
Map<String, List<String>> customFields, List<String> tags,
String license, boolean visible, String source, long version,
String authorName, String authorSurname, String authorEmail, String maintainer,
String maintainerEmail, String ownerIdentifier,
List<OrganizationBean> organizationList, String selectedOrganization,
ResourceElementBean resourceRoot,
List<MetaDataProfileBean> metadataList, List<OrganizationBean> groups, List<String> tagsVocabulary) {
super();
this.id = id;
this.title = title;
this.description = description;
this.customFields = customFields;
this.tags = tags;
this.license = license;
this.visible = visible;
this.source = source;
this.version = version;
this.authorName = authorName;
this.authorSurname = authorSurname;
this.authorEmail = authorEmail;
this.maintainer = maintainer;
this.maintainerEmail = maintainerEmail;
this.ownerIdentifier = ownerIdentifier;
this.organizationList = organizationList;
this.selectedOrganization = selectedOrganization;
this.resourceRoot = resourceRoot;
this.metadataList = metadataList;
this.groups = groups;
this.tagsVocabulary = tagsVocabulary;
}
public String getChosenType() {
return chosenType;
}
public void setChosenType(String chosenType) {
this.chosenType = chosenType;
}
public List<MetaDataProfileBean> getMetadataList() {
return metadataList;
}
public void setMetadataList(List<MetaDataProfileBean> metadataListTypes) {
this.metadataList = metadataListTypes;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOwnerIdentifier() {
return ownerIdentifier;
}
public void setOwnerIdentifier(String ownerIdentifier) {
this.ownerIdentifier = ownerIdentifier;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Map<String, List<String>> getCustomFields() {
return customFields;
}
public void setCustomFields(Map<String, List<String>> customFields) {
this.customFields = customFields;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = license;
}
public boolean getVisibility() {
return visible;
}
public void setVisibile(boolean visibile) {
this.visible = visibile;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getAuthorSurname() {
return authorSurname;
}
public void setAuthorSurname(String authorSurname) {
this.authorSurname = authorSurname;
}
public String getAuthorEmail() {
return authorEmail;
}
public void setAuthorEmail(String authorEmail) {
this.authorEmail = authorEmail;
}
public String getMaintainer() {
return maintainer;
}
public void setMaintainer(String maintainer) {
this.maintainer = maintainer;
}
public String getMaintainerEmail() {
return maintainerEmail;
}
public void setMaintainerEmail(String maintainerEmail) {
this.maintainerEmail = maintainerEmail;
}
public List<OrganizationBean> getOrganizationList() {
return organizationList;
}
public void setOrganizationList(List<OrganizationBean> organizationList) {
this.organizationList = organizationList;
}
public String getSelectedOrganization() {
return selectedOrganization;
}
public void setSelectedOrganization(String selectedOrganization) {
this.selectedOrganization = selectedOrganization;
}
public ResourceElementBean getResourceRoot() {
return resourceRoot;
}
public void setResourceRoot(ResourceElementBean resourceRoot) {
this.resourceRoot = resourceRoot;
}
public String getAuthorFullName() {
return authorFullName;
}
public void setAuthorFullName(String authorFullName) {
this.authorFullName = authorFullName;
}
public List<OrganizationBean> getGroups() {
return groups;
}
public void setGroups(List<OrganizationBean> groups) {
this.groups = groups;
}
public List<String> getTagsVocabulary() {
return tagsVocabulary;
}
public void setTagsVocabulary(List<String> tagsVocabulary) {
this.tagsVocabulary = tagsVocabulary;
}
public List<OrganizationBean> getGroupsForceCreation() {
return groupsForceCreation;
}
public void setGroupsForceCreation(List<OrganizationBean> groupsForceCreation) {
this.groupsForceCreation = groupsForceCreation;
}
@Override
public String toString() {
return "DatasetBean ["
+ (id != null ? "id=" + id + ", " : "")
+ (title != null ? "title=" + title + ", " : "")
+ (description != null ? "description=" + description + ", "
: "")
+ (license != null ? "license=" + license + ", " : "")
+ (source != null ? "source=" + source + ", " : "")
+ (authorName != null ? "authorName=" + authorName + ", " : "")
+ (authorSurname != null ? "authorSurname=" + authorSurname
+ ", " : "")
+ (authorFullName != null ? "authorFullName=" + authorFullName
+ ", " : "")
+ (authorEmail != null ? "authorEmail=" + authorEmail + ", "
: "")
+ (maintainer != null ? "maintainer=" + maintainer + ", " : "")
+ (maintainerEmail != null ? "maintainerEmail="
+ maintainerEmail + ", " : "")
+ (ownerIdentifier != null ? "ownerIdentifier="
+ ownerIdentifier + ", " : "")
+ (chosenType != null ? "chosenType=" + chosenType + ", " : "")
+ (selectedOrganization != null ? "selectedOrganization="
+ selectedOrganization + ", " : "")
+ "version="
+ version
+ ", visible="
+ visible
+ ", "
+ (organizationList != null ? "organizationList="
+ organizationList + ", " : "")
+ (resourceRoot != null ? "resourceRoot=" + resourceRoot + ", "
: "")
+ (metadataList != null ? "metadataList=" + metadataList + ", "
: "")
+ (tags != null ? "tags=" + tags + ", " : "")
+ (tagsVocabulary != null ? "tagsVocabulary=" + tagsVocabulary
+ ", " : "")
+ (customFields != null ? "customFields=" + customFields + ", "
: "")
+ (groups != null ? "groups=" + groups + ", " : "")
+ (groupsForceCreation != null ? "groupsForceCreation="
+ groupsForceCreation : "") + "]";
}
}

View File

@ -0,0 +1,75 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.catalogue;
import java.io.Serializable;
/**
* A ckan organization/group (you can check its nature by looking at getIsOrganization();) like bean with name and title
* @author Costantino Perciante (costantino.perciante@isti.cnr.it)
*/
public class OrganizationBean implements Serializable{
private static final long serialVersionUID = -6566519399945530602L;
private String title;
private String name;
private boolean isOrganization;
private boolean propagateUp; // an item linked to this group has to be added on the whole hierarchy chain
public OrganizationBean(){
super();
}
public OrganizationBean(String title, String name, boolean isOrganization) {
super();
this.title = title;
this.name = name;
this.isOrganization = isOrganization;
}
public OrganizationBean(String title, String name, boolean isOrganization, boolean propagateUp) {
super();
this.title = title;
this.name = name;
this.isOrganization = isOrganization;
this.propagateUp = propagateUp;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isOrganization() {
return isOrganization;
}
public void setOrganization(boolean isOrganization) {
this.isOrganization = isOrganization;
}
public boolean isPropagateUp() {
return propagateUp;
}
public void setPropagateUp(boolean propagateUp) {
this.propagateUp = propagateUp;
}
@Override
public String toString() {
return "OrganizationBean [title=" + title + ", name=" + name
+ ", isOrganization=" + isOrganization + ", propagateUp="
+ propagateUp + "]";
}
}

View File

@ -0,0 +1,252 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.catalogue;
import java.io.Serializable;
import java.util.List;
import com.google.gwt.view.client.ProvidesKey;
/**
* A resource element bean. Contains part of the logic used into the TwinColumn widget
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable{
private static final long serialVersionUID = -1230871392599580669L;
private String name;
private String editableName;
private boolean toBeAdded;
private boolean isFolder;
private String fullPath;
private String originalIdInWorkspace;
private String mimeType;
private String url;
private String description;
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
private ResourceElementBean parent;
private List<ResourceElementBean> children;
// to generate the GWT identifiers
private static int nextId = 0;
// identifier of this instance
private int identifierGWT;
/**
* The key provider that provides the unique ID of a bean.
*/
public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() {
@Override
public Object getKey(ResourceElementBean item) {
return item == null ? null : item.identifierGWT;
}
};
/**
* Copy constructor
* @param another
*/
public ResourceElementBean(ResourceElementBean another) {
this.name = another.name;
this.toBeAdded = another.toBeAdded;
this.fullPath = another.fullPath;
this.editableName = another.editableName;
this.originalIdInWorkspace = another.originalIdInWorkspace;
this.mimeType = another.mimeType;
this.url = another.url;
this.description = another.description;
this.organizationNameDatasetParent = another.organizationNameDatasetParent;
}
/**
* Default constructor
*/
public ResourceElementBean(){
super();
this.identifierGWT = nextId;
nextId++;
}
/**
* @param identifier
* @param parentFolder
* @param name
* @param movedToRight
* @param isFolder
*/
public ResourceElementBean(
ResourceElementBean parent,
String name,
boolean isFolder,
List<ResourceElementBean> children,
String fullPath) {
this.identifierGWT = nextId;
nextId++;
this.parent = parent;
this.name = name;
this.isFolder = isFolder;
this.children = children;
this.fullPath = fullPath;
}
/**
* @param name
* @param toBeAdded
* @param isFolder
* @param parent
* @param children
* @param fullPath
* @param originalIdInWorkspace
* @param mimeType
* @param url
* @param description
* @param organizationNameDatasetParent
*/
public ResourceElementBean(String name, boolean toBeAdded,
boolean isFolder, ResourceElementBean parent,
List<ResourceElementBean> children, String fullPath,
String originalIdInWorkspace, String mimeType, String url,
String description, String organizationNameDatasetParent) {
super();
this.identifierGWT = nextId;
nextId++;
this.name = name;
this.toBeAdded = toBeAdded;
this.isFolder = isFolder;
this.parent = parent;
this.children = children;
this.fullPath = fullPath;
this.originalIdInWorkspace = originalIdInWorkspace;
this.mimeType = mimeType;
this.url = url;
this.description = description;
this.organizationNameDatasetParent = organizationNameDatasetParent;
}
public ResourceElementBean getParent() {
return parent;
}
public void setParent(ResourceElementBean parent) {
this.parent = parent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isToBeAdded() {
return toBeAdded;
}
public void setToBeAdded(boolean toBeAdded) {
this.toBeAdded = toBeAdded;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getOrganizationNameDatasetParent() {
return organizationNameDatasetParent;
}
public void setOrganizationNameDatasetParent(
String organizationNameDatasetParent) {
this.organizationNameDatasetParent = organizationNameDatasetParent;
}
public boolean isFolder() {
return isFolder;
}
public void setFolder(boolean isFolder) {
this.isFolder = isFolder;
}
public List<ResourceElementBean> getChildren() {
return children;
}
public void setChildren(List<ResourceElementBean> children) {
this.children = children;
}
public String getFullPath() {
return fullPath;
}
public void setFullPath(String fullPath) {
this.fullPath = fullPath;
}
public String getOriginalIdInWorkspace() {
return originalIdInWorkspace;
}
public void setOriginalIdInWorkspace(String originalIdInWorkspace) {
this.originalIdInWorkspace = originalIdInWorkspace;
}
public String getEditableName() {
return editableName;
}
public void setEditableName(String newName) {
this.editableName = newName;
}
@Override
public boolean equals(Object o) {
boolean toReturn = false;
if (o instanceof ResourceElementBean) {
toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT;
}
return toReturn;
}
@Override
public int compareTo(ResourceElementBean o) {
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
return toReturn;
}
@Override
public String toString() {
return "ResourceElementBean [identifierGWT=" + identifierGWT
+ ", name=" + name + ", editableName=" + editableName
+ ", toBeAdded=" + toBeAdded + ", isFolder=" + isFolder
+ ", fullPath=" + fullPath + ", originalIdInWorkspace="
+ originalIdInWorkspace + ", mimeType=" + mimeType + ", url="
+ url + ", description=" + description
+ ", organizationNameDatasetParent="
+ organizationNameDatasetParent + ", parent=" + parent
+ ", children number=" + (children == null ? 0 : children.size()) + "]";
}
}

View File

@ -3,17 +3,25 @@
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Responsive design -->
<set-property name="bootstrap.responsiveDesign" value="true" />
<inherits name='com.github.gwtbootstrap.datetimepicker.Datetimepicker' />
<inherits name='com.github.gwtbootstrap.datepicker.Datepicker' />
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='com.google.gwt.json.JSON'/>
<inherits
name='org.gcube.portlets.widgets.openlayerbasicwidgets.olbasicwidgets' />
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<!--<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />-->
<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />
<!-- Specify the paths for translatable code -->
<source path='client' />

View File

@ -17,7 +17,7 @@
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<title>"Metadata Profile Form Builder Web Application</title>
<!-- -->
<!-- This script loads your compiled module. -->
@ -46,18 +46,6 @@
</noscript>
<h1>Web Application Starter Project</h1>
<table align="center">
<tr>
<td colspan="2" style="font-weight:bold;">Please enter your name:</td>
</tr>
<tr>
<td id="nameFieldContainer"></td>
<td id="sendButtonContainer"></td>
</tr>
<tr>
<td colspan="2" style="color:red;" id="errorLabelContainer"></td>
</tr>
</table>
<div id="metadataprofileformbuilder"></div>
</body>
</html>

View File

@ -7,13 +7,13 @@
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-name>mpformbuilderServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/MetadataProfileFormBuilder/greet</url-pattern>
<servlet-name>mpformbuilderServlet</servlet-name>
<url-pattern>/MetadataProfileFormBuilder/mpformbuilderservice</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->