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

The following examples show how to use com.google.gwt.core.client.JsArrayString. 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: document-management-system   Author: openkm   File: RichTextToolbar.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** 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];
   }-*/;
 
Example #2
Source Project: swellrt   Author: SwellRT   File: JsEditorUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Transform a Javascript object (array or string) to
 * a StringSet.
 *
 * @param obj an array or string
 * @return
 */
public static StringSet toStringSet(JavaScriptObject obj) throws IllegalStateException {

  StringSet set = CollectionUtils.createStringSet();

  // from array
  JsArrayString array = asArray(obj);
  if (array != null) {
    for (int i = 0; i < array.length(); i++)
      set.add(array.get(i));
  }


  // from string
  String s = asString(obj);
  if (s!=null)
    set.add(s);

  return set;
}
 
Example #3
Source Project: requestor   Author: reinert   File: BucketsImpl.java    License: Apache License 2.0 6 votes vote down vote up
public boolean isEquals(BucketsOverlay other) {
    if (super.equals(other))
        return true;

    final JsArrayString keys = getKeysNative();
    final JsArrayString otherKeys = other.getKeysNative();
    if (arraysEquals(keys, otherKeys)) {
        for (int i = 0; i < keys.length(); i++) {
            if (!arraysEquals(getNative(keys.get(i)), other.getNative(otherKeys.get(i)))) {
                return false;
            }
        }
        return true;
    }

    return false;
}
 
Example #4
Source Project: requestor   Author: reinert   File: BucketsImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static native boolean arraysEquals(JsArrayString a, JsArrayString b) /*-{
    if (a === b) return true;
    if (a == null || b == null) return false;
    if (a.length != b.length) return false;

    // clone arrays and sort them
    var a1 = [], b1 = [], l = a1.length;
    for (var i = 0; i < l; ++i) {
        a1[i] = a[i];
        b1[i] = b[i];
    }
    a1.sort();
    b1.sort();

    // compare sorted arrays
    for (var i = 0; i < l; ++i) {
        if (a1[i] !== b1[i]) return false;
    }

    return true;
}-*/;
 
Example #5
Source Project: gwt-jackson   Author: nmorel   File: AbstractJsonReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testNextJavaScriptObjectRootArray() {
    // safeEval
    JsonReader reader = newJsonReader( "       [\"Bob\",\"Morane\"]  " );
    JsArrayString array = reader.nextJavaScriptObject( true ).cast();
    assertEquals( 2, array.length() );
    assertEquals( "Bob", array.get( 0 ) );
    assertEquals( "Morane", array.get( 1 ) );
    assertEquals( JsonToken.END_DOCUMENT, reader.peek() );

    // unsafeEval
    reader = newJsonReader( "[\"Bob\",\"Morane\"]" );
    array = reader.nextJavaScriptObject( false ).cast();
    assertEquals( 2, array.length() );
    assertEquals( "Bob", array.get( 0 ) );
    assertEquals( "Morane", array.get( 1 ) );
    assertEquals( JsonToken.END_DOCUMENT, reader.peek() );
}
 
Example #6
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SliderBase.java    License: Apache License 2.0 6 votes vote down vote up
private List<String> getStringArrayAttribute(SliderOption option, List<String> defaultValue) {

        // Get array attribute
        JsArrayString array = null;
        if (isAttached()) {
            array = getStringArrayAttribute(getElement(), option.getName());
        } else {
            String value = attributeMixin.getAttribute(option.getDataAttribute());
            if (value != null && !value.isEmpty()) {
                array = JsonUtils.safeEval(value);
            }
        }

        // Attribute not set
        if (array == null) {
            return defaultValue;
        }

        // Put array to list
        List<String> list = new ArrayList<String>(array.length());
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }
        return list;
    }
 
Example #7
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: MultipleSelect.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setSelectedValue(List<String> value) {
    if (isAttached()) {
        final JsArrayString arr = JavaScriptObject.createArray().cast();
        for (final String val : value) {
            arr.push(val);
        }
        setValue(getElement(), arr);
    } else {
        for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
            Option opt = entry.getValue();
            boolean selected = value.contains(opt.getValue());
            opt.setSelected(selected);
        }
    }
}
 
Example #8
Source Project: appinventor-extensions   Author: mit-cml   File: AssetManager.java    License: Apache License 2.0 5 votes vote down vote up
public static JsArrayString getExtensionsToLoad() {
  JsArrayString result = JsArrayString.createArray().cast();
  if (INSTANCE != null) {
    for (String s : INSTANCE.extensions) {
      result.push(s);
    }
  }
  return result;
}
 
Example #9
Source Project: document-management-system   Author: openkm   File: RichTextToolbar.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** 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()));
}
 
Example #10
Source Project: geowe-core   Author: geowe   File: Projections.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #11
Source Project: gwt-material-addins   Author: GwtMaterialDesign   File: ToolBarManager.java    License: Apache License 2.0 5 votes vote down vote up
protected JsArrayString extractOptions(ToolbarButton[] options) {
    JsArrayString jsOptions = JsArrayString.createArray().cast();
    for (ToolbarButton option : options) {
        jsOptions.push(option.getId());
    }
    return jsOptions;
}
 
Example #12
Source Project: swellrt   Author: SwellRT   File: GwtStatisticsEvent.java    License: Apache License 2.0 5 votes vote down vote up
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
}-*/;
 
Example #13
Source Project: swellrt   Author: SwellRT   File: JsRegExp.java    License: Apache License 2.0 5 votes vote down vote up
@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>();
}
 
Example #14
Source Project: bitcoin-transaction-explorer   Author: yogh-io   File: StringUtils.java    License: MIT License 5 votes vote down vote up
public static String join(final String delimiter, final String... text) {
  final JsArrayString jsa = JavaScriptObject.createArray().cast();

  for (int i = 0; i < text.length; i++) {
    jsa.push(text[i]);
  }

  return jsa.join(delimiter);
}
 
Example #15
Source Project: lumongo   Author: lumongo   File: JSHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static JsArrayString toJsArray(Iterable<String> values) {
	JsArrayString array = JsArrayString.createArray().cast();
	for (String value : values) {
		array.push(value);
	}
	return array;
}
 
Example #16
Source Project: incubator-retired-wave   Author: apache   File: GwtStatisticsEvent.java    License: Apache License 2.0 5 votes vote down vote up
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
}-*/;
 
Example #17
Source Project: incubator-retired-wave   Author: apache   File: JsRegExp.java    License: Apache License 2.0 5 votes vote down vote up
@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>();
}
 
Example #18
Source Project: gwt-jackson   Author: nmorel   File: FastArrayString.java    License: Apache License 2.0 5 votes vote down vote up
public FastArrayString(){
	if(GWT.isScript()) {
		stackNative = JsArrayString.createArray().cast();
	} else {
		stackJava = new JsList<String>();
	}
}
 
Example #19
Source Project: gwt-jackson   Author: nmorel   File: JavaScriptObjectGwtTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testRootJsArrayString() {
    JsArrayString array = JavaScriptObject.createArray().cast();
    array.push( "Hello" );
    array.push( "World" );
    array.push( "!" );

    String json = JsArrayStringMapper.INSTANCE.write( array );
    assertEquals( "[\"Hello\",\"World\",\"!\"]", json );

    array = JsArrayStringMapper.INSTANCE.read( json );
    assertEquals( 3, array.length() );
    assertEquals( "Hello", array.get( 0 ) );
    assertEquals( "World", array.get( 1 ) );
    assertEquals( "!", array.get( 2 ) );
}
 
Example #20
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SliderBase.java    License: Apache License 2.0 5 votes vote down vote up
private void updateSliderForStringArray(SliderOption option, List<String> value) {
    JsArrayString array = JavaScriptObject.createArray().cast();
    for (String val : value) {
        array.push(val);
    }
    if (isAttached()) {
        setAttribute(getElement(), option.getName(), array);
        refresh();
    } else {
        String arrayStr = JsonUtils.stringify(array);
        attributeMixin.setAttribute(option.getDataAttribute(), arrayStr);
    }
}
 
Example #21
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: MultipleSelect.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getValue() {
    if (isAttached()) {
        JsArrayString arr = getValue(getElement());
        List<String> result = new ArrayList<>(arr.length());
        for (int i = 0; i < arr.length(); i++) {
            result.add(arr.get(i));
        }
        return result;
    }
    return getSelectedValues();
}
 
Example #22
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: TagsInputBase.java    License: Apache License 2.0 5 votes vote down vote up
protected static List<String> toMultiValue(JavaScriptObject js_multi_value) {
    List<String> retValue = new ArrayList<String>();
    
    if (js_multi_value != null) {
        JsArrayString js_string_array = js_multi_value.cast();
        
        for(int i=0; i<js_string_array.length(); i++) {
            retValue.add(js_string_array.get(i));
        }
    }
    
    return retValue;
}
 
Example #23
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SuggestionCallback.java    License: Apache License 2.0 5 votes vote down vote up
public void execute(final Collection<Suggestion<T>> suggestions) {
    JsArray<Suggestion<T>> jsArray = JsArrayString.createArray().cast();
    if (suggestions != null) {
        for (Suggestion<T> s : suggestions) {
            jsArray.push(s);
        }
    }
    invokeCallback(jsCallback, jsArray);
}
 
Example #24
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SummernoteBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set customized font names.
 *
 * @param fontNames customized font names
 * @see SummernoteFontName
 */
public void setFontNames(final SummernoteFontName... fontNames) {
    JsArrayString array = JavaScriptObject.createArray().cast();
    for (SummernoteFontName fontName : fontNames) {
        array.push(fontName.getName());
    }
    options.setFontNames(array);
}
 
Example #25
Source Project: gwtbootstrap3-extras   Author: gwtbootstrap3   File: SummernoteOptions.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new toolbar group.
 *
 * @param name
 * @param buttons
 * @return
 */
static final JsArrayMixed newToolbarGroup(String name, ToolbarButton... buttons) {
    JsArrayString arr = JavaScriptObject.createArray().cast();
    for (ToolbarButton button : buttons) {
        arr.push(button.getId());
    }
    return getToolbarGroup(name, arr);
}
 
Example #26
Source Project: core   Author: hal   File: GwtStatisticsEvent.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
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
}-*/;
 
Example #27
Source Project: cuba   Author: cuba-platform   File: GwtAceEditor.java    License: Apache License 2.0 4 votes vote down vote up
public final native JsArrayString getLines(int startRow, int endRow) /*-{
	return this.getSession().getLines(startRow, endRow);
}-*/;
 
Example #28
Source Project: actor-platform   Author: actorapp   File: JsContentContact.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
public native static JsContentContact create(String name, String photo64, JsArrayString phones,
                                             JsArrayString emails)/*-{
    return {content: "contact", name: name, photo64: photo64, pones: phones, emails: emails};
}-*/;
 
Example #29
Source Project: geowe-core   Author: geowe   File: Projections.java    License: GNU General Public License v3.0 4 votes vote down vote up
private static native JsArrayString getProjDefs() /*-{
	return Object.keys($wnd.Proj4js.defs);
}-*/;
 
Example #30
Source Project: gwt-material-demo   Author: GwtMaterialDesign   File: MaterialGeoChart.java    License: Apache License 2.0 4 votes vote down vote up
private native JsArrayString getNativeArray() /*-{
	return ["0d47a1", "1565c0", "1976d2", "1e88e5", "2196f3", "42a5f5"];
}-*/;