<commit_before>/*
 * Copyright 2010 IT Mill Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.vaadin.terminal.gwt.client.ui;

import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.dom.client.TableElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.*;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class VTabsheet extends VTabsheetBase {

    private class TabSheetCaption extends VCaption implements ActionOwner {

        private boolean hidden = false;
        private boolean closable = false;
        private Element closeButton;

        private String[] actionKeys = null;

        TabSheetCaption() {
            super(null, client);
            sinkEvents(Event.ONCONTEXTMENU);
        }

        @Override
        public boolean updateCaption(UIDL uidl) {
            if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)
                    || uidl.hasAttribute(ATTRIBUTE_ERROR)) {
                TooltipInfo tooltipInfo = new TooltipInfo();
                tooltipInfo.setTitle(uidl
                        .getStringAttribute(ATTRIBUTE_DESCRIPTION));
                if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
                    tooltipInfo.setErrorUidl(uidl.getErrors());
                }
                client.registerTooltip(VTabsheet.this, getElement(),
                        tooltipInfo);
            } else {
                client.registerTooltip(VTabsheet.this, getElement(), null);
            }

            boolean ret = super.updateCaption(uidl);

            setClosable(uidl.hasAttribute("closable"));

            if (uidl.hasAttribute("al")) {
                actionKeys = uidl.getStringArrayAttribute("al");
            }

            return ret;
        }

        @Override
        public void onBrowserEvent(Event event) {
            if (closable && event.getTypeInt() == Event.ONCLICK
                    && event.getEventTarget().cast() == closeButton) {
                if (isEnabled()) {
                    client.updateVariable(id, "close", getTabKey(), true);
                    event.stopPropagation();
                    event.preventDefault();
                    return;
                }
            } else if (event.getTypeInt() == Event.ONCONTEXTMENU
                    && isEnabled() && actionKeys != null && actionKeys.length > 0)
            {
                showContextMenu(event);
                return;
            }

            super.onBrowserEvent(event);

            if (event.getTypeInt() == Event.ONLOAD) {
                // icon onloads may change total width of tabsheet
                if (isDynamicWidth()) {
                    updateDynamicWidth();
                }
                updateTabScroller();
            }
            client.handleTooltipEvent(event, VTabsheet.this, getElement());
        }

        private void showContextMenu(Event event) {
            int left = event.getClientX();
            int top = event.getClientY();
            top += Window.getScrollTop();
            left += Window.getScrollLeft();
            client.getContextMenu().showAt(this, left, top);
            event.stopPropagation();
            event.preventDefault();
        }

        private boolean isEnabled() {
            return !disabledTabKeys.contains(getTabKey());
        }

        private String getTabKey() {
            return tabKeys.get(tb.getTabIndex(this))
                        .toString();
        }

        @Override
        public void setWidth(String width) {
            super.setWidth(width);
            if (BrowserInfo.get().isIE7()) {<commit_msg>Fixes #349 (При закрытие вкладки всплывающая подсказка остается висеть в воздухе)<commit_after>/*
 * Copyright 2010 IT Mill Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.vaadin.terminal.gwt.client.ui;

import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.dom.client.TableElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.*;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class VTabsheet extends VTabsheetBase {

    private class TabSheetCaption extends VCaption implements ActionOwner {

        private boolean hidden = false;
        private boolean closable = false;
        private Element closeButton;

        private String[] actionKeys = null;

        TabSheetCaption() {
            super(null, client);
            sinkEvents(Event.ONCONTEXTMENU);
        }

        @Override
        public boolean updateCaption(UIDL uidl) {
            if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)
                    || uidl.hasAttribute(ATTRIBUTE_ERROR)) {
                TooltipInfo tooltipInfo = new TooltipInfo();
                tooltipInfo.setTitle(uidl
                        .getStringAttribute(ATTRIBUTE_DESCRIPTION));
                if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
                    tooltipInfo.setErrorUidl(uidl.getErrors());
                }
                client.registerTooltip(VTabsheet.this, getElement(),
                        tooltipInfo);
            } else {
                client.registerTooltip(VTabsheet.this, getElement(), null);
            }

            boolean ret = super.updateCaption(uidl);

            setClosable(uidl.hasAttribute("closable"));

            if (uidl.hasAttribute("al")) {
                actionKeys = uidl.getStringArrayAttribute("al");
            }

            return ret;
        }

        @Override
        public void onBrowserEvent(Event event) {
            client.handleTooltipEvent(event, VTabsheet.this, getElement());
            if (closable && event.getTypeInt() == Event.ONCLICK
                    && event.getEventTarget().cast() == closeButton) {
                if (isEnabled()) {
                    client.updateVariable(id, "close", getTabKey(), true);
                    event.stopPropagation();
                    event.preventDefault();
                    return;
                }
            } else if (event.getTypeInt() == Event.ONCONTEXTMENU
                    && isEnabled() && actionKeys != null && actionKeys.length > 0)
            {
                showContextMenu(event);
                return;
            }

            super.onBrowserEvent(event);

            if (event.getTypeInt() == Event.ONLOAD) {
                // icon onloads may change total width of tabsheet
                if (isDynamicWidth()) {
                    updateDynamicWidth();
                }
                updateTabScroller();
            }
        }

        private void showContextMenu(Event event) {
            int left = event.getClientX();
            int top = event.getClientY();
            top += Window.getScrollTop();
            left += Window.getScrollLeft();
            client.getContextMenu().showAt(this, left, top);
            event.stopPropagation();
            event.preventDefault();
        }

        private boolean isEnabled() {
            return !disabledTabKeys.contains(getTabKey());
        }

        private String getTabKey() {
            return tabKeys.get(tb.getTabIndex(this))
                        .toString();
        }

        @Override
        public void setWidth(String width) {
            super.setWidth(width);
            if (BrowserInfo.get().isIE7()) {
{'fraction_non_alphanumeric': 0.09922222222222223, 'fraction_numerical': 0.0025555555555555557, 'mean_word_length': 1.973571192599934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936953', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2315, 'n_words': 544}