List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:org.eclipse.wb.internal.css.dialogs.color.ColorDialog.java
/** * @return the {@link RGB} of given named color, may be <code>null</code>. *//*w w w . j a va2 s. com*/ public static RGB getRGB(String name) { RGB rgb; rgb = NamedColorsComposite.getRGB(name); if (rgb == null && SystemUtils.IS_OS_WINDOWS) { rgb = SystemColorsComposite.getRGB(name); } if (rgb == null && name.length() == 7) { name = StringUtils.removeStart(name, "#"); int r = Integer.parseInt(name.substring(0, 2), 16); int g = Integer.parseInt(name.substring(2, 4), 16); int b = Integer.parseInt(name.substring(4, 6), 16); rgb = new RGB(r, g, b); } if (rgb == null && name.length() == 4) { name = StringUtils.removeStart(name, "#"); int r0 = Integer.parseInt(name.substring(0, 1), 16); int g0 = Integer.parseInt(name.substring(1, 2), 16); int b0 = Integer.parseInt(name.substring(2, 3), 16); int r = (r0 << 4) + r0; int g = (g0 << 4) + g0; int b = (b0 << 4) + b0; rgb = new RGB(r, g, b); } return rgb; }
From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo.java
/** * @return {@link PropertyBindableInfo} property that association with given reference or or * <code>null</code>. *//* ww w.j av a 2 s. co m*/ @Override public final PropertyBindableInfo resolvePropertyReference(String reference) throws Exception { if (reference.indexOf('.') == -1 || !reference.startsWith("\"")) { for (PropertyBindableInfo property : getProperties()) { if (reference.equals(property.getReference())) { return property; } } } else { String localReference = StringUtils.removeStart(reference, "\""); localReference = StringUtils.removeEnd(localReference, "\""); return resolvePropertyReference(reference, StringUtils.split(localReference, "."), 0); } return null; }
From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo.java
protected final PropertyBindableInfo resolvePropertyReference(String reference, String[] references, int index) throws Exception { if (index == references.length - 1) { for (PropertyBindableInfo property : getProperties()) { if (reference.equals(property.getReference())) { return property; }/* w w w. j av a2 s . co m*/ } } else { String localReference = references[index]; // for (PropertyBindableInfo property : getProperties()) { String propertyReference = StringUtils.removeStart(property.getReference(), "\""); propertyReference = StringUtils.removeEnd(propertyReference, "\""); int pointIndex = propertyReference.lastIndexOf('.'); // if (pointIndex != -1) { propertyReference = propertyReference.substring(pointIndex + 1); } if (localReference.equals(propertyReference)) { return property.resolvePropertyReference(reference, references, index + 1); } } } return null; }
From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanPropertyDescriptorBindableInfo.java
private static IObservePresentation createPresentation(IObserveInfo parent, String reference, Class<?> objectType) throws Exception { if (parent instanceof BeanPropertyDescriptorBindableInfo) { BeanPropertyDescriptorBindableInfo bindableParent = (BeanPropertyDescriptorBindableInfo) parent; String parentReference = StringUtils.removeStart(bindableParent.getReference(), "\""); parentReference = StringUtils.removeEnd(parentReference, "\""); ////from www . ja v a2 s .c o m final String bindingReference = parentReference + "." + reference; return new SimpleObservePresentation(reference, bindingReference, TypeImageProvider.getImage(objectType)); } return new SimpleObservePresentation(reference, TypeImageProvider.getImage(objectType)); }
From source file:org.eclipse.wb.internal.rcp.databinding.model.ControllerSupport.java
/** * Create for given {@link JavaInfo} public getter method. *//*from ww w . j av a 2 s. com*/ public static String ensureControllerReference(DatabindingsProvider provider, JavaInfo javaInfo, boolean commit) throws Exception { // prepare target TypeDeclaration typeDeclaration = JavaInfoUtils.getTypeDeclaration(javaInfo); BodyDeclarationTarget target = new BodyDeclarationTarget(typeDeclaration, null, false); // prepare method name String reference = JavaInfoReferenceProvider.getReference(javaInfo); String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES); fieldPrefix = fieldPrefix == null ? "m_" : fieldPrefix; String methodName = "get" + StringUtils.capitalize(StringUtils.removeStart(reference, fieldPrefix)) + "()"; // prepare method header String header = "public " + javaInfo.getDescription().getComponentClass().getName() + " " + methodName; // prepare method lines List<String> methodLines = ImmutableList.of("return " + reference + ";"); // add method javaInfo.getEditor().addMethodDeclaration(header, methodLines, target); if (commit) { javaInfo.getEditor().commitChanges(); } // controller reference return provider.getControllerViewerField() + "." + methodName; }
From source file:org.eclipse.wb.internal.swing.parser.SwingRewriteProcessor.java
private void rewrite_SuperMethodInvocation() { typeDeclaration.accept(new AstVisitorEx() { @Override// w w w.j a va 2 s. c o m public void endVisitEx(SuperMethodInvocation node) throws Exception { if (AstNodeUtils.isMethodInvocation(node, "java.awt.Container", "setLayout(java.awt.LayoutManager)")) { String superSource = editor.getSource(node); String source = StringUtils.removeStart(superSource, "super."); editor.replaceExpression(node, source); } } }); }
From source file:org.eclipse.wb.internal.xwt.model.jface.ViewerInfo.java
/** * @return the name of property which corresponds to the given getter {@link Method}. *//*ww w. j a v a 2s. c om*/ private static String getPropertyName(Method method) { String property = StringUtils.removeStart(method.getName(), "get"); return StringUtils.uncapitalize(property); }
From source file:org.eclipse.wb.internal.xwt.model.layout.form.FormDataInfo.java
private static String getAttachmentSideName(FormAttachmentInfo attachment) { String property = attachment.getElement().getParent().getTag(); return StringUtils.removeStart(property, "FormData."); }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.color.ColorSupport.java
/** * @return the {@link ColorInfo}s for {@link SWT} constants. *//*from www. jav a 2 s . c om*/ public static synchronized ColorInfo[] getSystemColors() { if (m_systemColors == null) { String[] names = XWTMaps.getColorKeys().toArray(new String[0]); m_systemColors = new ColorInfo[names.length]; for (int i = 0; i < names.length; i++) { String name = names[i]; // prepare Color Color color; { int id = XWTMaps.getColor(name); color = SwtResourceManager.getColor(id); } // create ColorInfo { name = StringUtils.removeStart(name, "SWT."); ColorInfo colorInfo = new ColorInfo(name, color.getRGB()); colorInfo.setData(name); m_systemColors[i] = colorInfo; } } } return m_systemColors; }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.ImagePropertyEditor.java
@Override protected void openDialog(Property property) throws Exception { GenericProperty genericProperty = (GenericProperty) property; EditorContext context = genericProperty.getObject().getContext(); IJavaProject javaProject = context.getJavaProject(); String packagePath = getContextPackagePath(context); // create dialog ImageDialog imageDialog = new ImageDialog(javaProject); // set input for dialog {//from www .ja va2 s .c om String text = getText(property); if (text == null) { imageDialog.setInput(DefaultImagePage.ID, null); } else { if (!text.startsWith("/")) { text = packagePath + text; } imageDialog.setInput(ClasspathImagePage.ID, text); } } // open dialog if (imageDialog.open() == Window.OK) { ImageInfo imageInfo = imageDialog.getImageInfo(); // prepare expression String expression = null; { String pageId = imageInfo.getPageId(); if (pageId == DefaultImagePage.ID) { } else { expression = "/" + imageInfo.getData(); expression = StringUtils.removeStart(expression, packagePath); } } // set expression genericProperty.setExpression(expression, Property.UNKNOWN_VALUE); } }