workspace-tree-widget/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.java

449 lines
12 KiB
Java
Raw Normal View History

2020-07-08 18:14:06 +02:00
package org.gcube.portlets.user.workspace.client.view.windows;
2020-07-13 15:35:02 +02:00
import java.util.Date;
2020-07-08 18:14:06 +02:00
import java.util.List;
2020-07-10 18:14:15 +02:00
import java.util.Map;
2020-07-08 18:14:06 +02:00
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
2020-07-13 15:35:02 +02:00
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
2020-07-10 15:07:03 +02:00
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
2020-07-13 15:35:02 +02:00
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
2020-07-08 18:14:06 +02:00
import org.gcube.portlets.user.workspace.client.model.FileModel;
2020-07-10 18:14:15 +02:00
import com.github.gwtbootstrap.client.ui.Button;
2020-07-08 18:14:06 +02:00
import com.github.gwtbootstrap.client.ui.ControlGroup;
2020-07-10 15:07:03 +02:00
import com.github.gwtbootstrap.client.ui.Label;
2020-07-08 18:14:06 +02:00
import com.github.gwtbootstrap.client.ui.TextArea;
2020-07-10 15:07:03 +02:00
import com.github.gwtbootstrap.client.ui.constants.LabelType;
2020-07-13 15:35:02 +02:00
import com.github.gwtbootstrap.client.ui.constants.ResizeType;
2020-07-08 18:14:06 +02:00
import com.google.gwt.core.client.GWT;
2020-07-10 15:07:03 +02:00
import com.google.gwt.dom.client.Style.Unit;
2020-07-10 12:55:36 +02:00
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
2020-07-10 18:14:15 +02:00
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
2020-07-13 15:35:02 +02:00
import com.google.gwt.i18n.client.NumberFormat;
2020-07-08 18:14:06 +02:00
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
2020-07-10 18:14:15 +02:00
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
2020-07-08 18:14:06 +02:00
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
2020-07-10 12:55:36 +02:00
import com.google.gwt.user.client.ui.HTML;
2020-07-10 15:07:03 +02:00
import com.google.gwt.user.client.ui.HorizontalPanel;
2020-07-08 18:14:06 +02:00
import com.google.gwt.user.client.ui.Widget;
public class DialogGetInfoBootstrap extends Composite {
private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class);
interface DialogGetInfoBootstrapUiBinder extends UiBinder<Widget, DialogGetInfoBootstrap> {
}
2020-07-13 15:35:02 +02:00
public static final String EMPTY = "empty";
private final NumberFormat number = ConstantsExplorer.numberFormatterKB;
2020-07-08 18:14:06 +02:00
public DialogGetInfoBootstrap() {
initWidget(uiBinder.createAndBindUi(this));
}
2020-07-13 15:35:02 +02:00
public static final String NOT_AVAILABLE = "n.a.";
2020-07-10 18:14:15 +02:00
private Map<String, String> gCubeProperties;
2020-07-08 18:14:06 +02:00
2020-07-10 15:07:03 +02:00
@UiField
HorizontalPanel hpItemType;
2020-07-13 15:35:02 +02:00
@UiField
HorizontalPanel hpHeaderDetails;
2020-07-10 18:14:15 +02:00
2020-07-08 18:14:06 +02:00
@UiField
2020-07-10 12:55:36 +02:00
HTML txtName;
2020-07-08 18:14:06 +02:00
@UiField
2020-07-10 12:55:36 +02:00
HTML txtId;
2020-07-08 18:14:06 +02:00
@UiField
2020-07-10 12:55:36 +02:00
HTML txtLocation;
2020-07-08 18:14:06 +02:00
@UiField
ControlGroup cgTxtIsPublic;
@UiField
2020-07-10 12:55:36 +02:00
HTML txtIsPublic;
2020-07-08 18:14:06 +02:00
2020-07-13 15:35:02 +02:00
@UiField
HTML txtMimeType;
2020-07-10 18:14:15 +02:00
@UiField
ControlGroup cgThreddsSynched;
@UiField
HTML txtThreddsSynched;
@UiField
ControlGroup cgGcubeProperties;
@UiField
TextArea txtAreaGcubeProperties;
2020-07-08 18:14:06 +02:00
@UiField
TextArea txtAreaDescription;
2020-07-13 15:35:02 +02:00
@UiField
HTML txtOwner;
@UiField
HTML txtCreated;
@UiField
HTML txtLastMofication;
@UiField
HTML txtSize;
@UiField
HTML txtShared;
2020-07-10 18:14:15 +02:00
@UiField
Button buttonUpdateDescription;
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
@UiField
Button buttonUpdateGcubeProperties;
private FileModel fileModel;
2020-07-13 15:35:02 +02:00
2020-07-08 18:14:06 +02:00
/*
* textAreaSharedWith = new TextArea(); private Html htmlUsersWidget = new
* Html(); private Html htmlPropertiesWidget = new Html(); private final
* NumberFormat number = ConstantsExplorer.numberFormatterKB; // private
* TextField<String> txtGcubeItemProperties; private HorizontalPanel
* hpGcubeProperties; private DialogEditProperties editProperties = null;
*/
public DialogGetInfoBootstrap(final FileModel fileModel) {
initWidget(uiBinder.createAndBindUi(this));
2020-07-10 18:14:15 +02:00
this.fileModel = fileModel;
2020-07-13 15:35:02 +02:00
hpHeaderDetails.add(new HTML("Details"));
2020-07-10 18:14:15 +02:00
2020-07-10 15:07:03 +02:00
hpItemType.add(fileModel.getIcon());
Label labelItemType = new Label();
labelItemType.setType(LabelType.INFO);
labelItemType.getElement().getStyle().setMarginLeft(10, Unit.PX);
String label = null;
2020-07-10 18:14:15 +02:00
2020-07-10 15:07:03 +02:00
GXTFolderItemTypeEnum typeEnum = fileModel.getGXTFolderItemType();
2020-07-10 18:14:15 +02:00
if (typeEnum != null) {
2020-07-10 15:07:03 +02:00
label = typeEnum.getLabel();
label = label.replace("External ", "");
2020-07-13 15:35:02 +02:00
// loading gcube properties
if (typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM))
2020-07-10 18:14:15 +02:00
loadGcubeItemProperties();
} else {
2020-07-10 15:07:03 +02:00
label = fileModel.getType();
}
2020-07-10 18:14:15 +02:00
2020-07-10 15:07:03 +02:00
labelItemType.setText(label);
hpItemType.add(labelItemType);
2020-07-08 18:14:06 +02:00
// Setting name
2020-07-10 12:55:36 +02:00
htmlSetValue(txtName, fileModel.getName());
htmlSetValue(txtId, fileModel.getIdentifier());
2020-07-08 18:14:06 +02:00
if (fileModel.isRoot())
2020-07-10 12:55:36 +02:00
txtLocation.setHTML("/");
2020-07-08 18:14:06 +02:00
else
loadLocation(fileModel.getIdentifier());
if (fileModel.isDirectory()) {
cgTxtIsPublic.setVisible(true);
2020-07-10 18:14:15 +02:00
htmlSetValue(txtIsPublic, fileModel.isPublic() + "");
if (fileModel.getSynchedThreddsStatus() != null) {
txtThreddsSynched.setVisible(true);
htmlSetValue(txtThreddsSynched, fileModel.getSynchedThreddsStatus() + "");
txtThreddsSynched.setHTML(fileModel.getSynchedThreddsStatus() + "");
}
2020-07-08 18:14:06 +02:00
}
2020-07-13 15:35:02 +02:00
//mimetype
htmlSetValue(txtMimeType, fileModel.getType());
2020-07-08 18:14:06 +02:00
2020-07-13 15:35:02 +02:00
txtAreaDescription.setResize(ResizeType.VERTICAL);
2020-07-08 18:14:06 +02:00
if (fileModel.isDirectory()) {
txtAreaDescription.setValue(fileModel.getDescription());
// add(txtAreaDescription);
} else
loadDescription(fileModel.getIdentifier());
2020-07-10 18:14:15 +02:00
2020-07-13 15:35:02 +02:00
//owner
htmlSetValue(txtOwner, fileModel.getOwnerFullName());
//creation date
loadCreationDate(fileModel.getIdentifier());
if(fileModel instanceof FileGridModel) {
FileGridModel fileGridModel = ((FileGridModel) fileModel);
//last update
htmlSetValue(txtLastMofication, fileGridModel.getLastModification().toString());
//size
htmlSetValue(txtSize, getFormattedSize(fileGridModel.getSize()));
}else {
loadLastModificationDate(fileModel.getIdentifier());
loadSize(fileModel.getIdentifier());
}
htmlSetValue(txtShared, fileModel.isShared()+"");
2020-07-10 12:55:36 +02:00
addHandlers();
}
2020-07-10 18:14:15 +02:00
2020-07-10 12:55:36 +02:00
private void addHandlers() {
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
txtAreaDescription.addKeyPressHandler(new KeyPressHandler() {
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
@Override
public void onKeyPress(KeyPressEvent event) {
2020-07-13 15:35:02 +02:00
GWT.log(event.getUnicodeCharCode() + "");
if (event.getUnicodeCharCode() == 13) {
2020-07-10 18:14:15 +02:00
txtAreaDescription.setReadOnly(true);
Window.alert("Updating description");
}
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
}
});
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
buttonUpdateDescription.addClickHandler(new ClickHandler() {
2020-07-13 15:35:02 +02:00
2020-07-10 12:55:36 +02:00
@Override
public void onClick(ClickEvent event) {
2020-07-10 18:14:15 +02:00
txtAreaDescription.setReadOnly(false);
txtAreaDescription.setFocus(true);
}
});
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
final Command cmdReloadProperties = new Command() {
@Override
public void execute() {
loadGcubeItemProperties();
}
};
2020-07-13 15:35:02 +02:00
2020-07-10 18:14:15 +02:00
buttonUpdateGcubeProperties.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
2020-07-13 15:35:02 +02:00
final DialogEditProperties editProperties = new DialogEditProperties(fileModel, cmdReloadProperties);
2020-07-10 18:14:15 +02:00
editProperties.show();
2020-07-13 15:35:02 +02:00
editProperties.setProperties(gCubeProperties);
2020-07-10 12:55:36 +02:00
}
});
2020-07-08 18:14:06 +02:00
}
2020-07-10 12:55:36 +02:00
private void htmlSetValue(HTML field, String value) {
2020-07-08 18:14:06 +02:00
if (value == null || value.isEmpty())
2020-07-13 15:35:02 +02:00
field.setHTML(NOT_AVAILABLE);
2020-07-08 18:14:06 +02:00
else
2020-07-10 12:55:36 +02:00
field.setHTML(value);
2020-07-08 18:14:06 +02:00
}
2020-07-13 15:35:02 +02:00
private String getFormattedSize(long value) {
if (value > 0) {
double kb = value / 1024;
if (kb < 1)
kb = 1;
return number.format(kb);
} else if (value == 0) {
return EMPTY;
} else
return "";
}
2020-07-08 18:14:06 +02:00
private void loadLocation(String itemId) {
2020-07-10 12:55:36 +02:00
setPlaceholder(txtLocation, "loading...");
2020-07-08 18:14:06 +02:00
AppControllerExplorer.rpcWorkspaceService.getListParentsByItemIdentifier(itemId, false,
new AsyncCallback<List<FileModel>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("failure get list parents by item identifier " + caught);
2020-07-10 12:55:36 +02:00
removePlaceHolder(txtLocation);
2020-07-13 15:35:02 +02:00
txtLocation.setHTML(NOT_AVAILABLE);
2020-07-10 18:14:15 +02:00
// txtLocation.set(false);
2020-07-08 18:14:06 +02:00
}
@Override
public void onSuccess(List<FileModel> result) {
2020-07-10 12:55:36 +02:00
removePlaceHolder(txtLocation);
2020-07-10 18:14:15 +02:00
2020-07-08 18:14:06 +02:00
String location = "";
if (result != null) {
for (FileModel fileModel : result) {
if (fileModel != null)
location += "/" + fileModel.getName();
}
}
if (location.isEmpty())
location = "/";
2020-07-10 12:55:36 +02:00
txtLocation.setHTML(location);
2020-07-08 18:14:06 +02:00
}
});
}
2020-07-13 15:35:02 +02:00
private void loadSize(final String itemId) {
GWT.log("Load size");
setPlaceholder(txtSize, "loading...");
AppControllerExplorer.rpcWorkspaceService.loadSizeByItemId(itemId, new AsyncCallback<Long>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured in load creation date by Id " + itemId + " " + caught.getMessage());
removePlaceHolder(txtSize);
}
@Override
public void onSuccess(Long result) {
GWT.log("Loaded size=" + result);
removePlaceHolder(txtSize);
if(result!=null)
htmlSetValue(txtSize, getFormattedSize(result));
else
htmlSetValue(txtSize, null);
}
});
}
private void loadCreationDate(final String itemId) {
setPlaceholder(txtCreated, "loading...");
AppControllerExplorer.rpcWorkspaceService.getItemCreationDateById(itemId, new AsyncCallback<Date>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured in load creation date by Id " + itemId + " " + caught.getMessage());
removePlaceHolder(txtCreated);
}
@Override
public void onSuccess(Date result) {
removePlaceHolder(txtCreated);
if (result != null)
htmlSetValue(txtCreated, result.toString());
else
htmlSetValue(txtCreated, null);
}
});
}
private void loadLastModificationDate(final String itemId) {
setPlaceholder(txtLastMofication, "loading...");
AppControllerExplorer.rpcWorkspaceService.loadLastModificationDateById(itemId, new AsyncCallback<Date>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("an error occured in loadLastModificationDateById " + itemId + " " + caught.getMessage());
removePlaceHolder(txtLastMofication);
}
@Override
public void onSuccess(Date result) {
removePlaceHolder(txtLastMofication);
if (result != null)
htmlSetValue(txtLastMofication, result.toString());
else
htmlSetValue(txtLastMofication, null);
}
});
}
2020-07-10 18:14:15 +02:00
2020-07-08 18:14:06 +02:00
/**
* @param identifier
*/
private void loadDescription(String identifier) {
txtAreaDescription.setEnabled(false);
AppControllerExplorer.rpcWorkspaceService.getItemDescriptionById(identifier, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable arg0) {
txtAreaDescription.setEnabled(false);
}
@Override
public void onSuccess(String result) {
if (result != null)
txtAreaDescription.setValue(result);
else
txtAreaDescription.setValue("");
txtAreaDescription.setEnabled(true);
}
});
}
2020-07-10 18:14:15 +02:00
private void loadGcubeItemProperties() {
// mask("Loading properties...");
AppControllerExplorer.rpcWorkspaceService.loadGcubeItemProperties(fileModel.getIdentifier(),
new AsyncCallback<Map<String, String>>() {
@Override
public void onSuccess(Map<String, String> result) {
txtAreaGcubeProperties.setText("");
2020-07-13 15:35:02 +02:00
GWT.log("Gcube Item Properties: " + result);
2020-07-10 18:14:15 +02:00
gCubeProperties = result;
// unmask();
2020-07-13 15:35:02 +02:00
if (result != null && result.size() > 0) {
2020-07-10 18:14:15 +02:00
for (String key : result.keySet()) {
String text = txtAreaGcubeProperties.getText();
2020-07-13 15:35:02 +02:00
text += key + "=" + result.get(key) + ";\n";
2020-07-10 18:14:15 +02:00
txtAreaGcubeProperties.setText(text);
}
cgGcubeProperties.setVisible(true);
}
}
@Override
public void onFailure(Throwable caught) {
// unmask();
cgGcubeProperties.setVisible(false);
2020-07-13 15:35:02 +02:00
GWT.log("an error occured in loadGcubeItemProperties " + fileModel.getIdentifier() + " "
+ caught.getMessage());
2020-07-10 18:14:15 +02:00
}
});
}
2020-07-10 12:55:36 +02:00
private void setPlaceholder(HTML html, String placeholder) {
html.setHTML(placeholder);
html.getElement().getStyle().setColor("#E8E8E8");
}
2020-07-10 18:14:15 +02:00
2020-07-10 12:55:36 +02:00
private void removePlaceHolder(HTML html) {
html.setHTML("");
html.getElement().getStyle().setColor("#000");
}
2020-07-08 18:14:06 +02:00
}