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; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.Dialog; 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 { private int widthDialog = 450; private int heightTextArea = 50; private TextField txtName = new TextField(); private TextField txtType = new TextField(); private TextField txtCategory = new TextField(); private TextField txtOwner = new TextField(); private TextField txtCreated = new TextField(); private TextField txtSize = new TextField(); private TextField txtLocation = new TextField(); private TextField txtShared = new TextField(); private TextArea textAreaSharedWith = new TextArea(); 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); txtName = new TextField(); txtName.setFieldLabel("Name"); txtName.setReadOnly(true); textFieldSetValue(txtName,fileModel.getName()); add(txtName); txtLocation = new TextField(); txtLocation.setFieldLabel("Location"); txtLocation.setReadOnly(true); if(fileModel.isRoot()) txtLocation.setValue("/"); else loadLocation(fileModel.getIdentifier()); add(txtLocation); txtType = new TextField(); txtType.setFieldLabel("Type"); txtType.setReadOnly(true); textFieldSetValue(txtType,fileModel.getType()); add(txtType); txtCategory = new TextField(); txtCategory.setFieldLabel("Category"); txtCategory.setReadOnly(true); textFieldSetValue(txtCategory,fileModel.getShortcutCategory()); add(txtCategory); txtOwner = new TextField(); txtOwner.setFieldLabel("Owner"); txtOwner.setReadOnly(true); loadOwner(fileModel.getIdentifier()); add(txtOwner); txtCreated = new TextField(); txtCreated.setFieldLabel("Created"); txtCreated.setReadOnly(true); if(fileModel instanceof FileGridModel) textFieldSetValue(txtCreated, ((FileGridModel) fileModel).getCreationDate().toString()); else loadCreationDate(fileModel.getIdentifier()); add(txtCreated); txtSize = new TextField(); 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(); txtShared.setFieldLabel("Shared"); txtShared.setReadOnly(true); textFieldSetValue(txtShared,fileModel.isShared()+""); add(txtShared); if(fileModel.isShared()){ textAreaSharedWith.setFieldLabel("Shared with"); textAreaSharedWith.setHeight(heightTextArea); textAreaSharedWith.setReadOnly(true); loadListSharedContacts(fileModel.getIdentifier()); add(textAreaSharedWith); } this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener() { @Override public void componentSelected(ButtonEvent ce) { hide(); } }); this.show(); } private void textFieldSetValue(TextField field, String value){ if(value==null || value.isEmpty()) field.setValue("unknown"); else field.setValue(value); } private void loadOwner(final String itemId){ txtOwner.mask(); // System.out.println("owner by id "+itemId); AppControllerExplorer.rpcWorkspaceService.getOwnerByItemId(itemId, new AsyncCallback() { @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){ txtSize.mask(); AppControllerExplorer.rpcWorkspaceService.loadSizeByItemId(itemId, new AsyncCallback() { @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) { textFieldSetValue(txtSize,getFormattedSize(result)); txtSize.unmask(); } }); } private void loadCreationDate(final String itemId){ txtCreated.mask(); AppControllerExplorer.rpcWorkspaceService.getItemCreationDateById(itemId, new AsyncCallback() { @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(); } }); } private void loadListSharedContacts(String sharedId){ textAreaSharedWith.mask(); AppControllerExplorer.rpcWorkspaceService.getListUserSharedBySharedItem(sharedId, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { textAreaSharedWith.unmask(); } @Override public void onSuccess(List 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(); } }); } private String getFormattedSize(long value){ if(value>0){ double kb = value/1024; if(kb<1) kb=1; return number.format(kb); }else return ""; } private void loadLocation(String itemId){ txtLocation.mask(); AppControllerExplorer.rpcWorkspaceService.getListParentsByItemIdentifier(itemId, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { GWT.log("failure get list parents by item identifier "+caught); txtLocation.unmask(); } @Override public void onSuccess(List result) { String location=""; if(result!=null){ for (FileModel fileModel : result) { location+="/"+fileModel.getName(); } } if(location.isEmpty()) location ="/"; txtLocation.setValue(location); txtLocation.unmask(); } }); } }