Search in sources :

Example 16 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project opennms by OpenNMS.

the class GWTVertex method create.

public static D3Behavior create() {
    return new D3Behavior() {

        @Override
        public D3 run(D3 selection) {
            D3 vertex = selection.append("g").attr("class", "vertex");
            vertex.attr("opacity", 1e-6).style("cursor", "pointer");
            vertex.append("svg:rect").attr("class", "status").attr("fill", "none").attr("stroke-width", 5).attr("stroke-location", "outside").attr("stroke", "blue").attr("opacity", 0);
            D3 svgIconContainer = vertex.append("g").attr("class", "icon-container").attr("opacity", 0);
            D3 svgIcon = svgIconContainer.append("use");
            D3 svgIconRollover = svgIconContainer.append("use");
            D3 svgIconActive = svgIconContainer.append("use");
            D3 statusCounter = vertex.append("g");
            D3 statusBadge = vertex.append("g");
            D3 textSelection = vertex.append("text");
            D3 navigateTo = vertex.append("g").attr("class", "navigate-to");
            vertex.append("svg:rect").attr("class", "svgIconOverlay").attr("width", 100).attr("height", 100).attr("opacity", 0).call(new D3Behavior() {

                @Override
                public D3 run(D3 selection) {
                    return selection.on("mouseover", new D3Events.Handler<Object>() {

                        @Override
                        public void call(Object o, int index) {
                            NativeEvent event = D3.getEvent();
                            SVGRect element = event.getCurrentEventTarget().cast();
                            SVGGElement parent = element.getParentElement().cast();
                            D3 selection = D3.d3().select(parent);
                            selection.select(".overIcon").attr("opacity", 1);
                        }
                    }).on("mouseout", new D3Events.Handler<Object>() {

                        @Override
                        public void call(Object o, int index) {
                            NativeEvent event = D3.getEvent();
                            SVGRect element = event.getCurrentEventTarget().cast();
                            SVGGElement parent = element.getParentElement().cast();
                            D3 selection = D3.d3().select(parent);
                            selection.select(".overIcon").attr("opacity", 0);
                        }
                    });
                }
            });
            svgIcon.attr("xlink:href", svgIconId("")).attr("class", "upIcon");
            svgIconRollover.attr("xlink:href", svgIconId("_rollover")).attr("class", "overIcon").attr("opacity", 0);
            svgIconActive.attr("xlink:href", svgIconId("_active")).attr("class", "activeIcon").attr("opacity", 0);
            // Status Counter
            statusCounter.attr("class", "node-status-counter").append("svg:rect").attr("height", 20).attr("width", 20).attr("rx", 10).attr("ry", 10);
            statusCounter.append("text").attr("x", "6px").attr("y", "14px").attr("class", "status-counter");
            // Status Badge
            statusBadge.attr("class", "status-badge-container");
            statusBadge.append("text").attr("x", "0px").attr("y", "0px").attr("class", "status-badge");
            // Navigate To indicator
            navigateTo.append("text").attr("class", "text").attr("opacity", 1).attr("x", -23).attr("y", 23).text(// ion-record
            "");
            textSelection.text(label()).attr("class", "vertex-label").attr("x", "0px").attr("text-anchor", "middle").attr("alignment-baseline", "text-before-edge");
            vertex.call(draw());
            return vertex;
        }
    };
}
Also used : D3Events(org.opennms.features.topology.app.internal.gwt.client.d3.D3Events) SVGGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) D3Behavior(org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior) SVGRect(org.opennms.features.topology.app.internal.gwt.client.svg.SVGRect) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 17 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project perun by CESNET.

the class FindSimilarPublications method getEmptyTable.

/**
	 * Returns table of users publications
	 * @return table
	 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No similar publications found.");
    // show checkbox column
    if (this.checkable) {
        // checkbox column column
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.getLocked() == true) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.getLocked() == true) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.getLocked() == true) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.getLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }

        ;
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 18 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project GwtMobile by dennisjzh.

the class Utils method loadUrl.

//The url loaded by this method can be intercepted by 
//WebViewClient.shouldOverrideUrlLoading
public static void loadUrl(String url) {
    Anchor a = new Anchor("", url);
    RootLayoutPanel.get().add(a);
    NativeEvent event = Document.get().createClickEvent(1, 1, 1, 1, 1, false, false, false, false);
    a.getElement().dispatchEvent(event);
    RootLayoutPanel.get().remove(a);
}
Also used : Anchor(com.google.gwt.user.client.ui.Anchor) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 19 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project che by eclipse.

the class KeyboardNavigationHandler method handleEvent.

public void handleEvent(NativeEvent event) {
    int code = event.getKeyCode();
    NativeEvent e = event;
    String type = event.getType();
    if ("keydown".equals(type) && keyEvent == Event.ONKEYDOWN || "keypress".equals(type) && keyEvent == Event.ONKEYPRESS) {
    } else {
        return;
    }
    if (component != null && component.getElement() != e.getCurrentEventTarget().cast()) {
        return;
    }
    if (preventDefault) {
        event.preventDefault();
    }
    onKeyPress(e);
    switch(code) {
        case KeyCodes.KEY_ALT:
            onAlt(e);
            break;
        case KeyCodes.KEY_BACKSPACE:
            onBackspace(e);
            break;
        case KeyCodes.KEY_CTRL:
            onControl(e);
            break;
        case KeyCodes.KEY_DELETE:
            onDelete(e);
            break;
        case KeyCodes.KEY_DOWN:
            onDown(e);
            break;
        case KeyCodes.KEY_END:
            onEnd(e);
            break;
        case KeyCodes.KEY_ENTER:
            onEnter(e);
            break;
        case KeyCodes.KEY_ESCAPE:
            onEsc(e);
            break;
        case KeyCodes.KEY_HOME:
            onHome(e);
            break;
        case KeyCodes.KEY_LEFT:
            onLeft(e);
            break;
        case KeyCodes.KEY_PAGEDOWN:
            onPageDown(e);
            break;
        case KeyCodes.KEY_PAGEUP:
            onPageUp(e);
            break;
        case KeyCodes.KEY_SHIFT:
            onShift(e);
            break;
        case KeyCodes.KEY_TAB:
            onTab(e);
            break;
        case KeyCodes.KEY_RIGHT:
            onRight(e);
            break;
        case KeyCodes.KEY_UP:
            onUp(e);
            break;
    }
}
Also used : NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 20 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project libgdx by libgdx.

the class AssetDownloader method loadImage.

public void loadImage(final String url, final String mimeType, final String crossOrigin, final AssetLoaderListener<ImageElement> listener) {
    if (useBrowserCache || useInlineBase64) {
        loadBinary(url, new AssetLoaderListener<Blob>() {

            @Override
            public void onProgress(double amount) {
                listener.onProgress(amount);
            }

            @Override
            public void onFailure() {
                listener.onFailure();
            }

            @Override
            public void onSuccess(Blob result) {
                final ImageElement image = createImage();
                if (crossOrigin != null) {
                    image.setAttribute("crossOrigin", crossOrigin);
                }
                hookImgListener(image, new ImgEventListener() {

                    @Override
                    public void onEvent(NativeEvent event) {
                        if (event.getType().equals("error"))
                            listener.onFailure();
                        else
                            listener.onSuccess(image);
                    }
                });
                if (isUseInlineBase64()) {
                    image.setSrc("data:" + mimeType + ";base64," + result.toBase64());
                } else {
                    image.setSrc(url);
                }
            }
        });
    } else {
        final ImageElement image = createImage();
        if (crossOrigin != null) {
            image.setAttribute("crossOrigin", crossOrigin);
        }
        hookImgListener(image, new ImgEventListener() {

            @Override
            public void onEvent(NativeEvent event) {
                if (event.getType().equals("error"))
                    listener.onFailure();
                else
                    listener.onSuccess(image);
            }
        });
        image.setSrc(url);
    }
}
Also used : ImageElement(com.google.gwt.dom.client.ImageElement) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

NativeEvent (com.google.gwt.dom.client.NativeEvent)35 Element (com.google.gwt.dom.client.Element)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 JsArrayString (com.google.gwt.core.client.JsArrayString)3 TableRowElement (com.google.gwt.dom.client.TableRowElement)3 Column (com.google.gwt.user.cellview.client.Column)3 D3 (org.opennms.features.topology.app.internal.gwt.client.d3.D3)3 MarqueeSelectHandler (org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler)3 PanHandler (org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler)3 SVGGElement (org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement)3 Context (com.google.gwt.cell.client.Cell.Context)2 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)2 JsArray (com.google.gwt.core.client.JsArray)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 EventTarget (com.google.gwt.dom.client.EventTarget)2 ImageElement (com.google.gwt.dom.client.ImageElement)2 HasHandlers (com.google.gwt.event.shared.HasHandlers)2 ImageResource (com.google.gwt.resources.client.ImageResource)2 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 HTML (com.google.gwt.user.client.ui.HTML)2