Example usage for com.google.gwt.view.client CellPreviewEvent getIndex

List of usage examples for com.google.gwt.view.client CellPreviewEvent getIndex

Introduction

In this page you can find the example usage for com.google.gwt.view.client CellPreviewEvent getIndex.

Prototype

public int getIndex() 

Source Link

Document

Get the index of the value where the event occurred.

Usage

From source file:com.retech.reader.web.client.labs.Labs.java

License:Apache License

@Inject
Labs(final CellList.Resources resource, final PlaceController placeController, final Provider<BasePlace> base) {
    this.setWaveContent(binder.createAndBindUi(this));

    setColor.setChangeElm(simplePanel.getElement());

    minimize.setIconElement(//from w ww  .j  a va2  s. c om
            AbstractImagePrototype.create(WaveTitleResources.image().waveTitleMinimize()).createElement());

    // add Data
    List<LabsIconDecorator> list = listDataProvider.getList();
    LabsIconDecorator touch = new LabsIconDecorator(bunder.laboratory(), "", WaveTest.class);
    list.add(touch);

    LabsIconDecorator flip = new LabsIconDecorator(bunder.laboratory(), "3D", BookFlip.class);
    list.add(flip);

    LabsIconDecorator contact = new LabsIconDecorator(bunder.laboratory(), "??",
            ContactPanel.class);
    list.add(contact);

    LabsIconDecorator treeTest = new LabsIconDecorator(bunder.laboratory(), "TreeTest", TreeTest.class);
    list.add(treeTest);

    LabsIconDecorator search = new LabsIconDecorator(bunder.laboratory(), "?", SearchPanel.class);
    list.add(search);

    LabsIconDecorator blipTest = new LabsIconDecorator(bunder.laboratory(), "BlipTest", BlipTest.class);
    list.add(blipTest);

    LabsIconDecorator blipTree = new LabsIconDecorator(bunder.laboratory(), "NestedBlipTest",
            NestedBlipTest.class);
    list.add(blipTree);

    LabsIconDecorator settingsView = new LabsIconDecorator(bunder.laboratory(), "", SettingsView.class);
    list.add(settingsView);

    LabsIconDecorator contactPanel = new LabsIconDecorator(bunder.laboratory(), "", ContactPanel.class);
    list.add(contactPanel);

    server.add(
            new Anchor("Android", "https://build.phonegap.com/apps/95095/download/android", "_blank"));
    server.add(
            new Anchor("iOS", "https://build.phonegap.com/apps/95095/download/ios", "_blank"));
    server.add(new Anchor("Google Play?",
            "https://play.google.com/store/apps/details?id=com.goodow.web.mobile", "_blank"));
    server.add(new Anchor("SCM - Subversion", SERVER_URL + "/svn/retech", "_blank"));
    server.add(new Anchor("Files", SERVER_URL + "/files", "_blank"));
    server.add(new Anchor("Document", SERVER_URL + "/svn/retech/document", "_blank"));
    server.add(new Anchor("CI - Hudson", SERVER_URL + ":8080", "_blank"));
    server.add(new Anchor("Repository - Nexus", SERVER_URL + ":8081/nexus", "_blank"));

    // add cell
    List<HasCell<LabsIconDecorator, ?>> hasCells = new ArrayList<HasCell<LabsIconDecorator, ?>>();
    hasCells.add(new HasCell<LabsIconDecorator, LabsIconDecorator>() {

        LabsIconDecoratorCell cell = new LabsIconDecoratorCell(
                new LabsIconDecoratorCell.Delegate<LabsIconDecorator>() {

                    @Override
                    public void execute(final LabsIconDecorator object) {
                        placeController.goTo(base.get().setPath(object.getClassName().getName()));
                    }
                });

        @Override
        public Cell<LabsIconDecorator> getCell() {
            return cell;
        }

        @Override
        public FieldUpdater<LabsIconDecorator, LabsIconDecorator> getFieldUpdater() {
            return null;
        }

        @Override
        public LabsIconDecorator getValue(final LabsIconDecorator object) {
            return object;
        }
    });

    hasCells.add(new HasCell<LabsIconDecorator, LabsIconDecorator>() {

        private TrangleButtonCell<LabsIconDecorator> tbc = new TrangleButtonCell<LabsIconDecorator>();

        @Override
        public Cell<LabsIconDecorator> getCell() {
            return tbc;
        }

        @Override
        public FieldUpdater<LabsIconDecorator, LabsIconDecorator> getFieldUpdater() {
            return null;
        }

        @Override
        public LabsIconDecorator getValue(final LabsIconDecorator object) {
            return object;
        }
    });

    compositeCell = new CompositeCell<LabsIconDecorator>(hasCells) {

        @Override
        public void render(final com.google.gwt.cell.client.Cell.Context context, final LabsIconDecorator value,
                final SafeHtmlBuilder sb) {
            super.render(context, value, sb);
        }

        @Override
        protected Element getContainerElement(final Element parent) {
            return parent;
        }

        @Override
        protected <X> void render(final com.google.gwt.cell.client.Cell.Context context,
                final LabsIconDecorator value, final SafeHtmlBuilder sb,
                final HasCell<LabsIconDecorator, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            cell.render(context, hasCell.getValue(value), sb);
        }
    };

    // add cellList
    cellList = new CellList<LabsIconDecorator>(compositeCell, resource);

    // add cellPreviewHanler
    cellList.addCellPreviewHandler(new CellPreviewEvent.Handler<LabsIconDecorator>() {

        @Override
        public void onCellPreview(final CellPreviewEvent<LabsIconDecorator> event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            boolean isClick = nativeEvent.getType().equals(BrowserEvents.CLICK);
            if (isClick) {
                Element clickelm = cellList.getRowElement(event.getIndex());
                Element eventTarget = Element.as(nativeEvent.getEventTarget());
                if (clickelm.getFirstChildElement() == eventTarget) {
                    if (Labs.this.lastElm == null) {
                        Labs.this.lastElm = clickelm;
                    }
                    if (Labs.this.lastElm != clickelm) {
                        Labs.this.lastElm.removeClassName(LabsResources.css().cellListSelectionItem());
                        clickelm.addClassName(LabsResources.css().cellListSelectionItem());
                        Labs.this.lastElm = clickelm;
                    } else if (Labs.this.lastElm == clickelm) {
                        clickelm.addClassName(LabsResources.css().cellListSelectionItem());
                    }
                }
            }
        }
    });
    simplePanel.add(cellList);
}

From source file:org.aksw.TripleCheckMate.client.widgets.EvaluationTable.java

License:Apache License

private void createTable() {
    // Link to data provider
    dataProvider.addDataDisplay(tblEvalTriples);

    // Table properties
    tblEvalTriples.setPageSize(arrPagerSizes[0]);

    // Set Pagers (add both bottom and top)
    pgrTop.setDisplay(tblEvalTriples);//ww  w  .ja  va2  s.  co  m
    pgrBottom.setDisplay(tblEvalTriples);

    // Table columns
    final SafeHtmlCell cellP = new SafeHtmlCell();
    Column<EvaluateItem, SafeHtml> colPred = new Column<EvaluateItem, SafeHtml>(cellP) {

        public SafeHtml getValue(EvaluateItem item) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant(item.P.toHTMLString());
            return sb.toSafeHtml();
        }
    };

    tblEvalTriples.addColumn(colPred, "Predicate");

    final SafeHtmlCell cellO = new SafeHtmlCell();
    Column<EvaluateItem, SafeHtml> colObj = new Column<EvaluateItem, SafeHtml>(cellO) {

        public SafeHtml getValue(EvaluateItem item) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant(item.O.toHTMLString());
            return sb.toSafeHtml();
        }
    };
    tblEvalTriples.addColumn(colObj, "Object");

    Column<EvaluateItem, Boolean> colIsValid = new Column<EvaluateItem, Boolean>(
            new CheckboxCell(true, false)) {

        public Boolean getValue(EvaluateItem item) {
            return item.isWrong;
        }
    };

    tblEvalTriples.addColumn(colIsValid, "Is Wrong");

    // Add a field updater to be notified when the user enters a new name.
    colIsValid.setFieldUpdater(new FieldUpdater<EvaluateItem, Boolean>() {

        public void update(int index, EvaluateItem object, Boolean value) {
            dataProvider.getList().get(index).isWrong = value;
            if (value == false) {
                dataProvider.getList().get(index).errorTittle = "";
                tblEvalTriples.redraw();
            } else {
                dlgEdit.setEvaluateItem(dataProvider.getList().get(index), true);
                dlgEdit.center();
                dlgEdit.show();
            }

        }
    });

    tblEvalTriples.addCellPreviewHandler(new CellPreviewEvent.Handler<EvaluateItem>() {

        long lastClick = -1000;

        public void onCellPreview(CellPreviewEvent<EvaluateItem> event) {

            long clictAt = System.currentTimeMillis();

            if (event.getNativeEvent().getType().contains("click")) {
                if (clictAt - lastClick < 600) { // dblclick on 2 clicks detected within 300 ms
                    int index = event.getIndex();
                    dlgEdit.setEvaluateItem(dataProvider.getList().get(index), false);
                    dlgEdit.center();
                    dlgEdit.show();
                }
                lastClick = System.currentTimeMillis();

            }
        }
    });

    final SafeHtmlCell cellError = new SafeHtmlCell();
    Column<EvaluateItem, SafeHtml> colError = new Column<EvaluateItem, SafeHtml>(cellError) {

        public SafeHtml getValue(EvaluateItem item) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant(item.errorTittle);
            return sb.toSafeHtml();
        }
    };
    tblEvalTriples.addColumn(colError, "Error");

    // Setup sorting

    colPred.setSortable(true);
    sortHandler.setComparator(colPred, new Comparator<EvaluateItem>() {
        public int compare(EvaluateItem o1, EvaluateItem o2) {
            return o1.P.toString().compareTo(o2.P.toString());
        }
    });

    colObj.setSortable(true);
    sortHandler.setComparator(colObj, new Comparator<EvaluateItem>() {
        public int compare(EvaluateItem o1, EvaluateItem o2) {
            return o1.P.toString().compareTo(o2.P.toString());
        }
    });

    colIsValid.setSortable(true);
    sortHandler.setComparator(colIsValid, new Comparator<EvaluateItem>() {
        public int compare(EvaluateItem o1, EvaluateItem o2) {
            if (o1.isWrong == o2.isWrong)
                return 0;
            else
                return (o1.isWrong ? 1 : -1);
        }
    });

    colError.setSortable(true);
    sortHandler.setComparator(colError, new Comparator<EvaluateItem>() {
        public int compare(EvaluateItem o1, EvaluateItem o2) {
            return o1.errorTittle.compareTo(o2.errorTittle);
        }
    });

    tblEvalTriples.addColumnSortHandler(sortHandler);
    tblEvalTriples.getColumnSortList().push(colObj);
    tblEvalTriples.getColumnSortList().push(colPred);

    for (int i = 0; i < arrPagerSizes.length; i++) {
        lstPager.addItem("" + arrPagerSizes[i]);
    }
    lstPager.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            tblEvalTriples.setPageSize(arrPagerSizes[lstPager.getSelectedIndex()]);
        }
    });
}

From source file:org.eclipse.che.ide.ext.datasource.client.sqllauncher.ResultCellTable.java

License:Open Source License

@Inject
public ResultCellTable(final @Assisted int pageSize,
        final @NotNull CellTableResourcesQueryResults cellTableResources,
        final @NotNull SqlRequestLauncherConstants constants) {
    super(pageSize, cellTableResources);

    final InlineLabel emptyWidget = new InlineLabel(constants.emptyResult());
    setEmptyTableWidget(emptyWidget);//from   w w  w  .j av  a  2s .c om
    emptyWidget.setStyleName(cellTableResources.cellTableStyle().emptyTableWidget());

    addCellPreviewHandler(new CellPreviewEvent.Handler<List<String>>() {
        @Override
        public void onCellPreview(CellPreviewEvent<List<String>> event) {
            if ("click".equals(event.getNativeEvent().getType())) {
                TableCellElement cellElement = getRowElement(event.getIndex()).getCells()
                        .getItem(event.getColumn());
                cellElement.setTitle(cellElement.getInnerText());
            }
        }
    });
}

From source file:org.gss_project.gss.web.client.GSSSelectionEventManager.java

License:Open Source License

/**
 * Handle an event that could cause a value to be selected for a
 * {@link MultiSelectionModel}. This overloaded method adds support for both
 * the control and shift keys. If the shift key is held down, all rows between
 * the previous selected row and the current row are selected.
 * /*from  w  ww  . ja  v a 2  s.c  o m*/
 * @param event the {@link CellPreviewEvent} that triggered selection
 * @param action the action to handle
 * @param selectionModel the {@link SelectionModel} to update
 */
protected void handleMultiSelectionEvent(CellPreviewEvent<T> event, SelectAction action,
        MultiSelectionModel<? super T> selectionModel) {
    NativeEvent nativeEvent = event.getNativeEvent();
    String type = nativeEvent.getType();
    boolean rightclick = "mousedown".equals(type) && nativeEvent.getButton() == NativeEvent.BUTTON_RIGHT;
    if (rightclick) {
        boolean shift = nativeEvent.getShiftKey();
        boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey();
        boolean clearOthers = (translator == null) ? !ctrlOrMeta : translator.clearCurrentSelection(event);
        if (action == null || action == SelectAction.DEFAULT) {
            action = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT;
        }
        //if the row is selected then do nothing
        if (selectionModel.isSelected(event.getValue())) {
            return;
        }
        doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift,
                clearOthers);
    } else if ("click".equals(type)) {
        /*
         * Update selection on click. Selection is toggled only if the user
         * presses the ctrl key. If the user does not press the control key,
         * selection is additive.
         */
        boolean shift = nativeEvent.getShiftKey();
        boolean ctrlOrMeta = nativeEvent.getCtrlKey() || nativeEvent.getMetaKey();
        boolean clearOthers = (translator == null) ? !ctrlOrMeta : translator.clearCurrentSelection(event);
        if (action == null || action == SelectAction.DEFAULT) {
            action = ctrlOrMeta ? SelectAction.TOGGLE : SelectAction.SELECT;
        }
        doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action, shift,
                clearOthers);
        if (ctrlOrMeta) {
            event.setCanceled(true);
        }
    } else if ("keyup".equals(type)) {
        int keyCode = nativeEvent.getKeyCode();
        if (keyCode == 32) {
            /*
             * Update selection when the space bar is pressed. The spacebar always
             * toggles selection, regardless of whether the control key is pressed.
             */
            boolean shift = nativeEvent.getShiftKey();
            boolean clearOthers = (translator == null) ? false : translator.clearCurrentSelection(event);
            if (action == null || action == SelectAction.DEFAULT) {
                action = SelectAction.TOGGLE;
            }
            doMultiSelection(selectionModel, event.getDisplay(), event.getIndex(), event.getValue(), action,
                    shift, clearOthers);
        }
    }
}

From source file:org.rstudio.core.client.widget.ModifyKeyboardShortcutsWidget.java

License:Open Source License

private void onShortcutCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) {
    NativeEvent event = preview.getNativeEvent();
    String type = event.getType();

    if (type.equals("keydown")) {
        int keyCode = event.getKeyCode();
        int modifiers = KeyboardShortcut.getModifierValue(event);

        // Don't handle raw 'Enter' keypresses (let underlying input
        // widget process)
        if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0)
            return;

        // Handle any other key events.
        if (modifiers != 0)
            swallowNextKeyUpEvent_ = true;

        event.stopPropagation();//  w  ww .jav  a2  s  . c o  m
        event.preventDefault();

        if (KeyboardHelper.isModifierKey(event.getKeyCode()))
            return;

        if (keyCode == KeyCodes.KEY_BACKSPACE && modifiers == 0) {
            buffer_.pop();
        } else if (keyCode == KeyCodes.KEY_DELETE && modifiers == 0) {
            buffer_.clear();
        } else if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) {
            buffer_.set(preview.getValue().getOriginalKeySequence());
        } else {
            buffer_.add(event);
        }

        // Sneak into the element and find the active <input>, then update it.
        Element el = getElement(table_, preview.getIndex(), preview.getColumn());
        Element input = el.getFirstChildElement().getFirstChildElement();
        if (input == null)
            return;

        assert input.getTagName().toLowerCase().equals("input") : "Failed to find <input> element in table";

        String bufferString = buffer_.toString();
        input.setAttribute("value", bufferString);
        input.setInnerHTML(bufferString);

        // Move the cursor to the end of the selection.
        DomUtils.setSelectionRange(input, bufferString.length(), bufferString.length());
    }
}