Example usage for com.google.gwt.user.client.ui TabPanel getWidgetIndex

List of usage examples for com.google.gwt.user.client.ui TabPanel getWidgetIndex

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TabPanel getWidgetIndex.

Prototype

public int getWidgetIndex(Widget widget) 

Source Link

Usage

From source file:org.drools.brms.client.ruleeditor.EditorLauncher.java

License:Apache License

/**
 * This will show the rule viewer. If it was previously opened, it will show that dialog instead
 * of opening it again.//from www.j  a v  a  2  s  . c om
 */
public static void showLoadEditor(final Map openedViewers, final TabPanel tab, final String uuid,
        final boolean readonly) {

    if (openedViewers.containsKey(uuid)) {
        if (tab.getWidgetIndex((Widget) openedViewers.get(uuid)) == -1) {
            String featurename = tab.getWidget(0) instanceof PackageExplorerWidget ? "Rule Viewer"
                    : "Package Manager";
            Window.alert("Asset already opened in " + featurename);
        } else {
            tab.selectTab(tab.getWidgetIndex((Widget) openedViewers.get(uuid)));
        }
        LoadingPopup.close();
        return;
    }

    RepositoryServiceFactory.getService().loadRuleAsset(uuid, new GenericCallback() {

        public void onSuccess(Object o) {
            final RuleAsset asset = (RuleAsset) o;

            SuggestionCompletionCache cache = SuggestionCompletionCache.getInstance();
            cache.doAction(asset.metaData.packageName, new Command() {
                public void execute() {
                    openRuleViewer(openedViewers, tab, uuid, readonly, asset);
                }

            });
        }

    });

}

From source file:org.drools.brms.client.ruleeditor.EditorLauncher.java

License:Apache License

/**
 * This will actually show the viewer once everything is loaded and ready.
 * @param openedViewers/*  w  w w. j a  va 2  s. co m*/
 * @param tab
 * @param uuid
 * @param readonly
 * @param asset
 */
private static void openRuleViewer(final Map openedViewers, final TabPanel tab, final String uuid,
        final boolean readonly, RuleAsset asset) {
    final RuleViewer view = new RuleViewer(asset, readonly);

    String displayName = asset.metaData.name;
    if (displayName.length() > 10) {
        displayName = displayName.substring(0, 7) + "...";
    }
    String icon = getAssetFormatIcon(asset.metaData.format);

    tab.add(view, "<img src='images/" + icon + "'>" + displayName, true);

    if (openedViewers != Collections.EMPTY_MAP) {
        openedViewers.put(uuid, view);
    }

    view.setCloseCommand(new Command() {
        public void execute() {
            tab.remove(tab.getWidgetIndex(view));
            tab.selectTab(0);
            if (openedViewers != Collections.EMPTY_MAP) {
                openedViewers.remove(uuid);
            }

        }
    });
    tab.selectTab(tab.getWidgetIndex(view));
}

From source file:org.freemedsoftware.gwt.client.PatientScreenInterface.java

License:Open Source License

/**
 * Close this screen by removing it from the tab panel.
 */// w w w  .j a  v  a 2  s . c  o m
public void closeScreen() {
    TabPanel t = patientScreen.getTabPanel();
    if (t.getWidgetIndex(this) != -1) {
        t.selectTab(t.getWidgetIndex(this) - 1);
        t.remove(t.getWidgetIndex(this));
    }
    Integer patientId = getPatientId();
    CurrentState.getPatientSubScreenMap().get(patientId).remove(this.getClass().getName());
}

From source file:org.freemedsoftware.gwt.client.ScreenInterface.java

License:Open Source License

/**
 * Remove the current ScreenInterface from the parent TabPanel.
 *//* w  ww  . j  ava  2 s.c  o  m*/
public void closeScreen() {
    TabPanel t = CurrentState.getTabPanel();
    if (t.getWidgetIndex(this) != -1) {
        t.selectTab(t.getWidgetIndex(this) - 1);
        t.remove(t.getWidgetIndex(this));
    }
    this.removeFromParent();
}

From source file:org.freemedsoftware.gwt.client.Util.java

License:Open Source License

/**
 * Close tab from main window/*from w  w  w . j  a  v a 2  s .c o m*/
 * 
 * @param screen
 *            Object containing extended composite with content
 */
public static synchronized void closeTab(ScreenInterface screen) {

    TabPanel t = CurrentState.getTabPanel();
    t.selectTab(t.getWidgetIndex(screen) - 1);
    t.remove(t.getWidgetIndex(screen));

    // Special handling for PatientScreen
    if (screen instanceof PatientScreen) {
        HashMap<Integer, PatientScreen> map = CurrentState.getPatientScreenMap();
        Integer oldId = ((PatientScreen) screen).getPatient();
        if (map.get(oldId) != null) {
            map.remove(oldId);
        }
    }
}

From source file:org.freemedsoftware.gwt.client.widget.ClosableTab.java

License:Open Source License

public ClosableTab(String labelText, Widget w, ClosableTabInterface cTI) {
    // Store in namespace where we can see it later
    widget = w;/*from www .ja v  a  2  s. co m*/
    closableTabInterface = cTI;

    final HorizontalPanel panel = new HorizontalPanel();
    initWidget(panel);

    final Label label = new Label(labelText);
    label.setStyleName(AppConstants.STYLE_LABEL_TAB);
    panel.add(label);
    panel.setTitle(labelText);
    panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_LEFT);
    panel.setCellVerticalAlignment(label, HasVerticalAlignment.ALIGN_TOP);

    final Image image = new Image();
    image.setUrl("resources/images/close_x.16x16.png");

    // Create spacer
    panel.add(new HTML("&nbsp;"));

    panel.add(image);
    panel.setCellVerticalAlignment(image, HasVerticalAlignment.ALIGN_TOP);
    panel.setCellHorizontalAlignment(image, HasHorizontalAlignment.ALIGN_RIGHT);

    image.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent evt) {
            boolean goodToGo = true;
            // If we have a ClosableTabInterface, make sure it's ready to
            // die
            if (closableTabInterface != null) {
                goodToGo = closableTabInterface.isReadyToClose();
            }
            if (goodToGo) {
                if (closableTabInterface != null) {
                    closableTabInterface.onClose();
                }
                TabPanel t = ((TabPanel) widget.getParent().getParent().getParent());
                t.selectTab(t.getWidgetIndex(widget) - 1);
                widget.removeFromParent();

                // If we're dealing with PatientScreen, remove from mapping
                if (widget instanceof ScreenInterface) {
                    ScreenInterface screen = (ScreenInterface) widget;
                    screen.closeScreen();
                }
            }
        }
    });
}

From source file:org.pentaho.mantle.client.solutionbrowser.tabs.TabWidget.java

License:Open Source License

public TabWidget(String text, String tooltip, final SolutionBrowserPerspective perspective,
        final TabPanel tabPanel, final Widget tabContent) {
    // BISERVER-2317 Request for more IDs for Mantle UI elements
    // the id for each tab shall be the text which it displays
    getElement().setId("tab-" + text); //$NON-NLS-1$

    this.tabPanel = tabPanel;
    this.tabContent = tabContent;
    this.perspective = perspective;
    this.fullText = text;
    setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    panel.setStyleName("tabWidget"); //$NON-NLS-1$
    leftCap.setStyleName("tabWidgetCap"); //$NON-NLS-1$
    Image leftCapImage = new Image();
    MantleImages.images.space1x20().applyTo(leftCapImage);
    leftCap.setSpacing(0);/*from www.j a v a  2 s . c o m*/
    leftCapImage.setWidth("5px"); //$NON-NLS-1$
    leftCap.add(leftCapImage);

    setLabelText(text);
    setLabelTooltip(tooltip);
    textLabel.setWordWrap(false);
    textLabel.addMouseListener(this);

    tabPanel.addTabListener(new TabListener() {

        public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
            return true;
        }

        public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
            ElementUtils.blur(getElement().getParentElement());
            if (tabIndex == tabPanel.getWidgetIndex(tabContent)) {
                panel.setStyleName("tabWidget-selected"); //$NON-NLS-1$
                leftCap.setStyleName("tabWidgetCap-selected"); //$NON-NLS-1$
            } else {
                panel.setStyleName("tabWidget"); //$NON-NLS-1$
                leftCap.setStyleName("tabWidgetCap"); //$NON-NLS-1$
            }
        }

    });

    MantleImages.images.closeTab().applyTo(closeTabImage);
    closeTabImage.setTitle(Messages.getString("closeTab")); //$NON-NLS-1$
    closeTabImage.addMouseListener(this);
    closeTabImage.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            closeTab();
        }

    });
    closeTabImage.getElement().setId("killTab"); //$NON-NLS-1$

    panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    panel.add(textLabel);
    if (perspective != null) {
        panel.add(closeTabImage);
        DOM.setStyleAttribute(closeTabImage.getElement(), "margin", "5px"); //$NON-NLS-1$ //$NON-NLS-2$
        DOM.setStyleAttribute(textLabel.getElement(), "margin", "5px 0px 5px 0px"); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        DOM.setStyleAttribute(textLabel.getElement(), "margin", "4px 5px 5px 5px"); //$NON-NLS-1$ //$NON-NLS-2$
        DOM.setStyleAttribute(textLabel.getElement(), "paddingRight", "5px"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    add(leftCap);
    add(panel);
    sinkEvents(Event.ONDBLCLICK | Event.ONMOUSEUP);
}

From source file:org.pentaho.ui.xul.gwt.widgets.GwtTabWidget.java

License:Open Source License

public GwtTabWidget(String text, String tooltip, final TabPanel tabPanel, final Widget tabContent) {
    this.tabPanel = tabPanel;
    this.tabContent = tabContent;
    this.fullText = text;
    setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    panel.setStyleName("pentaho-tabWidget"); //$NON-NLS-1$
    Image leftCapImage = new Image(GWT.getModuleBaseURL() + "images/spacer.gif");
    leftCapImage.setStylePrimaryName("tab-spacer");

    setLabelText(text);/*from w ww .  j  a  va2  s .c  o  m*/
    setLabelTooltip(tooltip);
    textLabel.setStyleName("pentaho-tabWidgetLabel");
    textLabel.setWordWrap(false);
    tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

        public void onSelection(SelectionEvent<Integer> event) {
            int tabIndex = event.getSelectedItem();
            ElementUtils.blur(getElement().getParentElement());
            if (tabIndex == tabPanel.getWidgetIndex(tabContent)) {
                panel.addStyleName("pentaho-tabWidget-selected"); //$NON-NLS-1$
            } else {
                panel.removeStyleName("pentaho-tabWidget-selected"); //$NON-NLS-1$
            }
        }
    });

    panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    panel.add(textLabel);
    add(leftCapImage);
    leftCapImage.getElement().getParentElement().setAttribute("class", "tab-spacer-wrapper");
    add(panel);
    sinkEvents(Event.ONDBLCLICK | Event.ONMOUSEUP);
}