001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.components; 029 030import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_CACHE; 031import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_COPYRIGHT; 032import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_DATE_CREATED; 033import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_DATE_EXPIRED; 034import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_DATE_MODIFIED; 035import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_DATE_RELEASED; 036import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_INSIDE_PROJECT; 037import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_IN_NAVIGATION; 038import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_IS_FOLDER; 039import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_NAVIGATION_POSITION; 040import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_NAVIGATION_TEXT; 041import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_PERMISSIONS; 042import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_PROJECT; 043import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED; 044import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_RESOURCE_NAME; 045import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_RESOURCE_TYPE; 046import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_SITE_PATH; 047import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_SIZE; 048import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_STATE; 049import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_STATE_NAME; 050import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_TITLE; 051import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_TYPE_ICON; 052import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_USER_CREATED; 053import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_USER_LOCKED; 054import static org.opencms.ui.components.CmsResourceTableProperty.PROPERTY_USER_MODIFIED; 055 056import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 057import org.opencms.db.CmsResourceState; 058import org.opencms.file.CmsObject; 059import org.opencms.file.CmsProperty; 060import org.opencms.file.CmsPropertyDefinition; 061import org.opencms.file.CmsResource; 062import org.opencms.file.types.I_CmsResourceType; 063import org.opencms.main.CmsException; 064import org.opencms.main.CmsLog; 065import org.opencms.main.OpenCms; 066import org.opencms.ui.A_CmsUI; 067import org.opencms.ui.CmsCssIcon; 068import org.opencms.ui.CmsVaadinUtils; 069import org.opencms.ui.util.I_CmsItemSorter; 070import org.opencms.util.CmsStringUtil; 071import org.opencms.util.CmsUUID; 072import org.opencms.workplace.CmsWorkplaceMessages; 073import org.opencms.workplace.explorer.CmsResourceUtil; 074 075import java.util.ArrayList; 076import java.util.Arrays; 077import java.util.Collection; 078import java.util.Collections; 079import java.util.HashMap; 080import java.util.LinkedHashSet; 081import java.util.List; 082import java.util.Locale; 083import java.util.Map; 084import java.util.Set; 085 086import org.apache.commons.logging.Log; 087 088import com.google.common.collect.Lists; 089import com.google.common.collect.Sets; 090import com.vaadin.event.dd.DropHandler; 091import com.vaadin.ui.CustomComponent; 092import com.vaadin.v7.data.Item; 093import com.vaadin.v7.data.util.IndexedContainer; 094import com.vaadin.v7.shared.ui.label.ContentMode; 095import com.vaadin.v7.ui.Label; 096import com.vaadin.v7.ui.Table; 097import com.vaadin.v7.ui.Table.RowHeaderMode; 098import com.vaadin.v7.ui.Table.TableDragMode; 099 100/** 101 * Generic table for displaying lists of resources.<p> 102 */ 103public class CmsResourceTable extends CustomComponent { 104 105 /** 106 * Helper class for easily configuring a set of columns to display, together with their visibility / collapsed status.<p> 107 */ 108 public class ColumnBuilder { 109 110 /** The column entries configured so far. */ 111 private List<ColumnEntry> m_columnEntries = Lists.newArrayList(); 112 113 /** 114 * Sets up the table and its container using the columns configured so far.<p> 115 */ 116 public void buildColumns() { 117 118 Set<CmsResourceTableProperty> visible = new LinkedHashSet<CmsResourceTableProperty>(); 119 Set<CmsResourceTableProperty> collapsed = new LinkedHashSet<CmsResourceTableProperty>(); 120 for (ColumnEntry entry : m_columnEntries) { 121 CmsResourceTableProperty prop = entry.getColumn(); 122 m_container.addContainerProperty(prop, prop.getColumnType(), prop.getDefaultValue()); 123 if (entry.isCollapsed()) { 124 collapsed.add(entry.getColumn()); 125 } 126 if (entry.isVisible()) { 127 visible.add(entry.getColumn()); 128 } 129 } 130 m_fileTable.setVisibleColumns(visible.toArray(new Object[0])); 131 setCollapsedColumns(collapsed.toArray(new Object[0])); 132 for (CmsResourceTableProperty visibleProp : visible) { 133 String headerKey = visibleProp.getHeaderKey(); 134 if (!CmsStringUtil.isEmptyOrWhitespaceOnly(headerKey)) { 135 m_fileTable.setColumnHeader(visibleProp, CmsVaadinUtils.getMessageText(headerKey)); 136 } else { 137 m_fileTable.setColumnHeader(visibleProp, ""); 138 } 139 m_fileTable.setColumnCollapsible(visibleProp, visibleProp.isCollapsible()); 140 if (visibleProp.getColumnWidth() > 0) { 141 m_fileTable.setColumnWidth(visibleProp, visibleProp.getColumnWidth()); 142 } 143 if (visibleProp.getExpandRatio() > 0) { 144 m_fileTable.setColumnExpandRatio(visibleProp, visibleProp.getExpandRatio()); 145 } 146 if (visibleProp.getConverter() != null) { 147 m_fileTable.setConverter(visibleProp, visibleProp.getConverter()); 148 } 149 } 150 } 151 152 /** 153 * Adds a new column.<p> 154 * 155 * @param prop the column 156 * 157 * @return this object 158 */ 159 public ColumnBuilder column(CmsResourceTableProperty prop) { 160 161 column(prop, 0); 162 return this; 163 } 164 165 /** 166 * Adds a new column.<p< 167 * 168 * @param prop the column 169 * @param flags the flags for the column 170 * 171 * @return this object 172 */ 173 public ColumnBuilder column(CmsResourceTableProperty prop, int flags) { 174 175 ColumnEntry entry = new ColumnEntry(); 176 entry.setColumn(prop); 177 entry.setFlags(flags); 178 m_columnEntries.add(entry); 179 return this; 180 } 181 } 182 183 /** 184 * Contains the data for the given column, along with some flags to control visibility/collapsed status.<p> 185 * 186 */ 187 public static class ColumnEntry { 188 189 /** The column. */ 190 private CmsResourceTableProperty m_column; 191 192 /** The flags. */ 193 private int m_flags; 194 195 /** 196 * Returns the column.<p> 197 * 198 * @return the column 199 */ 200 public CmsResourceTableProperty getColumn() { 201 202 return m_column; 203 } 204 205 /** 206 * Returns the collapsed.<p> 207 * 208 * @return the collapsed 209 */ 210 public boolean isCollapsed() { 211 212 return (m_flags & COLLAPSED) != 0; 213 } 214 215 /** 216 * Returns the visible.<p> 217 * 218 * @return the visible 219 */ 220 public boolean isVisible() { 221 222 return 0 == (m_flags & INVISIBLE); 223 } 224 225 /** 226 * Sets the column.<p> 227 * 228 * @param column the column to set 229 */ 230 public void setColumn(CmsResourceTableProperty column) { 231 232 m_column = column; 233 } 234 235 /** 236 * Sets the flags.<p> 237 * 238 * @param flags the flags to set 239 */ 240 public void setFlags(int flags) { 241 242 m_flags = flags; 243 } 244 245 } 246 247 /** 248 * Provides item property values for additional table columns.<p> 249 */ 250 public static interface I_ResourcePropertyProvider { 251 252 /** 253 * Adds the property values to the given item.<p> 254 * 255 * @param resourceItem the resource item 256 * @param cms the cms context 257 * @param resource the resource 258 * @param locale the workplace locale 259 */ 260 void addItemProperties(Item resourceItem, CmsObject cms, CmsResource resource, Locale locale); 261 } 262 263 /** 264 * Extending the indexed container to make the number of un-filtered items available.<p> 265 */ 266 protected static class ItemContainer extends IndexedContainer { 267 268 /** The serial version id. */ 269 private static final long serialVersionUID = -2033722658471550506L; 270 271 /** 272 * @see com.vaadin.v7.data.util.IndexedContainer#getSortableContainerPropertyIds() 273 */ 274 @Override 275 public Collection<?> getSortableContainerPropertyIds() { 276 277 if (getItemSorter() instanceof I_CmsItemSorter) { 278 return ((I_CmsItemSorter)getItemSorter()).getSortableContainerPropertyIds(this); 279 } else { 280 return super.getSortableContainerPropertyIds(); 281 } 282 } 283 284 /** 285 * Returns the number of items in the container, not considering any filters.<p> 286 * 287 * @return the number of items 288 */ 289 protected int getItemCount() { 290 291 return getAllItemIds().size(); 292 } 293 } 294 295 /** Flag to mark columns as initially collapsed.*/ 296 public static final int COLLAPSED = 1; 297 298 /** Flag to mark columns as invisible. */ 299 public static final int INVISIBLE = 2; 300 301 /** The logger instance for this class. */ 302 private static final Log LOG = CmsLog.getLog(CmsResourceTable.class); 303 304 /** Serial version id. */ 305 private static final long serialVersionUID = 1L; 306 307 /** The resource data container. */ 308 protected ItemContainer m_container = new ItemContainer(); 309 310 /** The table used to display the resource data. */ 311 protected Table m_fileTable = new Table(); 312 313 /** Property provider for additional columns. */ 314 protected List<I_ResourcePropertyProvider> m_propertyProviders; 315 316 /** 317 * Creates a new instance.<p> 318 * 319 * This constructor does *not* set up the columns of the table; use the ColumnBuilder inner class for this. 320 */ 321 public CmsResourceTable() { 322 323 m_propertyProviders = new ArrayList<I_ResourcePropertyProvider>(); 324 m_fileTable.setContainerDataSource(m_container); 325 setCompositionRoot(m_fileTable); 326 m_fileTable.setRowHeaderMode(RowHeaderMode.HIDDEN); 327 } 328 329 /** 330 * Static helper method to initialize the 'standard' properties of a data item from a given resource.<p> 331 * @param resourceItem the resource item to fill 332 * @param cms the CMS context 333 * @param resource the resource 334 * @param locale the locale 335 */ 336 public static void fillItemDefault(Item resourceItem, CmsObject cms, CmsResource resource, Locale locale) { 337 338 if (resource == null) { 339 LOG.error("Error rendering item for 'null' resource"); 340 return; 341 } 342 343 if (resourceItem == null) { 344 LOG.error("Error rendering 'null' item for resource " + resource.getRootPath()); 345 return; 346 } 347 if (cms == null) { 348 cms = A_CmsUI.getCmsObject(); 349 LOG.warn("CmsObject was 'null', using thread local CmsObject"); 350 } 351 CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource); 352 Map<String, CmsProperty> resourceProps = null; 353 try { 354 List<CmsProperty> props = cms.readPropertyObjects(resource, false); 355 resourceProps = new HashMap<String, CmsProperty>(); 356 for (CmsProperty prop : props) { 357 resourceProps.put(prop.getName(), prop); 358 } 359 } catch (CmsException e1) { 360 LOG.debug("Unable to read properties for resource '" + resource.getRootPath() + "'.", e1); 361 } 362 I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource); 363 if (resourceItem.getItemProperty(PROPERTY_TYPE_ICON) != null) { 364 resourceItem.getItemProperty(PROPERTY_TYPE_ICON).setValue( 365 new CmsResourceIcon(resUtil, resource.getState(), true)); 366 } 367 368 if (resourceItem.getItemProperty(PROPERTY_PROJECT) != null) { 369 Label projectFlag = null; 370 switch (resUtil.getProjectState().getMode()) { 371 case 1: 372 projectFlag = new Label( 373 new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_CURRENT).getHtml(resUtil.getLockedInProjectName()), 374 ContentMode.HTML); 375 break; 376 case 2: 377 projectFlag = new Label( 378 new CmsCssIcon(OpenCmsTheme.ICON_PROJECT_OTHER).getHtml(resUtil.getLockedInProjectName()), 379 ContentMode.HTML); 380 break; 381 case 5: 382 projectFlag = new Label( 383 new CmsCssIcon(OpenCmsTheme.ICON_PUBLISH).getHtml(resUtil.getLockedInProjectName()), 384 ContentMode.HTML); 385 break; 386 default: 387 } 388 resourceItem.getItemProperty(PROPERTY_PROJECT).setValue(projectFlag); 389 } 390 391 if (resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT) != null) { 392 resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT).setValue(Boolean.valueOf(resUtil.isInsideProject())); 393 } 394 395 if (resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED) != null) { 396 resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED).setValue( 397 Boolean.valueOf(resUtil.isReleasedAndNotExpired())); 398 } 399 400 if (resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME) != null) { 401 resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME).setValue(resource.getName()); 402 } 403 404 if (resourceItem.getItemProperty(PROPERTY_SITE_PATH) != null) { 405 resourceItem.getItemProperty(PROPERTY_SITE_PATH).setValue(cms.getSitePath(resource)); 406 } 407 408 if ((resourceItem.getItemProperty(PROPERTY_TITLE) != null) && (resourceProps != null)) { 409 resourceItem.getItemProperty(PROPERTY_TITLE).setValue( 410 resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_TITLE) 411 ? resourceProps.get(CmsPropertyDefinition.PROPERTY_TITLE).getValue() 412 : ""); 413 } 414 boolean inNavigation = false; 415 if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT) != null) && (resourceProps != null)) { 416 resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT).setValue( 417 resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT) 418 ? resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVTEXT).getValue() 419 : ""); 420 inNavigation = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT); 421 } 422 423 if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION) != null) && (resourceProps != null)) { 424 try { 425 Float navPos = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS) 426 ? Float.valueOf(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVPOS).getValue()) 427 : (inNavigation ? Float.valueOf(Float.MAX_VALUE) : null); 428 resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION).setValue(navPos); 429 inNavigation = navPos != null; 430 } catch (Exception e) { 431 LOG.debug("Error evaluating navPos property", e); 432 } 433 } 434 435 if (resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION) != null) { 436 if (inNavigation 437 && (resourceProps != null) 438 && resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVINFO) 439 && CmsClientSitemapEntry.HIDDEN_NAVIGATION_ENTRY.equals( 440 resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVINFO).getValue())) { 441 inNavigation = false; 442 } 443 resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION).setValue(Boolean.valueOf(inNavigation)); 444 } 445 446 if ((resourceItem.getItemProperty(PROPERTY_COPYRIGHT) != null) && (resourceProps != null)) { 447 resourceItem.getItemProperty(PROPERTY_COPYRIGHT).setValue( 448 resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_COPYRIGHT) 449 ? resourceProps.get(CmsPropertyDefinition.PROPERTY_COPYRIGHT).getValue() 450 : ""); 451 } 452 453 if ((resourceItem.getItemProperty(PROPERTY_CACHE) != null) && (resourceProps != null)) { 454 resourceItem.getItemProperty(PROPERTY_CACHE).setValue( 455 resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_CACHE) 456 ? resourceProps.get(CmsPropertyDefinition.PROPERTY_CACHE).getValue() 457 : ""); 458 } 459 460 if (resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE) != null) { 461 resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE).setValue( 462 CmsWorkplaceMessages.getResourceTypeName(locale, type.getTypeName())); 463 } 464 465 if (resourceItem.getItemProperty(PROPERTY_IS_FOLDER) != null) { 466 resourceItem.getItemProperty(PROPERTY_IS_FOLDER).setValue(Boolean.valueOf(resource.isFolder())); 467 } 468 469 if (resourceItem.getItemProperty(PROPERTY_SIZE) != null) { 470 if (resource.isFile()) { 471 resourceItem.getItemProperty(PROPERTY_SIZE).setValue(Integer.valueOf(resource.getLength())); 472 } 473 } 474 475 if (resourceItem.getItemProperty(PROPERTY_PERMISSIONS) != null) { 476 resourceItem.getItemProperty(PROPERTY_PERMISSIONS).setValue(resUtil.getPermissionString()); 477 } 478 479 if (resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED) != null) { 480 resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED).setValue(Long.valueOf(resource.getDateLastModified())); 481 } 482 483 if (resourceItem.getItemProperty(PROPERTY_USER_MODIFIED) != null) { 484 resourceItem.getItemProperty(PROPERTY_USER_MODIFIED).setValue(resUtil.getUserLastModified()); 485 } 486 487 if (resourceItem.getItemProperty(PROPERTY_DATE_CREATED) != null) { 488 resourceItem.getItemProperty(PROPERTY_DATE_CREATED).setValue(Long.valueOf(resource.getDateCreated())); 489 } 490 491 if (resourceItem.getItemProperty(PROPERTY_USER_CREATED) != null) { 492 resourceItem.getItemProperty(PROPERTY_USER_CREATED).setValue(resUtil.getUserCreated()); 493 } 494 495 if (resourceItem.getItemProperty(PROPERTY_DATE_RELEASED) != null) { 496 long release = resource.getDateReleased(); 497 if (release != CmsResource.DATE_RELEASED_DEFAULT) { 498 resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(Long.valueOf(release)); 499 } else { 500 resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(null); 501 } 502 } 503 504 if (resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED) != null) { 505 long expire = resource.getDateExpired(); 506 if (expire != CmsResource.DATE_EXPIRED_DEFAULT) { 507 resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(Long.valueOf(expire)); 508 } else { 509 resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(null); 510 } 511 } 512 513 if (resourceItem.getItemProperty(PROPERTY_STATE_NAME) != null) { 514 resourceItem.getItemProperty(PROPERTY_STATE_NAME).setValue(resUtil.getStateName()); 515 } 516 517 if (resourceItem.getItemProperty(PROPERTY_STATE) != null) { 518 resourceItem.getItemProperty(PROPERTY_STATE).setValue(resource.getState()); 519 } 520 521 if (resourceItem.getItemProperty(PROPERTY_USER_LOCKED) != null) { 522 resourceItem.getItemProperty(PROPERTY_USER_LOCKED).setValue(resUtil.getLockedByName()); 523 } 524 } 525 526 /** 527 * Gets the CSS style name for the given resource state.<p> 528 * 529 * @param state the resource state 530 * @return the CSS style name 531 */ 532 public static String getStateStyle(CmsResourceState state) { 533 534 String stateStyle = ""; 535 if (state != null) { 536 if (state.isDeleted()) { 537 stateStyle = OpenCmsTheme.STATE_DELETED; 538 } else if (state.isNew()) { 539 stateStyle = OpenCmsTheme.STATE_NEW; 540 } else if (state.isChanged()) { 541 stateStyle = OpenCmsTheme.STATE_CHANGED; 542 } 543 } 544 return stateStyle; 545 } 546 547 /** 548 * Adds a property provider.<p> 549 * 550 * @param provider the property provider 551 */ 552 public void addPropertyProvider(I_ResourcePropertyProvider provider) { 553 554 m_propertyProviders.add(provider); 555 } 556 557 /** 558 * Clears the value selection.<p> 559 */ 560 public void clearSelection() { 561 562 m_fileTable.setValue(Collections.emptySet()); 563 } 564 565 /** 566 * Fills the resource table.<p> 567 * 568 * @param cms the current CMS context 569 * @param resources the resources which should be displayed in the table 570 */ 571 public void fillTable(CmsObject cms, List<CmsResource> resources) { 572 573 fillTable(cms, resources, true); 574 } 575 576 /** 577 * Fills the resource table.<p> 578 * 579 * @param cms the current CMS context 580 * @param resources the resources which should be displayed in the table 581 * @param clearFilter <code>true</code> to clear the search filter 582 */ 583 public void fillTable(CmsObject cms, List<CmsResource> resources, boolean clearFilter) { 584 585 fillTable(cms, resources, clearFilter, true); 586 } 587 588 /** 589 * Fills the resource table.<p> 590 * 591 * @param cms the current CMS context 592 * @param resources the resources which should be displayed in the table 593 * @param clearFilter <code>true</code> to clear the search filter 594 * @param sort <code>true</code> to sort the table entries 595 */ 596 public void fillTable(CmsObject cms, List<CmsResource> resources, boolean clearFilter, boolean sort) { 597 598 Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms); 599 m_container.removeAllItems(); 600 if (clearFilter) { 601 m_container.removeAllContainerFilters(); 602 } 603 for (CmsResource resource : resources) { 604 fillItem(cms, resource, wpLocale); 605 } 606 if (sort) { 607 m_fileTable.sort(); 608 } 609 clearSelection(); 610 } 611 612 /** 613 * Gets structure ids of resources for current folder in current sort order.<p> 614 * 615 * @return the structure ids of the current folder contents 616 */ 617 @SuppressWarnings("unchecked") 618 public List<CmsUUID> getAllIds() { 619 620 return itemIdsToUUIDs((List<String>)m_fileTable.getContainerDataSource().getItemIds()); 621 } 622 623 /** 624 * Returns the number of currently visible items.<p> 625 * 626 * @return the number of currentliy visible items 627 */ 628 public int getItemCount() { 629 630 return m_container.getItemCount(); 631 } 632 633 /** 634 * Returns the structure id to the given string item id.<p> 635 * 636 * @param itemId the item id 637 * 638 * @return the structure id 639 */ 640 public CmsUUID getUUIDFromItemID(String itemId) { 641 642 return new CmsUUID(itemId); 643 } 644 645 /** 646 * Returns if the column with the given property id is visible and not collapsed.<p> 647 * 648 * @param propertyId the property id 649 * 650 * @return <code>true</code> if the column is visible 651 */ 652 public boolean isColumnVisible(CmsResourceTableProperty propertyId) { 653 654 return Arrays.asList(m_fileTable.getVisibleColumns()).contains(propertyId) 655 && !m_fileTable.isColumnCollapsed(propertyId); 656 } 657 658 /** 659 * Removes a property provider.<p> 660 * 661 * @param provider the provider to remove 662 */ 663 public void removePropertyProvider(I_ResourcePropertyProvider provider) { 664 665 m_propertyProviders.remove(provider); 666 } 667 668 /** 669 * Selects all resources.<p> 670 */ 671 public void selectAll() { 672 673 m_fileTable.setValue(m_fileTable.getItemIds()); 674 } 675 676 /** 677 * Sets the list of collapsed columns.<p> 678 * 679 * @param collapsedColumns the list of collapsed columns 680 */ 681 public void setCollapsedColumns(Object... collapsedColumns) { 682 683 Set<Object> collapsedSet = Sets.newHashSet(); 684 for (Object collapsed : collapsedColumns) { 685 collapsedSet.add(collapsed); 686 } 687 for (Object key : m_fileTable.getVisibleColumns()) { 688 m_fileTable.setColumnCollapsed(key, collapsedSet.contains(key)); 689 } 690 } 691 692 /** 693 * Sets the table drag mode.<p> 694 * 695 * @param dragMode the drag mode 696 */ 697 public void setDragMode(TableDragMode dragMode) { 698 699 m_fileTable.setDragMode(dragMode); 700 } 701 702 /** 703 * Sets the table drop handler.<p> 704 * 705 * @param handler the drop handler 706 */ 707 public void setDropHandler(DropHandler handler) { 708 709 m_fileTable.setDropHandler(handler); 710 } 711 712 /** 713 * Selects an given object in table.<p> 714 * 715 * @param o object to be selected. 716 */ 717 public void setValue(Set<String> o) { 718 719 m_fileTable.setValue(o); 720 } 721 722 /** 723 * Fills the file item data.<p> 724 * 725 * @param cms the cms context 726 * @param resource the resource 727 * @param locale the workplace locale 728 */ 729 protected void fillItem(CmsObject cms, CmsResource resource, Locale locale) { 730 731 Item resourceItem = m_container.getItem(resource.getStructureId().toString()); 732 if (resourceItem == null) { 733 resourceItem = m_container.addItem(resource.getStructureId().toString()); 734 } 735 fillItemDefault(resourceItem, cms, resource, locale); 736 for (I_ResourcePropertyProvider provider : m_propertyProviders) { 737 provider.addItemProperties(resourceItem, cms, resource, locale); 738 } 739 } 740 741 /** 742 * Transforms the given item ids into UUIDs.<p> 743 * 744 * @param itemIds the item ids 745 * 746 * @return the UUIDs 747 */ 748 protected List<CmsUUID> itemIdsToUUIDs(Collection<String> itemIds) { 749 750 List<CmsUUID> ids = new ArrayList<CmsUUID>(); 751 for (String itemId : itemIds) { 752 ids.add(getUUIDFromItemID(itemId)); 753 } 754 return ids; 755 } 756 757}