2013-02-08 10:56:27 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.toolbars;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
2013-02-13 18:43:50 +01:00
|
|
|
import java.util.List;
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppController;
|
|
|
|
import org.gcube.portlets.user.workspace.client.event.PathElementSelectedEvent;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
|
|
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Text;
|
|
|
|
import com.extjs.gxt.ui.client.widget.WidgetComponent;
|
|
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
2014-05-16 17:44:31 +02:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2013-02-08 10:56:27 +01:00
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
*/
|
2014-02-17 19:20:45 +01:00
|
|
|
public class GxtBreadcrumbPathPanel {
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
private static final String ROOT_NAME = "Workspace";
|
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
private HorizontalPanel hpToolBar = new HorizontalPanel();
|
2013-02-08 10:56:27 +01:00
|
|
|
private Text txtPath = new Text("PATH ");
|
2013-02-13 18:43:50 +01:00
|
|
|
private LinkedHashMap<String, FileModel> hashFileModel = new LinkedHashMap<String, FileModel>();// Ordered-HashMap
|
2013-02-08 10:56:27 +01:00
|
|
|
boolean rootAdded = false;
|
2013-03-26 17:30:49 +01:00
|
|
|
protected WidgetComponent hardDiskIcon = new WidgetComponent(new Image (Resources.getImageHardDisk()));
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2013-02-13 18:43:50 +01:00
|
|
|
private FileModel lastParent;
|
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
public GxtBreadcrumbPathPanel() {
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar = new HorizontalPanel();
|
|
|
|
hpToolBar.setId("myToolbarPath");
|
|
|
|
hpToolBar.setHeight("25px");
|
2013-02-08 10:56:27 +01:00
|
|
|
initToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
public HorizontalPanel getToolBarPathPanel() {
|
2014-05-16 17:44:31 +02:00
|
|
|
return hpToolBar;
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 18:43:50 +01:00
|
|
|
public void setPath(List<FileModel> parents) {
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
initToolbarWithoutFakeRoot();
|
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
refreshSize();
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
if (parents != null && parents.size() > 0) {
|
|
|
|
|
|
|
|
ArrayList<Button> listButtons = new ArrayList<Button>();
|
|
|
|
|
|
|
|
hashFileModel = new LinkedHashMap<String, FileModel>();
|
|
|
|
|
|
|
|
// arrayFileModel = new ArrayList<FileModel>();
|
|
|
|
|
|
|
|
for (FileModel parent : parents) {
|
|
|
|
|
|
|
|
Button butt = new Button(parent.getName());
|
|
|
|
butt.setId(parent.getIdentifier());
|
|
|
|
butt.setStyleAttribute("top", "-4px");
|
|
|
|
butt.setStyleName("button-hyperlink");
|
|
|
|
// butt.setHeight(12);
|
|
|
|
|
|
|
|
hashFileModel.put(parent.getIdentifier(), parent);
|
|
|
|
|
|
|
|
// arrayFileModel.set(parent.getIdentifier(),parent);
|
|
|
|
|
|
|
|
butt.addListener(Events.OnClick, new Listener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleEvent(ButtonEvent be) {
|
|
|
|
|
|
|
|
// Window.alert("Name " + be.getButton().getText() +
|
|
|
|
// " ID: "+ be.getButton().getId());
|
|
|
|
|
2013-03-26 17:30:49 +01:00
|
|
|
FileModel target = hashFileModel.get(be.getButton().getId());
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2013-03-26 17:30:49 +01:00
|
|
|
AppController.getEventBus().fireEvent(new PathElementSelectedEvent(target));
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
listButtons.add(butt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int size = listButtons.size();
|
|
|
|
for (int i = 0; i < size - 1; i++) {
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.add(listButtons.get(i));
|
|
|
|
hpToolBar.add(new WidgetComponent(new Image(Resources.getImagePathSeparator())));
|
|
|
|
// toolBar.getWidth();
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
2013-02-13 18:43:50 +01:00
|
|
|
|
|
|
|
lastParent = parents.get(parents.size()-1);
|
2013-02-08 10:56:27 +01:00
|
|
|
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.add(listButtons.get(size - 1)); // Add last element
|
|
|
|
hpToolBar.layout(true);
|
|
|
|
|
|
|
|
int currentWidth = hpToolBar.el().getChild(0).getRegion().right;
|
|
|
|
int maxWidth = hpToolBar.getWidth();
|
|
|
|
|
|
|
|
// GWT.log("toolBar maxWidth width is: "+maxWidth);
|
|
|
|
// GWT.log("toolBar currentWidth is: "+currentWidth);
|
|
|
|
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 18:43:50 +01:00
|
|
|
|
|
|
|
public boolean breadcrumbIsEmpty(){
|
|
|
|
|
|
|
|
if(hashFileModel.size() == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public FileModel getLastParent(){
|
|
|
|
return lastParent;
|
|
|
|
}
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
private void initToolbar() {
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.removeAll();
|
|
|
|
hpToolBar.setStyleName("myToolbar");
|
|
|
|
hpToolBar.setStyleAttribute("padding-top", "5px");
|
2013-02-08 10:56:27 +01:00
|
|
|
txtPath.setStyleAttribute("padding-right", "10px");
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.add(new WidgetComponent(new Image(Resources.getImagePathSeparator())));
|
|
|
|
hpToolBar.layout(true);
|
2013-02-08 10:56:27 +01:00
|
|
|
|
|
|
|
Button butt = new Button(ROOT_NAME);
|
|
|
|
butt.setId("");
|
|
|
|
butt.setStyleAttribute("top", "-4px");
|
|
|
|
butt.setStyleName("button-hyperlink");
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.add(butt);
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initToolbarWithoutFakeRoot() {
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.removeAll();
|
|
|
|
hpToolBar.setStyleName("myToolbar");
|
|
|
|
hpToolBar.setStyleAttribute("padding-top", "5px");
|
2013-02-08 10:56:27 +01:00
|
|
|
txtPath.setStyleAttribute("padding-right", "10px");
|
2014-05-16 17:44:31 +02:00
|
|
|
hpToolBar.add(new WidgetComponent(new Image(Resources.getImagePathSeparator())));
|
|
|
|
hpToolBar.layout(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void refreshSize() {
|
|
|
|
GWT.log("Refreshed size");
|
2013-02-08 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|