209 lines
5.1 KiB
Java
209 lines
5.1 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.widgets.wsexplorer.client.view.gcubeitem;
|
|
|
|
import java.util.Map;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
|
|
import org.gcube.portlets.widgets.wsexplorer.client.resources.WorkspaceExplorerResources;
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
|
|
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.resources.client.ImageResource;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Button;
|
|
import com.google.gwt.user.client.ui.DialogBox;
|
|
import com.google.gwt.user.client.ui.DockPanel;
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.Image;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
/**
|
|
* The Class DialogShowGcubeItem.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* May 17, 2016
|
|
*
|
|
* Shows a Dialog with gcube items related to WorkspaceItemId.
|
|
*/
|
|
public class DialogShowGcubeItem extends DialogBox implements ClickHandler {
|
|
|
|
private DockPanel dock = new DockPanel();
|
|
private Button yesButton;
|
|
private VerticalPanel vpContainer;
|
|
private ImageResource loading = WorkspaceExplorerResources.ICONS.loading();
|
|
private HorizontalPanel hpButtons = new HorizontalPanel();
|
|
|
|
|
|
/**
|
|
* Instantiates a new dialog show gcube items related to WorkspaceItemId.
|
|
*
|
|
* @param caption the caption
|
|
* @param text the text
|
|
* @param item the worksapce item id
|
|
*/
|
|
public DialogShowGcubeItem(String caption, String text, Item item) {
|
|
getElement().setClassName("gwt-DialogBoxNew");
|
|
dock.setSpacing(4);
|
|
dock.setWidth("100%");
|
|
setText(caption);
|
|
|
|
yesButton = new Button("Ok");
|
|
yesButton.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
hide();
|
|
}
|
|
});
|
|
|
|
vpContainer = new VerticalPanel();
|
|
// vpContainer.getElement().getStyle().setMargin(5.0, Unit.PX);
|
|
vpContainer.add(new HTML(text));
|
|
hpButtons = new HorizontalPanel();
|
|
hpButtons.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
|
|
hpButtons.setSpacing(3);
|
|
// yesButton.getElement().getStyle().setMarginRight(20.0, Unit.PX);
|
|
hpButtons.add(yesButton);
|
|
|
|
dock.add(hpButtons, DockPanel.SOUTH);
|
|
dock.setCellHorizontalAlignment(hpButtons, DockPanel.ALIGN_CENTER);
|
|
|
|
dock.add(vpContainer, DockPanel.CENTER);
|
|
setWidget(dock);
|
|
|
|
|
|
if(item.getGcubeProperties()!=null){
|
|
FlexTable table = buildGcubeItemView(item.getGcubeProperties());
|
|
addToCenterPanel(table);
|
|
|
|
}else{
|
|
addLoader("Re-loading Gcube Properties Info...");
|
|
WorkspaceExplorerConstants.workspaceNavigatorService.getGcubePropertiesForWorspaceId(item.getId(), new AsyncCallback<Map<String,String>>() {
|
|
|
|
@Override
|
|
public void onSuccess(Map<String, String> result) {
|
|
FlexTable table = buildGcubeItemView(result);
|
|
removeLoader();
|
|
addToCenterPanel(table);
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
removeLoader();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Builds the gcube item view.
|
|
*
|
|
* @param map the map
|
|
* @return the flex table
|
|
*/
|
|
private FlexTable buildGcubeItemView(Map<String, String> map){
|
|
|
|
FlexTable table = new FlexTable();
|
|
table.setWidth("100%");
|
|
|
|
|
|
if(map.size()==0){
|
|
table.setHTML(0, 0, "No properties");
|
|
return table;
|
|
}
|
|
|
|
table.addStyleName("gcube-item-table");
|
|
table.setHTML(0, 0, "N.");
|
|
table.setHTML(0, 1, "Key");
|
|
table.setHTML(0, 2, "Value");
|
|
table.getRowFormatter().getElement(0).addClassName("gcube-item-table-header");
|
|
|
|
int i = 0;
|
|
for (String key : map.keySet()) {
|
|
String value = map.get(key);
|
|
int index = i+1;
|
|
table.setHTML(index, 0, index+"-");
|
|
table.setHTML(index, 1, key);
|
|
table.setHTML(index, 2, value);
|
|
|
|
}
|
|
return table;
|
|
}
|
|
|
|
/*
|
|
* (non-Javadoc)
|
|
*
|
|
* @see
|
|
* com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event
|
|
* .dom.client.ClickEvent)
|
|
*/
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
// hide();
|
|
}
|
|
|
|
|
|
/**
|
|
* Adds the loader.
|
|
*
|
|
* @param message the message
|
|
*/
|
|
private void addLoader(String message){
|
|
try{
|
|
dock.remove(hpButtons);
|
|
}catch(Exception e){}
|
|
vpContainer.clear();
|
|
HorizontalPanel hpMask = new HorizontalPanel();
|
|
hpMask.add(new Image(loading));
|
|
HTML html = new HTML(message);
|
|
html.getElement().getStyle().setMarginLeft(5, Unit.PX);
|
|
hpMask.add(html);
|
|
vpContainer.add(hpMask);
|
|
}
|
|
|
|
/**
|
|
* Removes the loader.
|
|
*/
|
|
private void removeLoader(){
|
|
try{
|
|
dock.add(hpButtons);
|
|
}catch(Exception e){}
|
|
vpContainer.clear();
|
|
}
|
|
|
|
/**
|
|
* Adds the to center panel.
|
|
*
|
|
* @param w the w
|
|
*/
|
|
public void addToCenterPanel(Widget w) {
|
|
vpContainer.add(w);
|
|
}
|
|
|
|
/**
|
|
* Gets the dock.
|
|
*
|
|
* @return the dock
|
|
*/
|
|
public DockPanel getDock() {
|
|
return dock;
|
|
}
|
|
|
|
/**
|
|
* Gets the yes button.
|
|
*
|
|
* @return the yes button
|
|
*/
|
|
public Button getYesButton() {
|
|
return yesButton;
|
|
}
|
|
} |