workspace/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java

188 lines
4.8 KiB
Java
Raw Normal View History

package org.gcube.portlets.user.workspace.client.view.toolbars;
import org.gcube.portlets.user.workspace.client.AppController;
import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent;
import org.gcube.portlets.user.workspace.client.event.AccountingReadersEvent;
import org.gcube.portlets.user.workspace.client.event.GetInfoEvent;
import org.gcube.portlets.user.workspace.client.event.TrashEvent;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.client.util.GetPermissionIconByACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Text;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class GxtBottomToolBarItem extends ToolBar{
/**
*
*/
protected static final String INFO = "Info";
/**
*
*/
protected static final String READ = "Read";
/**
*
*/
protected static final String HISTORY = "History";
private TextField<String> txfName = new TextField<String>();
private Text txtOwner = new Text("Empty");
private Text txtCreationTime = new Text("Empty");
private Text txtDimension = new Text("Empty");
private Button btnGetInfo;
private Button bHistory;
private Button bRead;
private Button btnGetTrash;
private ACLDivInfo aclDivInfo;
public GxtBottomToolBarItem(){
super();
initToolbar();
}
private void initToolbar(){
bHistory = new Button(HISTORY);
bHistory.setIcon(Resources.getIconHistory());
bHistory.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
AppController.getEventBus().fireEvent(new AccountingHistoryEvent(null));
}
});
bRead = new Button(READ);
bRead.setIcon(Resources.getIconNotRead());
bRead.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
AppController.getEventBus().fireEvent(new AccountingReadersEvent(null));
}
});
btnGetInfo = new Button(INFO);
btnGetInfo.setIcon(Resources.getIconInfo());
btnGetInfo.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
AppController.getEventBus().fireEvent(new GetInfoEvent(null));
}
});
add(btnGetInfo);
add(new SeparatorToolItem());
add(bHistory);
//COMMENTED AT 29/08/2013
// add(new SeparatorToolItem());
// add(bRead);
add(new FillToolItem());
aclDivInfo = new ACLDivInfo("", null);
add(aclDivInfo);
btnGetTrash = new Button("Trash");
btnGetTrash.setIcon(Resources.getTrashEmpty());
btnGetTrash.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.SHOW, null));
}
});
add(new FillToolItem());
add(btnGetTrash);
enableInfoHistoryButtons(false);
}
public void resetDetails(){
this.txtDimension.setText("");
this.txtCreationTime.setText("");
this.txfName.reset();
this.txtOwner.setText("");
}
public void enableInfoHistoryButtons(boolean enable){
bHistory.setEnabled(enable);
bRead.setEnabled(enable);
btnGetInfo.setEnabled(enable);
}
public void setDetails(String itemName, String description, String dimension, String creationTime, String owner){
this.resetDetails();
this.txtDimension.setText(dimension);
this.txtCreationTime.setText(creationTime);
this.txfName.setValue(itemName);
this.txtOwner.setText(owner);
}
/**
* @param markAsRead
*/
public void setRead(boolean markAsRead) {
if(markAsRead)
bRead.setIcon(Resources.getIconRead());
else
bRead.setIcon(Resources.getIconNotRead());
bRead.setEnabled(markAsRead);
}
public void updateACLInfo(WorkspaceACL acl){
if(acl==null){
aclDivInfo.updateInfo(null, null);
return;
}
AbstractImagePrototype img = GetPermissionIconByACL.getImage(acl);
aclDivInfo.updateInfo(acl.getLabel(), img);
this.layout();
}
public void updateTrashIcon(boolean trashIsFull){
if(trashIsFull)
btnGetTrash.setIcon(Resources.getTrashFull());
else
btnGetTrash.setIcon(Resources.getTrashEmpty());
}
}