Example usage for com.google.gwt.core.client JsArrayString get

List of usage examples for com.google.gwt.core.client JsArrayString get

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayString get.

Prototype

public final native String get(int index) ;

Source Link

Document

Gets the value at a given index.

Usage

From source file:com.codenvy.ide.ext.java.jdt.core.util.JsUtil.java

License:Open Source License

public static char[] toCharArray(JsArrayString stringArray) {
    char[] result = new char[stringArray.length()];
    for (int i = 0; i < stringArray.length(); i++) {
        result[i] = stringArray.get(i).charAt(0);
    }//w w w  .j  a v  a2 s  .c o m
    return result;
}

From source file:com.codenvy.ide.ext.java.jdt.core.util.JsUtil.java

License:Open Source License

public static byte[] toByteArray(JsArrayString stringArray) {
    byte[] result = new byte[stringArray.length()];
    for (int i = 0; i < stringArray.length(); i++) {
        result[i] = Byte.valueOf(stringArray.get(i));
    }//  ww  w. j  a  va 2 s.  c  o m
    return result;
}

From source file:com.codenvy.ide.ext.java.jdt.core.util.JsUtil.java

License:Open Source License

public static String[] toStringArray(JsArrayString stringArray) {
    String[] result = new String[stringArray.length()];
    for (int i = 0; i < stringArray.length(); i++) {
        result[i] = stringArray.get(i);
    }/* w  w  w .ja va  2  s  .  c  o m*/
    return result;
}

From source file:com.codenvy.ide.ext.web.css.editor.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 w  ww.j  ava 2  s  .  c  om*/
 *
 * @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
 */
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.codenvy.ide.ext.web.css.editor.CssPartialParser.java

License:Open Source License

public JsoArray<CssCompletionProposal> 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<CssCompletionProposal> proposals = JsoArray.create();
    JsArray<JavaScriptObject> valuesForAllSlots = getPropertyValues(property);
    if (valuesForAllSlots == null) {
        return proposals;
    }/* w  w w.ja v a2s.c  o m*/
    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);
    valuesForSlotInQuestion.<Jso>cast().removeGwtObjectId();
    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();
            triggers.<Jso>cast().removeGwtObjectId();
            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 CssCompletionProposal(valueProposals.get(i), CompletionType.VALUE));
                            }
                        }
                    }
                } 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 CssCompletionProposal(
                                            specialValueProposalsAfterCheck.get(i), CompletionType.VALUE));
                                }
                            }
                        }
                    } else if (valuesBefore.get(triggerSlot).compareTo(triggerValue) == 0) {
                        shouldBeIncluded = true;
                    }
                }
            }
            if (shouldBeIncluded) {
                if (currentValue.startsWith(incomplete)
                        && (isRepeatingProperty || !inExistingValues(currentValue, valuesAndSpecialValuesBefore,
                                valuesAndSpecialValuesAfter))) {
                    proposals.add(new CssCompletionProposal(currentValue, CompletionType.VALUE));
                }
            }
        }
    }
    return proposals;
}

From source file:com.codenvy.ide.ext.web.css.editor.CssPartialParser.java

License:Open Source License

private boolean inExistingValues(String currentValue, JsArrayString valuesAndSpecialValuesAfter,
        JsArrayString valuesAndSpecialValuesBefore) {
    for (int i = 0; i < valuesAndSpecialValuesAfter.length(); i++) {
        if (valuesAndSpecialValuesAfter.get(i).equals(currentValue)) {
            return true;
        }/*from w w w. ja  v a 2s  .co m*/
    }
    for (int i = 0; i < valuesAndSpecialValuesBefore.length(); i++) {
        if (valuesAndSpecialValuesBefore.get(i).equals(currentValue)) {
            return true;
        }
    }
    return false;
}

From source file:com.codenvy.ide.ext.web.css.editor.CssPartialParser.java

License:Open Source License

private JsArrayString getValuesAndSpecialValues(JsArrayString existingValues) {
    JsArrayString valuesAndSpecialValuesAfter = JavaScriptObject.createArray().cast();
    for (int i = 0; i < existingValues.length(); i++) {
        String value = existingValues.get(i);
        JsArrayString specialValues = getSpecialValues(value);
        if (specialValues.length() == 0) {
            valuesAndSpecialValuesAfter.push(value);
        }/*from   ww  w  .  j  a  v a 2  s  .c  o m*/
        for (int j = 0; j < specialValues.length(); j++) {
            valuesAndSpecialValuesAfter.push(specialValues.get(j));
        }
    }
    return valuesAndSpecialValuesAfter;
}

From source file:com.eaw1805.www.client.widgets.RichTextToolbar.java

License:Open Source License

/**
 * Method called to toggle the style in HTML-Mode *
 *//*from  w  w w. ja  v  a 2 s.  com*/
private void changeHtmlStyle(final String startTag, final String stopTag) {
    final JsArrayString tx = getSelection(styleText.getElement());
    final String txbuffer = styleText.getText();
    final Integer startpos = Integer.parseInt(tx.get(1));
    final String selectedText = tx.get(0);
    styleText.setText(txbuffer.substring(0, startpos) + startTag + selectedText + stopTag
            + txbuffer.substring(startpos + selectedText.length()));
}

From source file:com.edgenius.wiki.gwt.client.editor.MCEInsertTableDialog.java

License:Open Source License

/**
 * @param tiny/*  ww  w . java 2 s  .  com*/
 */
public MCEInsertTableDialog(TinyMCE tiny, boolean update) {
    super(tiny);
    this.update = update;
    this.setText(Msg.consts.insert_table());

    FlexTable options = new FlexTable();

    options.setWidget(0, 0, asTable);
    options.setWidget(0, 1, asGrid);
    asTable.setValue(true);
    asTable.addClickHandler(this);
    asGrid.addClickHandler(this);
    options.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    options.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    options.setStyleName(Css.OPTIONS);

    FlexTable tableParamLayout = new FlexTable();
    tableParamLayout.setWidget(0, 0, new Label(Msg.consts.rows()));
    tableParamLayout.setWidget(0, 1, rows);

    tableParamLayout.setWidget(0, 2, new Label(Msg.consts.cols()));
    tableParamLayout.setWidget(0, 3, cols);

    tableParamLayout.setWidget(1, 0, new Label(Msg.consts.bk_color()));
    tableParamLayout.setWidget(1, 1, bkPicker);

    tableParamLayout.setWidget(1, 2, new Label(Msg.consts.border_color()));
    tableParamLayout.setWidget(1, 3, borderPicker);

    tableParamLayout.setWidget(2, 0, new Label(Msg.consts.border()));
    tableParamLayout.setWidget(2, 1, border);

    tableParamLayout.setWidget(2, 2, hasTitle);
    tableParamLayout.getFlexCellFormatter().setColSpan(2, 2, 2);

    tableParamLayout.getColumnFormatter().setWidth(0, "120px");
    tableParamLayout.getColumnFormatter().setWidth(2, "120px");
    rows.setStyleName(Css.TINY_TEXT_BOX);
    cols.setStyleName(Css.TINY_TEXT_BOX);
    border.setStyleName(Css.TINY_TEXT_BOX);

    FlexTable gridParamLayout = new FlexTable();
    gridParamLayout.setWidget(0, 0, new Label(Msg.consts.rows()));
    gridParamLayout.setWidget(0, 1, gridRows);

    gridParamLayout.setWidget(0, 2, new Label(Msg.consts.cols()));
    gridParamLayout.setWidget(0, 3, gridCols);
    gridRows.setStyleName(Css.TINY_TEXT_BOX);
    gridCols.setStyleName(Css.TINY_TEXT_BOX);

    tableParamLayout.setWidth("100%");
    tableParamLayout.setCellSpacing(5);
    gridParamLayout.setWidth("100%");
    gridParamLayout.setCellSpacing(5);
    options.setWidth("100%");
    options.setCellSpacing(5);
    deck.setWidth("100%");

    deck.insert(tableParamLayout, 0);
    deck.insert(gridParamLayout, 1);

    if (update) {
        JsArrayString list = getProperties();
        if (list.get(8).toLowerCase().indexOf("macrogrid") != -1) {
            asGrid.setValue(true);
            gridRows.setText(list.get(0));
            gridCols.setText(list.get(1));
            //set it to same value for switch back
            rows.setText(list.get(0));
            cols.setText(list.get(1));
            //disable some unable to change attributes
            gridRows.setEnabled(false);
            gridCols.setEnabled(false);
            deck.showWidget(1);
        } else {
            asTable.setValue(true);
            deck.showWidget(0);
            //this sequence is according to method getProperties() on  table.js in TinyMCE table plugin
            rows.setText(list.get(0));
            cols.setText(list.get(1));
            gridRows.setText(list.get(0));
            gridCols.setText(list.get(1));

            final String color = StringUtil.isBlank(list.get(2)) ? SharedConstants.TABLE_BG_DEFAULT_COLOR
                    : list.get(2);
            if (GwtClientUtils.isIE()) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    public void execute() {
                        //stupid IE need this deferred set
                        bkPicker.setColor(color);
                    }
                });
            } else
                bkPicker.setColor(color);
            final String bcolor = StringUtil.isBlank(list.get(3)) ? SharedConstants.TABLE_BORDER_DEFAULT_COLOR
                    : list.get(3);
            if (GwtClientUtils.isIE()) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    public void execute() {
                        //stupid IE need this deferred set
                        borderPicker.setColor(bcolor);
                    }
                });
            } else
                borderPicker.setColor(bcolor);

            hasTitle.setValue(BooleanUtil.toBoolean(list.get(4)));
            width = GwtUtils.removeUnit(list.get(5));
            height = GwtUtils.removeUnit(list.get(6));
            String borderS = GwtUtils.removeUnit(list.get(7));
            border.setText(StringUtil.isBlank(borderS) ? DEFAULT_BORDER_SIZE + "" : borderS);

            //disable some unable to change attributes
            rows.setEnabled(false);
            cols.setEnabled(false);
        }
    } else {
        //initial values
        gridRows.setText("1");
        gridCols.setText("3");

        rows.setText("2");
        cols.setText("2");
        border.setText("1");
        hasTitle.setValue(true);
        deck.showWidget(0);

        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            public void execute() {
                rows.setFocus(true);
            }
        });
    }

    VerticalPanel form = new VerticalPanel();
    form.setWidth("100%");
    form.add(options);
    form.add(deck);
    this.setWidget(form);

}

From source file:com.eemi.ext4j.explorer.client.data.DataUtil.java

License:Open Source License

private static ArrayList<String> getFields() {
    ArrayList<String> fields = new ArrayList<String>();
    JsArrayString values = getF();
    for (int i = 0; i < values.length(); i++) {
        fields.add(values.get(i));
    }/*from   ww  w . ja va 2s  .  c om*/
    return fields;
}