/** * */ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ClickedCMSManageProductButtonEvent; 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.PublishOnZenodoEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShareLinkEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowDatasetsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowGroupsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowHomeEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowManageProductWidgetEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowOrganizationsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowStatisticsEvent; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowTypesEvent; import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.google.gwt.dom.client.Style.Float; 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.event.shared.HandlerManager; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.InlineHTML; /** * The Class CkanMetadataManagementPanel. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Costantino Perciante costantino.perciante@isti.cnr.it Jun 9, 2016 * */ public class CkanMetadataManagementPanel extends FlowPanel { /** * */ private static final String MY_PREFIX = "My "; private static final String MANAGE_GRSF_ITEM_TOOLTIP = "By pushing on this button, you will be able to manage the item you are viewing." + " Manageable items are the GRSF ones."; private static final String MANAGE_CMS_ITEMS_TOOLTIP = "By pushing on this button, you will be able to manage (APPROVING or REJECTING) the item under approval" + "Manageable items are not APPROVED and NOT PUBLISHED in the Catalogue."; private AlertBlock nav = new AlertBlock(); // generic private Button home = new Button("Home"); private Button organizations = new Button("Organizations"); private Button groups = new Button("Groups"); private Button items = new Button("Items"); private Button types = new Button("Types"); // user's own private InlineHTML separatorMyInfo = null; private InlineHTML separatorAdminButtons = null; private Button myDatasets = new Button("My Items"); private Button myOrganizations = new Button("My Organizations"); private Button myGroups = new Button("My Groups"); // statistics private Button statistics = new Button("Statistics"); // other stuff private Button shareLink = new Button("Share Link"); private Button uploadToZenodo = new Button("Upload to Zenodo"); private Button insertMeta = new Button("Publish Item"); private Button editMeta = new Button("Edit Item"); private Button manageGRSFProduct = new Button("Manage GRSF Item"); private Button manageCMS = new Button("Manage Items"); private HandlerManager eventBus; /** * Instantiates a new ckan metadata management panel. * * @param eventBus the event bus */ public CkanMetadataManagementPanel(HandlerManager eventBus) { this.eventBus = eventBus; // this.getElement().getStyle().setPaddingTop(H_OFFSET, Unit.PX); // this.getElement().getStyle().setPaddingBottom(H_OFFSET, Unit.PX); // set link style buttons home.setType(ButtonType.LINK); organizations.setType(ButtonType.LINK); groups.setType(ButtonType.LINK); items.setType(ButtonType.LINK); types.setType(ButtonType.LINK); myDatasets.setType(ButtonType.LINK); myOrganizations.setType(ButtonType.LINK); myGroups.setType(ButtonType.LINK); statistics.setType(ButtonType.LINK); shareLink.setType(ButtonType.LINK); uploadToZenodo.setType(ButtonType.LINK); insertMeta.setType(ButtonType.LINK); editMeta.setType(ButtonType.LINK); manageGRSFProduct.setType(ButtonType.PRIMARY); manageGRSFProduct.getElement().getStyle().setFloat(Float.RIGHT); manageCMS.setType(ButtonType.PRIMARY); manageCMS.getElement().getStyle().setFloat(Float.RIGHT); // set icons home.setIcon(IconType.HOME); organizations.setIcon(IconType.BUILDING); groups.setIcon(IconType.GROUP); items.setIcon(IconType.SITEMAP); types.setIcon(IconType.FILE_TEXT); shareLink.setIcon(IconType.SHARE); uploadToZenodo.setIcon(IconType.CIRCLE_ARROW_UP); myDatasets.setIcon(IconType.SITEMAP); myOrganizations.setIcon(IconType.BUILDING); myGroups.setIcon(IconType.GROUP); insertMeta.setIcon(IconType.FILE); editMeta.setIcon(IconType.EDIT_SIGN); statistics.setIcon(IconType.BAR_CHART); manageGRSFProduct.setIcon(IconType.CHECK_SIGN); manageCMS.setIcon(IconType.CHECK_SIGN); // hide edit and insert shareLink.setEnabled(false); uploadToZenodo.setEnabled(false); editMeta.setVisible(false); insertMeta.setVisible(false); manageGRSFProduct.setVisible(false); manageGRSFProduct.setEnabled(false); manageCMS.setVisible(false); manageCMS.setEnabled(false); // manage GRSF item info manageGRSFProduct.setTitle(MANAGE_GRSF_ITEM_TOOLTIP); manageGRSFProduct.getElement().getStyle().setFontWeight(FontWeight.BOLD); // manage CMS item info manageCMS.setTitle(MANAGE_CMS_ITEMS_TOOLTIP); manageCMS.getElement().getStyle().setFontWeight(FontWeight.BOLD); // add to navigation bar nav.add(home); nav.add(organizations); nav.add(groups); nav.add(items); nav.add(types); nav.add(statistics); separatorMyInfo = new InlineHTML("|"); separatorMyInfo.setVisible(true); nav.add(separatorMyInfo); nav.add(myOrganizations); nav.add(myGroups); nav.add(myDatasets); separatorAdminButtons = new InlineHTML("|"); separatorAdminButtons.setVisible(true); nav.add(separatorAdminButtons); nav.add(shareLink); nav.add(uploadToZenodo); nav.add(insertMeta); nav.add(editMeta); nav.add(manageGRSFProduct); nav.add(manageCMS); nav.setClose(false); nav.setType(AlertType.INFO); nav.getElement().getStyle().setMarginBottom(0, Unit.PX); nav.getElement().getStyle().setBackgroundColor("#FFF"); addHandlers(); add(nav); } /** * Adds the handlers. */ private void addHandlers() { home.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowHomeEvent()); } }); organizations.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowOrganizationsEvent(false)); } }); groups.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowGroupsEvent(false)); } }); items.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowDatasetsEvent(false)); } }); types.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowTypesEvent(false)); } }); insertMeta.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new InsertMetadataEvent()); } }); editMeta.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new EditMetadataEvent()); } }); myDatasets.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowDatasetsEvent(true)); } }); myOrganizations.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowOrganizationsEvent(true)); } }); myGroups.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowGroupsEvent(true)); } }); statistics.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowStatisticsEvent()); } }); manageGRSFProduct.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShowManageProductWidgetEvent( GCubeCkanDataCatalogPanel.getLatestSelectedProductIdentifier())); } }); manageCMS.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ClickedCMSManageProductButtonEvent()); } }); shareLink.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent(new ShareLinkEvent(GCubeCkanDataCatalogPanel.getLatestSelectedProductIdentifier())); } }); uploadToZenodo.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { eventBus.fireEvent( new PublishOnZenodoEvent(GCubeCkanDataCatalogPanel.getLatestSelectedProductIdentifier())); } }); } /** * Gets the current height. * * @return the current height */ public int getCurrentHeight() { return this.getOffsetHeight(); } /** * Those buttons can be only visible when the logged user has role * edit/admin/sysadmin. * * @param show the show */ public void showInsertAndEditProductButtons(boolean show) { // editMeta.setVisible(show); TODO // separatorAdminButtons.setVisible(show); insertMeta.setVisible(show); } /** * Button to manage the GRSF product.. for example in grsf case * * @param value true or false */ public void showManageGRSFProductButton(boolean value) { manageGRSFProduct.setVisible(value); } /** * Enable or disable the manage product button. * * @param value the value */ public void enableManageGRSFProductButton(boolean value) { manageGRSFProduct.setEnabled(value); } /** * Button to manage the CMS products.. * * @param value true or false */ public void showManageCMSProductsButton(boolean value) { manageCMS.setVisible(value); } /** * Enable manage CMS products button. * * @param value the value */ public void enableManageCMSProductsButton(boolean value) { manageCMS.setEnabled(value); } /** * Enable or disable the share link button. * * @param value the value */ public void enableShareItemButton(boolean value) { shareLink.setEnabled(value); } /** * Enable publish on zenodo button. * * @param value the value */ public void enablePublishOnZenodoButton(boolean value) { uploadToZenodo.setEnabled(value); } /** * Visibility publish on zenodo button. * * @param value the value */ public void visibilityPublishOnZenodoButton(boolean value) { uploadToZenodo.setVisible(value); } /** * Show only home/statistics buttons. */ public void doNotShowUserRelatedInfo() { separatorMyInfo.setVisible(false); separatorAdminButtons.setVisible(false); shareLink.setVisible(false); uploadToZenodo.setVisible(false); insertMeta.setVisible(false); editMeta.setVisible(false); myDatasets.setVisible(false); myOrganizations.setVisible(false); myGroups.setVisible(false); manageGRSFProduct.setVisible(false); manageCMS.setVisible(false); } /** * Removes the generic management buttons. */ public void removeGenericManagementButtons() { home.setVisible(true); organizations.setVisible(false); groups.setVisible(false); items.setVisible(false); types.setVisible(false); separatorMyInfo.setVisible(false); separatorAdminButtons.setVisible(false); myDatasets.setVisible(false); myOrganizations.setVisible(false); myGroups.setVisible(false); statistics.setVisible(false); manageGRSFProduct.setVisible(false); manageCMS.setVisible(false); } /** * Customize label according translate. * * @param labelName the label name * @param translateValue the translate value */ public void customizeLabelAccordingTranslate(String labelName, String translateValue) { if (labelName == null || labelName.isEmpty() || translateValue == null || translateValue.isEmpty()) return; // GWT.log("labelName "+labelName); // GWT.log("translateValue "+translateValue); // GWT.log("organizations "+organizations.getText()); if (labelName.compareToIgnoreCase(organizations.getText().trim()) == 0) { organizations.setText(translateValue); // return; } else if (labelName.compareToIgnoreCase(groups.getText().trim()) == 0) { groups.setText(translateValue); // return; } else if (labelName.compareToIgnoreCase(items.getText().trim()) == 0) { items.setText(translateValue); // return; } else if (labelName.compareToIgnoreCase(types.getText().trim()) == 0) { types.setText(translateValue); // return; } String mylabelName = MY_PREFIX + labelName; // GWT.log("mylabelName "+mylabelName); // GWT.log("myDatasets.getText() "+myDatasets.getText()); if (mylabelName.compareToIgnoreCase(myDatasets.getText().trim()) == 0) { myDatasets.setText(MY_PREFIX + translateValue); // return; } else if (mylabelName.compareToIgnoreCase(myOrganizations.getText().trim()) == 0) { myOrganizations.setText(MY_PREFIX + translateValue); // return; } else if (mylabelName.compareToIgnoreCase(myGroups.getText().trim()) == 0) { myGroups.setText(MY_PREFIX + translateValue); // return; } } /** * Capitalize. * * @param stringValue the translate value * @return the string */ public static String capitalize(String stringValue) { return stringValue.substring(0, 1).toUpperCase() + stringValue.substring(1, stringValue.length()); } }