Example usage for com.google.gwt.user.client.ui Widget addStyleName

List of usage examples for com.google.gwt.user.client.ui Widget addStyleName

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget addStyleName.

Prototype

public void addStyleName(String style) 

Source Link

Document

Adds a secondary or dependent style name to this object.

Usage

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputGallery.java

License:Open Source License

private void addThumbnail(int idx, ChunkOutputPage page) {
    final Widget thumbnail = page.thumbnailWidget();

    thumbnail.getElement().setTabIndex(0);
    thumbnail.addStyleName(style.thumbnail());

    // apply editor color to thumbnail before 
    syncThumbnailColor(thumbnail, ChunkOutputWidget.getEditorColors());
    filmstrip_.insert(thumbnail, idx);/*  w ww  .  j  a v  a 2 s  .c o m*/

    // lock to this console if we don't have one already
    if (page instanceof ChunkConsolePage && console_ == null)
        console_ = (ChunkConsolePage) page;

    final int ordinal = page.ordinal();
    DOM.sinkEvents(thumbnail.getElement(), Event.ONCLICK | Event.ONKEYDOWN);
    DOM.setEventListener(thumbnail.getElement(), new EventListener() {
        @Override
        public void onBrowserEvent(Event evt) {
            switch (DOM.eventGetType(evt)) {
            case Event.ONCLICK:
                // convert ordinal back to index (index can change with
                // out-of-order insertions)
                for (int i = 0; i < pages_.size(); i++) {
                    if (pages_.get(i).ordinal() == ordinal) {
                        setActivePage(i);
                        break;
                    }
                }
                break;
            case Event.ONKEYDOWN:
                int dir = 0;
                if (evt.getKeyCode() == KeyCodes.KEY_LEFT)
                    dir = -1;
                if (evt.getKeyCode() == KeyCodes.KEY_RIGHT)
                    dir = 1;
                if (dir != 0)
                    navigateActivePage(dir);
                break;
            }
            ;
        }
    });
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ChunkOutputStream.java

License:Open Source License

@Override
public void setPlotPending(boolean pending, String pendingStyle) {
    for (Widget w : this) {
        if (w instanceof FixedRatioWidget && ((FixedRatioWidget) w).getWidget() instanceof Image) {
            if (pending)
                w.addStyleName(pendingStyle);
            else//w ww .  j a  v  a  2 s.  c  o m
                w.removeStyleName(pendingStyle);
        }
    }
}

From source file:org.rstudio.studio.client.workbench.views.source.SourcePane.java

License:Open Source License

public void setDirty(Widget widget, boolean dirty) {
    Widget tab = tabPanel_.getTabWidget(widget);
    if (dirty)/*from   ww w . ja v  a  2  s.c o  m*/
        tab.addStyleName(ThemeStyles.INSTANCE.dirtyTab());
    else
        tab.removeStyleName(ThemeStyles.INSTANCE.dirtyTab());
}

From source file:org.sigmah.client.ui.view.project.logframe.grid.FlexTableView.java

License:Open Source License

/**
 * Inserts a new group of rows at the given position.
 * //w ww  .  java 2s.com
 * @param position
 *          The position at which the group will be inserted among the groups list (for example, a index equals to
 *          <code>2</code> means that the group will be the second one).
 *          If this index is lower or equal than <code>0</code>, the group will be the first one. An index greater
 *          than the number of group will insert the group at the last position.
 * @param group
 *          The group.
 * @throws NullPointerException
 *           If the group is <code>null</code>.
 * @throws IllegalArgumentException
 *           If a group with the same id already exists.
 */
public void insertGroup(int position, final RowsGroup<?> group) {

    // Checks if the group is valid.
    if (group == null) {
        throw new NullPointerException("The group must not be null.");
    }

    final int id = group.getId();
    // Checks if the group doesn't exist already.
    if (groupsCodesMap.get(id) != null) {
        throw new IllegalArgumentException("The group with id #" + id + " already exists.");
    }

    // Re-adjusts the position to avoid out of bounds errors.
    if (position <= 0 || groupsOrderedList.isEmpty()) {
        position = 1;
    } else if (position > groupsOrderedList.size()) {
        position = groupsOrderedList.size() + 1;
    }

    if (Log.isDebugEnabled()) {
        Log.debug("[insertGroup] Inserts the new group #" + id + " at position # " + position + ".");
    }

    // Computes new group indexes.
    int row = computeGroupIndex(position);
    row = insertTableRow(row);
    int column = 0;

    // Builds group's widget.
    final Widget widget = group.getWidget();

    // Adds widget and sets row.
    table.setWidget(row, column, widget);
    table.getFlexCellFormatter().setColSpan(row, column, columnsCount + 2);
    HTMLTableUtils.applyCellStyles(table, row, column, false, true);
    table.getFlexCellFormatter().addStyleName(row, column, CSS_GROUP_CELL_STYLE_NAME);
    widget.addStyleName(CSS_GROUP_LABEL_STYLE_NAME);

    // Adds the group locally at the correct position.
    groupsOrderedList.add(position - 1, group);
    groupsCodesMap.put(group.getId(), group);

    // Hides the group header if needed.
    if (!group.isVisible()) {
        widget.setVisible(false);
    }

    fireGroupAdded(group);
}

From source file:org.sigmah.client.ui.view.project.logframe.grid.FlexTableView.java

License:Open Source License

/**
 * Refreshes the group widget.//from   w  w w .ja va  2s . co m
 * 
 * @param group
 *          The group.
 */
public void refreshGroupWidget(final RowsGroup<?> group) {

    // Checks if the group is valid.
    if (group == null) {
        throw new NullPointerException("The group must not be null.");
    }

    if (Log.isDebugEnabled()) {
        Log.debug("[refreshGroupWidget] Refreshes the group #" + group.getId() + ".");
    }

    // Computes new group indexes.
    int row = getGroupRowIndex(group) + shift;
    int column = 0;

    // Builds group's widget.
    final Widget widget = group.getWidget();

    // Sets the new widget.
    table.setWidget(row, column, widget);

    // Applies style names.
    HTMLTableUtils.applyCellStyles(table, row, column, false, true);
    widget.addStyleName(CSS_GROUP_LABEL_STYLE_NAME);
}

From source file:org.sigmah.client.ui.view.project.logframe.grid.HTMLTableUtils.java

License:Open Source License

/**
 * Applies the CSS column-header styles to a cell.
 * /*from w  w w.j a va 2 s .  c o m*/
 * @param table
 *          The GWT table.
 * @param row
 *          The row index.
 * @param column
 *          The column index.
 */
public static void applyColumnHeaderStyles(HTMLTable table, int row, int column) {
    table.getCellFormatter().addStyleName(row, column, "x-grid3-header");
    table.getCellFormatter().addStyleName(row, column, "x-grid3-hd");
    table.getCellFormatter().addStyleName(row, column, "x-grid3-hd-row");
    table.getCellFormatter().addStyleName(row, column, "x-grid3-td-favorite");
    table.getCellFormatter().addStyleName(row, column, "x-grid3-cell");

    final Widget w = table.getWidget(row, column);
    if (w != null) {
        w.addStyleName("x-grid3-hd-inner");
        w.addStyleName("x-grid3-hd-favorite ");
        w.addStyleName("x-component");
    }
}

From source file:org.sigmah.client.ui.view.project.logframe.grid.HTMLTableUtils.java

License:Open Source License

/**
 * Applies the CSS content style to a cell.
 * /*  w  ww  .j  a v  a  2  s . c o m*/
 * @param table
 *          The GWT table.
 * @param row
 *          The row index.
 * @param column
 *          The column index.
 * @param first
 *          If the cell is the first of its row.
 * @param last
 *          If the cell is the last of its row.
 */
public static void applyCellStyles(HTMLTable table, int row, int column, boolean first, boolean last) {
    table.getCellFormatter().addStyleName(row, column, "x-grid3-col");
    table.getCellFormatter().addStyleName(row, column, "x-grid3-cell");
    table.getCellFormatter().addStyleName(row, column, "html-table-cell");

    if (first) {
        table.getCellFormatter().addStyleName(row, column, "x-grid3-cell-first");
    }

    if (last) {
        table.getCellFormatter().addStyleName(row, column, "x-grid3-cell-last");
        table.getCellFormatter().addStyleName(row, column, "html-table-cell-last");
    }

    final Widget w = table.getWidget(row, column);
    if (w != null) {
        w.addStyleName("x-grid3-cell-inner");
    }
}

From source file:org.sigmah.client.ui.widget.form.ListComboBox.java

License:Open Source License

protected void buildComponent() {
    if (rootPanel == null) {
        // not yet initialized
        return;//  w w  w .j a va  2  s  . com
    }

    rootPanel.clear();

    formPanel = new FlowPanel();
    formPanel.addStyleName("list-combobox__form");

    if (enabled) {
        comboBox = Forms.combobox(null, false, valueField, displayField, availableValuesStore);
        comboBox.setStyleName("list-combobox__form__choices");
        if (availableValuesStore.getModels().isEmpty() && !ClientUtils.isBlank(noAvailableValueTooltip)) {
            comboBox.setToolTip(noAvailableValueTooltip);
        }
        formPanel.add(comboBox);

        Button addButton = new Button(I18N.CONSTANTS.addItem(), IconImageBundle.ICONS.add());
        addButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
            @Override
            public void componentSelected(ButtonEvent event) {
                T value = comboBox.getValue();
                if (value == null) {
                    return;
                }

                if (dataStore.findModel(valueField, value.get(valueField)) != null) {
                    return;
                }
                availableValuesStore.remove(value);
                dataStore.add(value);
            }
        });
        formPanel.add(addButton);
    } else {
        comboBox = null;
    }

    formPanel.setWidth("100%");
    rootPanel.add(formPanel);

    FlowPanel elementsPanel = new FlowPanel();
    elementsPanel.setStyleName("list-combobox__elements");
    for (int i = 0; i < dataStore.getModels().size(); i++) {
        final T element = dataStore.getModels().get(i);
        Widget label;
        if (enabled) {
            label = new ClickableLabel(element.get(displayField).toString());
            label.addStyleName("list-combobox__elements__element");
            ((ClickableLabel) label).addClickHandler(new ClickHandler() {
                @Override
                public void onClick(final ClickEvent event) {
                    availableValuesStore.add(element);
                    dataStore.remove(element);
                }
            });
        } else {
            label = new Label(i == 0 ? element.get(displayField).toString()
                    : ", " + element.get(displayField).toString());
        }
        elementsPanel.add(label);
    }
    rootPanel.add(elementsPanel);
}

From source file:org.sigmah.client.ui.widget.panel.FoldPanel.java

License:Open Source License

private void setState(int state) {
    // Removing the previous style
    final HorizontalPanel titleBar = (HorizontalPanel) super.getWidget(HEADER_INDEX);
    final Widget header = titleBar.getWidget(0);

    switch (this.state) {
    case STATE_EXPANDED:
        header.removeStyleName("fold-expanded");
        break;//from  www .  j  ava  2  s  .c om
    case STATE_FOLDED:
        header.removeStyleName("fold-folded");
        break;
    case STATE_COLLAPSED:
        header.removeStyleName("fold-collapsed");
        break;
    }

    // Adding the new style
    switch (state) {
    case STATE_EXPANDED:
        header.addStyleName("fold-expanded");
        break;
    case STATE_FOLDED:
        header.addStyleName("fold-folded");
        break;
    case STATE_COLLAPSED:
        header.addStyleName("fold-collapsed");
        break;
    }

    this.state = state;
}

From source file:org.sigmah.client.util.ClientUtils.java

License:Open Source License

/**
 * Adds the given {@code addedStyle} to the given {@code isWidget} and removes the given {@code removedStyles} from
 * the given {@code isWidget}.//w  w  w. j  a  v a2 s . c o  m
 * 
 * @param isWidget
 *          The widget.
 * @param addedStyle
 *          The added style name (if not {@code null} or empty).
 * @param removedStyles
 *          The removed style names (if not {@code null} or empty).
 */
public static <W extends IsWidget> void addAndRemoveStyles(W isWidget, String addedStyle,
        String... removedStyles) {
    if (isWidget == null) {
        return;
    }

    final Widget widget = isWidget.asWidget();
    if (widget == null) {
        return;
    }

    if (isNotEmpty(removedStyles)) {
        // Removing style names.
        for (final String removedStyle : removedStyles) {
            if (isBlank(removedStyle)) {
                continue;
            }
            widget.removeStyleName(removedStyle);
        }
    }

    if (isNotBlank(addedStyle)) {
        widget.addStyleName(addedStyle);
    }
}