List of usage examples for com.google.gwt.core.client JsArrayString length
public final native int length() ;
From source file:com.google.code.gwt.database.client.GenericRow.java
License:Apache License
/** * @return a {@link List} of all attribute names in this Row. *//*w ww .ja va2 s. c o m*/ public final List<String> getAttributeNames() { JsArrayString jas = getAttributeNames0(); List<String> attributeNames = new ArrayList<String>(jas.length()); for (int i = 0; i < jas.length(); i++) { attributeNames.add(jas.get(i)); } return attributeNames; }
From source file:com.google.collide.client.code.autocomplete.css.CssPartialParser.java
License:Open Source License
/** * Checks whether the passed-in string matches the format of the special value * type in question. If it does, it returns a list of proposals that should be * shown to the user for this query.//from ww w. ja va 2 s .c o m * * @param maybeSpecialValue * @param specialValueType a special value type, e.g., <integer>. This method * can be called with a specialValueType value that is not one of those * special values, in which case the method returns an empty array. * @return an array of strings corresponding to the proposals that should be * shown for the special value type */ @VisibleForTesting public JsArrayString checkIfSpecialValueAndGetSpecialValueProposals(String maybeSpecialValue, String specialValueType) { JsArrayString specialValues = getSpecialValues(maybeSpecialValue); for (int i = 0; i < specialValues.length(); i++) { if (specialValues.get(i).equals(specialValueType)) { return specialValueProposals.<Jso>cast().getJsObjectField(specialValueType).cast(); } } return JavaScriptObject.createArray().cast(); }
From source file:com.google.collide.client.code.autocomplete.css.CssPartialParser.java
License:Open Source License
public JsoArray<AutocompleteProposal> getAutocompletions(String property, JsArrayString valuesBefore, String incomplete, JsArrayString valuesAfter) { incomplete = incomplete.toLowerCase(); boolean isRepeatingProperty = repeatingProperties.hasKey(property); JsArrayString valuesAndSpecialValuesAfter = getValuesAndSpecialValues(valuesAfter); JsArrayString valuesAndSpecialValuesBefore = getValuesAndSpecialValues(valuesBefore); JsoArray<AutocompleteProposal> proposals = JsoArray.create(); JsArray<JavaScriptObject> valuesForAllSlots = getPropertyValues(property); if (valuesForAllSlots == null) { return proposals; }//from w w w . j av a 2 s. com int numSlots = valuesForAllSlots.length(); if (numSlots == 0) { return proposals; } int slot = valuesBefore.length(); // slots use 0-based counting if (slot >= numSlots) { // before giving up, see if the last entry is +, in which case we just // adjust the slot number JavaScriptObject lastSlotValues = valuesForAllSlots.get(numSlots - 1); JsArrayString keySet = getKeySet(lastSlotValues); if ((keySet.length() == 1) && (keySet.get(0).equals("+"))) { slot = numSlots - 1; } else { return proposals; } } JavaScriptObject valuesForSlotInQuestion = valuesForAllSlots.get(slot); JsArrayString keySet = getKeySet(valuesForSlotInQuestion); if ((keySet.length() == 1) && (keySet.get(0).equals("+"))) { valuesForSlotInQuestion = valuesForAllSlots.get(slot - 1); keySet = getKeySet(valuesForSlotInQuestion); } if (valuesForSlotInQuestion != null) { if (keySet.length() == 0) { return proposals; } for (int keyCt = 0; keyCt < keySet.length(); keyCt++) { String currentValue = keySet.get(keyCt); Boolean shouldBeIncluded = false; // TODO: Avoid using untyped native collections. JavaScriptObject triggers = valuesForSlotInQuestion.<Jso>cast().getJsObjectField(currentValue) .cast(); JsArrayString keyTriggerSet = getKeySet(triggers); if (keyTriggerSet.length() == 0) { if (currentValue.charAt(0) == '<') { JsArrayString valueProposals = specialValueProposals.<Jso>cast() .getJsObjectField(currentValue).cast(); if (valueProposals != null && valueProposals.length() != 0) { shouldBeIncluded = false; for (int i = 0; i < valueProposals.length(); i++) { if (valueProposals.get(i).startsWith(incomplete) && (isRepeatingProperty || !inExistingValues(currentValue, valuesAndSpecialValuesBefore, valuesAndSpecialValuesAfter))) { proposals.add(new AutocompleteProposal(valueProposals.get(i))); } } } } else { shouldBeIncluded = true; } } else { for (int keyTriggerCt = 0; keyTriggerCt < keyTriggerSet.length(); keyTriggerCt++) { String triggerValue = keyTriggerSet.get(keyTriggerCt); int triggerSlot = triggers.<Jso>cast().getIntField(triggerValue); if (triggerValue.charAt(0) == '<') { JsArrayString specialValueProposalsAfterCheck = checkIfSpecialValueAndGetSpecialValueProposals( valuesBefore.get(triggerSlot), triggerValue); if (specialValueProposalsAfterCheck.length() != 0) { shouldBeIncluded = false; for (int i = 0; i < specialValueProposalsAfterCheck.length(); i++) { if (specialValueProposalsAfterCheck.get(i).startsWith(incomplete) && (isRepeatingProperty || !inExistingValues(triggerValue, valuesAndSpecialValuesBefore, valuesAndSpecialValuesAfter))) { proposals.add( new AutocompleteProposal(specialValueProposalsAfterCheck.get(i))); } } } } else if (valuesBefore.get(triggerSlot).compareTo(triggerValue) == 0) { shouldBeIncluded = true; } } } if (shouldBeIncluded) { if (currentValue.startsWith(incomplete) && (isRepeatingProperty || !inExistingValues(currentValue, valuesAndSpecialValuesBefore, valuesAndSpecialValuesAfter))) { proposals.add(new AutocompleteProposal(currentValue)); } } } } return proposals; }
From source file:com.google.gerrit.client.change.IncludedInBox.java
License:Apache License
@Override protected void onLoad() { if (!loaded) { ChangeApi.includedIn(changeId.get(), new AsyncCallback<IncludedInInfo>() { @Override//www . j a v a 2 s .c o m 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) { } }); } }
From source file:com.google.gerrit.client.change.IncludedInBox.java
License:Apache License
private SafeHtml formatList(JsArrayString l) { SafeHtmlBuilder html = new SafeHtmlBuilder(); int size = l.length(); for (int i = 0; i < size; i++) { html.openSpan().addStyleName(style.includedInElement()).append(l.get(i)).closeSpan(); if (i < size - 1) { html.append(", "); }/*from w w w. j av a2 s. com*/ } return html; }
From source file:com.google.gerrit.client.change.QuickApprove.java
License:Apache License
void set(ChangeInfo info, String commit, ReplyAction action) { if (!info.hasPermittedLabels() || !info.status().isOpen()) { // Quick approve needs at least one label on an open change. setVisible(false);//from w w w .j ava 2s .co m return; } if (info.revision(commit).isEdit() || info.revision(commit).draft()) { setVisible(false); return; } String qName = null; String qValueStr = null; short qValue = 0; int index = info.getMissingLabelIndex(); if (index != -1) { LabelInfo label = Natives.asList(info.allLabels().values()).get(index); JsArrayString values = info.permittedValues(label.name()); String s = values.get(values.length() - 1); short v = LabelInfo.parseValue(s); if (v > 0 && s.equals(label.maxValue())) { qName = label.name(); qValueStr = s; qValue = v; } } if (qName != null) { changeId = info.legacyId(); revision = commit; input = ReviewInput.create(); input.drafts(DraftHandling.PUBLISH_ALL_REVISIONS); input.label(qName, qValue); replyAction = action; setText(qName + qValueStr); setVisible(true); } else { setVisible(false); } }
From source file:com.google.gerrit.client.change.ReplyBox.java
License:Apache License
private void renderLabels(List<String> names, NativeMap<LabelInfo> all, NativeMap<JsArrayString> permitted) { TreeSet<Short> values = new TreeSet<>(); List<LabelAndValues> labels = new ArrayList<>(permitted.size()); for (String id : names) { JsArrayString p = permitted.get(id); if (p != null) { if (!all.containsKey(id)) { continue; }/*from www .j av a 2s . co m*/ Set<Short> a = new TreeSet<>(); for (int i = 0; i < p.length(); i++) { a.add(LabelInfo.parseValue(p.get(i))); } labels.add(new LabelAndValues(all.get(id), a)); values.addAll(a); } } List<Short> columns = new ArrayList<>(values); labelsTable.resize(1 + labels.size(), 2 + values.size()); for (int c = 0; c < columns.size(); c++) { labelsTable.setText(0, 1 + c, LabelValue.formatValue(columns.get(c))); labelsTable.getCellFormatter().setStyleName(0, 1 + c, style.label_value()); } List<LabelAndValues> checkboxes = new ArrayList<>(labels.size()); int row = 1; for (LabelAndValues lv : labels) { if (isCheckBox(lv.info.valueSet())) { checkboxes.add(lv); } else { renderRadio(row++, columns, lv); } } for (LabelAndValues lv : checkboxes) { renderCheckBox(row++, lv); } }
From source file:com.google.gerrit.client.changes.PublishCommentScreen.java
License:Apache License
private void initLabel(String labelName, Panel body) { if (!change.has_permitted_labels()) { return;// w ww .ja va 2 s .c o m } JsArrayString nativeValues = change.permitted_values(labelName); if (nativeValues == null || nativeValues.length() == 0) { return; } List<String> values = new ArrayList<String>(nativeValues.length()); for (int i = 0; i < nativeValues.length(); i++) { values.add(nativeValues.get(i)); } Collections.reverse(values); LabelInfo label = change.label(labelName); body.add(new SmallHeading(label.name() + ":")); VerticalPanel vp = new VerticalPanel(); vp.setStyleName(Gerrit.RESOURCES.css().labelList()); Short prior = null; if (label.all() != null) { for (ApprovalInfo app : Natives.asList(label.all())) { if (app._account_id() == Gerrit.getUserAccount().getId().get()) { prior = app.value(); break; } } } for (String value : values) { ValueRadioButton b = new ValueRadioButton(label, value); SafeHtml buf = new SafeHtmlBuilder().append(b.format()); buf = commentLinkProcessor.apply(buf); SafeHtml.set(b, buf); if (lastState != null && patchSetId.equals(lastState.patchSetId) && lastState.approvals.containsKey(label.name())) { b.setValue(lastState.approvals.get(label.name()) == value); } else { b.setValue(b.parseValue() == (prior != null ? prior : 0)); } approvalButtons.add(b); vp.add(b); } body.add(vp); }
From source file:com.google.gerrit.client.diff.DiffInfo.java
License:Apache License
private static void append(StringBuilder s, JsArrayString lines) { for (int i = 0; i < lines.length(); i++) { s.append(lines.get(i)).append('\n'); }//from w w w . jav a 2s . c o m }
From source file:com.google.gerrit.client.diff.SideBySideChunkManager.java
License:Apache License
private void render(Region region, String diffColor) { int startA = lineMapper.getLineA(); int startB = lineMapper.getLineB(); JsArrayString a = region.a(); JsArrayString b = region.b();//from w w w . j a v a2 s . c o m int aLen = a != null ? a.length() : 0; int bLen = b != null ? b.length() : 0; String color = a == null || b == null ? diffColor : SideBySideTable.style.intralineBg(); colorLines(cmA, color, startA, aLen); colorLines(cmB, color, startB, bLen); markEdit(cmA, startA, a, region.editA()); markEdit(cmB, startB, b, region.editB()); addPadding(cmA, startA + aLen - 1, bLen - aLen); addPadding(cmB, startB + bLen - 1, aLen - bLen); addGutterTag(region, startA, startB); lineMapper.appendReplace(aLen, bLen); int endA = lineMapper.getLineA() - 1; int endB = lineMapper.getLineB() - 1; if (aLen > 0) { addDiffChunk(cmB, endA, aLen, bLen > 0); } if (bLen > 0) { addDiffChunk(cmA, endB, bLen, aLen > 0); } }