Example usage for org.apache.commons.lang StringUtils repeat

List of usage examples for org.apache.commons.lang StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils repeat.

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor.java

private static void appendSourceItems(JavaInfo javaInfo, int maxLevel, List<String> lines,
        List<ItemInformation> items) throws Exception {
    for (ItemInformation item : items) {
        int level = item.getLevel();
        String text = item.getText();
        String prefix = "\t\t\t" + StringUtils.repeat("\t", level - 1);
        // prepare node source
        String nodeCreation = "new javax.swing.tree.DefaultMutableTreeNode("
                + StringConverter.INSTANCE.toJavaSource(javaInfo, text) + ")";
        // prepare parent access
        String parentAccess;/*ww w .  j  ava  2 s  . c  o m*/
        if (level == 1) {
            parentAccess = "";
        } else {
            parentAccess = "node_" + (level - 1) + ".";
        }
        // add node
        if (item.getChildren().isEmpty()) {
            lines.add(prefix + parentAccess + "add(" + nodeCreation + ");");
        } else {
            // assign node
            lines.add(prefix + "node_" + level + " = " + nodeCreation + ";");
            // append children
            appendSourceItems(javaInfo, maxLevel, lines, item.getChildren());
            // add node
            lines.add(prefix + parentAccess + "add(node_" + level + ");");
        }
    }
}

From source file:org.eclipse.wb.internal.xwt.model.widgets.SashFormInfo.java

/**
 * Ensures that this {@link SashFormInfo} has "weights" attribute.
 *//*from w  w  w  .  j  a  va2 s .c  om*/
private String ensureWeights() throws Exception {
    DocumentElement element = getCreationSupport().getElement();
    String weightsString = element.getAttribute("weights");
    if (weightsString == null) {
        weightsString = StringUtils.repeat("1, ", getChildrenControls().size());
        weightsString = StringUtils.removeEnd(weightsString, ", ");
        element.setAttribute("weights", weightsString);
    }
    return weightsString;
}

From source file:org.eclipse.wb.internal.xwt.parser.XwtRenderer.java

/**
 * XWT behaves weird when "Composite" is rendered using XWT and used also in "x:Class" attribute.
 * So, we remove "x:Class" at design time.
 *//*from w ww.  ja  va  2 s.  co  m*/
private String removeCompositeClassAttribute(String content) {
    DocumentElement rootElement = m_context.getRootElement();
    DocumentAttribute classAttribute = rootElement.getDocumentAttribute("x:Class");
    if (rootElement.getTagLocal().equals("Composite") && classAttribute != null) {
        int begin = classAttribute.getNameOffset();
        int end = classAttribute.getValueOffset() + classAttribute.getValueLength() + 1;
        content = content.substring(0, begin) + StringUtils.repeat(" ", end - begin) + content.substring(end);
    }
    return content;
}

From source file:org.eclipse.wb.tests.designer.core.model.parser.AbstractJavaInfoRelatedTest.java

/**
 * Creates string for hierarchy of {@link JavaInfo}'s starting from given root.
 *//*  w ww  .j  a  va2 s  .com*/
protected static String printHierarchy(JavaInfo root) {
    final StringBuffer buffer = new StringBuffer();
    root.accept(new ObjectInfoVisitor() {
        private int m_level;

        @Override
        public boolean visit(ObjectInfo objectInfo) throws Exception {
            buffer.append(StringUtils.repeat("\t", m_level));
            buffer.append(objectInfo.toString());
            buffer.append("\n");
            m_level++;
            return true;
        }

        @Override
        public void endVisit(ObjectInfo objectInfo) throws Exception {
            m_level--;
        }
    });
    return buffer.toString();
}