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

The following examples show how to use com.google.gwt.core.client.JsArray. These examples are extracted from open source projects. 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 Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: Typeahead.java    License: 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 #2
Source Project: incubator-retired-wave   Author: apache   File: DomHelper.java    License: 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 #3
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #4
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #5
Source Project: requestor   Author: reinert   File: TurboOverlaySerdes.java    License: 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 #6
Source Project: requestor   Author: reinert   File: OverlaySerdesTest.java    License: 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 #7
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: CalendarConfig.java    License: 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 #8
Source Project: swellrt   Author: SwellRT   File: DomHelper.java    License: 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 #9
Source Project: dashbuilder   Author: dashbuilder   File: DoughnutChart.java    License: 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 #10
Source Project: dashbuilder   Author: dashbuilder   File: PolarAreaChart.java    License: 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 #11
Source Project: jts   Author: metteo   File: SimpleDemo.java    License: 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 #12
Source Project: cuba   Author: cuba-platform   File: ClientSideDocDiff.java    License: Apache License 2.0 5 votes vote down vote up
public static ClientSideDocDiff fromTransportDiff(TransportDiff ad) {
	
	JsArray<Patch> patches = dmp.patch_fromText(ad.patchesAsString);
	MarkerSetDiff msd = MarkerSetDiff.fromTransportDiff(ad.markerSetDiff);
	
	SetDiff<RowAnnotation,TransportRowAnnotation> rowAnns = ad.rowAnnDiff==null ? null : 
			SetDiff.fromTransport(ad.rowAnnDiff);
	SetDiff<MarkerAnnotation,TransportMarkerAnnotation> markerAnns =  ad.markerAnnDiff==null ? null : 
			SetDiff.fromTransport(ad.markerAnnDiff);
	
	return new ClientSideDocDiff(patches, msd, rowAnns, markerAnns);
}
 
Example #13
Source Project: cuba   Author: cuba-platform   File: GwtTextDiff.java    License: 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 #14
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: FullCalendar.java    License: 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 #15
Source Project: actor-platform   Author: actorapp   File: JsWebRTCProvider.java    License: 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 #16
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SummernoteImageUploadEvent.java    License: 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 #17
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #18
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #19
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #20
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #21
Source Project: actor-platform   Author: actorapp   File: JsFacade.java    License: 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 #22
Source Project: actor-platform   Author: actorapp   File: JsMentionFilterResult.java    License: 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 #23
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: TagsInputBase.java    License: 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 #24
Source Project: actor-platform   Author: actorapp   File: JsCall.java    License: 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);
}
 
Example #25
Source Project: actor-platform   Author: actorapp   File: JsMessagesBind.java    License: 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 #26
Source Project: actor-platform   Author: actorapp   File: JsMessage.java    License: 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 #27
Source Project: actor-platform   Author: actorapp   File: JsGroup.java    License: 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 #28
Source Project: actor-platform   Author: actorapp   File: JsBindingModule.java    License: 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 #29
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: Typeahead.java    License: Apache License 2.0 5 votes vote down vote up
protected void configure() {
    JsArray<JavaScriptObject> datasetJSOs = JsArray.createArray().cast();
    for (Dataset<T> dataset : datasets) {
        JavaScriptObject jso = toJSO(dataset);
        datasetJSOs.push(jso);
    }
    configure(getElement(), highlight, hint, minLength, datasetJSOs);
}
 
Example #30
Source Project: requestor   Author: reinert   File: JsonObjectSerdes.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <C extends Collection<T>> C deserialize(Class<C> collectionType, String response,
                                               DeserializationContext context) {
    if (!isArray(response))
        throw new UnableToDeserializeException("Response content is not an array.");

    C col = context.getInstance(collectionType);
    @SuppressWarnings("unchecked")
    JsArray<JavaScriptObject> jsArray = (JsArray<JavaScriptObject>) eval(response);
    for (int i = 0; i < jsArray.length(); i++) {
        JavaScriptObject jso = jsArray.get(i);
        col.add(readJson((JsonRecordReader) jso, context));
    }
    return col;
}