Resource picker widget is almost finished

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@133955 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-08 14:17:41 +00:00
parent ca9eec91a3
commit 41915d6745
11 changed files with 134 additions and 70 deletions

View File

@ -20,6 +20,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 excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">

View File

@ -40,7 +40,7 @@ public interface CKanPublisherService extends RemoteService {
/**
* Try to create such dataset starting from the information contained into the toCreate bean.
* @param toCreate
* @return the sent bean full filled with the needed information
* @return the sent bean filled with the needed information
*/
DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate);

View File

@ -13,12 +13,10 @@ public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
public void render(com.google.gwt.cell.client.Cell.Context context,
ResourceElementBean value, SafeHtmlBuilder sb) {
// Do not render an object if
// - is null;
// - is still on the left side
if (value == null || !value.isMovedToRight() || value.isFolder()) {
return;
}
sb.appendHtmlConstant("<table style='width:100%'");
sb.appendHtmlConstant("<tr><td>");
sb.appendHtmlConstant("<b>");

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnS
import java.util.List;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.view.client.ProvidesKey;
@ -120,14 +119,17 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>{
@Override
public boolean equals(Object o) {
boolean toReturn = false;
if (o instanceof ResourceElementBean) {
return identifier == ((ResourceElementBean) o).identifier;
toReturn = identifier == ((ResourceElementBean) o).identifier;
}
return false;
return toReturn;
}
@Override
public int compareTo(ResourceElementBean o) {
return (o == null || o.name == null) ? -1 : -o.fullPath.compareTo(fullPath);
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
return toReturn;
}
}

View File

@ -89,7 +89,6 @@ public class ShowMorePagerPanel extends AbstractPager{
/**
* 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) {

View File

@ -5,8 +5,11 @@ import java.util.List;
import java.util.Set;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.constants.Placement;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
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;
@ -15,6 +18,7 @@ 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.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
@ -44,9 +48,13 @@ public class TwinColumnSelectionMainPanel extends Composite{
Button allToLeftButton;
@UiField
Button goRootButton;
@UiField
Popover popoverResourceSelection;
@UiField
Button resourceInfoButton;
private final String PANEL_BORDER_COLOR = "#08c";
private final String PANEL_HEIGHT = "400px";
private static final String PANEL_BORDER_COLOR = "#08c";
private static final String PANEL_HEIGHT = "400px";
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel();
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel();
private CellList<ResourceElementBean> cellListLeft;
@ -56,6 +64,9 @@ public class TwinColumnSelectionMainPanel extends Composite{
private MultiSelectionModel<ResourceElementBean> selectionModelRight;
private MultiSelectionModel<ResourceElementBean> selectionModelLeft;
private final List<ResourceElementBean> initialElements;
private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>");
private final static HTML aboutBody = new HTML("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.");
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
.create(TwinColumnSelectionMainPanelUiBinder.class);
@ -70,15 +81,19 @@ public class TwinColumnSelectionMainPanel extends Composite{
this.initialElements = elements;
this.buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT);
goRootButton.getElement().getStyle().setPaddingLeft(0, Unit.PX);
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);
prepareHandlers();
initLeftSidePanel(elements);
initRightSidePanel(elements);
initRightSidePanel();
}
@ -103,26 +118,22 @@ public class TwinColumnSelectionMainPanel extends Composite{
selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator();
while (selectedObjectsIterator.hasNext()) {
ResourceElementBean selectedBean = (ResourceElementBean) selectedObjectsIterator.next();
if(selectedBean.isFolder()){
if(selectionModelLeft.getSelectedSet().size() == 1){
GWT.log("Selected folder");
dataProviderLeft.setList(selectedBean.getChildren());
dataProviderLeft.flush();
dataProviderLeft.refresh();
dataProviderLeft.flush();
}
selectionModelLeft.setSelected(selectedBean, false); // unselect the folder
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
dataProviderLeft.setList(elements);
@ -137,15 +148,12 @@ public class TwinColumnSelectionMainPanel extends Composite{
// add the list to the leftContainerPanel
leftContainer.add(showMorePanelLeft);
}
/**
* Initialize the left side panel
*/
private void initRightSidePanel(List<ResourceElementBean> elements) {
GWT.log("Size is " + elements.size());
private void initRightSidePanel() {
// initialize the left side list
ResourceCellRight cell = new ResourceCellRight();
@ -153,7 +161,6 @@ public class TwinColumnSelectionMainPanel extends Composite{
// 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.setPageSize(elements.size());
// Add a selection model so we can select cells.
selectionModelRight = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
@ -162,15 +169,10 @@ public class TwinColumnSelectionMainPanel extends Composite{
// perform an action on selection
selectionModelRight.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
// enable the buttons that allows to move the objects to the left
enableMoveToLeftButtons(selectionModelRight.getSelectedSet());
}
});
// set the list into the provider
dataProviderRight.setList(elements);
// set the cell list into the provider
dataProviderRight.addDataDisplay(cellListRight);
@ -191,7 +193,11 @@ public class TwinColumnSelectionMainPanel extends Composite{
*/
private void enableMoveToRightButtons(Set<ResourceElementBean> setselectedItemsLeft){
if(setselectedItemsLeft.size() > 1){
if(setselectedItemsLeft == null || setselectedItemsLeft.isEmpty()){
allToRightButton.setEnabled(false);
toRightButton.setEnabled(false);
}
else if(setselectedItemsLeft.size() > 1){
allToRightButton.setEnabled(true);
toRightButton.setEnabled(false);
}
@ -207,7 +213,11 @@ public class TwinColumnSelectionMainPanel extends Composite{
*/
private void enableMoveToLeftButtons(Set<ResourceElementBean> setselectedItemsRight){
if(setselectedItemsRight.size() > 1){
if(setselectedItemsRight == null || setselectedItemsRight.isEmpty()){
allToLeftButton.setEnabled(false);
allToLeftButton.setEnabled(false);
}
else if(setselectedItemsRight.size() > 1){
allToLeftButton.setEnabled(true);
toLeftButton.setEnabled(false);
}
@ -275,51 +285,50 @@ public class TwinColumnSelectionMainPanel extends Composite{
}
/**
* Move to right
* @param toMoveRight
* Move to right elements
* @param set the elements to move
*/
private void moveToRight(Set<ResourceElementBean> set){
private void moveToRight(Set<ResourceElementBean> setSelected){
if(set == null)
if(setSelected == null || setSelected.isEmpty())
return;
Iterator<ResourceElementBean> iterator = set.iterator();
Iterator<ResourceElementBean> iterator = setSelected.iterator();
while (iterator.hasNext()) {
ResourceElementBean resourceElementBean = (ResourceElementBean) iterator
.next();
resourceElementBean.setMovedToRight(true);
GWT.log("To move right " + resourceElementBean);
resourceElementBean.setMovedToRight(true);
boolean contains = dataProviderRight.getList().contains(resourceElementBean);
if(!contains)
dataProviderRight.getList().add(resourceElementBean);
}
// refresh providers
dataProviderLeft.flush();
dataProviderLeft.refresh();
dataProviderRight.flush();
dataProviderLeft.refresh();
dataProviderRight.refresh();
}
/**
* Move to right
* @param toMoveLeft
* Move to left elements
* @param setSelected the elements to move
*/
private void moveToLeft(Set<ResourceElementBean> set){
private void moveToLeft(Set<ResourceElementBean> setSelected){
if(set == null)
if(setSelected == null || setSelected.isEmpty())
return;
Iterator<ResourceElementBean> iterator = set.iterator();
Iterator<ResourceElementBean> iterator = setSelected.iterator();
while (iterator.hasNext()) {
ResourceElementBean resourceElementBean = (ResourceElementBean) iterator
.next();
ResourceElementBean resourceElementBean = (ResourceElementBean) iterator.next();
resourceElementBean.setMovedToRight(false);
GWT.log("To move left " + resourceElementBean);
}
// refresh providers
dataProviderLeft.flush();
dataProviderLeft.refresh();
dataProviderRight.flush();
dataProviderLeft.refresh();
dataProviderRight.refresh();
}

View File

@ -8,6 +8,11 @@
}
</ui:style>
<g:HTMLPanel>
<g:SimplePanel width="100%">
<b:Popover ui:field="popoverResourceSelection" html="true">
<b:Button ui:field="resourceInfoButton" type="LINK" icon="INFO_SIGN" size="LARGE"></b:Button>
</b:Popover>
</g:SimplePanel>
<b:FluidContainer>
<b:FluidRow>
<b:Column size="3" ui:field="leftColumn">
@ -20,15 +25,16 @@
<b:Button ui:field="allToRightButton" name="toRight"
enabled="false" title="Move selected files to right" text=">>" />
<b:Button ui:field="toRightButton" name="toRight"
enabled="false" title="Move file to the right" text=">" />
enabled="false" title="Move selected file to the right" text=">" />
<b:Button ui:field="toLeftButton" name="toLeft" enabled="false"
title="Move file to the left" text="&lt;" />
title="Move selected file to the left" text="&lt;" />
<b:Button ui:field="allToLeftButton" name="toRight"
enabled="false" title="Move selected files to left" text="&lt;&lt;" />
</g:VerticalPanel>
</b:Column>
<b:Column size="3" ui:field="rightColumn">
<g:VerticalPanel ui:field="rightContainer" styleName="{style.right-vertical-panel}" width="100%"></g:VerticalPanel>
<g:VerticalPanel ui:field="rightContainer"
styleName="{style.right-vertical-panel}" width="100%"></g:VerticalPanel>
</b:Column>
</b:FluidRow>
</b:FluidContainer>

View File

@ -60,12 +60,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
public DataCatalogue getCatalogue(String scope){
DataCatalogue instance = null;
String scopeInWhichDiscover = null;
try{
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope();
scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope();
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
}catch(Exception e){
logger.error("Unable to retrieve ckan utils", e);
logger.error("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover, e);
}
return instance;
}

View File

@ -241,9 +241,6 @@ public class Utils {
logger.debug("Organization name is " + organizationName);
// if(organizationName.equals(CKanUtilsImpl.PRODUCTION_CKAN_ORGNAME_ROOT))
// return CKanUtilsImpl.PRODUCTION_SCOPE_ROOT;
GroupManager gm = new LiferayGroupManager();
List<GCubeGroup> groups = gm.listGroups();
for (GCubeGroup gCubeGroup : groups) {

View File

@ -101,20 +101,21 @@ public class WorkspaceUtils {
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(userName).getWorkspace();
.getHome().getWorkspace();
WorkspaceItem originalFolder = ws.getItem(folderId);
// set some info
String onlyAlphanumeric = originalFolder.getName().replaceAll("[^A-Za-z0-9.-_]", " "); // that is, remove characters different than the ones inside
bean.setTitle(onlyAlphanumeric);
String onlyAlphanumericTitle = originalFolder.getName().replaceAll("[^A-Za-z0-9.-_]", " "); // that is, remove characters different than the ones inside
// since it will (likely) be the name of the product
bean.setTitle(onlyAlphanumericTitle);
bean.setDescription(originalFolder.getDescription());
// Create the folder in the catalogue
Map<String, String> folderItems = Utils.getGcubeItemProperties(originalFolder);
bean.setCustomFields(folderItems);
// check the resources within the folder (skip subdirectories for now TODO)
// check the resources within the folder
List<String> childrenIds = new ArrayList<String>();
for (WorkspaceItem file : originalFolder.getChildren()) {

View File

@ -17,12 +17,14 @@ public class ResourceBeanWrapper implements Serializable{
private boolean toBeAdded;
private String mimeType;
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
private List<ResourceBeanWrapper> subResources; // a list of sub resources TODO
private List<ResourceBeanWrapper> subResources; // a list of sub resources
private ResourceBeanWrapper parentResource;
private boolean isFolder;
public ResourceBeanWrapper(){
super();
}
/**
* @param url
* @param name
@ -30,9 +32,16 @@ public class ResourceBeanWrapper implements Serializable{
* @param id
* @param toBeAdded
* @param mimeType
* @param organizationNameDatasetParent
* @param subResources
* @param parentResource
* @param isFolder
*/
public ResourceBeanWrapper(String url, String name, String description,
String id, boolean toBeAdded, String mimeType, String organizationNameDatasetParent) {
String id, boolean toBeAdded, String mimeType,
String organizationNameDatasetParent,
List<ResourceBeanWrapper> subResources,
ResourceBeanWrapper parentResource, boolean isFolder) {
super();
this.url = url;
this.name = name;
@ -41,6 +50,31 @@ public class ResourceBeanWrapper implements Serializable{
this.toBeAdded = toBeAdded;
this.mimeType = mimeType;
this.organizationNameDatasetParent = organizationNameDatasetParent;
this.subResources = subResources;
this.parentResource = parentResource;
this.isFolder = isFolder;
}
/**
* Used when the user adds the resources after having created the product
* @param url
* @param name
* @param description
* @param id
* @param toAdd
* @param mimeType
* @param datasetOrg
*/
public ResourceBeanWrapper(String url, String name, String description,
String id, boolean toAdd, String mimeType, String datasetOrg) {
super();
this.id = id;
this.url = url;
this.name = name;
this.description = description;
this.toBeAdded = toAdd;
this.mimeType = mimeType;
this.organizationNameDatasetParent = datasetOrg;
}
/**
@ -84,7 +118,7 @@ public class ResourceBeanWrapper implements Serializable{
public void setDescription(String description) {
this.description = description;
}
/**
* @return the id
*/
@ -126,7 +160,7 @@ public class ResourceBeanWrapper implements Serializable{
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
/**
* @return the organizationNameDatasetParent
*/
@ -141,8 +175,7 @@ public class ResourceBeanWrapper implements Serializable{
String organizationNameDatasetParent) {
this.organizationNameDatasetParent = organizationNameDatasetParent;
}
public List<ResourceBeanWrapper> getSubResources() {
return subResources;
}
@ -151,6 +184,22 @@ public class ResourceBeanWrapper implements Serializable{
this.subResources = subResources;
}
public ResourceBeanWrapper getParentResource() {
return parentResource;
}
public void setParentResource(ResourceBeanWrapper parentResource) {
this.parentResource = parentResource;
}
public boolean isFolder() {
return isFolder;
}
public void setFolder(boolean isFolder) {
this.isFolder = isFolder;
}
@Override
public String toString() {
return "ResourceBeanWrapper [url=" + url + ", name=" + name
@ -158,6 +207,7 @@ public class ResourceBeanWrapper implements Serializable{
+ ", toBeAdded=" + toBeAdded + ", mimeType=" + mimeType
+ ", organizationNameDatasetParent="
+ organizationNameDatasetParent + ", subResources="
+ subResources + "]";
+ subResources + ", parentResource=" + parentResource
+ ", isFolder=" + isFolder + "]";
}
}