Search in sources :

Example 1 with NotAuthorizedWidget

use of cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget in project perun by CESNET.

the class TabManager method addTabToCurrentTabAuthorized.

/**
	 * The implementation of addTabToCurrentTab
	 *
	 * @param tab
	 * @param large whether tab large
	 * @return
	 */
private boolean addTabToCurrentTabAuthorized(TabItem tab, boolean large) {
    final int selectedTabUniqueId = session.getUiElements().getSelectedTabUniqueId();
    // find overlay
    final AbsolutePanel overlay = tabOverlays.get(selectedTabUniqueId);
    if (overlay == null) {
        return false;
    }
    if (large) {
        overlay.getWidget(0).addStyleName("tab-overlay-large");
    } else {
        overlay.getWidget(0).removeStyleName("tab-overlay-large");
    }
    // find parent
    TabItem parent = getTabItemByUniqueId(selectedTabUniqueId);
    // store place
    Widget widget;
    // authorization when not already opened
    if (tab.isAuthorized() == true) {
        // widget itself
        widget = tab.getWidget();
        // load page content
        tab.draw();
    } else {
        widget = new NotAuthorizedWidget();
    }
    // close button
    Button closeTabButton = new Button("X");
    closeTabButton.addStyleName("tabPanelCloseButton");
    closeTabButton.addStyleName("tab-overlay-close-button");
    closeTabButton.getElement().setAttribute("onclick", "jQuery(\"#tab-" + selectedTabUniqueId + " .tab-overlay-shield\").animate({ top : \"-1000px\" }, 'fast', function(){ jQuery(\"#tab-" + selectedTabUniqueId + " .tab-overlay-shield\").hide(''); }); jQuery(\"#tab-" + selectedTabUniqueId + " .tab-overlay\").animate({ top : \"-1000px\" }, 'fast', function(){ jQuery(\"#tab-" + selectedTabUniqueId + " .tab-overlay\").hide(''); }); jQuery(\"#tab-" + selectedTabUniqueId + " .tab-content\").fadeTo('fast', 1.0);");
    closeTabButton.setTitle(WidgetTranslation.INSTANCE.closeThisTab());
    // title
    final Widget title = tab.getTitle();
    title.addStyleName("tab-overlay-title");
    if (!overlay.getWidget(0).getStyleName().contains("tab-overlay-large")) {
        // shorten title only for small tabs
        title.getElement().setAttribute("style", "max-width: 330px;");
    }
    if (overlay.getWidget(0).getElement().hasChildNodes()) {
        overlay.getWidget(0).getElement().getFirstChildElement().removeFromParent();
    }
    if (overlay.getWidget(0).getElement().hasChildNodes()) {
        overlay.getWidget(0).getElement().getFirstChildElement().removeFromParent();
    }
    overlay.getWidget(0).getElement().appendChild(title.getElement());
    overlay.getWidget(0).getElement().appendChild(closeTabButton.getElement());
    // add
    ((SimplePanel) overlay.getWidget(0)).setWidget(widget);
    // shows the tab
    setTabOverlayVisible(selectedTabUniqueId, true);
    // local
    tabOverlaysTabItems.put(tab, parent);
    // set it as active overlay tab
    this.activeOverlayTab = tab;
    // run resize commands immediately
    UiElements.runResizeCommands(true);
    // run resize commands, after 400ms, when panel fully opened
    Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {

        @Override
        public boolean execute() {
            UiElements.runResizeCommandsForCurrentTab();
            return false;
        }
    }, 400);
    return true;
}
Also used : Scheduler(com.google.gwt.core.client.Scheduler) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget)

Example 2 with NotAuthorizedWidget

use of cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget in project perun by CESNET.

the class TabManager method addTabWhenPrepared.

/**
	 * Adding a tab
	 * With this method, the authorization must be already granted
	 *
	 * @param tab
	 * @param open
	 * @return
	 */
private boolean addTabWhenPrepared(TabItem tab, boolean open) {
    // store place
    final Widget widget;
    ImageResource tabIcon;
    // overlay tab
    final SimplePanel overlayTab = new SimplePanel();
    overlayTab.addStyleName("tab-overlay");
    final AbsolutePanel overlayShield = new AbsolutePanel();
    overlayShield.addStyleName("tab-overlay-shield");
    overlayShield.add(overlayTab);
    overlayTab.getElement().getStyle().setLeft(5, Unit.PCT);
    // authorization when not already opened
    if (tab.isAuthorized() == true) {
        // widget itself
        widget = tab.getWidget();
        tabIcon = tab.getIcon();
        // load page content
        tab.draw();
    } else {
        widget = new NotAuthorizedWidget();
        tabIcon = SmallIcons.INSTANCE.errorIcon();
    }
    // panel with overlay and widget contents
    final AbsolutePanel ap = new AbsolutePanel();
    ap.add(widget, 5, 5);
    ap.add(overlayShield, 0, -2000);
    //overlayShield.getElement().getStyle().setLeft(5, Unit.PCT);
    // set sizes
    ap.setSize("100%", "100%");
    widget.setWidth("100%");
    // update overlay position
    UiElements.addResizeCommand(new Command() {

        @Override
        public void execute() {
            // empty
            if (overlayTab.getWidget() == null) {
                return;
            }
            int clientWidth = (Window.getClientWidth() > WebGui.MIN_CLIENT_WIDTH) ? Window.getClientWidth() : WebGui.MIN_CLIENT_WIDTH;
            // if small, then fixed size in the center
            if (!overlayTab.getStyleName().contains("tab-overlay-large")) {
                int overlayWidth = overlayTab.getElement().getOffsetWidth();
                // main menu width
                int left = (clientWidth - MainMenu.MENU_WIDTH - overlayWidth) / 2;
                overlayShield.setWidgetPosition(overlayTab, left, overlayShield.getWidgetTop(overlayTab));
                return;
            }
        }
    }, tab);
    // has a help widget?
    if (tab instanceof TabItemWithHelp) {
        helpCounter++;
        final String helpWrapperId = "helpWidgetWrapper-" + helpCounter;
        TabItemWithHelp tabWithHelp = (TabItemWithHelp) tab;
        final AbsolutePanel helpWidgetWrapper = new AbsolutePanel();
        ap.add(helpWidgetWrapper, 100000, 0);
        helpWidgetWrapper.addStyleName("helpWidgetWrapper");
        helpWidgetWrapper.addStyleName(helpWrapperId);
        // help widget
        //FlexTable helpWidget = new FlexTable();
        VerticalPanel helpWidget = new VerticalPanel();
        helpWidget.setWidth("100%");
        final ScrollPanel sp = new ScrollPanel(helpWidget);
        // header
        //Image img = new Image(LargeIcons.INSTANCE.helpIcon());
        //helpWidget.setWidget(0, 0, img);
        //helpWidget.getCellFormatter().setWidth(0, 0, "40px");
        HTML helpHeader = new HTML("<h3>Quick help</h3>");
        helpWidget.add(helpHeader);
        helpWidget.setCellHeight(helpHeader, "45px");
        // content
        //helpWidget.getFlexCellFormatter().setColSpan(1, 0, 2);
        //helpWidget.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
        helpWidget.add(tabWithHelp.getHelpWidget());
        final SimplePanel helpWidgetInnerWrapper = new SimplePanel(sp);
        helpWidgetInnerWrapper.setStyleName("helpWidget");
        helpWidgetWrapper.add(helpWidgetInnerWrapper, 0, 0);
        /*helpWidgetInnerWrapper.setSize("100%", "100%");*/
        // open help widget button
        PushButton helpWidgetButton = new PushButton(new Image(HELP_WIDGET_BUTTON_IMAGE));
        final SimplePanel helpWidgetButtonWrapper = new SimplePanel(helpWidgetButton);
        helpWidgetButton.setStyleName("helpWidgetButton");
        helpWidgetButton.setTitle("Open / close Quick help");
        helpWidgetWrapper.add(helpWidgetButtonWrapper, -30, 0);
        helpWidgetButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                toggleHelp(helpWrapperId);
            }
        });
        UiElements.addResizeCommand(new Command() {

            public void execute() {
                int helpWidgetWidth = 400;
                int clientWidth = (Window.getClientWidth() > WebGui.MIN_CLIENT_WIDTH) ? Window.getClientWidth() : WebGui.MIN_CLIENT_WIDTH;
                //int clientHeight = (Window.getClientHeight() > WebGui.MIN_CLIENT_HEIGHT) ?  Window.getClientHeight() : WebGui.MIN_CLIENT_HEIGHT;
                clientWidth -= MainMenu.MENU_WIDTH;
                int newLeft = clientWidth;
                if (isHelpOpened(helpWrapperId)) {
                    newLeft -= helpWidgetWidth;
                }
                // update widget position
                ap.setWidgetPosition(helpWidgetWrapper, newLeft, 0);
                session.getUiElements().resizeSmallTabPanel(sp, 200);
            // update button top position
            //helpWidgetWrapper.setWidgetPosition(helpWidgetButtonWrapper, helpWidgetWrapper.getWidgetLeft(helpWidgetButtonWrapper), (clientHeight - 200) / 2);
            }
        });
    }
    // add
    int tabId = session.getUiElements().contentAddTab(ap, tab.getTitle(), open, tabIcon);
    // add to current map
    this.tabs.put(tab, tabId);
    if (open) {
        activeTab = tab;
        // call the event
        if (tab.isAuthorized()) {
            tab.open();
        }
    // DO NOT CHANGE MENU, IT'S HANDLED BY TAB
    // ON IT'S OWN VIA tab.open()
    //session.getUiElements().getMenu().updateLinks();
    }
    tabOverlays.put(tabId, overlayShield);
    // refresh URL
    refreshUrl();
    return true;
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget) NotAuthorizedWidget(cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget) ImageResource(com.google.gwt.resources.client.ImageResource) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Command(com.google.gwt.user.client.Command)

Aggregations

NotAuthorizedWidget (cz.metacentrum.perun.webgui.widgets.NotAuthorizedWidget)2 Scheduler (com.google.gwt.core.client.Scheduler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 Command (com.google.gwt.user.client.Command)1