Search in sources :

Example 1 with UIObject

use of com.google.gwt.user.client.ui.UIObject in project rstudio by rstudio.

the class TextEditingTarget method initStatusBar.

private void initStatusBar() {
    statusBar_ = view_.getStatusBar();
    docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {

        public void onCursorChanged(CursorChangedEvent event) {
            updateStatusBarPosition();
            if (docDisplay_.isScopeTreeReady(event.getPosition().getRow()))
                updateCurrentScope();
        }
    });
    updateStatusBarPosition();
    updateStatusBarLanguage();
    // build file type menu dynamically (so it can change according
    // to whether e.g. knitr is installed)
    statusBar_.getLanguage().addMouseDownHandler(new MouseDownHandler() {

        @Override
        public void onMouseDown(MouseDownEvent event) {
            // build menu with all file types - also track whether we need
            // to add the current type (may be the case for types which we 
            // support but don't want to expose on the menu -- e.g. Rmd 
            // files when knitr isn't installed)
            boolean addCurrentType = true;
            final StatusBarPopupMenu menu = new StatusBarPopupMenu();
            TextFileType[] fileTypes = fileTypeCommands_.statusBarFileTypes();
            for (TextFileType type : fileTypes) {
                menu.addItem(createMenuItemForType(type));
                if (addCurrentType && type.equals(fileType_))
                    addCurrentType = false;
            }
            // add the current type if isn't on the menu 
            if (addCurrentType)
                menu.addItem(createMenuItemForType(fileType_));
            // show the menu
            menu.showRelativeToUpward((UIObject) statusBar_.getLanguage(), true);
        }
    });
    statusBar_.getScope().addMouseDownHandler(new MouseDownHandler() {

        public void onMouseDown(MouseDownEvent event) {
            // Unlike the other status bar elements, the function outliner
            // needs its menu built on demand
            JsArray<Scope> tree = docDisplay_.getScopeTree();
            final StatusBarPopupMenu menu = new StatusBarPopupMenu();
            MenuItem defaultItem = null;
            if (fileType_.isRpres()) {
                String path = docUpdateSentinel_.getPath();
                if (path != null) {
                    presentationHelper_.buildSlideMenu(docUpdateSentinel_.getPath(), dirtyState_.getValue(), TextEditingTarget.this, new CommandWithArg<StatusBarPopupRequest>() {

                        @Override
                        public void execute(StatusBarPopupRequest request) {
                            showStatusBarPopupMenu(request);
                        }
                    });
                }
            } else {
                defaultItem = addFunctionsToMenu(menu, tree, "", docDisplay_.getCurrentScope(), true);
                showStatusBarPopupMenu(new StatusBarPopupRequest(menu, defaultItem));
            }
        }
    });
}
Also used : UIObject(com.google.gwt.user.client.ui.UIObject) JsArray(com.google.gwt.core.client.JsArray) StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) StatusBarPopupRequest(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)

Example 2 with UIObject

use of com.google.gwt.user.client.ui.UIObject in project gwt-test-utils by gwt-test-utils.

the class PotentialElementPatcher method resolve.

@PatchMethod
static Element resolve(Element maybePotential) {
    if (isPotential(maybePotential)) {
        UIObject o = JavaScriptObjects.getObject(maybePotential, POTENTIALELEMENT_UIOBJECT);
        GwtReflectionUtils.callPrivateMethod(o, "resolvePotentialElement");
        return JavaScriptObjects.getObject(maybePotential, POTENTIALELEMENT_WRAPPED_ELEMENT);
    } else {
        return maybePotential;
    }
}
Also used : UIObject(com.google.gwt.user.client.ui.UIObject) PatchMethod(com.googlecode.gwt.test.patchers.PatchMethod)

Example 3 with UIObject

use of com.google.gwt.user.client.ui.UIObject in project gwt-test-utils by gwt-test-utils.

the class UiBinderBeanUtils method populateObject.

/**
     * @param o
     * @param properties
     * @see BeanUtilsBean#populate(Object, Map)
     */
public static void populateObject(Object o, Map<String, Object> properties) {
    try {
        Map<String, Object> filteredProperties = new HashMap<String, Object>();
        for (String key : properties.keySet()) {
            if (PropertyUtils.isWriteable(o, key)) {
                filteredProperties.put(key, properties.get(key));
            }
        }
        UIBINDER_BEANUTILS.populate(o, filteredProperties);
    } catch (Exception e) {
        throw new ReflectionException("UiBinder error while setting properties for '" + o.getClass().getSimpleName() + "'", e);
    }
    // handle specifics
    String[] styles = (String[]) properties.get("addStyleNames");
    if (styles != null) {
        for (String style : styles) {
            if (o instanceof IsWidget) {
                ((IsWidget) o).asWidget().addStyleName(style);
            } else if (o instanceof UIObject) {
                ((UIObject) o).addStyleName(style);
            }
        }
    }
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) ReflectionException(com.googlecode.gwt.test.exceptions.ReflectionException) UIObject(com.google.gwt.user.client.ui.UIObject) HashMap(java.util.HashMap) UIObject(com.google.gwt.user.client.ui.UIObject) ReflectionException(com.googlecode.gwt.test.exceptions.ReflectionException)

Example 4 with UIObject

use of com.google.gwt.user.client.ui.UIObject in project gwt-test-utils by gwt-test-utils.

the class UiTagBuilder method endTag.

UiTagBuilder<T> endTag(String nameSpaceURI, String localName) {
    // ignore <UiBinder> tag
    if (UiBinderXmlUtils.isUiBinderTag(nameSpaceURI, localName)) {
        return this;
    }
    Object currentObject = currentTag.endTag();
    UiTag<?> parentTag = currentTag.getParentTag();
    currentTag = parentTag;
    if (UiBinderXmlUtils.isResourceTag(nameSpaceURI, localName) || UiBinderXmlUtils.isImportTag(nameSpaceURI, localName)) {
        // ignore <ui:data>, <ui:image>, <ui:style> <ui:text> and <ui:import> tags
        return this;
    } else if (UiBinderXmlUtils.isMsgTag(nameSpaceURI, localName) || UiBinderXmlUtils.isTextTag(nameSpaceURI, localName)) {
        // special <ui:msg> and <ui:text> case
        parentTag.appendText((String) currentObject);
        return this;
    }
    if (parentTag == null) {
        // parsing is finished, this must be the root component
        if (rootComponent != null) {
            throw new GwtTestUiBinderException("UiBinder template '" + owner.getClass().getName() + "' should declare only one root widget in its corresponding .ui.xml file");
        } else {
            rootComponent = currentObject;
        }
    } else {
        // add to its parent
        if (IsWidget.class.isInstance(currentObject)) {
            parentTag.addWidget((IsWidget) currentObject);
        } else if (UIObject.class.isInstance(currentObject)) {
            // UIObject instance that is not a Widget
            parentTag.addUiObject((UIObject) currentObject);
        } else {
            parentTag.addElement((Element) currentObject);
        }
    }
    return this;
}
Also used : GwtTestUiBinderException(com.googlecode.gwt.test.exceptions.GwtTestUiBinderException) UIObject(com.google.gwt.user.client.ui.UIObject) Element(com.google.gwt.dom.client.Element) UIObject(com.google.gwt.user.client.ui.UIObject)

Example 5 with UIObject

use of com.google.gwt.user.client.ui.UIObject in project gerrit by GerritCodeReview.

the class NavigationTable method scrollIntoView.

protected void scrollIntoView(final Element tr) {
    if (!computedScrollType) {
        parentScrollPanel = null;
        Widget w = getParent();
        while (w != null) {
            if (w instanceof ScrollPanel) {
                parentScrollPanel = (ScrollPanel) w;
                break;
            }
            w = w.getParent();
        }
        computedScrollType = true;
    }
    if (parentScrollPanel != null) {
        parentScrollPanel.ensureVisible(new UIObject() {

            {
                setElement(tr);
            }
        });
    } else {
        int rt = tr.getAbsoluteTop();
        int rl = tr.getAbsoluteLeft();
        int rb = tr.getAbsoluteBottom();
        int wt = Window.getScrollTop();
        int wl = Window.getScrollLeft();
        int wh = Window.getClientHeight();
        int ww = Window.getClientWidth();
        int wb = wt + wh;
        // wb < rb: Row bottom is below bottom of window.
        if (rl < wl || rt < wt || wb < rt || wb < rb) {
            if (rl < wl) {
                // If the row fully fits in the window, set 0.
                if (tr.getAbsoluteRight() < ww) {
                    wl = 0;
                } else {
                    wl = Math.max(tr.getAbsoluteLeft() - 5, 0);
                }
            }
            // Vertically center the row in the window.
            int h = (wh - (rb - rt)) / 2;
            Window.scrollTo(wl, Math.max(rt - h, 0));
        }
    }
}
Also used : UIObject(com.google.gwt.user.client.ui.UIObject) Widget(com.google.gwt.user.client.ui.Widget) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Aggregations

UIObject (com.google.gwt.user.client.ui.UIObject)5 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Element (com.google.gwt.dom.client.Element)1 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 Widget (com.google.gwt.user.client.ui.Widget)1 GwtTestUiBinderException (com.googlecode.gwt.test.exceptions.GwtTestUiBinderException)1 ReflectionException (com.googlecode.gwt.test.exceptions.ReflectionException)1 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)1 HashMap (java.util.HashMap)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 StatusBarPopupMenu (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu)1 StatusBarPopupRequest (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)1