List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:org.eclipse.wb.internal.core.utils.XmlWriter.java
/** * Closes previously open tag. Calling closeTag() when "tag1" is open will results writing * "</tag1>" into underlying {@link PrintWriter}. If tag was open for adding attribute then * closing this tag causes write "/>".After this operation is possibly to open new tag. *//* www . ja va 2 s . co m*/ public void closeTag() { checkOpen(); TagInfo currentTag = peek(); boolean validState = false; if (isState(currentTag, TAG_STATE_BEGIN_NOT_ENDED)) { m_printWriter.println("/>"); m_isShortTagClosed = true; validState = true; } else if (hasState(currentTag, TAG_STATE_OPEN)) { if (hasState(currentTag, TAG_STATE_HAS_CHILDRED)) { if (hasState(currentTag, TAG_STATE_HAS_VALUE)) { m_printWriter.println(); } m_printWriter.print(StringUtils.repeat(getIndent(), m_tagStack.size() - 1)); } m_printWriter.println("</" + currentTag.getName() + ">"); validState = true; } else if (hasState(currentTag, TAG_STATE_CDATA_OPEN)) { m_printWriter.println("</" + currentTag.getName() + ">"); validState = true; } if (!validState) { close(); throw new IllegalStateException("Can't do close operation when currently no open tag."); } m_tagStack.pop(); }
From source file:org.eclipse.wb.internal.rcp.model.widgets.SashFormInfo.java
/** * Ensures that this {@link SashFormInfo} has "setWeights()" invocation. * /*from w w w. ja v a2 s. com*/ * @return the {@link ArrayInitializer} for weights. */ private ArrayInitializer ensureWeights() throws Exception { MethodInvocation invocation = getMethodInvocation("setWeights(int[])"); if (invocation == null) { String elementsSource; { elementsSource = StringUtils.repeat("1, ", getChildrenControls().size()); elementsSource = StringUtils.removeEnd(elementsSource, ", "); } // add invocation String arraySource = "new int[] {" + elementsSource + "}"; invocation = addMethodInvocation("setWeights(int[])", arraySource); } return ((ArrayCreation) DomGenerics.arguments(invocation).get(0)).getInitializer(); }
From source file:org.eclipse.wb.internal.swing.databinding.wizards.autobindings.SwingDatabindingProvider.java
public String performSubstitutions(String code, ImportsManager imports) throws Exception { // calculate states boolean blockMode = useBlockMode(); boolean lazyVariables = createLazyVariables(); ////from ww w.j a v a2 s. com DataBindingsCodeUtils.ensureDBLibraries(m_javaProject); CodeGenerationSupport generationSupport = new CodeGenerationSupport(CoreUtils.useGenerics(m_javaProject)); // prepare imports Collection<String> importList = Sets.newHashSet(); importList.add("java.awt.GridBagLayout"); importList.add("java.awt.GridBagConstraints"); importList.add("java.awt.Insets"); importList.add("javax.swing.JLabel"); importList.add("org.jdesktop.beansbinding.AutoBinding"); importList.add("org.jdesktop.beansbinding.Bindings"); importList.add("org.jdesktop.beansbinding.BeanProperty"); // if (!generationSupport.useGenerics()) { importList.add("org.jdesktop.beansbinding.Property"); } // bean class, field, name, field access String beanClassName = m_beanClass.getName().replace('$', '.'); String beanClassShortName = ClassUtils.getShortClassName(beanClassName); String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES); String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName); // code = StringUtils.replace(code, "%BeanClass%", beanClassName); // if (ReflectionUtils.getConstructorBySignature(m_beanClass, "<init>()") == null) { code = StringUtils.replace(code, "%BeanField%", fieldName); } else { code = StringUtils.replace(code, "%BeanField%", fieldName + " = new " + beanClassName + "()"); } // IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences(); String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : ""; String beanFieldAccess = accessPrefix + fieldName; // code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName)); code = StringUtils.replace(code, "%BeanFieldAccess%", accessPrefix + fieldName); // prepare properties final List<PropertyAdapter> properties = Lists.newArrayList(); Display.getDefault().syncExec(new Runnable() { public void run() { CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements()); } }); // prepare code StringBuffer componentFields = new StringBuffer(); StringBuffer components = new StringBuffer(); String swingContainer = StringUtils.substringBetween(code, "%Components%", "%"); String swingContainerWithDot = "this".equals(swingContainer) ? "" : swingContainer + "."; // int propertiesCount = properties.size(); int lastPropertyIndex = propertiesCount - 1; StringBuffer bindings = new StringBuffer(); // prepare layout code components.append("\t\tGridBagLayout gridBagLayout = new GridBagLayout();\r\n"); components.append("\t\tgridBagLayout.columnWidths = new int[]{0, 0, 0};\r\n"); components.append("\t\tgridBagLayout.rowHeights = new int[]{" + StringUtils.repeat("0, ", propertiesCount) + "0};\r\n"); components.append("\t\tgridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0E-4};\r\n"); components.append("\t\tgridBagLayout.rowWeights = new double[]{" + StringUtils.repeat("0.0, ", propertiesCount) + "1.0E-4};\r\n"); components.append("\t\t" + swingContainerWithDot + "setLayout(gridBagLayout);\r\n"); // StringBuffer group = new StringBuffer(); generationSupport.generateLocalName("bindingGroup"); // StringBuffer lazy = new StringBuffer(); // for (int i = 0; i < propertiesCount; i++) { String index = Integer.toString(i); // PropertyAdapter property = properties.get(i); Object[] editorData = m_propertyToEditor.get(property); SwingComponentDescriptor componentDescriptor = (SwingComponentDescriptor) editorData[0]; // String propertyName = property.getName(); // label addLabelCode(componentFields, components, lazy, swingContainerWithDot, blockMode, lazyVariables, propertyName, index); // String componentClassName = componentDescriptor.getComponentClass(); String componentShortClassName = ClassUtils.getShortClassName(componentClassName); String componentFieldName = fieldPrefix + propertyName + componentShortClassName; String componentFieldAccess = accessPrefix + componentFieldName; String componentLazyAccess = "get" + StringUtils.capitalize(propertyName) + componentShortClassName + "()"; String componentAccess = lazyVariables ? componentLazyAccess : componentFieldAccess; // importList.add(componentClassName); // field componentFields .append("\r\nfield\r\n\tprivate " + componentShortClassName + " " + componentFieldName + ";"); // component addComponentCode(components, lazy, swingContainerWithDot, blockMode, lazyVariables, componentShortClassName, componentFieldAccess, componentLazyAccess, index); // binding properties AutoBindingUpdateStrategyDescriptor strategyDescriptor = (AutoBindingUpdateStrategyDescriptor) editorData[1]; // String modelPropertyName = generationSupport.generateLocalName(propertyName, "Property"); String targetPropertyName = generationSupport.generateLocalName(componentDescriptor.getName(1), "Property"); String bindingName = generationSupport.generateLocalName("autoBinding"); String modelGeneric = null; String targetGeneric = null; // if (generationSupport.useGenerics()) { modelGeneric = beanClassName + ", " + GenericUtils.convertPrimitiveType(property.getType().getName()); bindings.append("\t\tBeanProperty<" + modelGeneric + "> "); } else { bindings.append("\t\tProperty "); } bindings.append(modelPropertyName + " = BeanProperty.create(\"" + propertyName + "\");\r\n"); // if (generationSupport.useGenerics()) { targetGeneric = componentDescriptor.getComponentClass() + ", " + componentDescriptor.getPropertyClass(); bindings.append("\t\tBeanProperty<" + targetGeneric + "> "); } else { bindings.append("\t\tProperty "); } bindings.append( targetPropertyName + " = BeanProperty.create(\"" + componentDescriptor.getName(1) + "\");\r\n"); // binding bindings.append("\t\tAutoBinding"); if (generationSupport.useGenerics()) { bindings.append("<" + modelGeneric + ", " + targetGeneric + ">"); } bindings.append(" " + bindingName + " = Bindings.createAutoBinding(" + strategyDescriptor.getSourceCode() + ", " + beanFieldAccess + ", " + modelPropertyName + ", " + componentAccess + ", " + targetPropertyName + ");\r\n"); bindings.append("\t\t" + bindingName + ".bind();"); // group.append("\t\tbindingGroup.addBinding(" + bindingName + ");"); // if (i < lastPropertyIndex) { componentFields.append("\r\n"); components.append("\r\n"); bindings.append("\r\n\t\t//\r\n"); group.append("\r\n"); } // } // replace template patterns code = StringUtils.replace(code, "%ComponentFields%", componentFields.toString()); code = StringUtils.replace(code, "%Components%" + swingContainer + "%", components.toString()); code = StringUtils.replace(code, "%Bindings%", bindings.toString()); code = StringUtils.replace(code, "%Group%", group.toString()); code = StringUtils.replace(code, "%LAZY%", lazy.toString()); // add imports for (String qualifiedTypeName : importList) { imports.addImport(qualifiedTypeName); } // return code; }
From source file:org.eclipse.wb.internal.swing.java6.model.GapSpringInfo.java
@Override public void dump(int level, StringBuffer buffer) { buffer.append(StringUtils.repeat(" ", level)); if (isContainer()) { buffer.append("G cont sizes="); buffer.append((m_pref == UNSET ? "UNSET" : m_pref) + " "); buffer.append((m_max == UNSET ? "UNSET" : m_max)); } else if (isPreferred()) { buffer.append("G pref=" + m_placement + " sizes="); buffer.append((m_pref == UNSET ? "UNSET" : m_pref) + " "); buffer.append((m_max == UNSET ? "UNSET" : m_max)); if (m_widget1 != null) { }// w w w.ja va 2 s . c o m } else { buffer.append("G sizes="); super.dump(level, buffer); } buffer.append("\n"); }
From source file:org.eclipse.wb.internal.swing.java6.model.ParallelGroupInfo.java
@Override protected String getCode(int level) throws Exception { String code = StringUtils.repeat(" ", level); if (m_alignment == Alignment.BASELINE && m_anchoredToTop) { code += GroupLayoutInfo.IDENTIFIER_CREATE_BASELINE_GROUP + "("; } else {// w w w .java 2s .c o m code += GroupLayoutInfo.IDENTIFIER_CREATE_PARALLEL_GROUP + "("; } return code; }
From source file:org.eclipse.wb.internal.swing.java6.model.ParallelGroupInfo.java
@Override public void dump(int level, StringBuffer buffer) { buffer.append(StringUtils.repeat(" ", level)); buffer.append("P align=" + m_alignment + " resiz=" + m_resizeable + "\n"); for (SpringInfo child : m_children) { child.dump(level + 1, buffer);//from w w w . j ava 2s . c o m } }
From source file:org.eclipse.wb.internal.swing.java6.model.SequentialGroupInfo.java
@Override public void dump(int level, StringBuffer buffer) { buffer.append(StringUtils.repeat(" ", level)); buffer.append("S\n"); for (SpringInfo child : m_children) { child.dump(level + 1, buffer);//from w ww. j a va 2s . com } }
From source file:org.eclipse.wb.internal.swing.java6.model.WidgetSpringInfo.java
@Override public void dump(int level, StringBuffer buffer) { String name = m_widget.getVariableSupport().getName(); buffer.append(StringUtils.repeat(" ", level)); buffer.append("W align=" + m_alignment + " name="); buffer.append((name == null ? m_widget.toString() : name) + " sizes="); super.dump(level, buffer); buffer.append("\n"); }
From source file:org.eclipse.wb.internal.swing.model.component.menu.JPopupMenuAssociation.java
/** * Ensures that {@link TypeDeclaration} has method "addPopup()", that is used by Designer to * attach {@link JPopupMenu} to {@link Component}. */// w w w .ja va 2 s. c om private void ensure_addPopup(AstEditor editor, StatementTarget target) throws Exception { TypeDeclaration typeDeclaration = editor.getEnclosingType(target.getPosition()); if (AstNodeUtils.getMethodBySignature(typeDeclaration, "addPopup(java.awt.Component,javax.swing.JPopupMenu)") == null) { // prepare method lines List<String> lines = Lists.newArrayList(); { lines.add("component.addMouseListener(new java.awt.event.MouseAdapter() {"); lines.add(" public void mousePressed(java.awt.event.MouseEvent e) {"); lines.add(" if (e.isPopupTrigger()) {"); lines.add(" showMenu(e);"); lines.add(" }"); lines.add(" }"); lines.add(" public void mouseReleased(java.awt.event.MouseEvent e) {"); lines.add(" if (e.isPopupTrigger()) {"); lines.add(" showMenu(e);"); lines.add(" }"); lines.add(" }"); lines.add(" private void showMenu(java.awt.event.MouseEvent e) {"); lines.add(" popup.show(e.getComponent(), e.getX(), e.getY());"); lines.add(" }"); lines.add("});"); // replace spaces with "\t" for (ListIterator<String> I = lines.listIterator(); I.hasNext();) { String line = I.next(); // prepare count of leading spaces int spaceCount = 0; for (char c : line.toCharArray()) { if (c != ' ') { break; } spaceCount++; } // replace each two leading spaces with one \t line = StringUtils.repeat("\t", spaceCount / 2) + line.substring(spaceCount); I.set(line); } } // add method { String header = "private static void addPopup(java.awt.Component component, " + "final javax.swing.JPopupMenu popup)"; BodyDeclarationTarget methodTarget = new BodyDeclarationTarget(typeDeclaration, false); editor.addMethodDeclaration(header, lines, methodTarget); } } }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.DimensionOperations.java
/** * Sets the value for element of {@link ArrayInitializer} assigned to field.<br> * If there are no assignment to this field, adds assignment. */// w w w.ja v a 2 s.c o m private void setFieldArrayElement(String fieldName, String typeName, String emptyElementSource, int index, String elementSource) throws Exception { ArrayInitializer initializer = getFieldArrayInitializer(fieldName); // ensure assignment if (initializer == null) { String initializerSource = StringUtils.repeat(", " + emptyElementSource, getDimensions().size()) .substring(2); String fieldSource = MessageFormat.format("new {0}[]'{'{1}'}'", typeName, initializerSource); m_layout.addFieldAssignment(fieldName, fieldSource); initializer = getFieldArrayInitializer(fieldName); } // replace element m_editor.replaceExpression(DomGenerics.expressions(initializer).get(index), elementSource); }