Search in sources :

Example 76 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project actor-platform by actorapp.

the class JsContent method createContent.

public static JsContent createContent(AbsContent src, int sender) {
    JsMessenger messenger = JsMessenger.getInstance();
    JsContent content;
    if (src instanceof TextContent) {
        TextContent textContent = (TextContent) src;
        if (textContent.getTextMessageEx() instanceof ApiTextModernMessage) {
            ApiTextModernMessage modernMessage = (ApiTextModernMessage) textContent.getTextMessageEx();
            String text = modernMessage.getText();
            JsParagraphStyle paragraphStyle = JsParagraphStyle.create(modernMessage.getStyle());
            JsArray<JsAttach> attaches = JsArray.createArray().cast();
            for (ApiTextModernAttach srcAttach : modernMessage.getAttaches()) {
                JsArray<JsAttachField> fields = JsArray.createArray().cast();
                for (ApiTextModernField f : srcAttach.getFields()) {
                    boolean isShort = f.isShort() != null ? f.isShort() : true;
                    fields.push(JsAttachField.create(f.getTitle(), f.getValue(), isShort));
                }
                attaches.push(JsAttach.create(srcAttach.getTitle(), srcAttach.getTitleUrl(), srcAttach.getText(), JsParagraphStyle.create(srcAttach.getStyle()), fields));
            }
            content = JsContentTextModern.create(text, paragraphStyle, attaches);
        } else {
            content = JsContentText.create(((TextContent) src).getText());
        }
    } else if (src instanceof ServiceContent) {
        content = JsContentService.create(messenger.getFormatter().formatFullServiceMessage(sender, (ServiceContent) src, false));
    } else if (src instanceof DocumentContent) {
        DocumentContent doc = (DocumentContent) src;
        String fileName = doc.getName();
        String fileExtension = doc.getExt();
        String fileSize = messenger.getFormatter().formatFileSize(doc.getSource().getSize());
        String fileUrl = null;
        if (doc.getSource() instanceof FileRemoteSource) {
            fileUrl = messenger.getFileUrl(((FileRemoteSource) doc.getSource()).getFileReference());
        }
        boolean isUploading = doc.getSource() instanceof FileLocalSource;
        String thumb = null;
        if (doc.getFastThumb() != null) {
            String thumbBase64 = Base64Utils.toBase64(doc.getFastThumb().getImage());
            thumb = "data:image/jpg;base64," + thumbBase64;
        }
        if (src instanceof PhotoContent && thumb != null) {
            PhotoContent photoContent = (PhotoContent) src;
            content = JsContentPhoto.create(fileName, fileExtension, fileSize, photoContent.getW(), photoContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) src;
            content = JsContentAnimation.create(fileName, fileExtension, fileSize, animationContent.getW(), animationContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) src;
            content = JsContentVoice.create(fileName, fileExtension, fileSize, fileUrl, isUploading, voiceContent.getDuration());
        } else {
            content = JsContentDocument.create(fileName, fileExtension, fileSize, thumb, fileUrl, isUploading);
        }
    } else if (src instanceof StickerContent) {
        StickerContent sticker = (StickerContent) src;
        ImageLocation stickerImage = sticker.getImage256();
        if (sticker.getImage512() != null) {
            stickerImage = sticker.getImage512();
        }
        String fileUrl = messenger.getFileUrl(stickerImage.getReference());
        String fileSize = messenger.getFormatter().formatFileSize(stickerImage.getReference().getFileSize());
        content = JsContentSticker.create(stickerImage.getReference().getFileName(), ".webp", fileSize, stickerImage.getWidth(), stickerImage.getHeight(), null, fileUrl, false);
    } else if (src instanceof ContactContent) {
        ContactContent contactContent = (ContactContent) src;
        JsArrayString phones = JsArray.createArray().cast();
        JsArrayString emails = JsArray.createArray().cast();
        for (String s : contactContent.getEmails()) {
            emails.push(s);
        }
        for (String s : contactContent.getPhones()) {
            phones.push(s);
        }
        content = JsContentContact.create(contactContent.getName(), contactContent.getPhoto64(), phones, emails);
    } else if (src instanceof LocationContent) {
        LocationContent locationContent = (LocationContent) src;
        content = JsContentLocation.create(locationContent.getLongitude(), locationContent.getLatitude(), locationContent.getStreet(), locationContent.getPlace());
    } else {
        content = JsContentUnsupported.create();
    }
    return content;
}
Also used : LocationContent(im.actor.core.entity.content.LocationContent) ApiTextModernField(im.actor.core.api.ApiTextModernField) AnimationContent(im.actor.core.entity.content.AnimationContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ContactContent(im.actor.core.entity.content.ContactContent) ImageLocation(im.actor.core.entity.ImageLocation) ApiTextModernMessage(im.actor.core.api.ApiTextModernMessage) JsMessenger(im.actor.core.js.JsMessenger) ServiceContent(im.actor.core.entity.content.ServiceContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) PhotoContent(im.actor.core.entity.content.PhotoContent) StickerContent(im.actor.core.entity.content.StickerContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ApiTextModernAttach(im.actor.core.api.ApiTextModernAttach) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) TextContent(im.actor.core.entity.content.TextContent)

Example 77 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project perun by CESNET.

the class JsonUtils method listFromJsArrayString.

/**
	 * Returns a Java List from JsArrayString.
	 *
	 * @param jsa javascript array of strings
	 * @return ArrayList<String> list of strings
	 */
public static ArrayList<String> listFromJsArrayString(JsArrayString jsa) {
    ArrayList<String> arrayList = new ArrayList<String>();
    for (int i = 0; i < jsa.length(); i++) {
        String str = jsa.get(i).toString();
        arrayList.add(str);
    }
    return arrayList;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 78 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project perun by CESNET.

the class PreferredShellsWidget method calculateAttrValue.

/**
	 * Takes values from input boxes and
	 * stores them to attribute
	 */
private void calculateAttrValue() {
    if (shellList.isEmpty()) {
        // clear value if empty
        a.setValueAsJso(null);
    } else {
        // fill value
        JsArrayString array = JavaScriptObject.createArray().cast();
        for (ListBox box : shellList) {
            String newValue = box.getValue(box.getSelectedIndex());
            if (newValue.equals(CUSTOM_TEXT)) {
                // process textbox
                if (!customMap.get(box).getTextBox().getText().trim().isEmpty()) {
                    // store only non-empty values
                    array.push(customMap.get(box).getTextBox().getText().trim());
                }
            } else {
                array.push(newValue);
            }
        }
        a.setValueAsJsArray(array);
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 79 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class Unified method newCm.

@Override
CodeMirror newCm(DiffInfo.FileMeta meta, String contents, Element parent) {
    JsArrayString gutters = JavaScriptObject.createArray().cast();
    gutters.push(UnifiedTable.style.lineNumbersLeft());
    gutters.push(UnifiedTable.style.lineNumbersRight());
    return CodeMirror.create(parent, Configuration.create().set("cursorBlinkRate", prefs.cursorBlinkRate()).set("cursorHeight", 0.85).set("gutters", gutters).set("inputStyle", "textarea").set("keyMap", "vim_ro").set("lineNumbers", false).set("lineWrapping", prefs.lineWrapping()).set("matchBrackets", prefs.matchBrackets()).set("mode", getFileSize() == FileSize.SMALL ? getContentType(meta) : null).set("readOnly", true).set("scrollbarStyle", "overlay").set("styleSelectedText", true).set("showTrailingSpace", prefs.showWhitespaceErrors()).set("tabSize", prefs.tabSize()).set("theme", prefs.theme().name().toLowerCase()).set("value", meta != null ? contents : "").set("viewportMargin", renderEntireFile() ? POSITIVE_INFINITY : 10));
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 80 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class UnifiedChunkManager method render.

private int render(Region region, int cmLine, boolean useIntralineBg) {
    int startA = lineMapper.getLineA();
    int startB = lineMapper.getLineB();
    JsArrayString a = region.a();
    JsArrayString b = region.b();
    int aLen = a != null ? a.length() : 0;
    int bLen = b != null ? b.length() : 0;
    boolean insertOrDelete = a == null || b == null;
    colorLines(cm, insertOrDelete && !useIntralineBg ? UnifiedTable.style.diffDelete() : UnifiedTable.style.intralineDelete(), cmLine, aLen);
    colorLines(cm, insertOrDelete && !useIntralineBg ? UnifiedTable.style.diffInsert() : UnifiedTable.style.intralineInsert(), cmLine + aLen, bLen);
    markEdit(DisplaySide.A, cmLine, a, region.editA());
    markEdit(DisplaySide.B, cmLine + aLen, b, region.editB());
    // TODO: verify addGutterTag
    addGutterTag(region, cmLine);
    lineMapper.appendReplace(aLen, bLen);
    int endA = lineMapper.getLineA() - 1;
    int endB = lineMapper.getLineB() - 1;
    if (aLen > 0) {
        addDiffChunk(DisplaySide.A, endA, aLen, cmLine, bLen > 0);
        for (int j = 0; j < aLen; j++) {
            host.setLineNumber(DisplaySide.A, cmLine + j, startA + j + 1);
            host.setLineNumberEmpty(DisplaySide.B, cmLine + j);
        }
    }
    if (bLen > 0) {
        addDiffChunk(DisplaySide.B, endB, bLen, cmLine + aLen, aLen > 0);
        for (int j = 0; j < bLen; j++) {
            host.setLineNumberEmpty(DisplaySide.A, cmLine + aLen + j);
            host.setLineNumber(DisplaySide.B, cmLine + aLen + j, startB + j + 1);
        }
    }
    return aLen + bLen;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)86 ArrayList (java.util.ArrayList)15 JSONString (com.google.gwt.json.client.JSONString)5 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)3 Command (com.google.gwt.user.client.Command)3 List (java.util.List)3 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)3 JsObject (org.rstudio.core.client.js.JsObject)3 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)3 JsArrayBoolean (com.google.gwt.core.client.JsArrayBoolean)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Label (com.google.gwt.user.client.ui.Label)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2