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.enableExpiredResourcesSearch(true); 312 m_searchTab.setTabTextAccessor(getTabTextAccessor(i)); 313 m_tabbedPanel.add(m_searchTab, Messages.get().key(Messages.GUI_TAB_TITLE_SEARCH_0)); 314 break; 315 case cms_tab_vfstree: 316 CmsVfsTabHandler vfsTabHandler = new CmsVfsTabHandler(controller); 317 m_vfsTab = new CmsVfsTab(vfsTabHandler, controller.isIncludeFiles()); 318 vfsTabHandler.setTab(m_vfsTab); 319 m_vfsTab.setTabTextAccessor(getTabTextAccessor(i)); 320 m_tabbedPanel.add(m_vfsTab, Messages.get().key(Messages.GUI_TAB_TITLE_VFS_0)); 321 break; 322 case cms_tab_sitemap: 323 CmsSitemapTabHandler sitemapTabHandler = new CmsSitemapTabHandler(controller); 324 m_sitemapTab = new CmsSitemapTab(sitemapTabHandler); 325 m_sitemapTab.setTabTextAccessor(getTabTextAccessor(i)); 326 m_tabbedPanel.add(m_sitemapTab, Messages.get().key(Messages.GUI_TAB_TITLE_SITEMAP_0)); 327 break; 328 case cms_tab_results: 329 m_resultsTab = new CmsResultsTab( 330 new CmsResultsTabHandler(controller), 331 m_dndHandler, 332 m_galleryHandler, 333 m_controller.getSearchScope(), 334 m_controller.getDefaultScope()); 335 m_resultsTab.setTabTextAccessor(getTabTextAccessor(i)); 336 m_tabbedPanel.addWithLeftMargin(m_resultsTab, Messages.get().key(Messages.GUI_TAB_TITLE_RESULTS_0)); 337 disableSearchTab(); 338 break; 339 default: 340 break; 341 } 342 } 343 m_tabbedPanel.addBeforeSelectionHandler(this); 344 m_tabbedPanel.addSelectionHandler(this); 345 truncateTabs(); 346 } 347 348 /** 349 * Returns the categories tab widget.<p> 350 * 351 * @return the categories widget 352 */ 353 public CmsCategoriesTab getCategoriesTab() { 354 355 return m_categoriesTab; 356 } 357 358 /** 359 * Returns the gallery controller.<p> 360 * 361 * @return the gallery controller 362 */ 363 public CmsGalleryController getController() { 364 365 return m_controller; 366 } 367 368 /** 369 * Returns the HTML id of the dialog element.<p> 370 * 371 * @return the HTML id of the dialog element 372 */ 373 public String getDialogId() { 374 375 return m_dialogElementId; 376 } 377 378 /** 379 * Returns the drag and drop handler.<p> 380 * 381 * @return the drag and drop handler 382 */ 383 public CmsDNDHandler getDndHandler() { 384 385 return m_dndHandler; 386 } 387 388 /** 389 * Returns the galleries tab widget.<p> 390 * 391 * @return the galleries widget 392 */ 393 public CmsGalleriesTab getGalleriesTab() { 394 395 return m_galleriesTab; 396 } 397 398 /** 399 * Returns the image format names.<p> 400 * 401 * @return the image format names 402 */ 403 public String getImageFormatNames() { 404 405 return m_imageFormatNames; 406 } 407 408 /** 409 * Returns the image formats.<p> 410 * 411 * @return the image formats 412 */ 413 public String getImageFormats() { 414 415 return m_imageFormats; 416 } 417 418 /** 419 * Returns the parent panel of the dialog.<p> 420 * 421 * @return the parent 422 */ 423 public FlowPanel getParentPanel() { 424 425 return m_parentPanel; 426 } 427 428 /** 429 * Returns the results tab widget.<p> 430 * 431 * @return the results widget 432 */ 433 public CmsResultsTab getResultsTab() { 434 435 return m_resultsTab; 436 } 437 438 /** 439 * Returns the searchTab.<p> 440 * 441 * @return the searchTab 442 */ 443 public CmsSearchTab getSearchTab() { 444 445 return m_searchTab; 446 } 447 448 /** 449 * Returns the sitemap tab.<p> 450 * 451 * @return the sitemap tab 452 */ 453 public CmsSitemapTab getSitemapTab() { 454 455 return m_sitemapTab; 456 } 457 458 /** 459 * Gets the tab with a given tab id, or null if the dialog has no such tab.<p> 460 * 461 * @param tabId the tab id to look for 462 * 463 * @return the tab with the given tab id, or null 464 */ 465 public A_CmsTab getTab(GalleryTabId tabId) { 466 467 for (A_CmsTab tab : m_tabbedPanel) { 468 if (tabId == GalleryTabId.valueOf(tab.getTabId())) { 469 return tab; 470 } 471 } 472 return null; 473 } 474 475 /** 476 * Returns the types tab widget.<p> 477 * 478 * @return the types widget 479 */ 480 public CmsTypesTab getTypesTab() { 481 482 return m_typesTab; 483 } 484 485 /** 486 * Returns the VFS tab widget.<p> 487 * 488 * @return the VFS tab widget 489 */ 490 public CmsVfsTab getVfsTab() { 491 492 return m_vfsTab; 493 } 494 495 /** 496 * Returns the widget handler.<p> 497 * 498 * @return the widget handler 499 */ 500 public I_CmsGalleryWidgetHandler getWidgetHandler() { 501 502 return m_widgetHandler; 503 } 504 505 /** 506 * Hides or shows the show-preview-button.<p> 507 * 508 * @param hide <code>true</code> to hide the button 509 */ 510 public void hideShowPreviewButton(boolean hide) { 511 512 // m_showPreview.setVisible(!hide); 513 } 514 515 /** 516 * Returns if the gallery is used as a native widget.<p> 517 * 518 * @return <code>true</code> if the gallery is used as a native widget 519 */ 520 public boolean isNativeWidget() { 521 522 return m_widgetHandler != null; 523 } 524 525 /** 526 * Returns true if the formats from this dialog object should be prioritized by the format handler.<p> 527 * 528 * @return the value of the 'override formats' flag 529 */ 530 public boolean isOverrideFormats() { 531 532 return m_overrideFormats; 533 } 534 535 /** 536 * Returns the use formats flag.<p> 537 * 538 * @return the use formats flag 539 */ 540 public boolean isUseFormats() { 541 542 return m_useFormats; 543 } 544 545 /** 546 * @see com.google.gwt.event.logical.shared.BeforeSelectionHandler#onBeforeSelection(com.google.gwt.event.logical.shared.BeforeSelectionEvent) 547 */ 548 public void onBeforeSelection(BeforeSelectionEvent<Integer> event) { 549 550 int selectedIndex = m_tabbedPanel.getSelectedIndex(); 551 int newIndex = event.getItem().intValue(); 552 if (m_tabbedPanel.isDisabledTab(newIndex)) { 553 event.cancel(); 554 return; 555 } 556 if (selectedIndex != newIndex) { 557 m_tabbedPanel.getWidget(selectedIndex).onDeselection(); 558 } 559 } 560 561 /** 562 * @see com.google.gwt.event.logical.shared.SelectionHandler#onSelection(com.google.gwt.event.logical.shared.SelectionEvent) 563 */ 564 public void onSelection(SelectionEvent<Integer> event) { 565 566 int selectedIndex = m_tabbedPanel.getSelectedIndex(); 567 568 final A_CmsTab tabWidget = m_tabbedPanel.getWidget(selectedIndex); 569 if ((tabWidget instanceof CmsResultsTab) && m_isInitialSearch) { 570 // no search here 571 m_isInitialSearch = false; 572 } else { 573 tabWidget.onSelection(); 574 } 575 Scheduler.get().scheduleDeferred(new ScheduledCommand() { 576 577 public void execute() { 578 579 updateSizeForTab(tabWidget); 580 } 581 }); 582 583 } 584 585 /** 586 * Selects a tab by the given id.<p> 587 * 588 * @param tabId the tab id 589 * @param fireEvent <code>true</code> to fire the tab event 590 */ 591 public void selectTab(GalleryTabId tabId, boolean fireEvent) { 592 593 A_CmsTab tab = getTab(tabId); 594 if (tab != null) { 595 m_tabbedPanel.selectTab(tab, fireEvent); 596 } 597 } 598 599 /** 600 * Selects a tab.<p> 601 * 602 * @param tabIndex the tab index to beselected 603 * @param isInitial flag for initial search 604 */ 605 public void selectTab(int tabIndex, boolean isInitial) { 606 607 m_isInitialSearch = isInitial; 608 m_tabbedPanel.selectTab(tabIndex); 609 } 610 611 /** 612 * Sets the size of the gallery parent panel and triggers the event to the tab.<p> 613 * 614 * @param width the new width 615 * @param height the new height 616 */ 617 public void setDialogSize(int width, int height) { 618 619 if (height > 50) { 620 m_height = height; 621 m_parentPanel.setHeight(m_height + "px"); 622 } 623 m_width = width; 624 m_parentPanel.setWidth(m_width + "px"); 625 truncateTabs(); 626 } 627 628 /** 629 * Sets the image format names.<p> 630 * 631 * @param imageFormatNames the image format names to set 632 */ 633 public void setImageFormatNames(String imageFormatNames) { 634 635 m_imageFormatNames = imageFormatNames; 636 } 637 638 /** 639 * Sets the image formats.<p> 640 * 641 * @param imageFormats the image formats to set 642 */ 643 public void setImageFormats(String imageFormats) { 644 645 m_imageFormats = imageFormats; 646 } 647 648 /** 649 * Sets the on attach command.<p> 650 * 651 * @param onAttachCommand the on attach command to set 652 */ 653 public void setOnAttachCommand(Command onAttachCommand) { 654 655 m_onAttachCommand = onAttachCommand; 656 } 657 658 /** 659 * Sets the 'override formats' flag, which tells the format handler to prioritize the formats from the gallery dialog object.<p> 660 * 661 * @param overrideFormats the new value for the 'override formats' flag 662 */ 663 public void setOverrideFormats(boolean overrideFormats) { 664 665 m_overrideFormats = overrideFormats; 666 } 667 668 /** 669 * Sets the preview visibility.<p> 670 * 671 * @param visible the preview visibility 672 */ 673 public void setPreviewVisible(boolean visible) { 674 675 m_previewVisible = visible; 676 if (m_previewVisible) { 677 useMaxDimensions(); 678 m_previewVisibility.setValue(I_CmsLayoutBundle.INSTANCE.previewDialogCss().previewVisible()); 679 if (m_galleryHandler instanceof CmsGalleryPopup) { 680 ((CmsGalleryPopup)m_galleryHandler).center(); 681 } 682 } else { 683 m_previewVisibility.setValue(I_CmsLayoutBundle.INSTANCE.previewDialogCss().hidePreview()); 684 updateSizes(); 685 } 686 } 687 688 /** 689 * Sets the use formats flag.<p> 690 * 691 * @param useFormats the use formats flag to set 692 */ 693 public void setUseFormats(boolean useFormats) { 694 695 m_useFormats = useFormats; 696 } 697 698 /** 699 * Sets the widget handler.<p> 700 * 701 * @param widgetHandler the widget handler 702 */ 703 public void setWidgetHandler(I_CmsGalleryWidgetHandler widgetHandler) { 704 705 m_widgetHandler = widgetHandler; 706 } 707 708 /** 709 * @see org.opencms.gwt.client.ui.I_CmsTruncable#truncate(java.lang.String, int) 710 */ 711 public void truncate(String textMetricsKey, int clientWidth) { 712 713 m_width = clientWidth; 714 m_parentPanel.setWidth(m_width + "px"); 715 truncateTabs(); 716 } 717 718 /** 719 * Updates the gallery data.<p> 720 * 721 * @param data the gallery data 722 */ 723 public void updateGalleryData(CmsGalleryDataBean data) { 724 725 m_controller.updateGalleryData(data); 726 } 727 728 /** 729 * Updates the dialog size according to the requirements of the selected tab.<p> 730 * 731 * @param tab the selected tab 732 */ 733 public void updateSizeForTab(A_CmsTab tab) { 734 735 if (tab == m_resultsTab) { 736 m_resultsTab.updateListSize(); 737 } 738 if (!m_previewVisible) { 739 int height = tab.getRequiredHeight() + 42; 740 int availableHeight = CmsToolbarPopup.getAvailableHeight(); 741 setDialogSize(m_width, height < availableHeight ? height : availableHeight); 742 tab.onResize(); 743 } 744 } 745 746 /** 747 * Updates variable ui-element dimensions, execute after dialog has been attached and it's content is displayed.<p> 748 */ 749 public void updateSizes() { 750 751 int tabIndex = m_tabbedPanel.getSelectedIndex(); 752 if (tabIndex >= 0) { 753 updateSizeForTab(m_tabbedPanel.getWidget(tabIndex)); 754 } 755 } 756 757 /** 758 * Sets the dialog to use the maximum available space.<p> 759 */ 760 public void useMaxDimensions() { 761 762 int availableHeight = CmsToolbarPopup.getAvailableHeight(); 763 int availableWidth = CmsToolbarPopup.getAvailableWidth(); 764 setDialogSize(availableWidth, availableHeight); 765 } 766 767 /** 768 * Make sure a notification widget is installed.<p> 769 */ 770 protected void ensureNotifications() { 771 772 I_CmsNotificationWidget oldWidget = CmsNotification.get().getWidget(); 773 if (oldWidget == null) { 774 CmsNotificationWidget newWidget = new CmsNotificationWidget(); 775 CmsNotification.get().setWidget(newWidget); 776 RootPanel.get().add(newWidget); 777 } 778 } 779 780 /** 781 * Creates a tab text accessor for a given text.<p> 782 * 783 * @param pos the index of the tab 784 * 785 * @return the tab text accessor for the tab at index pos 786 */ 787 protected HasText getTabTextAccessor(final int pos) { 788 789 HasText tabText = new HasText() { 790 791 /** 792 * @see com.google.gwt.user.client.ui.HasText#getText() 793 */ 794 public String getText() { 795 796 return m_tabbedPanel.getTabText(pos); 797 798 } 799 800 /** 801 * @see com.google.gwt.user.client.ui.HasText#setText(java.lang.String) 802 */ 803 public void setText(String text) { 804 805 m_tabbedPanel.setTabText(pos, text); 806 } 807 }; 808 return tabText; 809 } 810 811 /** 812 * @see com.google.gwt.user.client.ui.Composite#onAttach() 813 */ 814 @Override 815 protected void onAttach() { 816 817 super.onAttach(); 818 if (m_onAttachCommand != null) { 819 m_onAttachCommand.execute(); 820 m_onAttachCommand = null; 821 } 822 Scheduler.get().scheduleDeferred(new ScheduledCommand() { 823 824 public void execute() { 825 826 updateSizes(); 827 } 828 }); 829 } 830 831 /** 832 * Ensures all style sheets are loaded.<p> 833 */ 834 private void initCss() { 835 836 I_CmsLayoutBundle.INSTANCE.galleryDialogCss().ensureInjected(); 837 I_CmsLayoutBundle.INSTANCE.galleryResultItemCss().ensureInjected(); 838 I_CmsLayoutBundle.INSTANCE.listTreeCss().ensureInjected(); 839 I_CmsLayoutBundle.INSTANCE.previewDialogCss().ensureInjected(); 840 I_CmsLayoutBundle.INSTANCE.croppingDialogCss().ensureInjected(); 841 I_CmsLayoutBundle.INSTANCE.imageEditorFormCss().ensureInjected(); 842 I_CmsLayoutBundle.INSTANCE.imageAdvancedFormCss().ensureInjected(); 843 } 844 845 /** 846 * Truncates the gallery tabs to the available width.<p> 847 */ 848 private void truncateTabs() { 849 850 for (int i = 0; i < m_tabbedPanel.getTabCount(); i++) { 851 if (m_tabbedPanel.getWidget(i) instanceof I_CmsTruncable) { 852 I_CmsTruncable tab = (I_CmsTruncable)m_tabbedPanel.getWidget(i); 853 tab.truncate(TM_GALLERY_DIALOG, m_width - 50); 854 } 855 } 856 } 857}