2022-09-13 13:52:44 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.action;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2022-09-15 17:58:04 +02:00
|
|
|
import java.util.Set;
|
2022-09-13 13:52:44 +02:00
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
2022-09-13 13:52:44 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
2022-10-06 11:25:31 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp;
|
2022-09-13 16:18:40 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.WorkflowActionOnSelectedItemEvent;
|
2022-09-13 13:52:44 +02:00
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
|
|
import com.github.gwtbootstrap.client.ui.ButtonGroup;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2022-09-13 16:18:40 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2022-09-13 13:52:44 +02:00
|
|
|
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.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class ActionListPanel extends Composite {
|
|
|
|
|
|
|
|
private static ActionListPanelUiBinder uiBinder = GWT.create(ActionListPanelUiBinder.class);
|
|
|
|
|
|
|
|
interface ActionListPanelUiBinder extends UiBinder<Widget, ActionListPanel> {
|
|
|
|
}
|
|
|
|
|
|
|
|
private String projectName;
|
|
|
|
private String profileID;
|
|
|
|
private List<ActionDefinitionDV> listActionDefinition;
|
2022-09-13 16:18:40 +02:00
|
|
|
private HandlerManager appManagerBus;
|
2022-09-13 13:52:44 +02:00
|
|
|
|
2022-09-13 16:18:40 +02:00
|
|
|
public ActionListPanel(HandlerManager appManagerBus,String projectName, String profileID, List<ActionDefinitionDV> listActionDef) {
|
2022-09-13 13:52:44 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
GWT.log("Adding list of actions: " + listActionDef);
|
2022-09-13 16:18:40 +02:00
|
|
|
this.appManagerBus = appManagerBus;
|
2022-09-13 13:52:44 +02:00
|
|
|
this.projectName = projectName;
|
|
|
|
this.profileID = profileID;
|
|
|
|
this.listActionDefinition = listActionDef;
|
2022-09-13 16:18:40 +02:00
|
|
|
initActions(listActionDefinition);
|
2022-09-13 13:52:44 +02:00
|
|
|
actionListBasePanel.setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel actionListContainer;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel actionListBasePanel;
|
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
private Map<String, List<ActionDefButton>> mapPhaseListButtons;
|
2022-09-13 13:52:44 +02:00
|
|
|
|
|
|
|
private void initActions(List<ActionDefinitionDV> listActionDef) {
|
|
|
|
|
|
|
|
if (listActionDef.size() > 0) {
|
|
|
|
//actionListBasePanel.setVisible(true);
|
|
|
|
|
|
|
|
ButtonGroup buttonGroup = new ButtonGroup();
|
|
|
|
buttonGroup.getElement().addClassName("actions-button-group");
|
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
mapPhaseListButtons = new LinkedHashMap<String, List<ActionDefButton>>();
|
2022-09-13 13:52:44 +02:00
|
|
|
|
|
|
|
for (ActionDefinitionDV actionDefinitionDV : listActionDef) {
|
2022-10-06 11:25:31 +02:00
|
|
|
|
|
|
|
//skipping the special workflow action
|
|
|
|
if(actionDefinitionDV.getId().equals(ConstantsGeoPortalDataEntryApp.WORKFLOW_ACTION_POST_CREATION_ACTION_ID)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-13 13:52:44 +02:00
|
|
|
Button butt = new Button();
|
|
|
|
butt.setText(actionDefinitionDV.getTitle());
|
|
|
|
butt.setTitle(actionDefinitionDV.getDescription());
|
|
|
|
butt.setType(ButtonType.LINK);
|
|
|
|
butt.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
2022-09-13 16:18:40 +02:00
|
|
|
|
|
|
|
appManagerBus.fireEvent(new WorkflowActionOnSelectedItemEvent<ResultDocumentDV>(actionDefinitionDV));
|
2022-09-13 13:52:44 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
String[] displayOnPhases = actionDefinitionDV.getDisplayOnPhase();
|
|
|
|
|
|
|
|
for (String displayOnPhase : displayOnPhases) {
|
2022-09-15 17:58:04 +02:00
|
|
|
List<ActionDefButton> mapPhase = mapPhaseListButtons.get(displayOnPhase);
|
2022-09-13 13:52:44 +02:00
|
|
|
if (mapPhase == null)
|
2022-09-15 17:58:04 +02:00
|
|
|
mapPhase = new ArrayList<ActionDefButton>();
|
2022-09-13 13:52:44 +02:00
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
mapPhase.add(new ActionDefButton(actionDefinitionDV, butt));
|
2022-09-13 13:52:44 +02:00
|
|
|
mapPhaseListButtons.put(displayOnPhase, mapPhase);
|
|
|
|
}
|
|
|
|
buttonGroup.add(butt);
|
|
|
|
}
|
|
|
|
|
|
|
|
actionListContainer.add(buttonGroup);
|
|
|
|
} else {
|
|
|
|
actionListBasePanel.setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
public <T> void showActionsOnSelected(List<T> listSelected, GcubeUserRole userRole) {
|
2022-09-13 13:52:44 +02:00
|
|
|
setAllActionsVisible(false);
|
|
|
|
|
|
|
|
if (listSelected.size() == 1) {
|
|
|
|
|
|
|
|
for (T item : listSelected) {
|
|
|
|
|
|
|
|
if (item instanceof ResultDocumentDV) {
|
|
|
|
|
|
|
|
String itemPhase = ((ResultDocumentDV) item).getLifecycleInfo().getPhase();
|
|
|
|
|
2022-09-15 17:58:04 +02:00
|
|
|
List<ActionDefButton> listButtons = mapPhaseListButtons.get(itemPhase);
|
|
|
|
for (ActionDefButton actionDefButton : listButtons) {
|
|
|
|
|
|
|
|
Set<String> roles = actionDefButton.getActionDefinitionDV().getRoles();
|
|
|
|
|
|
|
|
//No role/s defined means enable the action by default
|
|
|
|
if(roles.isEmpty()) {
|
|
|
|
actionDefButton.getButton().setVisible(true);
|
|
|
|
actionListBasePanel.setVisible(true);
|
|
|
|
}else {
|
|
|
|
//Checking if the userRole is matching the role defined in the ActionDefinition
|
|
|
|
boolean isRoleIntoActionDef= roles.stream().anyMatch(userRole.getName()::equalsIgnoreCase);
|
|
|
|
if(isRoleIntoActionDef) {
|
|
|
|
actionDefButton.getButton().setVisible(true);
|
|
|
|
actionListBasePanel.setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 13:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setAllActionsVisible(boolean bool) {
|
2022-09-15 17:58:04 +02:00
|
|
|
Iterator<List<ActionDefButton>> collIterator = mapPhaseListButtons.values().iterator();
|
2022-09-13 13:52:44 +02:00
|
|
|
while (collIterator.hasNext()) {
|
2022-09-15 17:58:04 +02:00
|
|
|
List<ActionDefButton> listButton = collIterator.next();
|
|
|
|
for (ActionDefButton actionDefButton : listButton) {
|
|
|
|
actionDefButton.getButton().setVisible(bool);
|
2022-09-13 13:52:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|