2017-02-20 14:57:17 +01:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.versioning;
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
import java.util.ArrayList;
|
2017-02-20 11:42:17 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppController;
|
|
|
|
import org.gcube.portlets.user.workspace.client.event.FileVersioningEvent;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
2017-02-20 18:04:57 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileVersionModel;
|
2017-02-20 11:42:17 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.windows.DialogConfirm;
|
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation;
|
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.ButtonScale;
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
|
|
import com.extjs.gxt.ui.client.Style.IconAlign;
|
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.store.GroupingStore;
|
|
|
|
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
|
import com.extjs.gxt.ui.client.store.Record;
|
|
|
|
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
|
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
2017-02-23 15:42:45 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
|
2017-02-20 11:42:17 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
2017-02-23 15:42:45 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
|
2017-02-20 11:42:17 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
|
2017-02-23 15:42:45 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.BooleanFilter;
|
2017-02-22 11:38:37 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.DateFilter;
|
2017-02-20 11:42:17 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.GridFilters;
|
|
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
|
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
|
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
|
|
|
|
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
2017-02-22 11:38:37 +01:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2017-02-20 11:42:17 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
/**
|
|
|
|
* The Class VersioningInfoContainer.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
2017-02-22 11:38:37 +01:00
|
|
|
* Feb 21, 2017
|
2017-02-20 11:42:17 +01:00
|
|
|
*/
|
|
|
|
public class VersioningInfoContainer extends LayoutContainer {
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
private Grid<FileVersionModel> grid;
|
2017-02-20 11:42:17 +01:00
|
|
|
private ContentPanel cp;
|
2017-02-22 11:38:37 +01:00
|
|
|
private GroupingStore<FileVersionModel> store = new GroupingStore<FileVersionModel>();
|
|
|
|
private ListStore<FileVersionModel> typeStoreOperation = new ListStore<FileVersionModel>();
|
2017-02-20 11:42:17 +01:00
|
|
|
//private GridDropTarget gridDropTarget;
|
|
|
|
private Button buttonDelete;
|
|
|
|
private Button buttonRestore;
|
2017-02-20 18:04:57 +01:00
|
|
|
private Button buttonDownload;
|
|
|
|
private Button buttonEmptyVersions;
|
2017-02-20 14:57:17 +01:00
|
|
|
private FileModel currentVersion;
|
|
|
|
private WindowVersioning windowVersioning;
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new versioning info container.
|
|
|
|
*
|
|
|
|
* @param file the versioning files
|
2017-02-22 11:38:37 +01:00
|
|
|
* @param windowVersioning the window versioning
|
2017-02-20 11:42:17 +01:00
|
|
|
*/
|
2017-02-20 14:57:17 +01:00
|
|
|
public VersioningInfoContainer(FileModel file, WindowVersioning windowVersioning) {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
initContentPanel();
|
|
|
|
initGrid();
|
|
|
|
createToolBar();
|
2017-02-20 14:57:17 +01:00
|
|
|
this.currentVersion = file;
|
|
|
|
this.windowVersioning = windowVersioning;
|
2017-02-20 11:42:17 +01:00
|
|
|
activeButtonOnSelection(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the content panel.
|
|
|
|
*/
|
|
|
|
private void initContentPanel() {
|
|
|
|
setLayout(new FitLayout());
|
|
|
|
getAriaSupport().setPresentation(true);
|
|
|
|
cp = new ContentPanel();
|
|
|
|
cp.setHeaderVisible(false);
|
|
|
|
cp.setBodyBorder(true);
|
|
|
|
cp.setLayout(new FitLayout());
|
|
|
|
cp.setButtonAlign(HorizontalAlignment.CENTER);
|
|
|
|
cp.setScrollMode(Scroll.AUTOY);
|
|
|
|
add(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check selection.
|
|
|
|
*
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
|
|
|
private boolean checkSelection(){
|
|
|
|
|
|
|
|
if(grid.getSelectionModel().getSelectedItems().size()==0){
|
|
|
|
MessageBox.info("Attention", "You must pick at least one item", null);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
GWT.log("Returning checkSelection");
|
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the tool bar.
|
|
|
|
*/
|
|
|
|
private void createToolBar() {
|
|
|
|
|
|
|
|
ToolBar bar = new ToolBar();
|
|
|
|
|
|
|
|
buttonRestore = new Button(WorkspaceVersioningOperation.RESTORE.getLabel(),Resources.getIconUndo());
|
|
|
|
buttonRestore.setToolTip(WorkspaceVersioningOperation.RESTORE.getOperationDescription());
|
|
|
|
buttonRestore.setScale(ButtonScale.SMALL);
|
|
|
|
buttonRestore.setIconAlign(IconAlign.TOP);
|
|
|
|
|
|
|
|
buttonRestore.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
if(checkSelection()){
|
|
|
|
//ONLY THE FIRST ITEM SELECTED CAN BE RESTORED
|
|
|
|
final List<FileVersionModel> firstFileToRestore = new ArrayList<FileVersionModel>(1);
|
|
|
|
firstFileToRestore.add(grid.getSelectionModel().getSelectedItems().get(0));
|
|
|
|
String msg = "Restoring the previous version: " +
|
|
|
|
"<br/>"+firstFileToRestore.get(0).getName();
|
|
|
|
msg+="<br/>Confirm?";
|
|
|
|
|
|
|
|
String title = "Restore version ";
|
2017-02-22 14:16:13 +01:00
|
|
|
title+=" of: "+currentVersion.getName();
|
2017-02-22 11:38:37 +01:00
|
|
|
final DialogConfirm box = new DialogConfirm(null, title, msg);
|
|
|
|
box.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.RESTORE, currentVersion, firstFileToRestore, windowVersioning));
|
|
|
|
box.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box.setModal(true);
|
|
|
|
box.center();
|
|
|
|
|
|
|
|
}
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bar.add(buttonRestore);
|
|
|
|
|
|
|
|
|
|
|
|
buttonDelete = new Button(WorkspaceVersioningOperation.DELETE_PERMANENTLY.getLabel(),Resources.getIconDeleteItem());
|
|
|
|
buttonDelete.setToolTip(WorkspaceVersioningOperation.DELETE_PERMANENTLY.getOperationDescription());
|
|
|
|
buttonDelete.setScale(ButtonScale.SMALL);
|
|
|
|
buttonDelete.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
if(checkSelection()){
|
|
|
|
final List<FileVersionModel> selectedItems = grid.getSelectionModel().getSelectedItems();
|
2017-02-22 11:53:09 +01:00
|
|
|
String msg = "Deleting older ";
|
|
|
|
msg+=selectedItems.size()>1?"versions:":"version:";
|
2017-02-22 11:38:37 +01:00
|
|
|
for (FileVersionModel file : selectedItems) {
|
|
|
|
msg+="<br/> - "+file.getName();
|
|
|
|
}
|
|
|
|
msg+="<br/>Confirm?";
|
|
|
|
|
2017-02-22 11:49:54 +01:00
|
|
|
String title = selectedItems.size()>1?"Delete versions":"Delete version";
|
|
|
|
title+=" of: "+currentVersion.getName();
|
2017-02-22 11:38:37 +01:00
|
|
|
final DialogConfirm box = new DialogConfirm(null, title, msg);
|
|
|
|
box.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DELETE_PERMANENTLY, currentVersion, selectedItems, windowVersioning));
|
|
|
|
box.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box.setModal(true);
|
|
|
|
box.center();
|
|
|
|
}
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bar.add(buttonDelete);
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
buttonDownload = new Button(WorkspaceVersioningOperation.DOWNLOAD.getLabel(),Resources.getIconDownload());
|
2017-02-20 18:04:57 +01:00
|
|
|
buttonDownload.setToolTip(WorkspaceVersioningOperation.DOWNLOAD.getOperationDescription());
|
|
|
|
buttonDownload.setScale(ButtonScale.SMALL);
|
|
|
|
buttonDownload.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonDownload.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
if(checkSelection())
|
2017-02-22 11:38:37 +01:00
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DOWNLOAD, currentVersion, grid.getSelectionModel().getSelectedItems(), windowVersioning));
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-20 18:04:57 +01:00
|
|
|
bar.add(buttonDownload);
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
bar.add(new SeparatorMenuItem());
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
buttonEmptyVersions = new Button(WorkspaceVersioningOperation.DELETE_ALL_OLDER_VERSIONS.getLabel(),Resources.getTrashEmpty());
|
|
|
|
buttonEmptyVersions.setToolTip(WorkspaceVersioningOperation.DELETE_ALL_OLDER_VERSIONS.getOperationDescription());
|
2017-02-20 18:04:57 +01:00
|
|
|
buttonEmptyVersions.setScale(ButtonScale.SMALL);
|
|
|
|
buttonEmptyVersions.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonEmptyVersions.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
2017-02-23 15:54:53 +01:00
|
|
|
if(store.getModels().size()>0){
|
|
|
|
|
|
|
|
String msg = "Deleting all older versions of: <br/> - "+ currentVersion.getName()+"." +
|
|
|
|
"<br/>Confirm?";
|
2017-02-24 17:34:10 +01:00
|
|
|
final DialogConfirm box = new DialogConfirm(null, "Delete older versions of: "+ currentVersion.getName(), msg);
|
2017-02-23 15:54:53 +01:00
|
|
|
box.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
2017-02-24 17:34:10 +01:00
|
|
|
box.hide();
|
2017-02-23 15:54:53 +01:00
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DELETE_ALL_OLDER_VERSIONS, currentVersion, store.getModels(), windowVersioning));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box.setModal(true);
|
|
|
|
box.center();
|
|
|
|
}
|
2017-02-22 11:38:37 +01:00
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-20 18:04:57 +01:00
|
|
|
bar.add(buttonEmptyVersions);
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
bar.add(new FillToolItem());
|
|
|
|
|
|
|
|
Button buttonRefresh = new Button(WorkspaceTrashOperation.REFRESH.getLabel(),Resources.getIconRefresh());
|
|
|
|
buttonRefresh.setToolTip(WorkspaceTrashOperation.REFRESH.getOperationDescription());
|
|
|
|
buttonRefresh.setScale(ButtonScale.SMALL);
|
|
|
|
buttonRefresh.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonRefresh.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
2017-02-20 14:57:17 +01:00
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.REFRESH, currentVersion, null, windowVersioning));
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bar.add(buttonRefresh);
|
|
|
|
cp.setTopComponent(bar);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the grid.
|
|
|
|
*/
|
|
|
|
public void initGrid() {
|
|
|
|
|
|
|
|
//ColumnConfig icon = new ColumnConfig(FileGridModel.ICON, "", 25);
|
2017-02-24 14:49:31 +01:00
|
|
|
ColumnConfig name = createSortableColumnConfig(FileModel.NAME, "Version Id", 120);
|
2017-02-20 18:04:57 +01:00
|
|
|
//ColumnConfig type = createSortableColumnConfig(FileModel.TYPE, FileModel.TYPE, 80);
|
2017-02-22 11:38:37 +01:00
|
|
|
//ColumnConfig originalPath = createSortableColumnConfig(FileVersionModel.PATH, "Original Path", 200);
|
2017-02-24 14:49:31 +01:00
|
|
|
ColumnConfig created = createSortableColumnConfig(FileVersionModel.CREATED, "Created", 120);
|
2017-02-20 11:42:17 +01:00
|
|
|
//ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Deleted Date", 90);
|
|
|
|
//deleteDate.setDateTimeFormat(DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy"));
|
2017-02-24 14:49:31 +01:00
|
|
|
ColumnConfig user = createSortableColumnConfig(FileVersionModel.USER_VERSIONING, "User", 130);
|
2017-03-01 11:49:16 +01:00
|
|
|
ColumnConfig currVersion = createSortableColumnConfig(FileVersionModel.IS_CURRENT_VERSION, "Current Version", 75);
|
2017-02-23 15:42:45 +01:00
|
|
|
|
|
|
|
ColumnModel cm = new ColumnModel(Arrays.asList(name, created, user, currVersion));
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
grid = new Grid<FileVersionModel>(this.store, cm);
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
GroupingView view = new GroupingView();
|
|
|
|
view.setShowGroupedColumn(false);
|
|
|
|
|
|
|
|
this.grid.setView(view);
|
|
|
|
this.grid.setContextMenu(null);
|
|
|
|
|
|
|
|
GridFilters filters = new GridFilters();
|
|
|
|
filters.setLocal(true);
|
|
|
|
|
|
|
|
StringFilter nameFilter = new StringFilter(FileModel.NAME);
|
2017-02-22 11:38:37 +01:00
|
|
|
DateFilter dateFilter = new DateFilter(FileVersionModel.CREATED);
|
|
|
|
StringFilter userFilter = new StringFilter(FileVersionModel.USER_VERSIONING);
|
2017-02-23 15:42:45 +01:00
|
|
|
BooleanFilter currVersionFilter = new BooleanFilter(FileVersionModel.IS_CURRENT_VERSION);
|
|
|
|
|
|
|
|
final ColumnModel columnModel = cm;
|
|
|
|
|
|
|
|
GridCellRenderer<FileVersionModel> nameRender = new GridCellRenderer<FileVersionModel>() {
|
|
|
|
@Override
|
|
|
|
public String render(FileVersionModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileVersionModel> store, Grid<FileVersionModel> grid) {
|
|
|
|
Boolean isCurrVersion = model.isCurrentVersion();
|
|
|
|
String val = model.get(property);
|
|
|
|
String color = "black";
|
|
|
|
|
|
|
|
if(val!=null && isCurrVersion != null && isCurrVersion){
|
|
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='font-weight: bold;color:" + color + "'>" + val + "</span>";
|
|
|
|
}else{
|
|
|
|
if(val==null)
|
|
|
|
val = "";
|
|
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='color:" + color + "'>" + val + "</span>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-03-01 11:19:56 +01:00
|
|
|
GridCellRenderer<FileVersionModel> currVersionRender = new GridCellRenderer<FileVersionModel>() {
|
|
|
|
@Override
|
|
|
|
public String render(FileVersionModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileVersionModel> store, Grid<FileVersionModel> grid) {
|
|
|
|
Boolean isCurrVersion = model.isCurrentVersion();
|
2017-03-01 11:49:16 +01:00
|
|
|
//String val = model.get(property);
|
2017-03-01 11:19:56 +01:00
|
|
|
|
2017-03-01 11:49:16 +01:00
|
|
|
if(isCurrVersion != null && isCurrVersion){
|
2017-03-01 14:36:52 +01:00
|
|
|
return "<span title='Current Version'>Yes</span>";
|
2017-03-01 11:19:56 +01:00
|
|
|
}else{
|
2017-03-01 14:36:52 +01:00
|
|
|
return "<span title='Previous Version'>No</span>";
|
2017-03-01 11:19:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-23 15:42:45 +01:00
|
|
|
name.setRenderer(nameRender);
|
2017-03-01 11:19:56 +01:00
|
|
|
currVersion.setRenderer(currVersionRender);
|
2017-02-20 11:42:17 +01:00
|
|
|
filters.addFilter(nameFilter);
|
2017-02-22 11:38:37 +01:00
|
|
|
filters.addFilter(dateFilter);
|
2017-02-20 18:04:57 +01:00
|
|
|
filters.addFilter(userFilter);
|
2017-02-23 15:42:45 +01:00
|
|
|
filters.addFilter(currVersionFilter);
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
grid.addPlugin(filters);
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<FileVersionModel>() {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
@Override
|
2017-02-22 11:38:37 +01:00
|
|
|
public void selectionChanged(SelectionChangedEvent<FileVersionModel> se) {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-03-01 18:21:47 +01:00
|
|
|
List<FileVersionModel> selected = grid.getSelectionModel().getSelectedItems();
|
|
|
|
boolean selection = selected.size()>0;
|
2017-02-20 11:42:17 +01:00
|
|
|
activeButtonOnSelection(selection);
|
2017-03-01 18:21:47 +01:00
|
|
|
|
|
|
|
for (FileVersionModel fileVersionModel : selected) {
|
|
|
|
activeCurrentVersionOperation(!fileVersionModel.isCurrentVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(selected.size()>1)
|
|
|
|
activeDownloadOperation(false);
|
|
|
|
|
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
2017-03-01 18:21:47 +01:00
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
grid.getView().setAutoFill(true);
|
|
|
|
grid.setBorders(true);
|
|
|
|
grid.setStripeRows(true);
|
|
|
|
grid.getView().setShowDirtyCells(false);
|
|
|
|
grid.setColumnLines(true);
|
|
|
|
grid.setColumnReordering(true);
|
|
|
|
grid.setStyleAttribute("borderTop", "none");
|
|
|
|
cp.add(grid);
|
|
|
|
|
2017-03-01 18:21:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 11:42:17 +01:00
|
|
|
|
2017-03-01 18:21:47 +01:00
|
|
|
/**
|
|
|
|
* Active download operation.
|
|
|
|
*
|
|
|
|
* @param b the b
|
|
|
|
*/
|
|
|
|
private void activeDownloadOperation(boolean b) {
|
|
|
|
buttonDownload.setEnabled(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Active current version operation.
|
|
|
|
*
|
|
|
|
* @param bool the bool
|
|
|
|
*/
|
|
|
|
private void activeCurrentVersionOperation(boolean bool){
|
|
|
|
buttonDelete.setEnabled(bool);
|
|
|
|
buttonRestore.setEnabled(bool);
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the panel size.
|
|
|
|
*
|
|
|
|
* @param width the width
|
|
|
|
* @param height the height
|
|
|
|
*/
|
|
|
|
public void setPanelSize(int width, int height) {
|
|
|
|
|
|
|
|
if (width > 0 && height > 0 && grid != null) {
|
|
|
|
cp.setSize(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update versions.
|
|
|
|
*
|
|
|
|
* @param versioningFiles the versioning files
|
|
|
|
*/
|
2017-02-20 18:04:57 +01:00
|
|
|
public void updateVersions(List<FileVersionModel> versioningFiles) {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
store.removeAll();
|
|
|
|
typeStoreOperation.removeAll();
|
|
|
|
store.add(versioningFiles);
|
|
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Active buttons on not emtpy.
|
|
|
|
*
|
|
|
|
* @param isNotEmpty the is not empty
|
|
|
|
*/
|
|
|
|
private void activeButtonsOnNotEmtpy(boolean isNotEmpty) {
|
2017-02-20 18:04:57 +01:00
|
|
|
buttonEmptyVersions.setEnabled(isNotEmpty);
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Active button on selection.
|
|
|
|
*
|
|
|
|
* @param bool the bool
|
|
|
|
*/
|
|
|
|
protected void activeButtonOnSelection(boolean bool) {
|
|
|
|
buttonDelete.setEnabled(bool);
|
|
|
|
buttonRestore.setEnabled(bool);
|
2017-02-20 18:04:57 +01:00
|
|
|
buttonDownload.setEnabled(bool);
|
2017-02-20 11:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update store.
|
|
|
|
*
|
|
|
|
* @param store the store
|
|
|
|
*/
|
2017-02-22 11:38:37 +01:00
|
|
|
private void updateStore(ListStore<FileVersionModel> store) {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
resetStore();
|
|
|
|
this.grid.getStore().add(store.getModels());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset store.
|
|
|
|
*/
|
|
|
|
public void resetStore() {
|
|
|
|
this.grid.getStore().removeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the sortable column config.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param name the name
|
|
|
|
* @param width the width
|
|
|
|
* @return the column config
|
|
|
|
*/
|
|
|
|
public ColumnConfig createSortableColumnConfig(String id, String name,
|
|
|
|
int width) {
|
|
|
|
ColumnConfig columnConfig = new ColumnConfig(id, name, width);
|
|
|
|
columnConfig.setSortable(true);
|
|
|
|
|
|
|
|
return columnConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the header title.
|
|
|
|
*
|
|
|
|
* @param title the new header title
|
|
|
|
*/
|
|
|
|
public void setHeaderTitle(String title) {
|
|
|
|
cp.setHeading(title);
|
|
|
|
// cp.layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the file model by identifier.
|
|
|
|
*
|
|
|
|
* @param identifier the identifier
|
|
|
|
* @return the file model by identifier
|
|
|
|
*/
|
2017-02-22 11:38:37 +01:00
|
|
|
public FileVersionModel getFileModelByIdentifier(String identifier){
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
return store.findModel(FileModel.IDENTIFIER, identifier);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete item.
|
|
|
|
*
|
|
|
|
* @param identifier (MANDATORY)
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
|
|
|
public boolean deleteItem(String identifier) {
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
FileVersionModel fileTarget = getFileModelByIdentifier(identifier);
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
if(fileTarget!=null){
|
|
|
|
return deleteItem(fileTarget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
System.out.println("Delete Error: file target with " + identifier + " identifier not exist in store" );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete item.
|
|
|
|
*
|
|
|
|
* @param fileTarget (MANDATORY)
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
2017-02-22 11:38:37 +01:00
|
|
|
private boolean deleteItem(FileVersionModel fileTarget) {
|
2017-02-20 11:42:17 +01:00
|
|
|
|
|
|
|
Record record = store.getRecord(fileTarget);
|
|
|
|
|
|
|
|
if (record != null) {
|
|
|
|
|
2017-02-22 11:38:37 +01:00
|
|
|
FileVersionModel item = (FileVersionModel) record.getModel();
|
2017-02-20 11:42:17 +01:00
|
|
|
store.remove(item);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
System.out.println("Record Error: file target with "
|
|
|
|
+ fileTarget.getIdentifier()
|
|
|
|
+ " identifier not exist in store");
|
|
|
|
|
|
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Versioning items.
|
|
|
|
*
|
|
|
|
* @return the int
|
|
|
|
*/
|
|
|
|
public int versioningItems(){
|
|
|
|
return store.getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the store.
|
|
|
|
*
|
|
|
|
* @return the store
|
|
|
|
*/
|
2017-02-22 11:38:37 +01:00
|
|
|
protected GroupingStore<FileVersionModel> getStore() {
|
2017-02-20 11:42:17 +01:00
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the cp.
|
|
|
|
*
|
|
|
|
* @return the cp
|
|
|
|
*/
|
|
|
|
public ContentPanel getCp() {
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|