Example usage for com.vaadin.ui Button getStyleName

List of usage examples for com.vaadin.ui Button getStyleName

Introduction

In this page you can find the example usage for com.vaadin.ui Button getStyleName.

Prototype

@Override
    public String getStyleName() 

Source Link

Usage

From source file:org.opencms.ui.editors.CmsSourceEditor.java

License:Open Source License

/**
 * @see org.opencms.ui.editors.I_CmsEditor#initUI(org.opencms.ui.apps.I_CmsAppUIContext, org.opencms.file.CmsResource, java.lang.String)
 *//* w  w w  .ja  v  a2  s  .  c  o m*/
public void initUI(I_CmsAppUIContext context, CmsResource resource, String backLink) {

    CmsMessages messages = Messages.get().getBundle(UI.getCurrent().getLocale());
    context.showInfoArea(false);
    context.setAppTitle(messages.key(Messages.GUI_SOURCE_EDITOR_TITLE_0));
    CmsAppWorkplaceUi.setWindowTitle(CmsVaadinUtils.getMessageText(
            org.opencms.ui.apps.Messages.GUI_CONTENT_EDITOR_TITLE_2, resource.getName(),
            CmsResource.getParentFolder(A_CmsUI.getCmsObject().getSitePath(resource))));
    m_backLink = backLink;
    m_codeMirror = new CmsCodeMirror();
    m_codeMirror.setSizeFull();
    context.setAppContent(m_codeMirror);
    context.enableDefaultToolbarButtons(false);
    m_saveAndExit = CmsToolBar.createButton(FontOpenCms.SAVE_EXIT,
            messages.key(Messages.GUI_BUTTON_SAVE_AND_EXIT_0), true);
    m_saveAndExit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            saveAndExit();
        }

    });
    m_saveAndExit.setEnabled(false);
    context.addToolbarButton(m_saveAndExit);

    m_save = CmsToolBar.createButton(FontOpenCms.SAVE, messages.key(Messages.GUI_BUTTON_SAVE_0), true);
    m_save.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            save();
        }

    });
    m_save.setEnabled(false);
    context.addToolbarButton(m_save);

    Button undo = CmsToolBar.createButton(FontOpenCms.UNDO, messages.key(Messages.GUI_BUTTON_UNDO_0), true);
    context.addToolbarButton(undo);

    Button redo = CmsToolBar.createButton(FontOpenCms.REDO, messages.key(Messages.GUI_BUTTON_REDO_0), true);
    context.addToolbarButton(redo);

    m_codeMirror.registerUndoRedo(undo, redo);

    Button search = CmsToolBar.createButton(FontOpenCms.SEARCH, messages.key(Messages.GUI_BUTTON_SEARCH_0),
            true);
    context.addToolbarButton(search);

    Button replace = CmsToolBar.createButton(FontOpenCms.SEARCH_REPLACE,
            messages.key(Messages.GUI_BUTTON_REPLACE_0), true);
    context.addToolbarButton(replace);

    m_codeMirror.registerSearchReplace(search, replace);

    EditorSettings settings;
    try {
        settings = OpenCms.getWorkplaceAppManager().getAppSettings(A_CmsUI.getCmsObject(),
                EditorSettings.class);

    } catch (Exception e) {
        settings = new EditorSettings();
    }

    final Button toggleHighlight = CmsToolBar.createButton(FontOpenCms.HIGHLIGHT,
            messages.key(Messages.GUI_BUTTON_TOGGLE_HIGHLIGHTING_0));
    toggleHighlight.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setHighlighting(!pressed);
        }

    });
    if (settings.m_highlighting) {
        m_codeMirror.setHighlighting(true);
        toggleHighlight.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setHighlighting(false);
    }
    context.addToolbarButtonRight(toggleHighlight);

    final Button toggleLineWrap = CmsToolBar.createButton(FontOpenCms.WRAP_LINES,
            messages.key(Messages.GUI_BUTTON_TOGGLE_LINE_WRAPPING_0));
    toggleLineWrap.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setLineWrapping(!pressed);
        }

    });
    if (settings.m_lineWrapping) {
        m_codeMirror.setLineWrapping(true);
        toggleLineWrap.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setLineWrapping(false);
    }
    context.addToolbarButtonRight(toggleLineWrap);

    final Button toggleBrackets = CmsToolBar.createButton(FontOpenCms.BRACKETS,
            messages.key(Messages.GUI_BUTTON_TOBBLE_BRACKET_AUTOCLOSE_0));
    toggleBrackets.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setCloseBrackets(!pressed);
        }

    });
    if (settings.m_closeBrackets) {
        m_codeMirror.setCloseBrackets(true);
        toggleBrackets.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setCloseBrackets(false);
    }
    context.addToolbarButtonRight(toggleBrackets);

    final Button toggleTabs = CmsToolBar.createButton(FontOpenCms.INVISIBLE_CHARS,
            messages.key(Messages.GUI_BUTTON_TOGGLE_TAB_VISIBILITY_0));
    toggleTabs.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setTabsVisible(!pressed);
        }

    });
    if (settings.m_tabsVisible) {
        m_codeMirror.setTabsVisible(true);
        toggleTabs.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setTabsVisible(false);
    }
    context.addToolbarButtonRight(toggleTabs);

    ComboBox modeSelect = new ComboBox();
    modeSelect.setWidth("115px");
    modeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    modeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    modeSelect.setNullSelectionAllowed(false);
    modeSelect.setImmediate(true);
    modeSelect.setNewItemsAllowed(false);
    for (CodeMirrorLanguage lang : CodeMirrorLanguage.values()) {
        modeSelect.addItem(lang);
        modeSelect.setItemCaption(lang, lang.name());
    }
    CodeMirrorLanguage lang = getHighlightMode(resource);
    modeSelect.setValue(lang);
    m_codeMirror.setLanguage(lang);
    modeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            m_codeMirror.setLanguage((CodeMirrorLanguage) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(modeSelect);

    ComboBox fontSizeSelect = new ComboBox();
    fontSizeSelect.setWidth("75px");
    fontSizeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    fontSizeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    fontSizeSelect.setNullSelectionAllowed(false);
    fontSizeSelect.setImmediate(true);
    fontSizeSelect.setNewItemsAllowed(false);
    for (int i = 0; i < FONT_SIZES.length; i++) {
        fontSizeSelect.addItem(FONT_SIZES[i]);
    }
    fontSizeSelect.setValue(settings.m_fontSize);
    fontSizeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            m_codeMirror.setFontSize((String) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(fontSizeSelect);
    m_codeMirror.setFontSize(settings.m_fontSize);

    m_exit = CmsToolBar.createButton(FontOpenCms.EXIT, messages.key(Messages.GUI_BUTTON_CANCEL_0), true);
    m_exit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            exit();
        }

    });
    context.addToolbarButtonRight(m_exit);

    try {
        m_file = LockedFile.lockResource(A_CmsUI.getCmsObject(), resource);
        String content = new String(m_file.getFile().getContents(), m_file.getEncoding());
        m_codeMirror.setValue(content);
    } catch (Exception e) {
        CmsErrorDialog.showErrorDialog(e);
    }
    m_codeMirror.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            onChange((String) event.getProperty().getValue());
        }
    });
}

From source file:rs.pupin.jpo.esta_ld.EstaLdComponent.java

private void refreshDimensions() {
    // clean everything just in case
    dimLayout.removeAllComponents();//from   w  w  w .ja v a  2  s. c o  m
    geoDimension = null;
    timeDimension = null;
    measures = null;
    btnGeo = null;
    boxGeo = null;
    dimNames = null;
    dimValues = null;

    if (selectDataSet.getValue() == null)
        return;

    //        VerticalLayout lLayout = new VerticalLayout();
    //        lLayout.setSizeUndefined();
    //        lLayout.setSpacing(true);
    //        lLayout.setDebugId("dim-btn-layout");
    //        dimLayout.addComponent(lLayout);
    //        VerticalLayout rLayout = new VerticalLayout();
    //        rLayout.setSizeUndefined();
    //        rLayout.setSpacing(true);
    //        rLayout.setWidth("100%");
    //        dimLayout.addComponent(rLayout);
    //        dimLayout.setExpandRatio(rLayout, 2.0f);

    final DataSet ds = (DataSet) selectDataSet.getValue();
    measures = ds.getStructure().getMeasures();
    StringBuilder builderMeasures = new StringBuilder();
    StringBuilder builderMeasureNames = new StringBuilder();
    for (Measure m : measures) {
        builderMeasures.append(", '");
        builderMeasures.append(m.getUri());
        builderMeasures.append("'");
        if (m.getLabel() != null) {
            builderMeasureNames.append(", '");
            builderMeasureNames.append(m.getLabel());
            builderMeasureNames.append("'");
        } else {
            builderMeasureNames.append(", undefined");
        }
    }
    builderMeasureNames.replace(0, 2, "[").append("]");
    builderMeasures.replace(0, 2, "javaSetMeasures([");
    builderMeasures.append("], ").append(builderMeasureNames.toString()).append(")");
    getWindow().executeJavaScript(builderMeasures.toString());
    measName = new Button("Measure");
    //        measName.setSizeUndefined();
    //        measName.setWidth("100%");
    measName.setHeight(CONTENT_ELEM_HEIGHT);
    measName.setWidth(CONTENT_ELEM_WIDTH);
    measName.addStyleName("dim-name");
    measName.addStyleName("unselectable");
    measValues = new ComboBox(null, measures);
    measValues.setImmediate(true);
    measValues.setSizeUndefined();
    measValues.setWidth("100%");
    measValues.setHeight(CONTENT_ELEM_HEIGHT);
    measValues.addStyleName("dim-value");
    measValues.setNullSelectionAllowed(false);
    measValues.select(measures.iterator().next());
    measValues.addListener(dimListener);
    //        measValues.addListener(new Property.ValueChangeListener() {
    //            public void valueChange(Property.ValueChangeEvent event) {
    //                Measure m = (Measure)event.getProperty().getValue();
    //                // put measure in
    //            }
    //        });
    int rowIndex = 0;
    int columnIndex = 0;
    dimLayout.addComponent(measName, columnIndex, rowIndex);
    columnIndex++;
    //        dimLayout.setExpandRatio(measName, 2.0f);
    dimLayout.addComponent(measValues, columnIndex, rowIndex, columnIndex + 1, rowIndex);
    columnIndex += 2;
    //        dimLayout.setComponentAlignment(measValues, Alignment.BOTTOM_LEFT);
    LinkedList<Dimension> dimsForShow = new LinkedList<Dimension>();
    for (Dimension dim : ds.getStructure().getDimensions()) {
        if (dim.isGeoDimension())
            geoDimension = dim;
        else if (dim.isTimeDimension()) {
            timeDimension = dim;
            dimsForShow.addFirst(dim);
        } else
            dimsForShow.add(dim);
    }
    dimNames = new Button[dimsForShow.size()];
    dimAggregIndicators = new Label[dimsForShow.size()];
    dimValues = new ComboBox[dimsForShow.size()];
    int i = 0;

    StringBuilder builderPossibleValues = new StringBuilder();
    boolean firstPass = true;

    for (Dimension dim : dimsForShow) {
        // add dimension pick
        // first create a button to represent dimension name
        final Button btnName = new Button(dim.toString());
        //            btnName.setSizeUndefined();
        //            btnName.setWidth("100%");
        btnName.setHeight(CONTENT_ELEM_HEIGHT);
        btnName.setWidth(CONTENT_ELEM_WIDTH);
        btnName.setData(dim);
        btnName.addStyleName("dim-name");
        if (firstPass) {
            btnName.addStyleName("selected");
            firstPass = false;
        }
        btnName.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                if (btnName.getStyleName().contains("selected")) {
                    btnName.removeStyleName("selected");
                } else {
                    btnName.addStyleName("selected");
                }
                freeDimensionsChanged();
            }
        });
        dimNames[i] = btnName;

        final Label btnAggreg = new Label("<span>&Sigma;</span>", Label.CONTENT_XHTML);
        btnAggreg.setWidth("30px");
        btnAggreg.setHeight(CONTENT_ELEM_HEIGHT);
        btnAggreg.setData(dim);
        btnAggreg.addStyleName("dim-name");
        btnAggreg.addStyleName("dim-aggreg");
        // this will have to go to the layout listener
        //            btnAggreg.addListener(new Button.ClickListener() {
        //                public void buttonClick(Button.ClickEvent event) {
        //                    if (btnAggreg.getStyleName().contains("selected")) {
        //                        btnAggreg.removeStyleName("selected");
        //                    } else {
        //                        btnAggreg.addStyleName("selected");
        //                        aggregDimensionsChanged();
        //                    }
        //                }
        //            });
        dimAggregIndicators[i] = btnAggreg;

        // create a combo box for picking dimension value
        Collection<Value> vals = ds.getValuesForDimension(dim);
        Collection<ValueWrapper> valsWrapped = new LinkedList<ValueWrapper>();
        for (Value v : vals)
            valsWrapped.add(new ValueWrapper(v));
        builderPossibleValues.append(",").append(stringifyCollection(vals));
        ComboBox boxValue = new ComboBox(null, valsWrapped);
        boxValue.setImmediate(true);
        boxValue.setNullSelectionAllowed(false);
        if (valsWrapped.iterator().hasNext())
            boxValue.select(valsWrapped.iterator().next());
        else
            boxValue.setEnabled(false);
        boxValue.setSizeUndefined();
        boxValue.setWidth("100%");
        boxValue.setHeight(CONTENT_ELEM_HEIGHT);
        boxValue.addStyleName("dim-value");
        boxValue.addListener(dimListener);
        dimValues[i] = boxValue;

        // put them in a horizontal layout and add to the view
        //            HorizontalLayout layout = new HorizontalLayout();
        //            layout.setSizeUndefined();
        //            layout.setWidth("100%");
        //            layout.setSpacing(true);
        //            dimLayout.addComponent(layout);
        //            dimLayout.setExpandRatio(layout, 2.0f);
        //            layout.addComponent(btnName);
        //            layout.addComponent(boxValue);
        //            layout.setExpandRatio(boxValue, 2.0f);

        //            lLayout.addComponent(btnName);
        //            lLayout.setExpandRatio(btnName, 2.0f);
        //            rLayout.addComponent(boxValue);
        //            rLayout.setComponentAlignment(boxValue, Alignment.BOTTOM_LEFT);
        dimLayout.addComponent(btnName, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        dimLayout.addComponent(btnAggreg, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        dimLayout.addComponent(boxValue, columnIndex, rowIndex);
        if (++columnIndex == 6) {
            columnIndex = 0;
            rowIndex++;
            dimLayout.setRows(rowIndex + 1);
        }
        i++;
    }

    if (timeDimension != null)
        getWindow().executeJavaScript("javaSetHasTimeDimension(true)");
    else
        getWindow().executeJavaScript("javaSetHasTimeDimension(false)");

    if (geoDimension != null) {
        btnGeo = new Button(geoDimension.toString());
        //            btnGeo.setSizeUndefined();
        //            btnGeo.setWidth("100%");
        btnGeo.setHeight(CONTENT_ELEM_HEIGHT);
        btnGeo.setWidth(CONTENT_ELEM_WIDTH);
        btnGeo.setData(geoDimension);
        btnGeo.addStyleName("dim-name");
        btnGeo.addStyleName("geo-name");
        btnGeo.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                if (btnGeo.getStyleName().contains("selected")) {
                    btnGeo.removeStyleName("selected");
                } else {
                    btnGeo.addStyleName("selected");
                }
                freeDimensionsChanged();
            }
        });

        btnAggregGeo = new Label("<span>&Sigma;</span>", Label.CONTENT_XHTML);
        btnAggregGeo.setHeight(CONTENT_ELEM_HEIGHT);
        btnAggregGeo.setData(geoDimension);
        btnAggregGeo.addStyleName("dim-name");
        btnAggregGeo.addStyleName("dim-aggreg");

        StringBuilder builder = new StringBuilder();
        Collection<Value> posVals = ds.getValuesForDimension(geoDimension);
        Collection<ValueWrapper> posValsWrapped = new LinkedList<ValueWrapper>();
        for (Value v : posVals)
            posValsWrapped.add(new ValueWrapper(v));
        Value selectedVal = posVals.iterator().next();
        String selectedValString = "";
        if (selectedVal instanceof URI) {
            selectedValString = "<" + selectedVal.stringValue() + ">";
        } else {
            selectedValString = "\"" + selectedVal.stringValue() + "\"";
            URI dataType = ((Literal) selectedVal).getDatatype();
            if (dataType != null && !dataType.stringValue().contains("string")) {
                selectedValString += "^^<" + dataType.stringValue() + ">";
            }
        }
        builder.append("javaSetGeoAll('").append(geoDimension.getUri());
        builder.append("',").append(stringifyCollection(posVals));
        builder.append(",'").append(selectedValString).append("',true)");
        boxGeo = new ComboBox(null, posValsWrapped);
        boxGeo.setData(posVals);
        boxGeo.setImmediate(true);
        boxGeo.setNullSelectionAllowed(false);
        boxGeo.select(posValsWrapped.iterator().next());
        boxGeo.setSizeUndefined();
        boxGeo.setWidth("100%");
        boxGeo.setHeight(CONTENT_ELEM_HEIGHT);
        boxGeo.addStyleName("geo-value");
        boxGeo.addListener(geoListener);
        //            lLayout.addComponent(btnGeo);
        //            lLayout.setExpandRatio(btnGeo, 2.0f);
        //            rLayout.addComponent(boxGeo);
        //            rLayout.setComponentAlignment(boxGeo, Alignment.BOTTOM_LEFT);
        dimLayout.addComponent(btnGeo, columnIndex, rowIndex);
        columnIndex++;
        dimLayout.addComponent(btnAggregGeo, columnIndex, rowIndex);
        columnIndex++;
        dimLayout.addComponent(boxGeo, columnIndex, rowIndex);
        columnIndex++;

        getWindow().executeJavaScript(builder.toString());
    } else {
        getWindow().executeJavaScript("javaSetGeoAll('',[],'',true)");
    }
    // TODO cover the case where there is more than 1 geo dimension

    builderPossibleValues.replace(0, 1, "javaSetPossibleValues([");
    builderPossibleValues.append("])");
    getWindow().executeJavaScript(builderPossibleValues.toString());
    if (dimsForShow.isEmpty()) {
        if (geoDimension != null)
            getWindow().executeJavaScript("javaSetGeoFree(true)");
        else
            getWindow().executeJavaScript("javaSetGeoFree(false)");
        getWindow().executeJavaScript("javaSetFreeDimensions([], true)");
    } else {
        getWindow().executeJavaScript("javaSetGeoFree(false)");
        getWindow().executeJavaScript("javaSetFreeDimensions([0], true)");
    }
    dimListener.valueChange(null);
    getWindow().executeJavaScript("setTimeout(expandDimNameButtons(),200)");
}