2013-03-25 12:35:05 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.windows;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
2014-02-18 14:40:19 +01:00
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
2013-03-25 12:35:05 +01:00
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
2014-02-18 14:40:19 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Html;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Label;
|
2013-03-25 12:35:05 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.i18n.client.NumberFormat;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class DialogGetInfo extends Dialog {
|
|
|
|
|
2014-11-03 14:45:36 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static final String EMPTY = "empty";
|
|
|
|
public static final String UNKNOWN = "unknown";
|
2013-03-25 12:35:05 +01:00
|
|
|
private int widthDialog = 450;
|
|
|
|
private int heightTextArea = 50;
|
|
|
|
private TextField<String> txtName = new TextField<String>();
|
2013-05-24 18:18:14 +02:00
|
|
|
private TextField<String> txtAreaDescription = new TextArea();
|
2013-03-25 12:35:05 +01:00
|
|
|
private TextField<String> txtType = new TextField<String>();
|
|
|
|
private TextField<String> txtCategory = new TextField<String>();
|
|
|
|
private TextField<String> txtOwner = new TextField<String>();
|
2013-03-26 12:35:58 +01:00
|
|
|
private TextField<String> txtLastMofication = new TextField<String>();
|
2013-03-25 12:35:05 +01:00
|
|
|
private TextField<String> txtCreated = new TextField<String>();
|
|
|
|
private TextField<String> txtSize = new TextField<String>();
|
|
|
|
private TextField<String> txtLocation = new TextField<String>();
|
|
|
|
private TextField<String> txtShared = new TextField<String>();
|
2014-02-18 14:40:19 +01:00
|
|
|
// private TextArea textAreaSharedWith = new TextArea();
|
|
|
|
private Html htmlUsersWidget = new Html();
|
2013-03-25 12:35:05 +01:00
|
|
|
private final NumberFormat number = ConstantsExplorer.numberFormatterKB;
|
|
|
|
|
|
|
|
|
|
|
|
public DialogGetInfo(FileModel fileModel) {
|
|
|
|
|
|
|
|
FormLayout layout = new FormLayout();
|
|
|
|
layout.setLabelWidth(90);
|
|
|
|
layout.setDefaultWidth(300);
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
|
|
setIcon(fileModel.getAbstractPrototypeIcon());
|
|
|
|
setHeading(fileModel.getName() + " Properties");
|
|
|
|
|
|
|
|
setButtonAlign(HorizontalAlignment.RIGHT);
|
|
|
|
setModal(true);
|
|
|
|
// setBodyBorder(true);
|
|
|
|
setBodyStyle("padding: 9px; background: none");
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setResizable(false);
|
|
|
|
setButtons(Dialog.OK);
|
2013-03-28 10:40:56 +01:00
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
txtName = new TextField<String>();
|
|
|
|
txtName.setFieldLabel("Name");
|
|
|
|
txtName.setReadOnly(true);
|
|
|
|
textFieldSetValue(txtName,fileModel.getName());
|
|
|
|
add(txtName);
|
|
|
|
|
2013-03-26 11:41:25 +01:00
|
|
|
txtLocation = new TextField<String>();
|
|
|
|
txtLocation.setFieldLabel("Location");
|
|
|
|
txtLocation.setReadOnly(true);
|
|
|
|
|
|
|
|
if(fileModel.isRoot())
|
|
|
|
txtLocation.setValue("/");
|
|
|
|
else
|
|
|
|
loadLocation(fileModel.getIdentifier());
|
|
|
|
|
|
|
|
add(txtLocation);
|
|
|
|
|
2014-11-04 18:20:06 +01:00
|
|
|
|
|
|
|
txtAreaDescription.setFieldLabel("Description");
|
|
|
|
txtAreaDescription.setHeight(30);
|
|
|
|
txtAreaDescription.setReadOnly(true);
|
|
|
|
add(txtAreaDescription);
|
|
|
|
|
|
|
|
|
2013-05-24 18:18:14 +02:00
|
|
|
if(fileModel.isDirectory()){
|
|
|
|
txtAreaDescription.setValue(fileModel.getDescription());
|
2014-11-04 18:20:06 +01:00
|
|
|
// add(txtAreaDescription);
|
|
|
|
}else
|
|
|
|
loadDescription(fileModel.getIdentifier());
|
2013-05-24 18:18:14 +02:00
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
txtType = new TextField<String>();
|
|
|
|
txtType.setFieldLabel("Type");
|
|
|
|
txtType.setReadOnly(true);
|
|
|
|
textFieldSetValue(txtType,fileModel.getType());
|
|
|
|
add(txtType);
|
|
|
|
|
|
|
|
txtCategory = new TextField<String>();
|
|
|
|
txtCategory.setFieldLabel("Category");
|
|
|
|
txtCategory.setReadOnly(true);
|
|
|
|
textFieldSetValue(txtCategory,fileModel.getShortcutCategory());
|
|
|
|
add(txtCategory);
|
2013-05-24 18:18:14 +02:00
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
txtOwner = new TextField<String>();
|
|
|
|
txtOwner.setFieldLabel("Owner");
|
|
|
|
txtOwner.setReadOnly(true);
|
|
|
|
loadOwner(fileModel.getIdentifier());
|
|
|
|
add(txtOwner);
|
2013-05-24 18:18:14 +02:00
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
txtCreated = new TextField<String>();
|
|
|
|
txtCreated.setFieldLabel("Created");
|
|
|
|
txtCreated.setReadOnly(true);
|
2013-11-15 12:12:17 +01:00
|
|
|
// if(fileModel instanceof FileGridModel)
|
|
|
|
// textFieldSetValue(txtCreated, ((FileGridModel) fileModel).getCreationDate().toString());
|
|
|
|
// else
|
|
|
|
// loadCreationDate(fileModel.getIdentifier());
|
|
|
|
|
|
|
|
loadCreationDate(fileModel.getIdentifier());
|
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
add(txtCreated);
|
|
|
|
|
2013-03-26 12:35:58 +01:00
|
|
|
|
|
|
|
txtLastMofication = new TextField<String>();
|
|
|
|
txtLastMofication.setFieldLabel("Last Mofication");
|
|
|
|
txtLastMofication.setReadOnly(true);
|
2013-11-15 12:12:17 +01:00
|
|
|
if(fileModel instanceof FileGridModel)
|
|
|
|
textFieldSetValue(txtLastMofication, ((FileGridModel) fileModel).getLastModification().toString());
|
|
|
|
else
|
|
|
|
loadLastModificationDate(fileModel.getIdentifier());
|
|
|
|
|
|
|
|
// loadLastModificationDate(fileModel.getIdentifier());
|
2013-03-26 12:35:58 +01:00
|
|
|
add(txtLastMofication);
|
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
txtSize = new TextField<String>();
|
|
|
|
txtSize.setFieldLabel("Size");
|
|
|
|
txtSize.setReadOnly(true);
|
|
|
|
|
|
|
|
if(fileModel instanceof FileGridModel)
|
|
|
|
textFieldSetValue(txtSize,getFormattedSize(((FileGridModel) fileModel).getSize()));
|
|
|
|
else
|
|
|
|
loadSize(fileModel.getIdentifier());
|
|
|
|
|
|
|
|
add(txtSize);
|
|
|
|
|
|
|
|
|
|
|
|
txtShared = new TextField<String>();
|
|
|
|
txtShared.setFieldLabel("Shared");
|
|
|
|
txtShared.setReadOnly(true);
|
|
|
|
textFieldSetValue(txtShared,fileModel.isShared()+"");
|
|
|
|
add(txtShared);
|
|
|
|
|
|
|
|
|
|
|
|
if(fileModel.isShared()){
|
|
|
|
|
2014-02-18 14:40:19 +01:00
|
|
|
HorizontalPanel hp = new HorizontalPanel();
|
|
|
|
hp.setStyleAttribute("padding-top", "6px");
|
|
|
|
Label label = new Label("Shared with");
|
|
|
|
label.setStyleAttribute("padding-right", "39px");
|
|
|
|
hp.add(label);
|
|
|
|
/*
|
2013-03-25 12:35:05 +01:00
|
|
|
textAreaSharedWith.setFieldLabel("Shared with");
|
|
|
|
textAreaSharedWith.setHeight(heightTextArea);
|
|
|
|
textAreaSharedWith.setReadOnly(true);
|
2013-03-26 11:41:25 +01:00
|
|
|
loadListSharedContacts(fileModel.getIdentifier());
|
2013-03-25 12:35:05 +01:00
|
|
|
add(textAreaSharedWith);
|
2014-02-18 14:40:19 +01:00
|
|
|
*/
|
|
|
|
// htmlUsersWidget.setStyleAttribute("border", "1px solid #B5B8C8");
|
|
|
|
loadListSharedContacts(fileModel.getIdentifier());
|
|
|
|
htmlUsersWidget.setHeight(heightTextArea);
|
|
|
|
htmlUsersWidget.setWidth("297px");
|
|
|
|
hp.add(htmlUsersWidget);
|
|
|
|
hp.setScrollMode(Scroll.AUTOY);
|
|
|
|
add(hp);
|
2013-03-25 12:35:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-02-21 11:06:32 +01:00
|
|
|
// System.out.println("fileModel in getinfo "+fileModel);
|
2013-03-25 12:35:05 +01:00
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
|
2014-11-04 18:20:06 +01:00
|
|
|
/**
|
|
|
|
* @param identifier
|
|
|
|
*/
|
|
|
|
private void loadDescription(String identifier) {
|
|
|
|
txtAreaDescription.mask();
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getItemDescriptionById(identifier, new AsyncCallback<String>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
txtAreaDescription.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
if(result!=null)
|
|
|
|
txtAreaDescription.setValue(result);
|
|
|
|
else
|
|
|
|
txtAreaDescription.setValue("");
|
|
|
|
|
|
|
|
txtAreaDescription.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-26 12:35:58 +01:00
|
|
|
private void loadLastModificationDate(final String itemId) {
|
|
|
|
|
|
|
|
txtLastMofication.mask();
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.loadLastModificationDateById(itemId, new AsyncCallback<Date>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("an error occured in loadLastModificationDateById "+itemId + " "+caught.getMessage());
|
|
|
|
txtLastMofication.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Date result) {
|
|
|
|
|
|
|
|
if(result!=null)
|
|
|
|
txtLastMofication.setValue(result.toString());
|
|
|
|
else
|
|
|
|
txtLastMofication.setValue(UNKNOWN);
|
|
|
|
|
|
|
|
txtLastMofication.unmask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
private void textFieldSetValue(TextField<String> field, String value){
|
|
|
|
|
|
|
|
if(value==null || value.isEmpty())
|
2013-03-26 12:35:58 +01:00
|
|
|
field.setValue(UNKNOWN);
|
2013-03-25 12:35:05 +01:00
|
|
|
else
|
|
|
|
field.setValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadOwner(final String itemId){
|
|
|
|
|
|
|
|
txtOwner.mask();
|
2013-03-25 18:36:21 +01:00
|
|
|
|
|
|
|
// System.out.println("owner by id "+itemId);
|
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
AppControllerExplorer.rpcWorkspaceService.getOwnerByItemId(itemId, new AsyncCallback<InfoContactModel>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("an error occured in get Owner by Id "+itemId + " "+caught.getMessage());
|
|
|
|
txtOwner.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(InfoContactModel result) {
|
|
|
|
textFieldSetValue(txtOwner,result.getName());
|
|
|
|
txtOwner.unmask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadSize(final String itemId){
|
2014-10-28 17:12:40 +01:00
|
|
|
GWT.log("Load size");
|
2013-03-25 12:35:05 +01:00
|
|
|
txtSize.mask();
|
|
|
|
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());
|
|
|
|
txtSize.unmask();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Long result) {
|
2014-10-28 17:12:40 +01:00
|
|
|
GWT.log("Loaded size="+result);
|
2013-03-25 12:35:05 +01:00
|
|
|
textFieldSetValue(txtSize,getFormattedSize(result));
|
|
|
|
txtSize.unmask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void loadCreationDate(final String itemId){
|
|
|
|
|
|
|
|
txtCreated.mask();
|
|
|
|
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());
|
|
|
|
txtCreated.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Date result) {
|
|
|
|
if(result!=null)
|
|
|
|
textFieldSetValue(txtCreated,result.toString());
|
|
|
|
|
|
|
|
txtCreated.unmask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-18 14:40:19 +01:00
|
|
|
// private void loadListSharedContacts(String sharedId){
|
|
|
|
//
|
|
|
|
// textAreaSharedWith.mask();
|
|
|
|
//
|
|
|
|
// AppControllerExplorer.rpcWorkspaceService.getListUserSharedBySharedItem(sharedId, new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void onFailure(Throwable caught) {
|
|
|
|
// textAreaSharedWith.unmask();
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void onSuccess(List<InfoContactModel> result) {
|
|
|
|
//
|
|
|
|
// String users = "";
|
|
|
|
//
|
|
|
|
// for (int i = 0; i < result.size()-1; i++) {
|
|
|
|
// users+= result.get(i).getName() + ", ";
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(result.size()>1)
|
|
|
|
// users += result.get(result.size()-1).getName();
|
|
|
|
//
|
|
|
|
// textAreaSharedWith.setValue(users);
|
|
|
|
//
|
|
|
|
// textAreaSharedWith.unmask();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
2013-03-26 11:41:25 +01:00
|
|
|
private void loadListSharedContacts(String sharedId){
|
2013-03-25 12:35:05 +01:00
|
|
|
|
2014-02-18 14:40:19 +01:00
|
|
|
htmlUsersWidget.mask();
|
2013-03-25 12:35:05 +01:00
|
|
|
|
2014-02-19 16:11:28 +01:00
|
|
|
AppControllerExplorer.rpcWorkspaceService.getACLsDescriptionForSharedFolderId(sharedId, new AsyncCallback<String>() {
|
2013-03-25 12:35:05 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-02-18 14:40:19 +01:00
|
|
|
htmlUsersWidget.unmask();
|
|
|
|
htmlUsersWidget.setHtml("Error on recovering users");
|
2013-03-25 12:35:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-18 14:40:19 +01:00
|
|
|
public void onSuccess(String result) {
|
|
|
|
htmlUsersWidget.unmask();
|
2014-07-17 11:11:35 +02:00
|
|
|
GWT.log("Loaded ACLs: "+result);
|
2014-02-18 14:40:19 +01:00
|
|
|
htmlUsersWidget.setHtml(result);
|
2013-03-25 12:35:05 +01:00
|
|
|
}
|
|
|
|
});
|
2014-02-18 14:40:19 +01:00
|
|
|
|
2013-03-25 12:35:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getFormattedSize(long value){
|
|
|
|
|
|
|
|
if(value>0){
|
|
|
|
double kb = value/1024;
|
|
|
|
if(kb<1)
|
|
|
|
kb=1;
|
|
|
|
return number.format(kb);
|
2014-11-03 14:45:36 +01:00
|
|
|
}else if(value==0){
|
|
|
|
return EMPTY;
|
2013-03-25 12:35:05 +01:00
|
|
|
}else
|
|
|
|
return "";
|
|
|
|
}
|
2013-03-26 11:41:25 +01:00
|
|
|
|
|
|
|
private void loadLocation(String itemId){
|
|
|
|
|
|
|
|
txtLocation.mask();
|
2013-09-12 12:27:18 +02:00
|
|
|
AppControllerExplorer.rpcWorkspaceService.getListParentsByItemIdentifier(itemId, false, new AsyncCallback<List<FileModel>>() {
|
2013-03-26 11:41:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("failure get list parents by item identifier "+caught);
|
|
|
|
txtLocation.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<FileModel> result) {
|
|
|
|
|
|
|
|
String location="";
|
|
|
|
|
|
|
|
if(result!=null){
|
|
|
|
|
|
|
|
for (FileModel fileModel : result) {
|
|
|
|
location+="/"+fileModel.getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(location.isEmpty())
|
|
|
|
location ="/";
|
|
|
|
|
|
|
|
txtLocation.setValue(location);
|
|
|
|
txtLocation.unmask();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2013-03-25 12:35:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|