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.ade.galleries.client.ui; 029 030import org.opencms.ade.galleries.client.CmsCategoriesTabHandler; 031import org.opencms.ade.galleries.client.CmsGalleriesTabHandler; 032import org.opencms.ade.galleries.client.CmsGalleryController; 033import org.opencms.ade.galleries.client.CmsResultsTabHandler; 034import org.opencms.ade.galleries.client.CmsSearchTabHandler; 035import org.opencms.ade.galleries.client.CmsSitemapTabHandler; 036import org.opencms.ade.galleries.client.CmsTypesTabHandler; 037import org.opencms.ade.galleries.client.CmsVfsTabHandler; 038import org.opencms.ade.galleries.client.I_CmsGalleryHandler; 039import org.opencms.ade.galleries.client.I_CmsGalleryWidgetHandler; 040import org.opencms.ade.galleries.client.Messages; 041import org.opencms.ade.galleries.client.ui.css.I_CmsLayoutBundle; 042import org.opencms.ade.galleries.shared.CmsGalleryDataBean; 043import org.opencms.ade.galleries.shared.CmsGalleryFolderBean; 044import org.opencms.ade.galleries.shared.CmsGallerySearchBean; 045import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryTabId; 046import org.opencms.gwt.client.dnd.CmsDNDHandler; 047import org.opencms.gwt.client.ui.CmsNotification; 048import org.opencms.gwt.client.ui.CmsNotificationWidget; 049import org.opencms.gwt.client.ui.CmsTabbedPanel; 050import org.opencms.gwt.client.ui.CmsTabbedPanel.CmsTabbedPanelStyle; 051import org.opencms.gwt.client.ui.CmsToolbarPopup; 052import org.opencms.gwt.client.ui.I_CmsAutoHider; 053import org.opencms.gwt.client.ui.I_CmsNotificationWidget; 054import org.opencms.gwt.client.ui.I_CmsTruncable; 055import org.opencms.gwt.client.util.CmsStyleVariable; 056 057import java.util.ArrayList; 058import java.util.Iterator; 059import java.util.List; 060 061import com.google.gwt.core.client.Scheduler; 062import com.google.gwt.core.client.Scheduler.ScheduledCommand; 063import com.google.gwt.dom.client.Style.Unit; 064import com.google.gwt.event.logical.shared.BeforeSelectionEvent; 065import com.google.gwt.event.logical.shared.BeforeSelectionHandler; 066import com.google.gwt.event.logical.shared.SelectionEvent; 067import com.google.gwt.event.logical.shared.SelectionHandler; 068import com.google.gwt.user.client.Command; 069import com.google.gwt.user.client.ui.Composite; 070import com.google.gwt.user.client.ui.FlowPanel; 071import com.google.gwt.user.client.ui.HTMLPanel; 072import com.google.gwt.user.client.ui.HasText; 073import com.google.gwt.user.client.ui.RootPanel; 074 075/** 076 * Provides the method for the gallery dialog.<p> 077 * 078 * @since 8.0. 079 */ 080public class CmsGalleryDialog extends Composite 081implements BeforeSelectionHandler<Integer>, SelectionHandler<Integer>, I_CmsTruncable { 082 083 /** The initial dialog width. */ 084 public static final int DEFAULT_DIALOG_HEIGHT = 486; 085 086 /** The initial dialog width. */ 087 public static final int DEFAULT_DIALOG_WIDTH = 800; 088 089 /** Text metrics key. */ 090 private static final String TM_GALLERY_DIALOG = "GalleryDialog"; 091 092 /** The parent panel for the gallery dialog. */ 093 protected FlowPanel m_parentPanel; 094 095 /** The tabbed panel. */ 096 protected CmsTabbedPanel<A_CmsTab> m_tabbedPanel; 097 098 /** The auto-hide parent to this dialog if present. */ 099 private I_CmsAutoHider m_autoHideParent; 100 101 /** The categories tab. */ 102 private CmsCategoriesTab m_categoriesTab; 103 104 /** The gallery controller. */ 105 private CmsGalleryController m_controller; 106 107 /** The HTML id of the dialog element. */ 108 private String m_dialogElementId; 109 110 /** The drag and drop handler. */ 111 private CmsDNDHandler m_dndHandler; 112 113 /** The galleries tab. */ 114 private CmsGalleriesTab m_galleriesTab; 115 116 /** The gallery handler. */ 117 private I_CmsGalleryHandler m_galleryHandler; 118 119 /** The dialog height. */ 120 private int m_height; 121 122 /** The image format names. */ 123 private String m_imageFormatNames; 124 125 /** The image formats. */ 126 private String m_imageFormats; 127 128 /** The flag for the initails search. */ 129 private boolean m_isInitialSearch; 130 131 /** The command which should be executed when this widget is attached to the DOM. */ 132 private Command m_onAttachCommand; 133 134 /** Flag which indicates that the formats from this object should have priority. */ 135 private boolean m_overrideFormats; 136 137 /** The preview visible style. */ 138 private CmsStyleVariable m_previewVisibility; 139 140 /** Flag indicating if the resource preview is visible. */ 141 private boolean m_previewVisible; 142 143 /** The results tab. */ 144 private CmsResultsTab m_resultsTab; 145 146 /** The Full-text search tab. */ 147 private CmsSearchTab m_searchTab; 148 149 /** The sitemap tab. */ 150 private CmsSitemapTab m_sitemapTab; 151 152 /** The types tab. */ 153 private CmsTypesTab m_typesTab; 154 155 /** The use formats flag. */ 156 private boolean m_useFormats; 157 158 /** The VFS folder tab. */ 159 private CmsVfsTab m_vfsTab; 160 161 /** The widget handler. */ 162 private I_CmsGalleryWidgetHandler m_widgetHandler; 163 164 /** The dialog width. */ 165 private int m_width; 166 167 /** 168 * The constructor.<p> 169 * 170 * @param galleryHandler the gallery handler 171 */ 172 public CmsGalleryDialog(I_CmsGalleryHandler galleryHandler) { 173 174 this(galleryHandler, CmsTabbedPanelStyle.buttonTabs); 175 } 176 177 /** 178 * The default constructor for the gallery dialog.<p> 179 * 180 * @param galleryHandler the gallery handler 181 * @param style the style for the panel 182 */ 183 public CmsGalleryDialog(I_CmsGalleryHandler galleryHandler, CmsTabbedPanelStyle style) { 184 185 initCss(); 186 m_height = DEFAULT_DIALOG_HEIGHT; 187 m_width = DEFAULT_DIALOG_WIDTH; 188 m_isInitialSearch = false; 189 // parent widget 190 m_parentPanel = new FlowPanel(); 191 m_parentPanel.setStyleName(I_CmsLayoutBundle.INSTANCE.galleryDialogCss().parentPanel()); 192 m_previewVisibility = new CmsStyleVariable(m_parentPanel); 193 m_previewVisibility.setValue(I_CmsLayoutBundle.INSTANCE.previewDialogCss().hidePreview()); 194 m_dialogElementId = HTMLPanel.createUniqueId(); 195 m_parentPanel.getElement().setId(m_dialogElementId); 196 // set the default height of the dialog 197 m_parentPanel.getElement().getStyle().setHeight((m_height), Unit.PX); 198 // tabs 199 m_tabbedPanel = new CmsTabbedPanel<A_CmsTab>(style); 200 // add tabs to parent widget 201 m_parentPanel.add(m_tabbedPanel); 202 // m_showPreview = new CmsPushButton(); 203 // m_showPreview.setText(Messages.get().key(Messages.GUI_PREVIEW_BUTTON_SHOW_0)); 204 // m_showPreview.addStyleName(I_CmsLayoutBundle.INSTANCE.galleryDialogCss().showPreview()); 205 // m_showPreview.addClickHandler(new ClickHandler() { 206 // 207 // public void onClick(ClickEvent event) { 208 // 209 // setPreviewVisible(true); 210 // } 211 // }); 212 // m_showPreview.setVisible(false); 213 // m_parentPanel.add(m_showPreview); 214 // All composites must call initWidget() in their constructors. 215 initWidget(m_parentPanel); 216 ensureNotifications(); 217 m_dndHandler = galleryHandler.getDndHandler(); 218 m_autoHideParent = galleryHandler.getAutoHideParent(); 219 m_galleryHandler = galleryHandler; 220 } 221 222 /** 223 * Disables the search tab.<p> 224 */ 225 public void disableSearchTab() { 226 227 if (m_resultsTab != null) { 228 m_tabbedPanel.disableTab(m_resultsTab, Messages.get().key(Messages.GUI_GALLERY_NO_PARAMS_0)); 229 } 230 } 231 232 /** 233 * Enables the search tab.<p> 234 */ 235 public void enableSearchTab() { 236 237 if (m_resultsTab != null) { 238 m_tabbedPanel.enableTab(m_resultsTab); 239 } 240 } 241 242 /** 243 * Displays the search result in the result tab.<p> 244 * 245 * @param searchObj the search object 246 */ 247 public void fillResultTab(CmsGallerySearchBean searchObj) { 248 249 if (m_resultsTab == null) { 250 return; 251 } 252 List<CmsSearchParamPanel> paramPanels = null; 253 boolean empty = searchObj.isEmpty(); 254 if (!searchObj.isEmpty()) { 255 enableSearchTab(); 256 paramPanels = new ArrayList<CmsSearchParamPanel>(); 257 Iterator<A_CmsTab> it = m_tabbedPanel.iterator(); 258 while (it.hasNext()) { 259 260 A_CmsTab tab = it.next(); 261 if (tab != m_resultsTab) { // parameters from the results tab are handled in the fillContent method 262 paramPanels.addAll(tab.getParamPanels(searchObj)); 263 } 264 } 265 m_resultsTab.fillContent(searchObj, paramPanels); 266 } 267 } 268 269 /** 270 * Fill the tabs with the content provided from the info bean. <p> 271 * 272 * @param controller the reference to the gallery controller 273 */ 274 public void fillTabs(CmsGalleryController controller) { 275 276 m_controller = controller; 277 GalleryTabId[] tabIds = m_controller.getTabIds(); 278 279 int i; 280 for (i = 0; i < tabIds.length; i++) { 281 switch (tabIds[i]) { 282 case cms_tab_types: 283 m_typesTab = new CmsTypesTab( 284 new CmsTypesTabHandler(controller), 285 m_dndHandler, 286 m_galleryHandler.getAdditionalTypeTabControl()); 287 m_typesTab.setTabTextAccessor(getTabTextAccessor(i)); 288 m_tabbedPanel.add(m_typesTab, Messages.get().key(Messages.GUI_TAB_TITLE_TYPES_0)); 289 break; 290 case cms_tab_galleries: 291 List<CmsGalleryFolderBean> availableGalleries = controller.getAvailableGalleries(); 292 if ((availableGalleries != null) && availableGalleries.isEmpty()) { 293 continue; 294 } 295 m_galleriesTab = new CmsGalleriesTab(new CmsGalleriesTabHandler(controller)); 296 m_galleriesTab.setTabTextAccessor(getTabTextAccessor(i)); 297 m_tabbedPanel.add(m_galleriesTab, Messages.get().key(Messages.GUI_TAB_TITLE_GALLERIES_0)); 298 break; 299 case cms_tab_categories: 300 m_categoriesTab = new CmsCategoriesTab(new CmsCategoriesTabHandler(controller)); 301 m_categoriesTab.setTabTextAccessor(getTabTextAccessor(i)); 302 m_tabbedPanel.add(m_categoriesTab, Messages.get().key(Messages.GUI_TAB_TITLE_CATEGORIES_0)); 303 break; 304 case cms_tab_search: 305 m_searchTab = new CmsSearchTab( 306 new CmsSearchTabHandler(controller), 307 m_autoHideParent, 308 m_controller.getStartLocale(), 309 m_controller.getAvailableLocales(), 310 m_controller.getShowExpiredDefault()); 311 m_searchTab.setTabTextAccessor(getTabTextAccessor(i)); 312 m_tabbedPanel.add(m_searchTab, Messages.get().key(Messages.GUI_TAB_TITLE_SEARCH_0)); 313 break; 314 case cms_tab_vfstree: 315 CmsVfsTabHandler vfsTabHandler = new CmsVfsTabHandler(controller); 316 m_vfsTab = new CmsVfsTab(vfsTabHandler, controller.isIncludeFiles()); 317 vfsTabHandler.setTab(m_vfsTab); 318 m_vfsTab.setTabTextAccessor(getTabTextAccessor(i)); 319 m_tabbedPanel.add(m_vfsTab, Messages.get().key(Messages.GUI_TAB_TITLE_VFS_0)); 320 break; 321 case cms_tab_sitemap: 322 CmsSitemapTabHandler sitemapTabHandler = new CmsSitemapTabHandler(controller); 323 m_sitemapTab = new CmsSitemapTab(sitemapTabHandler); 324 m_sitemapTab.setTabTextAccessor(getTabTextAccessor(i)); 325 m_tabbedPanel.add(m_sitemapTab, Messages.get().key(Messages.GUI_TAB_TITLE_SITEMAP_0)); 326 break; 327 case cms_tab_results: 328 m_resultsTab = new CmsResultsTab( 329 new CmsResultsTabHandler(controller), 330 m_dndHandler, 331 m_galleryHandler, 332 m_controller.getSearchScope(), 333 m_controller.getDefaultScope()); 334 m_resultsTab.setTabTextAccessor(getTabTextAccessor(i)); 335 m_tabbedPanel.addWithLeftMargin(m_resultsTab, Messages.get().key(Messages.GUI_TAB_TITLE_RESULTS_0)); 336 disableSearchTab(); 337 break; 338 default: 339 break; 340 } 341 } 342 m_tabbedPanel.addBeforeSelectionHandler(this); 343 m_tabbedPanel.addSelectionHandler(this); 344 truncateTabs(); 345 } 346 347 /** 348 * Returns the categories tab widget.<p> 349 * 350 * @return the categories widget 351 */ 352 public CmsCategoriesTab getCategoriesTab() { 353 354 return m_categoriesTab; 355 } 356 357 /** 358 * Returns the gallery controller.<p> 359 * 360 * @return the gallery controller 361 */ 362 public CmsGalleryController getController() { 363 364 return m_controller; 365 } 366 367 /** 368 * Returns the HTML id of the dialog element.<p> 369 * 370 * @return the HTML id of the dialog element 371 */ 372 public String getDialogId() { 373 374 return m_dialogElementId; 375 } 376 377 /** 378 * Returns the drag and drop handler.<p> 379 * 380 * @return the drag and drop handler 381 */ 382 public CmsDNDHandler getDndHandler() { 383 384 return m_dndHandler; 385 } 386 387 /** 388 * Returns the galleries tab widget.<p> 389 * 390 * @return the galleries widget 391 */ 392 public CmsGalleriesTab getGalleriesTab() { 393 394 return m_galleriesTab; 395 } 396 397 /** 398 * Returns the image format names.<p> 399 * 400 * @return the image format names 401 */ 402 public String getImageFormatNames() { 403 404 return m_imageFormatNames; 405 } 406 407 /** 408 * Returns the image formats.<p> 409 * 410 * @return the image formats 411 */ 412 public String getImageFormats() { 413 414 return m_imageFormats; 415 } 416 417 /** 418 * Returns the parent panel of the dialog.<p> 419 * 420 * @return the parent 421 */ 422 public FlowPanel getParentPanel() { 423 424 return m_parentPanel; 425 } 426 427 /** 428 * Returns the results tab widget.<p> 429 * 430 * @return the results widget 431 */ 432 public CmsResultsTab getResultsTab() { 433 434 return m_resultsTab; 435 } 436 437 /** 438 * Returns the searchTab.<p> 439 * 440 * @return the searchTab 441 */ 442 public CmsSearchTab getSearchTab() { 443 444 return m_searchTab; 445 } 446 447 /** 448 * Returns the sitemap tab.<p> 449 * 450 * @return the sitemap tab 451 */ 452 public CmsSitemapTab getSitemapTab() { 453 454 return m_sitemapTab; 455 } 456 457 /** 458 * Gets the tab with a given tab id, or null if the dialog has no such tab.<p> 459 * 460 * @param tabId the tab id to look for 461 * 462 * @return the tab with the given tab id, or null 463 */ 464 public A_CmsTab getTab(GalleryTabId tabId) { 465 466 for (A_CmsTab tab : m_tabbedPanel) { 467 if (tabId == GalleryTabId.valueOf(tab.getTabId())) { 468 return tab; 469 } 470 } 471 return null; 472 } 473 474 /** 475 * Returns the types tab widget.<p> 476 * 477 * @return the types widget 478 */ 479 public CmsTypesTab getTypesTab() { 480 481 return m_typesTab; 482 } 483 484 /** 485 * Returns the VFS tab widget.<p> 486 * 487 * @return the VFS tab widget 488 */ 489 public CmsVfsTab getVfsTab() { 490 491 return m_vfsTab; 492 } 493 494 /** 495 * Returns the widget handler.<p> 496 * 497 * @return the widget handler 498 */ 499 public I_CmsGalleryWidgetHandler getWidgetHandler() { 500 501 return m_widgetHandler; 502 } 503 504 /** 505 * Hides or shows the show-preview-button.<p> 506 * 507 * @param hide <code>true</code> to hide the button 508 */ 509 public void hideShowPreviewButton(boolean hide) { 510 511 // m_showPreview.setVisible(!hide); 512 } 513 514 /** 515 * Returns if the gallery is used as a native widget.<p> 516 * 517 * @return <code>true</code> if the gallery is used as a native widget 518 */ 519 public boolean isNativeWidget() { 520 521 return m_widgetHandler != null; 522 } 523 524 /** 525 * Returns true if the formats from this dialog object should be prioritized by the format handler.<p> 526 * 527 * @return the value of the 'override formats' flag 528 */ 529 public boolean isOverrideFormats() { 530 531 return m_overrideFormats; 532 } 533 534 /** 535 * Returns the use formats flag.<p> 536 * 537 * @return the use formats flag 538 */ 539 public boolean isUseFormats() { 540 541 return m_useFormats; 542 } 543 544 /** 545 * @see com.google.gwt.event.logical.shared.BeforeSelectionHandler#onBeforeSelection(com.google.gwt.event.logical.shared.BeforeSelectionEvent) 546 */ 547 public void onBeforeSelection(BeforeSelectionEvent<Integer> event) { 548 549 int selectedIndex = m_tabbedPanel.getSelectedIndex(); 550 int newIndex = event.getItem().intValue(); 551 if (m_tabbedPanel.isDisabledTab(newIndex)) { 552 event.cancel(); 553 return; 554 } 555 if (selectedIndex != newIndex) { 556 m_tabbedPanel.getWidget(selectedIndex).onDeselection(); 557 } 558 } 559 560 /** 561 * @see com.google.gwt.event.logical.shared.SelectionHandler#onSelection(com.google.gwt.event.logical.shared.SelectionEvent) 562 */ 563 public void onSelection(SelectionEvent<Integer> event) { 564 565 int selectedIndex = m_tabbedPanel.getSelectedIndex(); 566 567 final A_CmsTab tabWidget = m_tabbedPanel.getWidget(selectedIndex); 568 if ((tabWidget instanceof CmsResultsTab) && m_isInitialSearch) { 569 // no search here 570 m_isInitialSearch = false; 571 } else { 572 tabWidget.onSelection(); 573 } 574 Scheduler.get().scheduleDeferred(new ScheduledCommand() { 575 576 public void execute() { 577 578 updateSizeForTab(tabWidget); 579 } 580 }); 581 582 } 583 584 /** 585 * Selects a tab by the given id.<p> 586 * 587 * @param tabId the tab id 588 * @param fireEvent <code>true</code> to fire the tab event 589 */ 590 public void selectTab(GalleryTabId tabId, boolean fireEvent) { 591 592 A_CmsTab tab = getTab(tabId); 593 if (tab != null) { 594 m_tabbedPanel.selectTab(tab, fireEvent); 595 } 596 } 597 598 /** 599 * Selects a tab.<p> 600 * 601 * @param tabIndex the tab index to beselected 602 * @param isInitial flag for initial search 603 */ 604 public void selectTab(int tabIndex, boolean isInitial) { 605 606 m_isInitialSearch = isInitial; 607 m_tabbedPanel.selectTab(tabIndex); 608 } 609 610 /** 611 * Sets the size of the gallery parent panel and triggers the event to the tab.<p> 612 * 613 * @param width the new width 614 * @param height the new height 615 */ 616 public void setDialogSize(int width, int height) { 617 618 if (height > 50) { 619 m_height = height; 620 m_parentPanel.setHeight(m_height + "px"); 621 } 622 m_width = width; 623 m_parentPanel.setWidth(m_width + "px"); 624 truncateTabs(); 625 } 626 627 /** 628 * Sets the image format names.<p> 629 * 630 * @param imageFormatNames the image format names to set 631 */ 632 public void setImageFormatNames(String imageFormatNames) { 633 634 m_imageFormatNames = imageFormatNames; 635 } 636 637 /** 638 * Sets the image formats.<p> 639 * 640 * @param imageFormats the image formats to set 641 */ 642 public void setImageFormats(String imageFormats) { 643 644 m_imageFormats = imageFormats; 645 } 646 647 /** 648 * Sets the on attach command.<p> 649 * 650 * @param onAttachCommand the on attach command to set 651 */ 652 public void setOnAttachCommand(Command onAttachCommand) { 653 654 m_onAttachCommand = onAttachCommand; 655 } 656 657 /** 658 * Sets the 'override formats' flag, which tells the format handler to prioritize the formats from the gallery dialog object.<p> 659 * 660 * @param overrideFormats the new value for the 'override formats' flag 661 */ 662 public void setOverrideFormats(boolean overrideFormats) { 663 664 m_overrideFormats = overrideFormats; 665 } 666 667 /** 668 * Sets the preview visibility.<p> 669 * 670 * @param visible the preview visibility 671 */ 672 public void setPreviewVisible(boolean visible) { 673 674 m_previewVisible = visible; 675 if (m_previewVisible) { 676 useMaxDimensions(); 677 m_previewVisibility.setValue(I_CmsLayoutBundle.INSTANCE.previewDialogCss().previewVisible()); 678 if (m_galleryHandler instanceof CmsGalleryPopup) { 679 ((CmsGalleryPopup)m_galleryHandler).center(); 680 } 681 } else { 682 m_previewVisibility.setValue(I_CmsLayoutBundle.INSTANCE.previewDialogCss().hidePreview()); 683 updateSizes(); 684 } 685 } 686 687 /** 688 * Sets the use formats flag.<p> 689 * 690 * @param useFormats the use formats flag to set 691 */ 692 public void setUseFormats(boolean useFormats) { 693 694 m_useFormats = useFormats; 695 } 696 697 /** 698 * Sets the widget handler.<p> 699 * 700 * @param widgetHandler the widget handler 701 */ 702 public void setWidgetHandler(I_CmsGalleryWidgetHandler widgetHandler) { 703 704 m_widgetHandler = widgetHandler; 705 } 706 707 /** 708 * @see org.opencms.gwt.client.ui.I_CmsTruncable#truncate(java.lang.String, int) 709 */ 710 public void truncate(String textMetricsKey, int clientWidth) { 711 712 m_width = clientWidth; 713 m_parentPanel.setWidth(m_width + "px"); 714 truncateTabs(); 715 } 716 717 /** 718 * Updates the gallery data.<p> 719 * 720 * @param data the gallery data 721 */ 722 public void updateGalleryData(CmsGalleryDataBean data) { 723 724 m_controller.updateGalleryData(data); 725 } 726 727 /** 728 * Updates the dialog size according to the requirements of the selected tab.<p> 729 * 730 * @param tab the selected tab 731 */ 732 public void updateSizeForTab(A_CmsTab tab) { 733 734 if (tab == m_resultsTab) { 735 m_resultsTab.updateListSize(); 736 } 737 if (!m_previewVisible) { 738 int height = tab.getRequiredHeight() + 42; 739 int availableHeight = CmsToolbarPopup.getAvailableHeight(); 740 setDialogSize(m_width, height < availableHeight ? height : availableHeight); 741 tab.onResize(); 742 } 743 } 744 745 /** 746 * Updates variable ui-element dimensions, execute after dialog has been attached and it's content is displayed.<p> 747 */ 748 public void updateSizes() { 749 750 int tabIndex = m_tabbedPanel.getSelectedIndex(); 751 if (tabIndex >= 0) { 752 updateSizeForTab(m_tabbedPanel.getWidget(tabIndex)); 753 } 754 } 755 756 /** 757 * Sets the dialog to use the maximum available space.<p> 758 */ 759 public void useMaxDimensions() { 760 761 int availableHeight = CmsToolbarPopup.getAvailableHeight(); 762 int availableWidth = CmsToolbarPopup.getAvailableWidth(); 763 setDialogSize(availableWidth, availableHeight); 764 } 765 766 /** 767 * Make sure a notification widget is installed.<p> 768 */ 769 protected void ensureNotifications() { 770 771 I_CmsNotificationWidget oldWidget = CmsNotification.get().getWidget(); 772 if (oldWidget == null) { 773 CmsNotificationWidget newWidget = new CmsNotificationWidget(); 774 CmsNotification.get().setWidget(newWidget); 775 RootPanel.get().add(newWidget); 776 } 777 } 778 779 /** 780 * Creates a tab text accessor for a given text.<p> 781 * 782 * @param pos the index of the tab 783 * 784 * @return the tab text accessor for the tab at index pos 785 */ 786 protected HasText getTabTextAccessor(final int pos) { 787 788 HasText tabText = new HasText() { 789 790 /** 791 * @see com.google.gwt.user.client.ui.HasText#getText() 792 */ 793 public String getText() { 794 795 return m_tabbedPanel.getTabText(pos); 796 797 } 798 799 /** 800 * @see com.google.gwt.user.client.ui.HasText#setText(java.lang.String) 801 */ 802 public void setText(String text) { 803 804 m_tabbedPanel.setTabText(pos, text); 805 } 806 }; 807 return tabText; 808 } 809 810 /** 811 * @see com.google.gwt.user.client.ui.Composite#onAttach() 812 */ 813 @Override 814 protected void onAttach() { 815 816 super.onAttach(); 817 if (m_onAttachCommand != null) { 818 m_onAttachCommand.execute(); 819 m_onAttachCommand = null; 820 } 821 Scheduler.get().scheduleDeferred(new ScheduledCommand() { 822 823 public void execute() { 824 825 updateSizes(); 826 } 827 }); 828 } 829 830 /** 831 * Ensures all style sheets are loaded.<p> 832 */ 833 private void initCss() { 834 835 I_CmsLayoutBundle.INSTANCE.galleryDialogCss().ensureInjected(); 836 I_CmsLayoutBundle.INSTANCE.galleryResultItemCss().ensureInjected(); 837 I_CmsLayoutBundle.INSTANCE.listTreeCss().ensureInjected(); 838 I_CmsLayoutBundle.INSTANCE.previewDialogCss().ensureInjected(); 839 I_CmsLayoutBundle.INSTANCE.croppingDialogCss().ensureInjected(); 840 I_CmsLayoutBundle.INSTANCE.imageEditorFormCss().ensureInjected(); 841 I_CmsLayoutBundle.INSTANCE.imageAdvancedFormCss().ensureInjected(); 842 } 843 844 /** 845 * Truncates the gallery tabs to the available width.<p> 846 */ 847 private void truncateTabs() { 848 849 for (int i = 0; i < m_tabbedPanel.getTabCount(); i++) { 850 if (m_tabbedPanel.getWidget(i) instanceof I_CmsTruncable) { 851 I_CmsTruncable tab = (I_CmsTruncable)m_tabbedPanel.getWidget(i); 852 tab.truncate(TM_GALLERY_DIALOG, m_width - 50); 853 } 854 } 855 } 856}