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

114 lines
2.8 KiB
Java

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.resources.Resources;
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.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class GxtToolBarItemAccounting extends ToolBar{
/**
*
*/
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 bHistory;
private Button bRead;
public GxtToolBarItemAccounting(){
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));
}
});
add(bHistory);
add(new SeparatorToolItem());
add(bRead);
enableButtons(false);
}
public void resetDetails(){
this.txtDimension.setText("");
this.txtCreationTime.setText("");
this.txfName.reset();
this.txtOwner.setText("");
}
public void enableButtons(boolean enable){
bHistory.setEnabled(enable);
bRead.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);
}
}