Search in sources :

Example 76 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project rstudio by rstudio.

the class ChunkContextToolbar method createMenuItemForType.

private MenuItem createMenuItemForType(final AppCommand command, final String chunkType) {
    SafeHtml menuHTML = new SafeHtmlBuilder().appendHtmlConstant(command.getMenuHTML(false)).toSafeHtml();
    MenuItem menuItem = new MenuItem(menuHTML, new Command() {

        public void execute() {
            host_.switchChunk(chunkType);
        }
    });
    return menuItem;
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 77 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project rstudio by rstudio.

the class TextEditingTargetPresentationHelper method buildSlideMenu.

public void buildSlideMenu(final String path, boolean isDirty, final EditingTarget editor, final CommandWithArg<StatusBarPopupRequest> onCompleted) {
    // rpc response handler
    SimpleRequestCallback<SlideNavigation> requestCallback = new SimpleRequestCallback<SlideNavigation>() {

        @Override
        public void onResponseReceived(SlideNavigation slideNavigation) {
            // create the menu and make sure we have some slides to return
            StatusBarPopupMenu menu = new StatusBarPopupMenu();
            if (slideNavigation.getTotalSlides() == 0) {
                onCompleted.execute(new StatusBarPopupRequest(menu, null));
                return;
            }
            MenuItem defaultMenuItem = null;
            int length = slideNavigation.getItems().length();
            for (int i = 0; i < length; i++) {
                SlideNavigationItem item = slideNavigation.getItems().get(i);
                String title = item.getTitle();
                if (StringUtil.isNullOrEmpty(title))
                    title = "(Untitled Slide)";
                StringBuilder indentBuilder = new StringBuilder();
                for (int level = 0; level < item.getIndent(); level++) indentBuilder.append("&nbsp;&nbsp;");
                SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
                labelBuilder.appendHtmlConstant(indentBuilder.toString());
                labelBuilder.appendEscaped(title);
                final int targetSlide = i;
                final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {

                    public void execute() {
                        navigateToSlide(editor, targetSlide);
                    }
                });
                menu.addItem(menuItem);
                // see if this is the default menu item
                if (defaultMenuItem == null && item.getLine() >= (docDisplay_.getSelectionStart().getRow())) {
                    defaultMenuItem = menuItem;
                }
            }
            StatusBarPopupRequest request = new StatusBarPopupRequest(menu, defaultMenuItem);
            onCompleted.execute(request);
        }
    };
    // send code over the wire if we are dirty
    if (isDirty) {
        server_.getSlideNavigationForCode(docDisplay_.getCode(), FileSystemItem.createFile(path).getParentPathString(), requestCallback);
    } else {
        server_.getSlideNavigationForFile(path, requestCallback);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) StatusBarPopupRequest(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest) MenuItem(com.google.gwt.user.client.ui.MenuItem) SlideNavigation(org.rstudio.studio.client.common.presentation.model.SlideNavigation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) SlideNavigationItem(org.rstudio.studio.client.common.presentation.model.SlideNavigationItem) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 78 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project rstudio by rstudio.

the class TextEditingTarget method addFunctionsToMenu.

private MenuItem addFunctionsToMenu(StatusBarPopupMenu menu, final JsArray<Scope> funcs, String indent, Scope defaultFunction, boolean includeNoFunctionsMessage) {
    MenuItem defaultMenuItem = null;
    if (funcs.length() == 0 && includeNoFunctionsMessage) {
        String type = fileType_.canExecuteChunks() ? "chunks" : "functions";
        MenuItem noFunctions = new MenuItem("(No " + type + " defined)", false, (Command) null);
        noFunctions.setEnabled(false);
        noFunctions.getElement().addClassName("disabled");
        menu.addItem(noFunctions);
    }
    for (int i = 0; i < funcs.length(); i++) {
        final Scope func = funcs.get(i);
        String childIndent = indent;
        if (!StringUtil.isNullOrEmpty(func.getLabel())) {
            SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
            labelBuilder.appendHtmlConstant(indent);
            labelBuilder.appendEscaped(func.getLabel());
            final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {

                public void execute() {
                    docDisplay_.navigateToPosition(toSourcePosition(func), true);
                }
            });
            addScopeStyle(menuItem, func);
            menu.addItem(menuItem);
            childIndent = indent + "&nbsp;&nbsp;";
            if (defaultFunction != null && defaultMenuItem == null && func.getLabel().equals(defaultFunction.getLabel()) && func.getPreamble().getRow() == defaultFunction.getPreamble().getRow() && func.getPreamble().getColumn() == defaultFunction.getPreamble().getColumn()) {
                defaultMenuItem = menuItem;
            }
        }
        MenuItem childDefaultMenuItem = addFunctionsToMenu(menu, func.getChildren(), childIndent, defaultMenuItem == null ? defaultFunction : null, false);
        if (childDefaultMenuItem != null)
            defaultMenuItem = childDefaultMenuItem;
    }
    return defaultMenuItem;
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 79 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project rstudio by rstudio.

the class TextEditingTarget method createMenuItemForType.

private MenuItem createMenuItemForType(final TextFileType type) {
    SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
    labelBuilder.appendEscaped(type.getLabel());
    MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {

        public void execute() {
            docUpdateSentinel_.changeFileType(type.getTypeId(), new SaveProgressIndicator(null, type, null));
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    focus();
                }
            });
        }
    });
    return menuItem;
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 80 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project perun by CESNET.

the class ApplicationFormGui method loadVo.

/**
	 * Loads the VO by the parameter
	 */
public void loadVo(final JsonCallbackEvents events) {
    voName = Location.getParameter("vo");
    groupName = Location.getParameter("group");
    Initialize req = new Initialize(voName, groupName, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            JsArray<Attribute> list = JsonUtils.jsoAsArray(jso);
            // recreate VO and group
            vo = new JSONObject().getJavaScriptObject().cast();
            if (groupName != null && !groupName.isEmpty()) {
                group = new JSONObject().getJavaScriptObject().cast();
            }
            for (int i = 0; i < list.length(); i++) {
                Attribute a = list.get(i);
                if (a.getFriendlyName().equalsIgnoreCase("id")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setId(Integer.parseInt(a.getValue()));
                        if (group != null) {
                            group.setVoId(Integer.parseInt(a.getValue()));
                        }
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setId(Integer.parseInt(a.getValue()));
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("name")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setName(a.getValue());
                    } else if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("shortName")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:core")) {
                        vo.setShortName(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("description")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:group:attribute-def:core")) {
                        group.setDescription(a.getValue());
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("contactEmail")) {
                    if (a.getNamespace().equalsIgnoreCase("urn:perun:vo:attribute-def:def")) {
                        // set contact email
                        for (int n = 0; n < a.getValueAsJsArray().length(); n++) {
                            SafeHtmlBuilder s = new SafeHtmlBuilder();
                            if (n > 0) {
                                //others
                                s.appendHtmlConstant(voContact.getHTML().concat(", <a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            } else {
                                // first
                                s.appendHtmlConstant(voContact.getHTML().concat("<a href=\"mailto:" + a.getValueAsJsArray().get(n) + "\">" + a.getValueAsJsArray().get(n) + "</a>"));
                            }
                            voContact.setHTML(s.toSafeHtml());
                        }
                    }
                }
            }
            // store attrs
            vo.setAttributes(list);
            loadPerunPrincipal(events);
        }

        @Override
        public void onError(PerunError error) {
            // hides the loading box
            loadingBox.hide();
            RootLayoutPanel panel = RootLayoutPanel.get();
            panel.clear();
            panel.add(getErrorWidget(error));
        }
    });
    req.setHidden(true);
    req.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Initialize(cz.metacentrum.perun.webgui.json.registrarManager.Initialize)

Aggregations

SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)143 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)26 Test (org.junit.Test)18 Column (com.google.gwt.user.cellview.client.Column)17 Cell (com.google.gwt.cell.client.Cell)14 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)12 Context (com.google.gwt.cell.client.Cell.Context)7 MenuItem (com.google.gwt.user.client.ui.MenuItem)7 NativeEvent (com.google.gwt.dom.client.NativeEvent)6 Command (com.google.gwt.user.client.Command)6 ArrayList (java.util.ArrayList)6 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)5 GWT (com.google.gwt.core.client.GWT)5 Element (com.google.gwt.dom.client.Element)5 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)4 TextCell (com.google.gwt.cell.client.TextCell)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 ImageResource (com.google.gwt.resources.client.ImageResource)4 Map (java.util.Map)4