/** * Internal constructor used to load a JSArray already in another object. * @param values all values of an enumeration * @param array JS array instance */ JsEnumValueArrayList(E[] values, JsArrayStringImpl array) { // sets all enumeration values this.definedValues = values; // if null, creates a new JS array if (array == null){ this.array = (JsArrayStringImpl)JsArrayString.createArray().cast(); } else { // uses an existing array this.array = array; } }
/** * Returns a multi line label at a specific index. An array of strings is returned. * @param index index of label * @return an array of strings */ public final String[] getStrings(int index){ // checks range if (checkRange(index)){ // gets multi line array JsArrayString multiValues = getObject(index); // if consistent if (multiValues != null){ // creates an string array String[] result = new String[multiValues.length()]; // scans all values for (int i=0; i<multiValues.length(); i++){ // adds to java array result[i] = multiValues.get(i); } // returns array return result; } else { // returns an empty array return new String[0]; } } // returns an empty array return new String[0]; }
/** Native JavaScript that returns the selected text and position of the start **/ public static native JsArrayString getSelection(Element elem) /*-{ var txt = ""; var pos = 0; var range; var parentElement; var container; if (elem.contentWindow.getSelection) { txt = elem.contentWindow.getSelection(); pos = elem.contentWindow.getSelection().getRangeAt(0).startOffset; } else if (elem.contentWindow.document.getSelection) { txt = elem.contentWindow.document.getSelection(); pos = elem.contentWindow.document.getSelection().getRangeAt(0).startOffset; } else if (elem.contentWindow.document.selection) { range = elem.contentWindow.document.selection.createRange(); txt = range.text; parentElement = range.parentElement(); container = range.duplicate(); container.moveToElementText(parentElement); container.setEndPoint('EndToEnd', range); pos = container.text.length - range.text.length; } return ["" + txt, "" + pos]; }-*/;
private void addHashtag(String hashtags) { ChangeApi.hashtags(project.get(), changeId.get()) .post( PostInput.create(hashtags, null), new GerritCallback<JsArrayString>() { @Override public void onSuccess(JsArrayString result) { Gerrit.display( PageLinks.toChange(project, psId.getParentKey(), String.valueOf(psId.get()))); } @Override public void onFailure(Throwable err) { UIObject.setVisible(error, true); error.setInnerText( err instanceof StatusCodeException ? ((StatusCodeException) err).getEncodedResponse() : err.getMessage()); hashtagTextBox.setEnabled(true); } }); }
@Override protected void onRequestSuggestions(Request req, Callback cb) { RestApi api = ChangeApi.revision(project.get(), changeId.get(), revision.name()).view("files"); if (req.getQuery() != null) { api.addParameter("q", req.getQuery() == null ? "" : req.getQuery()); } api.background() .get( new AsyncCallback<JsArrayString>() { @Override public void onSuccess(JsArrayString result) { List<Suggestion> r = new ArrayList<>(); for (String path : Natives.asList(result)) { r.add(new PathSuggestion(path)); } cb.onSuggestionsReady(req, new Response(r)); } @Override public void onFailure(Throwable caught) { List<Suggestion> none = Collections.emptyList(); cb.onSuggestionsReady(req, new Response(none)); } }); }
@Override protected void onLoad() { if (!loaded) { ChangeApi.includedIn( project.get(), changeId.get(), new AsyncCallback<IncludedInInfo>() { @Override public void onSuccess(IncludedInInfo r) { branches.setInnerSafeHtml(formatList(r.branches())); tags.setInnerSafeHtml(formatList(r.tags())); for (String n : r.externalNames()) { JsArrayString external = r.external(n); if (external.length() > 0) { appendRow(n, external); } } loaded = true; } @Override public void onFailure(Throwable caught) {} }); } }
ReplyAction( ChangeInfo info, String revision, boolean hasDraftComments, ChangeScreen.Style style, CommentLinkProcessor clp, Widget replyButton, Widget quickApproveButton) { this.psId = new PatchSet.Id(info.legacyId(), info.revisions().get(revision)._number()); this.project = info.projectNameKey(); this.revision = revision; this.hasDraftComments = hasDraftComments; this.style = style; this.clp = clp; this.replyButton = replyButton; this.quickApproveButton = quickApproveButton; boolean current = revision.equals(info.currentRevision()); allLabels = info.allLabels(); permittedLabels = current && info.hasPermittedLabels() ? info.permittedLabels() : NativeMap.<JsArrayString>create(); }
private void ensureDependenciesAreLoaded(String mode) { JsArrayString deps = getDependencies(mode); for (int i = 0; i < deps.length(); i++) { String d = deps.get(i); if (loading.contains(d) || isModeLoaded(d)) { continue; } if (!canLoad(d)) { Logger.getLogger("net.codemirror") .log(Level.SEVERE, "CodeMirror mode " + d + " needs " + d); continue; } loading.add(d); beginLoading(d); } }
private static String getUrl(JavaScriptException e) { String baseUrl = baseUrl(); JsArrayString stack = getStack(e); for (int i = stack.length() - 1; i >= 0; i--) { String frame = stack.get(i); int at = frame.indexOf(baseUrl); if (at >= 0) { int end = frame.indexOf(':', at + baseUrl.length()); if (end < 0) { end = frame.length(); } return frame.substring(at, end); } } return UNKNOWN; }
private void markEdit(DisplaySide side, int startLine, JsArrayString lines, JsArray<Span> edits) { if (lines == null || edits == null) { return; } EditIterator iter = new EditIterator(lines, startLine); Configuration bg = Configuration.create().set("className", getIntralineBgFromSide(side)).set("readOnly", true); Configuration diff = Configuration.create().set("className", getDiffColorFromSide(side)).set("readOnly", true); Pos last = Pos.create(0, 0); for (Span span : Natives.asList(edits)) { Pos from = iter.advance(span.skip()); Pos to = iter.advance(span.mark()); if (from.line() == last.line()) { getMarkers().add(cm.markText(last, from, bg)); } else { getMarkers().add(cm.markText(Pos.create(from.line(), 0), from, bg)); } getMarkers().add(cm.markText(from, to, diff)); last = to; colorLines(cm, LineClassWhere.BACKGROUND, getDiffColorFromSide(side), from.line(), to.line()); } }
/** * Internal constructor used to load a JSArray already in another object. * @param array JS array instance */ JsStringArrayList(JsArrayStringImpl array) { // if null, creates a new JS array if (array == null){ this.array = (JsArrayStringImpl)JsArrayString.createArray().cast(); } else { // uses an existing array this.array = array; } }
/** * Adds a multi line label * @param values array ofstring which represents a multi line label */ public final void add(String... values){ // checks if is a valid array if (values != null && values.length > 0){ // creates new JS array JsArrayString multiValues = JsArrayString.createArray().cast(); // scans values for(String value: values){ // adds to JS array string multiValues.push(value); } // pushes array to JS array push(multiValues); } }
private static List<String> getProj4jsProjections() { List<String> projections = new ArrayList<String>(); JsArrayString projDefs = getProjDefs(); for (int i = 0; i < projDefs.length(); i++) { projections.add(projDefs.get(i).trim()); } return projections; }
public static JsArrayString getExtensionsToLoad() { JsArrayString result = JsArrayString.createArray().cast(); if (INSTANCE != null) { for (String s : INSTANCE.extensions) { result.push(s); } } return result; }
/** Method called to toggle the style in HTML-Mode **/ private void changeHtmlStyle(String startTag, String stopTag) { JsArrayString tx = getSelection(styleText.getElement()); String txbuffer = styleText.getText(); Integer startpos = Integer.parseInt(tx.get(1)); String selectedText = tx.get(0); styleText.setText(txbuffer.substring(0, startpos) + startTag + selectedText + stopTag + txbuffer.substring(startpos + selectedText.length())); }
private final native JsArrayString getExtraParameterNames0() /*-{ if (!this.extraParameters) { var a = new Array(); for (name in this) { if (name != "moduleName" && name != "subSystem" && name != "evtGroup" && name != "millis") { a.push(name); } } this.extraParameters = a; } return this.extraParameters }-*/;
@Override public List<String> getMatches(String test) { JsArrayString matches = matches(regExp, test); if (matches != null && matches.length() > 0) { List<String> result = new ArrayList<String>(matches.length()); for (int i = 0; i < matches.length(); ++i) { result.add(matches.get(i)); } return result; } return new ArrayList<String>(); }
private final String[] getScopes() { JsArrayString jsa = getScopesNative(); String[] arr = new String[jsa.length()]; for (int i = 0; i < jsa.length(); i++) { arr[i] = jsa.get(i); } return arr; }
public static Uint32Array glGetUniformIndices(int program, List<String> uniformNames) { JsArrayString arrayString = JsArrayString.createArray(uniformNames.size()).cast(); for (String uniformName : uniformNames) arrayString.push(uniformName); return glGetUniformIndices(program, arrayString); }
public static Uint32Array glGetUniformIndices(int program, String... uniformNames) { JsArrayString arrayString = JsArrayString.createArray(uniformNames.length).cast(); for (String uniformName : uniformNames) arrayString.push(uniformName); return glGetUniformIndices(program, arrayString); }
public static void glTransformFeedbackVaryings(int program, List<String> varyings, int bufferMode) { JsArrayString varyingsArray = JsArrayString.createArray(varyings.size()).cast(); for (String varying : varyings) varyingsArray.push(varying); glTransformFeedbackVaryings(program, varyingsArray, bufferMode); }
public T get(int i) { T wrapper = null; if (parameterType == JsonArrayNumber.class) { wrapper = (T) new GwtJsonArrayNumber((JsArrayNumber) jso.get(i)); } else if(parameterType == JsonArrayString.class) { wrapper = (T) new GwtJsonArrayString((JsArrayString) jso.get(i)); } return wrapper; }
public final int[] indexes() { checkNull(); JsArrayString a = keysImpl(); int[] ret = new int[a.length()]; for (int i = 0; i < a.length(); i++) { try { ret[i] = Integer.valueOf(a.get(i)); } catch (Exception e) { ret[i] = i; } } return ret; }
private native JsArrayString keysImpl() /*-{ var key, keys=[]; // Chrome in DevMode sets '__gwt_ObjectId' to JS objects // GWT sets '$H' when calling getHashCode (see com/google/gwt/core/client/impl/Impl.java) for(key in this) { if (this.hasOwnProperty(key) && key != '__gwt_ObjectId' && key != '$H') keys.push(String(key)); } return keys; }-*/;
public static JsArrayString fromStrings(Collection<String> collection) { JsArrayString array = JsArrayString.createArray().cast(); for(String item : collection) { array.push(item); } return array; }
public static List<String> toList(JsArrayString array) { List<String> list = new ArrayList<>(); if(array != null) { for (int i = 0; i < array.length(); i++) { list.add(array.get(i)); } } return list; }
void markReviewed(JsArrayString reviewed) { if (table != null) { table.markReviewed(reviewed); } else { this.reviewed = reviewed; } }
public void registerOccurrencesHandler( final JsArrayString contentTypes, final OrionOccurrencesHandler handler) { editorModule .getInitializerPromise() .then( new Operation<Void>() { @Override public void apply(Void arg) throws OperationException { registerOccurrencesHandler( codeEditWidgetProvider.get().getServiceRegistry(), contentTypes, handler); } }); }
public final void setContentTypes(String... theContentTypes) { JsArrayString arr = JavaScriptObject.createArray().cast(); for (String value : theContentTypes) { arr.push(value); } setContentTypes(arr); }
public final void setAnnotations(JsArray<BlameInfo> blameInfos) { if (blameInfos.length() > 0) { setBlameInfo(blameInfos); JsArrayString gutters = ((JsArrayString) JsArrayString.createArray()); gutters.push(ANNOTATION_GUTTER_ID); cm.setOption("gutters", gutters); annotated = true; DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT); JsArray<LintLine> annotations = JsArray.createArray().cast(); for (BlameInfo blameInfo : Natives.asList(blameInfos)) { for (RangeInfo range : Natives.asList(blameInfo.ranges())) { Date commitTime = new Date(blameInfo.time() * 1000L); String shortId = blameInfo.id().substring(0, 8); String shortBlame = C.shortBlameMsg(shortId, format.format(commitTime), blameInfo.author()); String detailedBlame = C.detailedBlameMsg( blameInfo.id(), blameInfo.author(), FormatUtil.mediumFormat(commitTime), blameInfo.commitMsg()); annotations.push( LintLine.create(shortBlame, detailedBlame, shortId, Pos.create(range.start() - 1))); } } cm.setOption("lint", getAnnotation(annotations)); } }
private static JsArrayString toJsArrayString(String commaSeparated) { if (commaSeparated == null || commaSeparated.equals("")) { return null; } JsArrayString array = JsArrayString.createArray().cast(); for (String hashtag : commaSeparated.split(",")) { array.push(hashtag.trim()); } return array; }
public final void setExtension(String... fileExtensions) { JsArrayString arr = JavaScriptObject.createArray().cast(); for (String value : fileExtensions) { arr.push(value); } setExtension(arr); }
@Override public final List<String> getLanguages() { JsArrayString langs = getLanguages0(); if(langs == null || langs.length() == 0) { return Collections.emptyList(); } List<String> ls = new ArrayList<>(); for(int i = 0; i < langs.length(); i++) { String l = langs.get(i); ls.add(l); } return ls; }
private void appendRow(String title, JsArrayString l) { TableRowElement row = table.insertRow(-1); TableCellElement th = Document.get().createTHElement(); th.setInnerText(title); row.appendChild(th); row.insertCell(-1).setInnerSafeHtml(formatList(l)); }
/** * Inspects the headers object of the given JS object and constructs a * {@link Map} of its keys and values. */ private static Map<String, HeaderValue> createHeadersMap(DynamicJso data) { DynamicJso headers = data.get("headers"); JsArrayString keys = headers.keys(); Map<String, HeaderValue> headersMap = Maps.newHashMapWithExpectedSize(keys.length()); for (int i = 0; i < keys.length(); i++) { String key = keys.get(i); String value = ""; switch (headers.typeofKey(key)) { case STRING: value = headers.getString(key); break; case BOOLEAN: value = String.valueOf(headers.getBoolean(key)); break; case NUMBER: value = String.valueOf(headers.getInteger(key)); break; case INTEGER: value = String.valueOf(headers.getDouble(key)); break; } headersMap.put(key.toLowerCase(), new HeaderValue(key, value)); } return headersMap; }
@Override public List<String> split(String string, String separator) { JsArrayString jsArrayString = nativeSplit(string, separator); List<String> result = new ArrayList<>(); for (int i = 0; i < jsArrayString.length(); i++) { result.add(jsArrayString.get(i)); } return result; }
public final void importScripts(String[] urls) { JsArrayString jsUrls = JsArrayString.createArray().cast(); for (int i = 0, l = urls.length; i < l; ++i) { jsUrls.set(i, urls[i]); } importScripts(jsUrls); }