diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/CkanEventHandlerManager.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/CkanEventHandlerManager.java index 5e43ffa..ed35422 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/CkanEventHandlerManager.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/CkanEventHandlerManager.java @@ -4,6 +4,8 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.EditMetada import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.EditMetadataEventHandler; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.InsertMetadataEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.InsertMetadataEventHandler; +import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowHomeEvent; +import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowHomeEventHandler; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowStatisticsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowStatisticsEventHandler; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserDatasetsEvent; @@ -37,6 +39,38 @@ public class CkanEventHandlerManager { private void bind() { + + // bind on show home event + eventBus.addHandler(ShowHomeEvent.TYPE, new ShowHomeEventHandler() { + + @Override + public void onShowHome(ShowHomeEvent showHomeEvent) { + + // get the current path + String currentPath = Window.Location.getHref(); + + // check if the "path" parameter is already present + String currentParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER); + + String finalPath; + + if(currentParameter == null){ + finalPath = currentPath; + + }else{ + + // remove from the first "path" on + int index = currentPath.lastIndexOf("?"+GCubeCkanDataCatalog.GET_PATH_PARAMETER); + String firstPartOfThePath = currentPath.substring(0, index); + finalPath = firstPartOfThePath; + + } + + // redirect + Window.Location.assign(finalPath); + + } + }); // bind on insert metadata eventBus.addHandler(InsertMetadataEvent.TYPE, new InsertMetadataEventHandler() { diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEvent.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEvent.java new file mode 100644 index 0000000..b01b759 --- /dev/null +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEvent.java @@ -0,0 +1,35 @@ +package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * Raised when the user wants to go to the catalogue home + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class ShowHomeEvent extends GwtEvent { + public static Type TYPE = new Type(); + + + /** + * Instantiates a new insert metadata event. + */ + public ShowHomeEvent() { + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler) + */ + @Override + protected void dispatch(ShowHomeEventHandler handler) { + handler.onShowHome(this); + } + +} diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEventHandler.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEventHandler.java new file mode 100644 index 0000000..48b5c28 --- /dev/null +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/event/ShowHomeEventHandler.java @@ -0,0 +1,17 @@ +package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The event handler interface for the show home event. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public interface ShowHomeEventHandler extends EventHandler { + + /** + * + * @param showHomeEvent + */ + void onShowHome(ShowHomeEvent showHomeEvent); + +} diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/CkanMetadataManagementPanel.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/CkanMetadataManagementPanel.java index 94c56d6..3842472 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/CkanMetadataManagementPanel.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/CkanMetadataManagementPanel.java @@ -5,6 +5,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.EditMetadataEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.InsertMetadataEvent; +import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowHomeEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowStatisticsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserDatasetsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowUserOrganizationsEvent; @@ -31,6 +32,7 @@ import com.google.gwt.user.client.ui.FlowPanel; public class CkanMetadataManagementPanel extends FlowPanel{ private AlertBlock nav = new AlertBlock(); + private Button home = new Button("Home"); private Button insertMeta = new Button("Publish Product"); private Button editMeta = new Button("Edit Product"); private Button myDatasets = new Button("My Products"); @@ -48,6 +50,7 @@ public class CkanMetadataManagementPanel extends FlowPanel{ // this.getElement().getStyle().setPaddingBottom(H_OFFSET, Unit.PX); // set link style buttons + home.setType(ButtonType.LINK); myDatasets.setType(ButtonType.LINK); myOrganizations.setType(ButtonType.LINK); insertMeta.setType(ButtonType.LINK); @@ -55,6 +58,7 @@ public class CkanMetadataManagementPanel extends FlowPanel{ statistics.setType(ButtonType.LINK); // set icons + home.setIcon(IconType.HOME); myDatasets.setIcon(IconType.SITEMAP); myOrganizations.setIcon(IconType.BUILDING); insertMeta.setIcon(IconType.FILE); @@ -66,6 +70,7 @@ public class CkanMetadataManagementPanel extends FlowPanel{ insertMeta.setVisible(false); // add to navigation bar + nav.add(home); nav.add(myDatasets); nav.add(myOrganizations); nav.add(statistics); @@ -83,6 +88,16 @@ public class CkanMetadataManagementPanel extends FlowPanel{ * */ private void addHandlers() { + + home.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + eventBus.fireEvent(new ShowHomeEvent()); + + } + }); insertMeta.addClickHandler(new ClickHandler() {