Example usage for org.apache.commons.collections CollectionUtils addAll

List of usage examples for org.apache.commons.collections CollectionUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils addAll.

Prototype

public static void addAll(Collection collection, Object[] elements) 

Source Link

Document

Adds all elements in the array to the given collection.

Usage

From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java

/**
 * Removes nature to the {@link IProject}.
 *///from w  w  w  .j  a  v a  2 s.  c  om
public static void removeNature(IProject project, String natureId) throws Exception {
    IProjectDescription description = project.getDescription();
    //
    List<String> natureIds = Lists.newArrayList();
    CollectionUtils.addAll(natureIds, description.getNatureIds());
    natureIds.remove(natureId);
    description.setNatureIds(natureIds.toArray(new String[natureIds.size()]));
    //
    project.setDescription(description, null);
}

From source file:org.eclipse.wb.internal.core.utils.reflect.CompositeClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    Set<URL> allResources = Sets.newHashSet();
    for (ClassLoader classLoader : m_classLoaders) {
        Enumeration<URL> resources = classLoader.getResources(name);
        CollectionUtils.addAll(allResources, resources);
    }/*from  www  .j a  v a  2  s.c  o m*/
    return Iterators.asEnumeration(allResources.iterator());
}

From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java

private static void addRuntimeClassPathEntries(List<String> entries, IJavaProject javaProject,
        Set<IJavaProject> visitedProjects, boolean fullClassPath) throws Exception {
    IProject project = javaProject.getProject();
    // not Java project
    if (!javaProject.exists()) {
        // add its location for resources
        if (project.exists()) {
            String path = project.getLocation().toPortableString();
            entries.add(path);/*from w  w  w  . ja  v a  2 s .c  o  m*/
        }
        // done
        return;
    }
    // check for recursion
    if (visitedProjects.contains(javaProject)) {
        return;
    }
    visitedProjects.add(javaProject);
    // do add classpath entries
    if (fullClassPath) {
        CollectionUtils.addAll(entries, getClasspath(javaProject));
    } else {
        IPath outputLocation = javaProject.getOutputLocation();
        addAbsoluteLocation(entries, outputLocation);
    }
    // include fragments
    addFragments(entries, project, visitedProjects);
}

From source file:org.eclipse.wb.internal.layout.group.model.assistant.GroupLayoutAlignmentPage.java

public void updatePage() {
    m_toolBarManager.removeAll();/*from ww  w  .ja v  a  2s  .c  o  m*/
    List<ObjectInfo> sel = Lists.newArrayList();
    List<Object> actions = Lists.newArrayList();
    CollectionUtils.addAll(sel, m_objects.iterator());
    new AlignmentsSupport(m_layout).addAlignmentActions(sel, actions);
    for (Object action : actions) {
        if (action instanceof IContributionItem) {
            m_toolBarManager.add((IContributionItem) action);
        } else if (action instanceof IAction) {
            m_toolBarManager.add((IAction) action);
        }
    }
    m_toolBarManager.update(true);
}

From source file:org.eclipse.wb.internal.rcp.databinding.ui.contentproviders.ChooseClassAndTreePropertiesUiContentProvider.java

protected void setClassNameAndProperties(Class<?> beanClass, String beanClassName, List<String> properties)
        throws Exception {
    if (beanClassName == null) {
        setClassName(CoreUtils.getClassName(beanClass));
    } else {/* w w  w  .j  a  v a  2s .co m*/
        setClassName(beanClassName);
    }
    //
    ClassLoader classLoader = JavaInfoUtils.getClassLoader(EditorState.getActiveJavaInfo());
    BeanSupport beanSupport = new BeanSupport(classLoader, null);
    BeanBindableInfo beanObjectInfo = new BeanBindableInfo(beanSupport, null, beanClass, null,
            (IObservePresentation) null);
    //
    Object[] adapters = new Object[properties.size()];
    for (int i = 0; i < adapters.length; i++) {
        adapters[i] = convertPropertyToAdapter(beanObjectInfo.resolvePropertyReference(properties.get(i)));
    }
    //
    setCheckedAndExpand(adapters);
    //
    if (m_orderPropertiesViewer != null) {
        CollectionUtils.addAll(m_orderProperties, adapters);
        m_orderPropertiesViewer.refresh();
    }
    //
    calculatePropertiesFinish();
}

From source file:org.eclipse.wb.internal.rcp.databinding.wizards.autobindings.SwtDatabindingProvider.java

public String performSubstitutions(String code, ImportsManager imports) throws Exception {
    // prepare properties
    final List<PropertyAdapter> properties = Lists.newArrayList();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements());
        }/*  w  w w.j  a v a2  s .  co  m*/
    });
    //
    if (m_firstPage.isCreateControlClass()) {
        return ControllerSupport.automaticWizardPerformSubstitutions(m_firstPage, code, imports, m_javaProject,
                m_classLoader, m_beanClass, properties, m_propertyToEditor);
    }
    //
    String begin = "";
    String end = "\t\t";
    String widgetStart = "";
    boolean blockMode = useBlockMode();
    if (blockMode) {
        begin = "\t\t{\r\n";
        end = "\t\t}";
        widgetStart = "\t";
    }
    // prepare imports
    Collection<String> importList = Sets.newHashSet();
    importList.add(SWT.class.getName());
    importList.add("org.eclipse.jface.databinding.swt.SWTObservables");
    importList.add("org.eclipse.core.databinding.observable.value.IObservableValue");
    importList.add("org.eclipse.core.databinding.UpdateValueStrategy");
    importList.add("org.eclipse.swt.widgets.Label");
    importList.add("org.eclipse.swt.layout.GridLayout");
    importList.add("org.eclipse.swt.layout.GridData");
    //
    DataBindingsCodeUtils.ensureDBLibraries(m_javaProject);
    //
    IAutomaticWizardStub automaticWizardStub = GlobalFactoryHelper.automaticWizardCreateStub(m_javaProject,
            m_classLoader, m_beanClass);
    //
    String observeMethod = null;
    if (automaticWizardStub == null) {
        if (ObservableInfo.isPojoBean(m_beanClass)) {
            String pojoClass = DataBindingsCodeUtils.getPojoObservablesClass();
            observeMethod = "ObserveValue = " + ClassUtils.getShortClassName(pojoClass) + ".observeValue(";
            importList.add(pojoClass);
        } else {
            observeMethod = "ObserveValue = BeansObservables.observeValue(";
            importList.add("org.eclipse.core.databinding.beans.BeansObservables");
        }
    } else {
        automaticWizardStub.addImports(importList);
    }
    // prepare bean
    String beanClassName = CoreUtils.getClassName(m_beanClass);
    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." : "";
    code = StringUtils.replace(code, "%BeanFieldAccess%", accessPrefix + fieldName);
    //
    code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName));
    // prepare code
    StringBuffer widgetFields = new StringBuffer();
    StringBuffer widgets = new StringBuffer();
    String swtContainer = StringUtils.substringBetween(code, "%Widgets%", "%");
    String swtContainerWithDot = "this".equals(swtContainer) ? "" : swtContainer + ".";
    //
    StringBuffer observables = new StringBuffer();
    StringBuffer bindings = new StringBuffer();
    //
    importList.add(GridLayout.class.getName());
    widgets.append("\t\t" + swtContainerWithDot + "setLayout(new GridLayout(2, false));\r\n");
    if (!blockMode) {
        widgets.append("\t\t\r\n");
    }
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = m_propertyToEditor.get(property);
        SwtWidgetDescriptor widgetDescriptor = (SwtWidgetDescriptor) editorData[0];
        JFaceBindingStrategyDescriptor strategyDescriptor = (JFaceBindingStrategyDescriptor) editorData[1];
        //
        String propertyName = property.getName();
        String widgetClassName = widgetDescriptor.getClassName();
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        // field
        widgetFields.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        // widget
        widgets.append(begin);
        widgets.append(widgetStart + "\t\tnew Label(" + swtContainer + ", SWT.NONE).setText(\""
                + StringUtils.capitalize(propertyName) + ":\");\r\n");
        widgets.append(end + "\r\n");
        //
        widgets.append(begin);
        widgets.append(
                "\t\t" + widgetFieldAccess + " = " + widgetDescriptor.getCreateCode(swtContainer) + ";\r\n");
        widgets.append(widgetStart + "\t\t" + widgetFieldAccess
                + ".setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));\r\n");
        widgets.append(end);
        // observables
        observables.append("\t\tIObservableValue " + propertyName + "ObserveWidget = "
                + widgetDescriptor.getBindingCode(widgetFieldName) + ";\r\n");
        if (automaticWizardStub == null) {
            observables.append("\t\tIObservableValue " + propertyName + observeMethod + fieldName + ", \""
                    + propertyName + "\");");
        } else {
            observables.append(automaticWizardStub.createSourceCode(fieldName, propertyName));
        }
        // bindings
        bindings.append("\t\tbindingContext.bindValue(" + propertyName + "ObserveWidget, " + propertyName
                + "ObserveValue, " + getStrategyValue(strategyDescriptor.getTargetStrategyCode()) + ", "
                + getStrategyValue(strategyDescriptor.getModelStrategyCode()) + ");");
        //
        if (I.hasNext()) {
            widgetFields.append("\r\n");
            widgets.append("\r\n");
            observables.append("\r\n");
            bindings.append("\r\n");
        }
        //
        importList.add(widgetDescriptor.getFullClassName());
    }
    // replace template patterns
    code = StringUtils.replace(code, "%WidgetFields%", widgetFields.toString());
    code = StringUtils.replace(code, "%Widgets%" + swtContainer + "%", widgets.toString());
    //
    code = StringUtils.replace(code, "%Observables%", observables.toString());
    code = StringUtils.replace(code, "%Bindings%", bindings.toString());
    // add imports
    for (String qualifiedTypeName : importList) {
        imports.addImport(qualifiedTypeName);
    }
    //
    return code;
}

From source file:org.eclipse.wb.internal.swing.databinding.ui.contentproviders.ColumnBindingUiContentProvider.java

private List<PropertyAdapter> getChoosenProperties() {
    List<PropertyAdapter> properties = Lists.newArrayList();
    CollectionUtils.addAll(properties, treeViewer.getCheckedElements());
    return properties;
}

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 www. j a va 2 s.  c o  m
    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.fao.geonet.services.metadata.XmlChildElementTextUpdate.java

private String getWhereClause(List<String> uuidList, String filterChoice, String uuids,
        List<Element> userGroups) {
    String whereClause = " where not (isharvested='y') and istemplate='n' and schemaid = 'iso19139'";
    int filter = Integer.parseInt(filterChoice);
    switch (filter) {
    case 1://ww w . j  av  a  2  s  .  c  o  m
        uuids = uuids.replaceAll("\\s+", "");
        if (!StringUtils.isBlank(uuids)) {
            whereClause += " and uuid in ('" + uuids.replaceAll("\'", "").replaceAll(",", "\',\'") + "')";
            CollectionUtils.addAll(uuidList, uuids.split(","));
        }
        break;
    case 2:
        List<String> groupIdList = new ArrayList<String>();
        for (Element group : userGroups) {
            groupIdList.add(group.getText());
        }
        whereClause += " and id in (select metadataid from operationallowed where groupid in ('"
                + StringUtils.join(groupIdList, "','") + "') and operationid = '2')";
        break;
    case 3:
        break;
    }
    return whereClause;
}

From source file:org.geolatte.geom.builder.client.DslTest.java

@Test
public void testLineString2D() {

    LineString<G2D> ls = linestring(WGS84, g(0, 0), g(1, 0), g(2, 0));

    assertEquals(2, ls.getCoordinateDimension());
    assertEquals(WGS84, ls.getCoordinateReferenceSystem());

    ArrayList<G2D> points = new ArrayList<G2D>();
    CollectionUtils.addAll(points, ls.getPositions().iterator());
    assertEquals(points.get(0).getLon(), 0, DELTA);
    assertEquals(points.get(0).getLat(), 0, DELTA);
    assertEquals(points.get(1).getLon(), 1, DELTA);
    assertEquals(points.get(1).getLat(), 0, DELTA);
    assertEquals(points.get(2).getLon(), 2, DELTA);
    assertEquals(points.get(2).getLat(), 0, DELTA);
}