Example usage for com.google.gwt.dom.client Element scrollIntoView

List of usage examples for com.google.gwt.dom.client Element scrollIntoView

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Element scrollIntoView.

Prototype

@Override
    public void scrollIntoView() 

Source Link

Usage

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

private static void scrollElementIntoView(Element e) {
    debugScroll(CommonUtils.formatJ("elt:%s", e));
    e.scrollIntoView();
}

From source file:com.ephesoft.gxt.core.client.ui.widget.ScrollableSuggestDisplay.java

License:Open Source License

/**
 * Scrolls the selectedItem in to the view. It ensures that selected item is always visible in the SuggestionDisplay.
 *//*from   w w  w. j  a  va  2  s .c om*/
private void scrollSelectedItemIntoView() {
    //TODO Refactoring. NULL Checks missing
    if (null != suggestionMenu) {
        final Element divElement = suggestionMenu.getElement();
        final Node tableNode = divElement.getChild(divElement.getChildCount() - 1);
        final NodeList<Node> optionsList = HTMLDomUtil.getGrandChildren(tableNode, 1);
        Element tableRowElement = null;
        if (optionsList != null) {
            for (int optionIndex = 0; optionIndex < optionsList.getLength(); optionIndex++) {
                tableRowElement = (Element) optionsList.getItem(optionIndex);
                if (((Element) tableRowElement.getChild(0)).getClassName()
                        .contains(StyleConstant.SUGGEST_BOX_SELECTED_ITEM_CLASS_APPENDER)) {
                    tableRowElement.scrollIntoView();
                    break;
                }
            }
        }
    }
}

From source file:com.ephesoft.gxt.rv.client.widget.DataTableGrid.java

License:Open Source License

private void setCurrentColumnCellSelection() {
    cellSelectionModel.addCellSelectionChangedHandler(new CellSelectionChangedHandler<Row>() {

        @Override/*from w  ww  .j  a va  2s.c o m*/
        public void onCellSelectionChanged(final CellSelectionChangedEvent<Row> event) {
            final CellSelection<Row> currentSelection = cellSelectionModel.getSelectCell();
            if (null != currentSelection) {
                final int column = currentSelection.getCell();
                final int row = currentSelection.getRow();
                final ValueProvider valueProvider = cm.getValueProvider(column);
                Column currentColumn = null;
                final Element cellElement = DataTableGrid.this.getView().getCell(row, column);
                if (valueProvider instanceof ColumnValueProvider) {
                    currentColumn = ((ColumnValueProvider) valueProvider).getColumn(store.get(row));
                }
                if (null != cellElement) {
                    cellElement.scrollIntoView();
                }
                final String pageIdentifier = currentColumn == null ? null : currentColumn.getPage();
                lastSelectedCell = currentSelection;
                if (ReviewValidateNavigator.isPageSelectionEnable()) {
                    ReviewValidateEventBus.fireEvent(new PageSelectionEvent(pageIdentifier));
                }
                ReviewValidateNavigator.setCurrentSelectedColumnField(currentColumn);
                ReviewValidateNavigator.setCurrentGrid(DataTableGrid.this);
                ReviewValidateEventBus.fireEvent(new FieldSelectionEvent(currentColumn));
            }
        }
    });
}

From source file:com.novartis.pcs.ontology.webapp.client.view.CodeListView.java

License:Apache License

@Override
public void onViewTerm(ViewTermEvent event) {
    final Term term = event.getTerm();
    final Ontology ontology = term.getOntology();

    if (ontology.isCodelist()) {
        if (currentCodelist == null || !currentCodelist.equals(ontology)) {
            list.setRowData(Collections.<Term>emptyList());
            list.setRowCount(0, true);/* ww  w. ja v a 2 s  . c  om*/
            termIndex.clear();

            service.loadOntologyTerms(ontology.getName(), new AsyncCallback<List<Term>>() {

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log("Failed to load all ontology terms", caught);
                    ErrorView.instance().onUncaughtException(caught);
                }

                @Override
                public void onSuccess(List<Term> terms) {
                    list.setRowData(terms);
                    list.setRowCount(terms.size(), true);
                    selection.setSelected(term, true);
                    currentCodelist = term.getOntology();

                    for (int i = 0; i < terms.size(); i++) {
                        Term t = terms.get(i);
                        termIndex.put(t, i);

                        if (t.equals(term)) {
                            Element row = list.getRowElement(i);
                            row.scrollIntoView();
                        }
                    }
                }
            });
        } else if (!selection.isSelected(term)) {
            selection.setSelected(term, true);

            Integer index = termIndex.get(term);
            if (index != null) {
                Element row = list.getRowElement(index);
                row.scrollIntoView();
            }
        }
    }
}

From source file:com.vaadin.client.debug.internal.LogSection.java

License:Apache License

/**
 * Activates or deactivates scroll lock//from   w w  w. j ava2 s . co  m
 * 
 * @param locked
 */
void setScrollLock(boolean locked) {
    if (locked && scrollTimer != null) {
        scrollTimer.cancel();
        scrollTimer = null;

    } else if (!locked && scrollTimer == null) {
        scrollTimer = new Timer() {
            @Override
            public void run() {
                Element el = (Element) contentElement.getLastChild();
                if (el != null) {
                    el = el.getFirstChildElement();
                    if (el != null) {
                        el.scrollIntoView();
                    }
                }
            }
        };

    }
    scroll.setStyleDependentName(VDebugWindow.STYLENAME_ACTIVE, locked);

}

From source file:org.eclipse.che.ide.ui.list.CategoryNodeElement.java

License:Open Source License

@SuppressWarnings("unchecked")
CategoryNodeElement(final Category category, boolean renderChildren,
        CategoriesList.SelectionManager selectionManager, CategoriesList.Resources resources) {
    this.category = category;
    this.selectionManager = selectionManager;
    CategoryRenderer renderer = category.getRenderer();
    this.resources = resources;
    setStyleName(resources.defaultCategoriesListCss().category());
    FlowPanel header = new FlowPanel();
    header.sinkEvents(Event.ONCLICK);
    header.addDomHandler(new ClickHandler() {
        @Override/*w  w w .j  a va  2  s .  c om*/
        public void onClick(ClickEvent event) {
            if (category.getData().isEmpty()) {
                return;
            }
            expandOrCollapse();
        }
    }, ClickEvent.getType());
    header.setStyleName(resources.defaultCategoriesListCss().categoryHeader());
    SpanElement label = Document.get().createSpanElement();
    label.setClassName(resources.defaultCategoriesListCss().categoryLabel());

    label.appendChild(renderer.renderCategory(category));

    header.getElement().appendChild(label);
    header.ensureDebugId("categoryHeader-" + category.getTitle());

    expandControl = Document.get().createDivElement();
    expandControl.appendChild(resources.arrowExpansionImage().getSvg().getElement());
    expandControl.setClassName(resources.defaultCategoriesListCss().expandControl());
    header.getElement().appendChild(expandControl);
    container = new FocusPanel();
    container.setTabIndex(1);
    container.setStyleName(resources.defaultCategoriesListCss().itemContainer());
    container.sinkEvents(Event.ONCLICK);
    container.addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            selectElement(Element.as(event.getNativeEvent().getEventTarget()));
        }
    }, ClickEvent.getType());
    container.sinkEvents(Event.ONKEYDOWN);
    container.addHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent keyDownEvent) {

            if (selectedElement == null) {
                return;
            }

            Element element = null;

            if (keyDownEvent.isDownArrow()) {
                element = selectedElement.getNextSiblingElement();
                if (element == null) {
                    return;
                }
            }

            if (keyDownEvent.isUpArrow()) {
                element = selectedElement.getPreviousSiblingElement();
                if (element.getClassName().equals("")) {
                    return;
                }
            }

            if (keyDownEvent.isUpArrow() || keyDownEvent.isDownArrow()) {
                keyDownEvent.preventDefault();
                element.scrollIntoView();
                selectElement(element);
            }
        }
    }, KeyDownEvent.getType());
    add(header);
    add(container);
    animator = new AnimationController.Builder().setCollapse(false).setFade(false).build();
    expanded = true;
    renderChildren();
    if (renderChildren) {
        expandControl.addClassName(resources.defaultCategoriesListCss().expandedImage());
    } else {
        expandOrCollapse();
    }
}

From source file:org.eclipse.che.ide.ui.smartTree.Tree.java

License:Open Source License

/**
 * Scroll focus element into specific node.
 *
 * @param node node to scroll//from w  w  w  .j ava 2  s . co  m
 */
public void scrollIntoView(Node node) {
    checkNotNull(node, NULL_NODE_MSG);
    NodeDescriptor descriptor = getNodeDescriptor(node);
    if (descriptor == null) {
        return;
    }
    Element container = descriptor.getNodeContainerElement();
    if (container == null) {
        return;
    }
    container.scrollIntoView();
    focusEl.getStyle().setLeft((nodeStorage.getDepth(node) - 1) * 16, Style.Unit.PX);
    focusEl.getStyle().setTop(container.getOffsetTop(), Style.Unit.PX);
}

From source file:org.sigmah.client.ui.presenter.admin.CategoriesAdminPresenter.java

License:Open Source License

/**
 * add category button listener/* w ww. j a v  a 2s .c om*/
 */
private void createCategoryButtonListener() {

    view.getAddCategoryTypeButton().addListener(Events.OnClick, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {

            if (view.getCategoryName().getValue() != null && view.getCategoryIcon().getValue() != null && view
                    .getCategoriesStore().findModel("label", view.getCategoryName().getValue()) == null) {

                Map<String, Object> newCategoryTypeProperties = new HashMap<String, Object>();

                newCategoryTypeProperties.put(AdminUtil.PROP_CATEGORY_TYPE_ICON,
                        CategoryIcon.getIcon(view.getCategoryIcon().getValue().getValue()));
                newCategoryTypeProperties.put(AdminUtil.PROP_CATEGORY_TYPE_NAME,
                        view.getCategoryName().getValue());

                dispatch.execute(new CreateEntity("CategoryType", newCategoryTypeProperties),
                        new CommandResultHandler<CreateResult>() {

                            @Override
                            public void onCommandFailure(Throwable caught) {
                                N10N.warn(I18N.CONSTANTS.adminCategoryTypeCreationBox(),
                                        I18N.MESSAGES.adminStandardCreationFailureF(
                                                I18N.CONSTANTS.adminCategoryTypeStandard() + " '"
                                                        + view.getCategoryName().getValue() + "'"));
                            }

                            @Override
                            public void onCommandSuccess(CreateResult result) {
                                if (result != null && result.getEntity() != null) {

                                    view.getCategoriesStore().add((CategoryTypeDTO) result.getEntity());
                                    view.getCategoriesStore().commitChanges();

                                    N10N.infoNotif(I18N.CONSTANTS.adminCategoryTypeCreationBox(),
                                            I18N.MESSAGES.adminStandardUpdateSuccessF(
                                                    I18N.CONSTANTS.adminCategoryTypeStandard() + " '"
                                                            + view.getCategoryName().getValue() + "'"));

                                    List<CategoryTypeDTO> selectedCategory = new ArrayList<CategoryTypeDTO>();
                                    selectedCategory.add((CategoryTypeDTO) result.getEntity()); // Focus and scroll to the new created
                                                                                                // category
                                    int rowIndex = view.getCategoriesStore()
                                            .indexOf((CategoryTypeDTO) result.getEntity());
                                    Element addedRow = view.getCategoriesGrid().getView().getRow(rowIndex);
                                    view.getCategoriesGrid().getSelectionModel().setSelection(selectedCategory);
                                    addedRow.setScrollTop(addedRow.getScrollTop());
                                    addedRow.scrollIntoView();

                                    view.getCategoryName().clear();
                                    view.getCategoryIcon().clearSelections();

                                } else {
                                    N10N.infoNotif(I18N.CONSTANTS.adminCategoryTypeCreationBox(),
                                            I18N.MESSAGES.adminStandardCreationNullF(
                                                    I18N.CONSTANTS.adminCategoryTypeStandard() + " '"
                                                            + view.getCategoryName().getValue() + "'"));
                                }
                            }
                        });
            } else {
                N10N.warn("", I18N.CONSTANTS.adminStandardInvalidValues());
            }
        };
    });
}

From source file:org.sigmah.client.ui.presenter.admin.ReportModelsAdminPresenter.java

License:Open Source License

private void reportModelAddButtonListener() {

    view.getAddReportButton().addListener(Events.OnClick, new Listener<BaseEvent>() {

        @Override/*w  ww  . j  a  v  a  2s  . co m*/
        public void handleEvent(BaseEvent be) {

            if (view.getReportName().getValue() != null
                    && view.getModelsStore().findModel("name", view.getReportName().getValue()) == null) {

                HashMap<String, Object> newReportProperties = new HashMap<String, Object>();
                // Store the report's name in properties variable
                newReportProperties.put(AdminUtil.PROP_REPORT_MODEL_NAME, view.getReportName().getValue());
                newReportProperties.put(AdminUtil.PROP_REPORT_SECTION_MODEL, null);

                dispatch.execute(new CreateEntity(ReportModelDTO.ENTITY_NAME, newReportProperties),
                        new CommandResultHandler<CreateResult>() {

                            @Override
                            public void onCommandFailure(Throwable caught) {

                                N10N.warn(I18N.CONSTANTS.adminReportModelCreationBox(),
                                        I18N.MESSAGES.adminStandardCreationFailure(
                                                I18N.CONSTANTS.adminReportModelStandard() + " '"
                                                        + view.getReportName().getValue() + "'"));

                                view.getSectionsToBeSaved().clear();

                            }

                            @Override
                            public void onCommandSuccess(CreateResult result) {

                                if (result != null) {

                                    // Refresh the report model grid
                                    view.getModelsStore().add((ReportModelDTO) result.getEntity());
                                    view.getModelsStore().commitChanges();
                                    N10N.infoNotif(I18N.CONSTANTS.adminReportModelCreationBox(),
                                            I18N.MESSAGES.adminStandardUpdateSuccess(
                                                    I18N.CONSTANTS.adminReportModelStandard() + " '"
                                                            + result.getEntity().getEntityName() + "'"));

                                    // Create a selected model list
                                    List<ReportModelDTO> selectedModel = new ArrayList<ReportModelDTO>();
                                    selectedModel.add((ReportModelDTO) result.getEntity());

                                    // Focus the new created model cell in the grid

                                    int rowIndex = view.getModelsStore()
                                            .indexOf((ReportModelDTO) result.getEntity());
                                    Element addedRow = view.getReportModelsGrid().getView().getRow(rowIndex);

                                    view.getReportModelsGrid().getSelectionModel().setSelection(selectedModel);

                                    addedRow.setScrollTop(addedRow.getScrollTop());
                                    addedRow.scrollIntoView();
                                    view.getReportName().clear();

                                } else {
                                    N10N.warn(I18N.CONSTANTS.adminReportModelCreationBox(),
                                            I18N.MESSAGES.adminStandardCreationNull(
                                                    I18N.CONSTANTS.adminReportModelStandard() + " '"
                                                            + view.getReportName().getValue() + "'"));
                                }

                                view.getSectionsToBeSaved().clear();
                            }
                        }, view.getReportModelsLoadingMonitor());

            } else {
                // Invalid input
                N10N.warn(I18N.CONSTANTS.adminReportModelCreationBox(),
                        I18N.CONSTANTS.adminStandardInvalidValues());
                view.getSectionsToBeSaved().clear();
            }

        };
    });

}