323 lines
8.7 KiB
Java
323 lines
8.7 KiB
Java
package org.gcube.portlets.user.workspace.client.view.windows;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
|
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
|
import com.github.gwtbootstrap.client.ui.Label;
|
|
import com.github.gwtbootstrap.client.ui.TextArea;
|
|
import com.github.gwtbootstrap.client.ui.constants.LabelType;
|
|
import com.google.gwt.core.client.GWT;
|
|
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.dom.client.KeyPressEvent;
|
|
import com.google.gwt.event.dom.client.KeyPressHandler;
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
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";
|
|
|
|
private Map<String, String> gCubeProperties;
|
|
|
|
@UiField
|
|
HorizontalPanel hpItemType;
|
|
|
|
@UiField
|
|
HTML txtName;
|
|
|
|
@UiField
|
|
HTML txtId;
|
|
|
|
@UiField
|
|
HTML txtLocation;
|
|
|
|
@UiField
|
|
ControlGroup cgTxtIsPublic;
|
|
|
|
@UiField
|
|
HTML txtIsPublic;
|
|
|
|
@UiField
|
|
ControlGroup cgThreddsSynched;
|
|
|
|
@UiField
|
|
HTML txtThreddsSynched;
|
|
|
|
@UiField
|
|
ControlGroup cgGcubeProperties;
|
|
|
|
@UiField
|
|
TextArea txtAreaGcubeProperties;
|
|
|
|
@UiField
|
|
TextArea txtAreaDescription;
|
|
|
|
@UiField
|
|
Button buttonUpdateDescription;
|
|
|
|
@UiField
|
|
Button buttonUpdateGcubeProperties;
|
|
|
|
private FileModel fileModel;
|
|
|
|
/*
|
|
* 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));
|
|
this.fileModel = fileModel;
|
|
|
|
hpItemType.add(fileModel.getIcon());
|
|
Label labelItemType = new Label();
|
|
labelItemType.setType(LabelType.INFO);
|
|
labelItemType.getElement().getStyle().setMarginLeft(10, Unit.PX);
|
|
String label = null;
|
|
|
|
GXTFolderItemTypeEnum typeEnum = fileModel.getGXTFolderItemType();
|
|
if (typeEnum != null) {
|
|
label = typeEnum.getLabel();
|
|
label = label.replace("External ", "");
|
|
|
|
//loading gcube properties
|
|
if(typeEnum.equals(GXTFolderItemTypeEnum.GCUBE_ITEM))
|
|
loadGcubeItemProperties();
|
|
|
|
} else {
|
|
label = fileModel.getType();
|
|
}
|
|
|
|
labelItemType.setText(label);
|
|
|
|
hpItemType.add(labelItemType);
|
|
|
|
// Setting name
|
|
htmlSetValue(txtName, fileModel.getName());
|
|
htmlSetValue(txtId, fileModel.getIdentifier());
|
|
|
|
if (fileModel.isRoot())
|
|
txtLocation.setHTML("/");
|
|
else
|
|
loadLocation(fileModel.getIdentifier());
|
|
|
|
if (fileModel.isDirectory()) {
|
|
cgTxtIsPublic.setVisible(true);
|
|
htmlSetValue(txtIsPublic, fileModel.isPublic() + "");
|
|
|
|
if (fileModel.getSynchedThreddsStatus() != null) {
|
|
txtThreddsSynched.setVisible(true);
|
|
htmlSetValue(txtThreddsSynched, fileModel.getSynchedThreddsStatus() + "");
|
|
txtThreddsSynched.setHTML(fileModel.getSynchedThreddsStatus() + "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileModel.isDirectory()) {
|
|
txtAreaDescription.setValue(fileModel.getDescription());
|
|
// add(txtAreaDescription);
|
|
} else
|
|
loadDescription(fileModel.getIdentifier());
|
|
|
|
addHandlers();
|
|
}
|
|
|
|
private void addHandlers() {
|
|
|
|
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() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
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();
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void htmlSetValue(HTML field, String value) {
|
|
|
|
if (value == null || value.isEmpty())
|
|
field.setHTML(UNKNOWN);
|
|
else
|
|
field.setHTML(value);
|
|
}
|
|
|
|
private void loadLocation(String itemId) {
|
|
|
|
setPlaceholder(txtLocation, "loading...");
|
|
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);
|
|
removePlaceHolder(txtLocation);
|
|
txtLocation.setHTML(UNKNOWN);
|
|
// txtLocation.set(false);
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<FileModel> result) {
|
|
removePlaceHolder(txtLocation);
|
|
|
|
String location = "";
|
|
if (result != null) {
|
|
for (FileModel fileModel : result) {
|
|
if (fileModel != null)
|
|
location += "/" + fileModel.getName();
|
|
}
|
|
}
|
|
if (location.isEmpty())
|
|
location = "/";
|
|
|
|
txtLocation.setHTML(location);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
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());
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
private void setPlaceholder(HTML html, String placeholder) {
|
|
html.setHTML(placeholder);
|
|
html.getElement().getStyle().setColor("#E8E8E8");
|
|
}
|
|
|
|
private void removePlaceHolder(HTML html) {
|
|
html.setHTML("");
|
|
html.getElement().getStyle().setColor("#000");
|
|
}
|
|
|
|
}
|