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

323 lines
8.7 KiB
Java
Raw Normal View History

2020-07-08 18:14:06 +02:00
package org.gcube.portlets.user.workspace.client.view.windows;
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-10 15:07:03 +02:00
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
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-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-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> {
}
public DialogGetInfoBootstrap() {
initWidget(uiBinder.createAndBindUi(this));
}
public static final String UNKNOWN = "unknown";
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-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-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-10 18:14:15 +02:00
@UiField
Button buttonUpdateDescription;
@UiField
Button buttonUpdateGcubeProperties;
private FileModel fileModel;
2020-07-08 18:14:06 +02:00
/*
* TextField<String> txtType = new TextField<String>(); private
* TextField<String> txtCategory = new TextField<String>(); private
* TextField<String> txtOwner = new TextField<String>(); private
* TextField<String> txtLastMofication = new TextField<String>(); private
* TextField<String> txtCreated = new TextField<String>(); private
* TextField<String> txtSize = new TextField<String>(); private
* TextField<String> txtLocation = new TextField<String>(); private
* TextField<String> txtIsPublic = new TextField<String>(); private
* TextField<String> txtThreddsSynched = new TextField<String>(); private
* TextField<String> txtShared = new TextField<String>(); // private TextArea
* 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-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-10 18:14:15 +02:00
//loading gcube properties
if(typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM))
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
}
if (fileModel.isDirectory()) {
txtAreaDescription.setValue(fileModel.getDescription());
// add(txtAreaDescription);
} else
loadDescription(fileModel.getIdentifier());
2020-07-10 18:14:15 +02:00
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-10 18:14:15 +02:00
txtAreaDescription.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
GWT.log(event.getUnicodeCharCode()+"");
if(event.getUnicodeCharCode()==13) {
txtAreaDescription.setReadOnly(true);
Window.alert("Updating description");
}
}
});
buttonUpdateDescription.addClickHandler(new ClickHandler() {
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);
}
});
final Command cmdReloadProperties = new Command() {
@Override
public void execute() {
loadGcubeItemProperties();
}
};
buttonUpdateGcubeProperties.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
DialogEditProperties editProperties = new DialogEditProperties(fileModel, cmdReloadProperties);
editProperties.setProperties(gCubeProperties);
editProperties.setZIndex(99999);
editProperties.show();
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-10 12:55:36 +02:00
field.setHTML(UNKNOWN);
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
}
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);
txtLocation.setHTML(UNKNOWN);
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-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("");
GWT.log("Gcube Item Properties: "+result);
gCubeProperties = result;
// unmask();
if(result!=null && result.size()>0) {
for (String key : result.keySet()) {
String text = txtAreaGcubeProperties.getText();
text+=key+"="+result.get(key)+";\n";
txtAreaGcubeProperties.setText(text);
}
cgGcubeProperties.setVisible(true);
}
}
@Override
public void onFailure(Throwable caught) {
// unmask();
cgGcubeProperties.setVisible(false);
GWT.log("an error occured in loadGcubeItemProperties " + fileModel.getIdentifier() + " " + caught.getMessage());
}
});
}
2020-07-10 12:55:36 +02:00
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
}