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 File: RichTextToolbar.java    From document-management-system with 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 File: BucketsImpl.java    From requestor with 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 #3
Source File: BucketsImpl.java    From requestor with 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 #4
Source File: MultipleSelect.java    From gwtbootstrap3-extras with 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 #5
Source File: SliderBase.java    From gwtbootstrap3-extras with 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 #6
Source File: AbstractJsonReaderTest.java    From gwt-jackson with 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 #7
Source File: JsEditorUtils.java    From swellrt with 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 #8
Source File: JSHelper.java    From lumongo with 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 #9
Source File: GwtStatisticsEvent.java    From incubator-retired-wave with 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 #10
Source File: AssetManager.java    From appinventor-extensions with 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 #11
Source File: JsRegExp.java    From incubator-retired-wave with 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 #12
Source File: FastArrayString.java    From gwt-jackson with 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 #13
Source File: JavaScriptObjectGwtTest.java    From gwt-jackson with 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 #14
Source File: SliderBase.java    From gwtbootstrap3-extras with 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 #15
Source File: MultipleSelect.java    From gwtbootstrap3-extras with 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 #16
Source File: TagsInputBase.java    From gwtbootstrap3-extras with 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 #17
Source File: SuggestionCallback.java    From gwtbootstrap3-extras with 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 #18
Source File: SummernoteBase.java    From gwtbootstrap3-extras with 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 #19
Source File: SummernoteOptions.java    From gwtbootstrap3-extras with 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 #20
Source File: GwtStatisticsEvent.java    From core with 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 #21
Source File: RichTextToolbar.java    From document-management-system with 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 #22
Source File: GwtStatisticsEvent.java    From swellrt with 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 #23
Source File: ToolBarManager.java    From gwt-material-addins with 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 #24
Source File: Projections.java    From geowe-core with 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 #25
Source File: StringUtils.java    From bitcoin-transaction-explorer with 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 #26
Source File: JsRegExp.java    From swellrt with 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 #27
Source File: Projections.java    From geowe-core with GNU General Public License v3.0 4 votes vote down vote up
private static native JsArrayString getProjDefs() /*-{
	return Object.keys($wnd.Proj4js.defs);
}-*/;
 
Example #28
Source File: Event.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
public native void setClassNames(JsArrayString classNames) /*-{
    var theInstance = this;
    theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.Event::event.className = className;
}-*/;
 
Example #29
Source File: JsEditorUtils.java    From swellrt with Apache License 2.0 4 votes vote down vote up
public static native JsArrayString asArray(JavaScriptObject o) /*-{
  if (Array.isArray(o))
    return o;

  return null;
}-*/;
 
Example #30
Source File: SliderBase.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
private native void setAttribute(Element e, String attr, JsArrayString value) /*-{
    if ([email protected]::isSliderNamespaceAvailable()())
        $wnd.jQuery(e).slider(@org.gwtbootstrap3.extras.slider.client.ui.base.SliderCommand::SET_ATTRIBUTE, attr, value);
    else
        $wnd.jQuery(e).bootstrapSlider(@org.gwtbootstrap3.extras.slider.client.ui.base.SliderCommand::SET_ATTRIBUTE, attr, value);
}-*/;