package org.gcube.portlets.user.workspace.client.view.windows; import java.util.List; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; import org.gcube.portlets.user.workspace.client.model.FileModel; import com.extjs.gxt.ui.client.widget.form.TextField; import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Text; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; 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.Widget; public class DialogGetInfoBootstrap extends Composite { private static DialogGetInfoBootstrapUiBinder uiBinder = GWT.create(DialogGetInfoBootstrapUiBinder.class); interface DialogGetInfoBootstrapUiBinder extends UiBinder { } public DialogGetInfoBootstrap() { initWidget(uiBinder.createAndBindUi(this)); } public static final String UNKNOWN = "unknown"; //@UiField //TextBox txtName; @UiField HTML txtName; @UiField HTML txtId; @UiField HTML txtLocation; @UiField ControlGroup cgTxtIsPublic; @UiField HTML txtIsPublic; @UiField TextArea txtAreaDescription; /* * TextField txtType = new TextField(); private * TextField txtCategory = new TextField(); private * TextField txtOwner = new TextField(); private * TextField txtLastMofication = new TextField(); private * TextField txtCreated = new TextField(); private * TextField txtSize = new TextField(); private * TextField txtLocation = new TextField(); private * TextField txtIsPublic = new TextField(); private * TextField txtThreddsSynched = new TextField(); private * TextField txtShared = new TextField(); // private TextArea * textAreaSharedWith = new TextArea(); private Html htmlUsersWidget = new * Html(); private Html htmlPropertiesWidget = new Html(); private final * NumberFormat number = ConstantsExplorer.numberFormatterKB; // private * TextField txtGcubeItemProperties; private HorizontalPanel * hpGcubeProperties; private DialogEditProperties editProperties = null; */ public DialogGetInfoBootstrap(final FileModel fileModel) { initWidget(uiBinder.createAndBindUi(this)); // 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); txtIsPublic.setHTML(fileModel.isPublic() + ""); /* * if (fileModel.getSynchedThreddsStatus() != null) { txtThreddsSynched = new * TextField(); txtThreddsSynched.setFieldLabel("Thredds Sync"); * txtThreddsSynched.setReadOnly(true); * txtThreddsSynched.setValue(fileModel.getSynchedThreddsStatus() + ""); * add(txtThreddsSynched); * * } */ } if (fileModel.isDirectory()) { txtAreaDescription.setValue(fileModel.getDescription()); // add(txtAreaDescription); } else loadDescription(fileModel.getIdentifier()); addHandlers(); } private void addHandlers() { txtAreaDescription.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { } }); } 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>() { @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 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() { @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 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"); } }