List of usage examples for com.google.gwt.user.cellview.client GssSimplePager GssSimplePager
@UiConstructor
public GssSimplePager(TextLocation location)
From source file:org.gss_project.gss.web.client.FileList.java
License:Open Source License
/** * Construct the file list widget. This entails setting up the widget * layout, fetching the number of files in the current folder from the * server and filling the local file cache of displayed files with data from * the server, as well./* w w w . j a v a 2s . c o m*/ * * @param _images */ public FileList(Images _images) { images = _images; DragAndDropCellTable.Resources resources = GWT.create(TableResources.class); ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>() { @Override public Object getKey(FileResource item) { return item.getUri(); } }; celltable = new DragAndDropCellTable<FileResource>(GSS.VISIBLE_FILE_COUNT, resources, keyProvider); DragAndDropColumn<FileResource, ImageResource> status = new DragAndDropColumn<FileResource, ImageResource>( new ImageResourceCell() { @Override public boolean handlesSelection() { return false; } }) { @Override public ImageResource getValue(FileResource entity) { return getFileIcon(entity); } }; celltable.addColumn(status, ""); initDragOperation(status); final DragAndDropColumn<FileResource, SafeHtml> nameColumn = new DragAndDropColumn<FileResource, SafeHtml>( new SafeHtmlCell()) { @Override public SafeHtml getValue(FileResource object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.append(Templates.INSTANCE.filenameSpan(object.getName())); if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) { sb.appendHtmlConstant(" ") .append(Templates.INSTANCE.viewLink( GSS.get().getTopPanel().getFileMenu().getDownloadURL(object), object.getOwner() + " : " + object.getPath() + object.getName())); } return sb.toSafeHtml(); } }; initDragOperation(nameColumn); celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name")); allHeaders.add(nameHeader); //nameHeader.setSorted(true); //nameHeader.toggleReverseSort(); nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name")); celltable.redrawHeaders(); SortableHeader aheader; DragAndDropColumn<FileResource, String> aColumn; celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { return GSS.get().findUserFullName(object.getOwner()); } }, aheader = new SortableHeader("Owner")); initDragOperation(aColumn); allHeaders.add(aheader); aheader.setUpdater(new FileValueUpdater(aheader, "owner")); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { // TODO Auto-generated method stub return object.getPath(); } }, aheader = new SortableHeader("Path")); initDragOperation(aColumn); allHeaders.add(aheader); aheader.setUpdater(new FileValueUpdater(aheader, "path")); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { if (object.isVersioned()) return object.getVersion().toString(); return "-"; } }, aheader = new SortableHeader("Version")); initDragOperation(aColumn); allHeaders.add(aheader); aheader.setUpdater(new FileValueUpdater(aheader, "version")); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { // TODO Auto-generated method stub return object.getFileSizeAsString(); } }, aheader = new SortableHeader("Size")); initDragOperation(aColumn); allHeaders.add(aheader); aheader.setUpdater(new FileValueUpdater(aheader, "size")); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { return formatter.format(object.getModificationDate()); } }, aheader = new SortableHeader("Last Modified")); allHeaders.add(aheader); aheader.setUpdater(new FileValueUpdater(aheader, "date")); provider.addDataDisplay(celltable); celltable.addDragStopHandler(dragStop); celltable.addDragStartHandler(new DragStartEventHandler() { public void onDragStart(DragStartEvent event) { FileResource value = event.getDraggableData(); com.google.gwt.dom.client.Element helper = event.getHelper(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant("<b>"); DisplayHelper.log(value.getName()); if (getSelectedFiles().size() == 1) sb.appendEscaped(value.getName()); else sb.appendEscaped(getSelectedFiles().size() + " files"); sb.appendHtmlConstant("</b>"); helper.setInnerHTML(sb.toSafeHtml().asString()); } }); VerticalPanel vp = new VerticalPanel(); vp.setWidth("100%"); pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER); pagerTop.setDisplay(celltable); uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>"); uploadButtonTop.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new UploadFileCommand(null).execute(); } }); HorizontalPanel topPanel = new HorizontalPanel(); topPanel.add(pagerTop); topPanel.add(uploadButtonTop); vp.add(topPanel); celltable.setWidth("100%"); vp.add(celltable); pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER); pagerBottom.setDisplay(celltable); HorizontalPanel bottomPanel = new HorizontalPanel(); bottomPanel.add(pagerBottom); uploadButtonBottom = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>"); uploadButtonBottom.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { new UploadFileCommand(null).execute(); } }); bottomPanel.add(uploadButtonBottom); vp.add(bottomPanel); vp.setCellWidth(celltable, "100%"); initWidget(vp); pagerBottom.setVisible(false); pagerTop.setVisible(false); celltable.setStyleName("gss-List"); selectionModel = new MultiSelectionModel<FileResource>(keyProvider); Handler selectionHandler = new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) { if (getSelectedFiles().size() == 1) GSS.get().setCurrentSelection(getSelectedFiles().get(0)); else GSS.get().setCurrentSelection(getSelectedFiles()); } }; selectionModel.addSelectionChangeHandler(selectionHandler); celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<FileResource>createDefaultManager()); celltable.setPageSize(GSS.VISIBLE_FILE_COUNT); //celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); Scheduler.get().scheduleIncremental(new RepeatingCommand() { @Override public boolean execute() { return fetchRootFolder(); } }); sinkEvents(Event.ONCONTEXTMENU); sinkEvents(Event.ONMOUSEUP); sinkEvents(Event.ONMOUSEDOWN); sinkEvents(Event.ONCLICK); sinkEvents(Event.ONKEYDOWN); sinkEvents(Event.ONDBLCLICK); GSS.preventIESelection(); }
From source file:org.gss_project.gss.web.client.SearchResults.java
License:Open Source License
/** * Construct the file list widget. This entails setting up the widget * layout, fetching the number of files in the current folder from the * server and filling the local file cache of displayed files with data from * the server, as well.// w ww. ja v a 2s. co m * * @param _images */ public SearchResults(Images _images) { images = _images; DragAndDropCellTable.Resources resources = GWT.create(TableResources.class); ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>() { @Override public Object getKey(FileResource item) { return item.getUri(); } }; celltable = new DragAndDropCellTable<FileResource>(GSS.VISIBLE_FILE_COUNT, resources, keyProvider) { @Override protected void onBrowserEvent2(Event event) { /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){ fireClickEvent((Element) event.getEventTarget().cast()); }*/ super.onBrowserEvent2(event); } }; provider.addDataDisplay(celltable); celltable.addDragStopHandler(dragStop); celltable.addDragStartHandler(new DragStartEventHandler() { public void onDragStart(DragStartEvent event) { FileResource value = event.getDraggableData(); com.google.gwt.dom.client.Element helper = event.getHelper(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant("<b>"); DisplayHelper.log(value.getName()); if (getSelectedFiles().size() == 1) sb.appendEscaped(value.getName()); else sb.appendEscaped(getSelectedFiles().size() + " files"); sb.appendHtmlConstant("</b>"); helper.setInnerHTML(sb.toSafeHtml().asString()); } }); DragAndDropColumn<FileResource, ImageResource> status = new DragAndDropColumn<FileResource, ImageResource>( new ImageResourceCell() { @Override public boolean handlesSelection() { return false; } }) { @Override public ImageResource getValue(FileResource entity) { return getFileIcon(entity); } }; celltable.addColumn(status, ""); initDragOperation(status); final DragAndDropColumn<FileResource, SafeHtml> nameColumn = new DragAndDropColumn<FileResource, SafeHtml>( new SafeHtmlCell()) { @Override public SafeHtml getValue(FileResource object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.append(FileList.Templates.INSTANCE.filenameSpan(object.getName())); if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) { sb.appendHtmlConstant(" ") .append(FileList.Templates.INSTANCE.viewLink( GSS.get().getTopPanel().getFileMenu().getDownloadURL(object), object.getOwner() + " : " + object.getPath() + object.getName())); } return sb.toSafeHtml(); } }; initDragOperation(nameColumn); celltable.addColumn(nameColumn, "Name"); DragAndDropColumn<FileResource, String> aColumn; celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { return GSS.get().findUserFullName(object.getOwner()); } }, "Owner"); initDragOperation(aColumn); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { if (object.isDeleted()) return object.getPath() + " (In Trash)"; return object.getPath(); } }, "Path"); initDragOperation(aColumn); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { if (object.isVersioned()) return object.getVersion().toString(); return "-"; } }, "Version"); initDragOperation(aColumn); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { // TODO Auto-generated method stub return object.getFileSizeAsString(); } }, "Size"); initDragOperation(aColumn); celltable.addColumn(aColumn = new DragAndDropColumn<FileResource, String>(new TextCell()) { @Override public String getValue(FileResource object) { return formatter.format(object.getModificationDate()); } }, "Last Modified"); VerticalPanel vp = new VerticalPanel(); vp.setWidth("100%"); celltable.setWidth("100%"); vp.add(searchResults); searchResults.addStyleName("gss-searchLabel"); pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER); pagerTop.setDisplay(celltable); vp.add(pagerTop); vp.add(celltable); pager = new GssSimplePager(GssSimplePager.TextLocation.CENTER); pager.setDisplay(celltable); //celltable.setPageSize(2); vp.add(pager); vp.setCellWidth(celltable, "100%"); initWidget(vp); //initWidget(celltable); celltable.setStyleName("gss-List"); selectionModel = new MultiSelectionModel<FileResource>(); Handler selectionHandler = new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) { if (getSelectedFiles().size() == 1) GSS.get().setCurrentSelection(getSelectedFiles().get(0)); else GSS.get().setCurrentSelection(getSelectedFiles()); //contextMenu.setFiles(getSelectedFiles()); } }; selectionModel.addSelectionChangeHandler(selectionHandler); celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<FileResource>createDefaultManager()); celltable.setPageSize(GSS.VISIBLE_FILE_COUNT); celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); Scheduler.get().scheduleIncremental(new RepeatingCommand() { @Override public boolean execute() { return fetchRootFolder(); } }); sinkEvents(Event.ONCONTEXTMENU); sinkEvents(Event.ONMOUSEUP); sinkEvents(Event.ONMOUSEDOWN); sinkEvents(Event.ONCLICK); sinkEvents(Event.ONKEYDOWN); sinkEvents(Event.ONDBLCLICK); GSS.preventIESelection(); }