com.google.gwt.core.client.JsArray Java Examples

The following examples show how to use com.google.gwt.core.client.JsArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OverlaySerdesTest.java    From requestor with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testDeserializeCollection() throws Exception {
    DeserializationContext ctx = new DeserializationContext(JavaScriptObject.class) {
        @Override
        public <T> T getInstance(Class<T> type) {
            return (T) new ArrayList<Object>();
        }
    };

    String input = "[{\"name\":\"John Doe\",\"age\":31},{\"name\":\"Alice\",\"age\":27}]";

    JsArray<JavaScriptObject> expected = (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
    expected.push(create("John Doe", 31));
    expected.push(create("Alice", 27));

    List<JavaScriptObject> output = serdes.deserialize(List.class, input, ctx);
    JsArray<JavaScriptObject> outputArray = (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
    outputArray.push(output.get(0));
    outputArray.push(output.get(1));

    assertEquals(JsonSerdes.stringify(expected), JsonSerdes.stringify(outputArray));
}
 
Example #2
Source File: SimpleDemo.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void showPoland() {
	WKTReader r = new WKTReader();
	try {
		Geometry g = r.read(s);
		g.setSRID(4326);

		Geometry g2 = g.buffer(1);
		Geometry g3 = g2.difference(g);

		JavaScriptObject f1 = parseWKT(g.toString());
		JavaScriptObject f2 = parseWKT(g3.toString());
		JsArray<JavaScriptObject> fs = JsArray.createArray().cast();
		fs.push(f1);
		fs.push(f2);

		addFeatures(mMap, fs);
	} catch (ParseException e) {
		sLogger.log(Level.WARNING, "Unable to parse wkb", e);
	}
}
 
Example #3
Source File: PolarAreaChart.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void reload() {
	if(provider == null)
		throw new NullPointerException("PieChartDataProvider is not initialized before invoking reload()");
	
	
	//TODO: show loading to user
	
	provider.reload(new AsyncCallback<JsArray<Series>>() {
		
		@Override
		public void onSuccess(JsArray<Series> result) {
               drawPolarArea(provider.getData());
		}
		
		@Override
		public void onFailure(Throwable caught) {
			// TODO Auto-generated method stub
			
		}
	});
}
 
Example #4
Source File: DoughnutChart.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void reload() {
	if(provider == null)
		throw new NullPointerException("PieCharDataProvider is not initialized before invoking reload()");
	
	//TODO: show loading
	provider.reload(new AsyncCallback<JsArray<Series>>() {
		
		@Override
		public void onSuccess(JsArray<Series> result) {
               drawDoughnut(result);
		}
		
		@Override
		public void onFailure(Throwable caught) {
			// TODO Auto-generated method stub
			
		}
	});
}
 
Example #5
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@UsedByApp
public JsPromise loadSessions() {
    return JsPromise.create(new JsPromiseExecutor() {
        @Override
        public void execute() {
            messenger.loadSessions().start(new CommandCallback<List<ApiAuthSession>>() {
                @Override
                public void onResult(List<ApiAuthSession> res) {
                    JsArray<JsAuthSession> jsSessions = JsArray.createArray().cast();

                    for (ApiAuthSession session : res) {
                        jsSessions.push(JsAuthSession.create(session));
                    }

                    resolve(jsSessions);
                }

                @Override
                public void onError(Exception e) {
                    Log.e(TAG, e);
                    reject(e.getMessage());
                }
            });
        }
    });
}
 
Example #6
Source File: DomHelper.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of descendants of e that match the given class name.
 *
 * If the browser has the native method, that will be called. Otherwise, it
 * traverses descendents of the given element and returns the list of elements
 * with matching classname.
 *
 * @param e
 * @param className
 */
public static NodeList<Element> getElementsByClassName(Element e, String className) {
  if (QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME) {
    return getElementsByClassNameNative(e, className);
  } else {
    NodeList<Element> all = e.getElementsByTagName("*");
    if (all == null) {
      return null;
    }
    JsArray<Element> ret = JavaScriptObject.createArray().cast();
    for (int i = 0; i < all.getLength(); ++i) {
      Element item = all.getItem(i);
      if (className.equals(item.getClassName())) {
        ret.push(item);
      }
    }
    return ret.cast();
  }
}
 
Example #7
Source File: Typeahead.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
private native void configure(
        Element e, boolean highlight, boolean hint, int minLength, JsArray<JavaScriptObject> datasets) /*-{
    var that = this;
    $wnd.jQuery(e).typeahead({
            highlight: highlight,
            hint: hint,
            minLength: minLength
        },
        datasets)
        .on('typeahead:opened', function (e) {
            [email protected]::onOpened(Lcom/google/gwt/user/client/Event;)(e);
        })
        .on('typeahead:closed', function (e) {
            [email protected]::onClosed(Lcom/google/gwt/user/client/Event;)(e);
        })
        .on('typeahead:cursorchanged', function (e, value, datasetName) {
            [email protected]::onCursorChanged(Lcom/google/gwt/user/client/Event;Lorg/gwtbootstrap3/extras/typeahead/client/base/Suggestion;)(e, value);
        })
        .on('typeahead:autocompleted', function (e, value, datasetName) {
            [email protected]::onAutoCompleted(Lcom/google/gwt/user/client/Event;Lorg/gwtbootstrap3/extras/typeahead/client/base/Suggestion;)(e, value);
        })
        .on('typeahead:selected', function (e, value, datasetName) {
            [email protected]::onSelected(Lcom/google/gwt/user/client/Event;Lorg/gwtbootstrap3/extras/typeahead/client/base/Suggestion;)(e, value);
        });
}-*/;
 
Example #8
Source File: CalendarConfig.java    From gwtbootstrap3-extras with Apache License 2.0 6 votes vote down vote up
public JsArray<JavaScriptObject> getJavaScriptParameters() {
    @SuppressWarnings("unchecked")
    final JsArray<JavaScriptObject> params = (JsArray<JavaScriptObject>) JsArray.createArray();
    setParameter(params, getGeneralDisplay());
    setParameter(params, getButtonText());
    setParameter(params, getMonthNames());
    setParameter(params, getDayNames());
    setParameter(params, getDragResizeConfig());
    setParameter(params, getClickHoverConfig());
    setParameter(params, getSelectConfig());
    setParameter(params, getEventConfig());
    setParameter(params, getColumnFormat());
    setParameter(params, getTimeFormat());
    setParameter(params, getTitleFormat());
    setParameter(params, getAgendaOptions());
    setParameter(params, getRenderConfig());
    return params;
}
 
Example #9
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@UsedByApp
private JsPromise loadArchivedDialogs(final boolean init) {
    return JsPromise.create(new JsPromiseExecutor() {
        @Override
        public void execute() {
            messenger.loadArchivedDialogs(init, new RpcCallback<ResponseLoadArchived>() {
                @Override
                public void onResult(ResponseLoadArchived response) {
                    JsArray<JsDialogShort> res = JsArray.createArray().cast();
                    for (ApiDialog d : response.getDialogs()) {
                        res.push(JsDialogShort.create(messenger.buildPeerInfo(EntityConverter.convert(d.getPeer())), d.getUnreadCount()));
                    }
                    Log.d(TAG, "loadArchivedDialogs:result");
                    resolve(res);
                }

                @Override
                public void onError(RpcException e) {
                    Log.d(TAG, "loadArchivedDialogs:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
 
Example #10
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of descendants of e that match the given class name.
 *
 * If the browser has the native method, that will be called. Otherwise, it
 * traverses descendents of the given element and returns the list of elements
 * with matching classname.
 *
 * @param e
 * @param className
 */
public static NodeList<Element> getElementsByClassName(Element e, String className) {
  if (QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME) {
    return getElementsByClassNameNative(e, className);
  } else {
    NodeList<Element> all = e.getElementsByTagName("*");
    if (all == null) {
      return null;
    }
    JsArray<Element> ret = JavaScriptObject.createArray().cast();
    for (int i = 0; i < all.getLength(); ++i) {
      Element item = all.getItem(i);
      if (className.equals(item.getClassName())) {
        ret.push(item);
      }
    }
    return ret.cast();
  }
}
 
Example #11
Source File: TurboOverlaySerdes.java    From requestor with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <C extends Collection<JavaScriptObject>> C deserialize(Class<C> collectionType, String response,
                                                              DeserializationContext context) {
    JsArray<JavaScriptObject> jsArray = eval(response);
    if (collectionType.equals(List.class) || collectionType.equals(Collection.class)
            || collectionType.equals(JsArrayList.class)) {
        return (C) new JsArrayList(jsArray);
    } else {
        C col = context.getInstance(collectionType);
        for (int i = 0; i < jsArray.length(); i++) {
            JavaScriptObject t = jsArray.get(i);
            col.add(t);
        }
        return col;
    }
}
 
Example #12
Source File: JsWebRTCProvider.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public Promise<WebRTCPeerConnection> createPeerConnection(final WebRTCIceServer[] webRTCIceServers, WebRTCSettings settings) {
    return new Promise<>((PromiseFunc<WebRTCPeerConnection>) resolver -> {
        JsArray<JsIceServer> servers = JsArray.createArray().cast();
        for (WebRTCIceServer s : webRTCIceServers) {
            if (s.getUsername() != null || s.getCredential() != null) {
                servers.push(JsIceServer.create(s.getUrl(), s.getUsername(), s.getCredential()));
            } else {
                servers.push(JsIceServer.create(s.getUrl()));
            }
        }
        resolver.result(new PeerConnection(JsPeerConnection.create(JsPeerConnectionConfig.create(servers))));
    });
}
 
Example #13
Source File: Util.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static JavaScriptObject convertParameterizedStringList(ParameterizedStringList list) {
  int size = list.getSize();
  JsArray<JavaScriptObject> array = newJsArray(size);
  for (int i = 0; i < size; i++) {
    array.set(i, getParameterizedString(list.getStringAt(i), list.getStringTypeAt(i)));
  }
  return array;
}
 
Example #14
Source File: JsGroup.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static native JsGroup create(int id, String name, String about, String avatar, String bigAvatar,
                                    String placeholder, String presence,
                                    JsArray<JsGroupMember> members)/*-{
    return {
        id: id, name: name, about: about, avatar: avatar, bigAvatar: bigAvatar, placeholder: placeholder,
        presence: presence, members: members
    };
}-*/;
 
Example #15
Source File: JsBindingModule.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public JsBindedValue<JsArray<JsDialogGroup>> getDialogsGroupedList() {
    if (dialogsGroupedList == null) {
        ValueModel<ArrayList<DialogGroup>> dialogGroups =
                context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel();
        dialogsGroupedList = new JsBindedValue<>();
        dialogGroups.subscribe(new ValueChangedListener<ArrayList<DialogGroup>>() {
            @Override
            public void onChanged(ArrayList<DialogGroup> val, Value<ArrayList<DialogGroup>> valueModel) {
                if (val == null) {
                    dialogsGroupedList.changeValue(JsArray.createArray().<JsArray<JsDialogGroup>>cast());
                } else {
                    JsArray<JsDialogGroup> res = JsArray.createArray().cast();
                    for (DialogGroup g : val) {
                        JsArray<JsDialogShort> resd = JsArray.createArray().cast();
                        for (DialogSmall ds : g.getDialogs()) {
                            resd.push(JsDialogShort.create(messenger.buildPeerInfo(ds.getPeer()), ds.getCounter()));
                        }
                        res.push(JsDialogGroup.create(g.getTitle(), g.getKey(), resd));
                    }
                    dialogsGroupedList.changeValue(res);
                }
            }
        });
    }

    return dialogsGroupedList;
}
 
Example #16
Source File: GwtTextDiff.java    From cuba with Apache License 2.0 5 votes vote down vote up
public List<Diff> getDiffs() {
	JsArray<Diff> diffs = getDiffsJsArray();
	LinkedList<Diff> dili = new LinkedList<Diff>();
	for (int i=0; i<diffs.length(); ++i) {
		dili.add(diffs.get(i));
	}
	return dili;
}
 
Example #17
Source File: PanListener.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTouchMove(TouchMoveEvent event) {
	if (touchId == null)
		return;
	JsArray<Touch> touches = event.getTouches();
	for (int i = 0; i < touches.length(); i++) {
		Touch touch = touches.get(i);
		if (touch.getIdentifier() != touchId)
			continue;
		pan(touch.getClientX() - x, touch.getClientY() - y);
		x = touch.getClientX();
		y = touch.getClientY();
		event.preventDefault();
	}
}
 
Example #18
Source File: GoogleCategoriesDisplayerView.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected SelectHandler createSelectHandler(final CoreChartWidget selectable) {
    return new SelectHandler() {
        public void onSelect(SelectEvent event) {
            JsArray<Selection> selections = selectable.getSelection();
            for (int i = 0; i < selections.length(); i++) {
                Selection selection = selections.get(i);
                int row = selection.getRow();
                getPresenter().onCategorySelected(getDataTable().getColumnId(0), row);
            }
        }
    };
}
 
Example #19
Source File: FullCalendar.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
public void addEvents(final List<Event> events) {
    if (loaded && events != null && !events.isEmpty()) {
        JsArray<JavaScriptObject> jsEvents = JavaScriptObject.createArray(events.size()).cast();
        int i = 0;
        for (final Event evt : events) {
            jsEvents.set(i++, evt.toJavaScript());
        }
        addEventSource(getElement().getId(), jsEvents);
    }
}
 
Example #20
Source File: JsMessagesBind.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCollectionChanged(JsArray<JsMessage> array, JsArray<JavaScriptObject> overlays) {
    this.arrays = array;
    this.overlays = overlays;
    if (!isLocked) {
        notifySubscriber();
    }
}
 
Example #21
Source File: SummernoteImageUploadEvent.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Fires a summernote image upload event on all registered handlers in the
 * handler manager. If no such handlers exist, this method will do nothing.
 *
 * @param source the source of the handlers
 */
public static void fire(final HasSummernoteImageUploadHandlers source, JsArray<ImageFile> images) {
    if (TYPE != null) {
        SummernoteImageUploadEvent event = new SummernoteImageUploadEvent(images);
        source.fireEvent(event);
    }
}
 
Example #22
Source File: JsMessage.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public JsMessage convert(Message value) {
    JsMessenger messenger = JsMessenger.getInstance();

    String rid = value.getRid() + "";
    String sortKey = value.getSortDate() + "";

    JsPeerInfo sender = messenger.buildPeerInfo(Peer.user(value.getSenderId()));
    boolean isOut = value.getSenderId() == messenger.myUid();
    boolean isOnServer = value.isOnServer();
    String date = messenger.getFormatter().formatTime(value.getDate());
    JsDate fullDate = JsDate.create(value.getDate());

    JsContent content = JsContent.createContent(value.getContent(),
            value.getSenderId());

    JsArray<JsReaction> reactions = JsArray.createArray().cast();

    for (Reaction r : value.getReactions()) {
        JsArrayInteger uids = (JsArrayInteger) JsArrayInteger.createArray();
        boolean isOwnSet = false;
        for (Integer i : r.getUids()) {
            uids.push(i);
            if (i == messenger.myUid()) {
                isOwnSet = true;
            }
        }
        reactions.push(JsReaction.create(r.getCode(), uids, isOwnSet));
    }
    double sortDate = value.getDate() / 1000.0;
    return create(rid, sortKey, sender, isOut, date, fullDate, Enums.convert(value.getMessageState()), isOnServer, content,
            reactions, sortDate);
}
 
Example #23
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@UsedByApp
public JsArray<JsMentionFilterResult> findMentions(int gid, String query) {
    List<MentionFilterResult> res = messenger.findMentions(gid, query);
    JsArray<JsMentionFilterResult> mentions = JsArray.createArray().cast();
    for (MentionFilterResult m : res) {
        mentions.push(JsMentionFilterResult.create(m));
    }
    return mentions;
}
 
Example #24
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@UsedByApp
public JsArray<JsBotCommand> findBotCommands(int uid, String query) {
    JsArray<JsBotCommand> commands = JsArray.createArray().cast();
    for (BotCommand c : messenger.getUser(uid).getBotCommands().get()) {
        if (c.getSlashCommand().startsWith(query)) {
            commands.push(JsBotCommand.create(c.getSlashCommand(), c.getDescription()));
        }
    }
    return commands;
}
 
Example #25
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@UsedByApp
public JsPromise loadBlockedUsers() {
    return JsPromise.from(messenger.loadBlockedUsers()
            .map(users -> {
                JsArray<JsUser> res = JsArray.createArray().cast();
                for (User u : users) {
                    res.push(getUser(u.getUid()));
                }
                return res;
            })
    );
}
 
Example #26
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private JsArray<JsMessageSearchEntity> convertSearchRes(List<MessageSearchEntity> res) {
    JsArray<JsMessageSearchEntity> jsRes = JsArray.createArray().cast();
    for (MessageSearchEntity e : res) {
        jsRes.push(JsMessageSearchEntity.create(e.getRid() + "",
                messenger.buildPeerInfo(Peer.user(e.getSenderId())),
                messenger.getFormatter().formatDate(e.getDate()),
                JsContent.createContent(e.getContent(),
                        e.getSenderId())));
    }
    return jsRes;
}
 
Example #27
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@UsedByApp
public JsPromise findUsers(final String query) {
    return JsPromise.create(new JsPromiseExecutor() {
        @Override
        public void execute() {
            messenger.findUsers(query).start(new CommandCallback<UserVM[]>() {
                @Override
                public void onResult(UserVM[] users) {
                    Log.d(TAG, "findUsers:result");
                    JsArray<JsUser> jsUsers = JsArray.createArray().cast();

                    for (UserVM user : users) {
                        jsUsers.push(messenger.getJsUser(user.getId()).get());
                    }

                    resolve(jsUsers);
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "findUsers:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
 
Example #28
Source File: JsMentionFilterResult.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static native JsMentionFilterResult create(JsPeerInfo peer,
                                                  String mentionText,
                                                  JsArray<JsStringMatch> mentionMatches,
                                                  String secondText,
                                                  JsArray<JsStringMatch> secondMatches,
                                                  boolean isNick)/*-{
    return {peer: peer, mentionText: mentionText, mentionMatches: mentionMatches, secondText: secondText, secondMatches: secondMatches, isNick: isNick };
}-*/;
 
Example #29
Source File: TagsInputBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Returns list of items contained in the
 *  
 * @return List of items
 */
public List<T> getItems() {
    JsArray<JavaScriptObject> js_items = getItems(getElement());
    List<T> items = new ArrayList<T>();
    
    for(int i=0; i<js_items.length(); i++) {
        @SuppressWarnings("unchecked")
        T item = (T) js_items.get(i);
        items.add(item);
    }
    
    return items;
}
 
Example #30
Source File: JsCall.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static JsCall create(JsMessenger messenger, CallVM model) {
    JsArray<JsPeerInfo> members = JsArray.createArray().cast();
    for (CallMember member : model.getMembers().get()) {
        members.push(messenger.buildPeerInfo(Peer.user(member.getUid())));
    }
    String state;
    switch (model.getState().get()) {
        case RINGING:
            state = "calling";
            break;
        case CONNECTING:
            state = "connecting";
            break;
        case IN_PROGRESS:
            state = "in_progress";
            break;
        default:
        case ENDED:
            state = "ended";
            break;
    }
    JsArray<JsMediaStreamTrack> tracks = JsArray.createArray().cast();
    for (WebRTCMediaTrack track : model.getTheirVideoTracks().get()) {
        tracks.push(((MediaTrack) track).getTrack());
    }
    ArrayList<WebRTCMediaTrack> ownTrack = model.getOwnVideoTracks().get();
    return create(JsPeer.create(model.getPeer()), model.isOutgoing(), members, state, !model.getIsAudioEnabled().get(), ownTrack.size() == 0 ? null : ((MediaTrack) ownTrack.get(0)).getTrack(), tracks);
}