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:de.xirp.ui.widgets.dialogs.RobotLookupDialog.java

/**
 * Opens the dialog. The flag <code>multi</code> indicates the
 * selection mode. <code>true</code>: multi select allowed.
 * /*from   w  ww . j ava 2  s . com*/
 * @param multi
 *            <code>true</code>: multi select allowed.<br>
 *            <code>false</code>: single select allowed.
 * @return The selection result robot-file file names.
 */
private List<String> open(boolean multi) {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    if (multi) {
        dialogShell.setTextForLocaleKey("RobotLookupDialog.gui.title.multi"); //$NON-NLS-1$
    } else {
        dialogShell.setTextForLocaleKey("RobotLookupDialog.gui.title.single"); //$NON-NLS-1$
    }
    Image image = ImageManager.getSystemImage(SystemImage.QUESTION);// /$NON-NLS-1$
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    if (multi) {
        list = new XList(dialogShell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    } else {
        list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    }
    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);

    File dir = new File(Constants.CONF_ROBOTS_DIR);
    File[] robotFiles = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(Constants.ROBOT_POSTFIX);
        }

    });

    for (File f : robotFiles) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(f.getName())) {
            list.add(f.getName());
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            robotFileNames = Arrays.asList(list.getSelection());
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            robotFileNames.clear();
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);
    list.setSelectionWithEvent(0);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return Collections.unmodifiableList(robotFileNames);
}

From source file:de.xirp.ui.widgets.dialogs.CommSpecsLookupDialog.java

/**
 * Opens the dialog. The flag <code>multi</code> indicates the
 * selection mode. <code>true</code>: multi select allowed.
 * /*from   w w  w  .j av a  2 s . c o m*/
 * @param multi
 *            <code>true</code>: multi select allowed.<br>
 *            <code>false</code>: single select allowed.
 * @return The selection result comm-spec-file file names.
 */
private List<String> open(boolean multi) {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /**
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    if (multi) {
        dialogShell.setTextForLocaleKey("CommSpecsLookupDialog.gui.title.multi"); //$NON-NLS-1$
    } else {
        dialogShell.setTextForLocaleKey("CommSpecsLookupDialog.gui.title.single"); //$NON-NLS-1$
    }
    Image image = ImageManager.getSystemImage(SystemImage.QUESTION);
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    if (multi) {
        list = new XList(dialogShell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    } else {
        list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    }
    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);

    File dir = new File(Constants.CONF_COMMSPECS_DIR);
    File[] cmsFiles = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(Constants.COMM_SPEC_POSTFIX);
        }

    });

    for (File f : cmsFiles) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(f.getName())) {
            list.add(f.getName());
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            commspecFileNames = Arrays.asList(list.getSelection());
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            commspecFileNames.clear();
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);
    list.setSelectionWithEvent(0);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return Collections.unmodifiableList(commspecFileNames);
}

From source file:de.xirp.ui.widgets.dialogs.PluginLookupDialog.java

/**
 * Opens the class lookup dialog with the fully qualified class
 * names of the loaded plugins. Corresponding to the requested
 * type(s) or all types./*from  w  w w.  j  a  va 2  s  . c om*/
 * 
 * @return The chosen class name(s).
 */
public java.util.List<String> open() {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        /**
         * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
         */
        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });

    dialogShell.setSize(WIDTH, HEIGHT);
    dialogShell.setTextForLocaleKey("ClassLookupDialog.gui.dialogTitle.chooseClass"); //$NON-NLS-1$
    image = ImageManager.getSystemImage(SystemImage.QUESTION);
    dialogShell.setImage(image);

    SWTUtil.setGridLayout(dialogShell, 2, true);

    if (multi) {
        list = new XList(dialogShell, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    } else {
        list = new XList(dialogShell, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    }
    SWTUtil.setGridData(list, true, true, SWT.FILL, SWT.FILL, 2, 1);
    for (String s : pluginNameLookup()) {
        Vector<String> itm = new Vector<String>();
        CollectionUtils.addAll(itm, list.getItems());
        if (!itm.contains(s)) {
            list.add(s);
        }
    }
    list.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (list.getSelectionCount() > 0) {
                ok.setEnabled(true);
            } else {
                ok.setEnabled(false);
            }
        }
    });

    ok = new XButton(dialogShell, XButtonType.OK);
    ok.setEnabled(false);
    SWTUtil.setGridData(ok, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    ok.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            CollectionUtils.addAll(classes, list.getSelection());
            dialogShell.close();
        }
    });

    cancel = new XButton(dialogShell, XButtonType.CANCEL);
    SWTUtil.setGridData(cancel, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    cancel.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            dialogShell.close();
        }
    });

    dialogShell.setDefaultButton(ok);

    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return Collections.unmodifiableList(classes);
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.StudyPolicyStatementController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<StudyPolicyStatement> getStudyPolicyStatements(
        @RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_USER_NAME, REQUEST_PARAM_STUDY_ID,
            REQUEST_PARAM_DATASET_ID, REQUEST_PARAM_ANALYSIS_TOOL_ID);

    if (!params.isEmpty()) {
        String userName = params.get(REQUEST_PARAM_USER_NAME);
        String studyId = params.get(REQUEST_PARAM_STUDY_ID);
        String dataSetId = params.get(REQUEST_PARAM_DATASET_ID);
        String toolId = params.get(REQUEST_PARAM_ANALYSIS_TOOL_ID);

        ArrayList<String> missingParams = new ArrayList<String>();
        if (studyId == null) {
            missingParams.add(REQUEST_PARAM_STUDY_ID);
        }//from w w  w  .  ja  v  a  2 s.  c  o m
        if (dataSetId == null) {
            missingParams.add(REQUEST_PARAM_DATASET_ID);
        }
        if (toolId == null) {
            missingParams.add(REQUEST_PARAM_ANALYSIS_TOOL_ID);
        }
        if (userName != null) {
            if (studyId != null) {
                return studyPolicyStatementRepository.findByUserNameAndStudyId(userName,
                        validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
            } else {
                return studyPolicyStatementRepository.findByUserName(userName);
            }
        }
        if ((studyId != null) && ((dataSetId == null) && (toolId == null))) {
            return studyPolicyStatementRepository
                    .findByStudyId(validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        }
        if (!missingParams.isEmpty()) {
            throw new BadRequestException("Required parameter(s) missing: " + missingParams);
        }
        return studyPolicyStatementRepository.findStudyPolicyStatementByStudyIdAndDataSetIdAndToolId(
                validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId),
                validateIntegerParameter(REQUEST_PARAM_DATASET_ID, dataSetId),
                validateIntegerParameter(REQUEST_PARAM_ANALYSIS_TOOL_ID, toolId));
    }

    List<StudyPolicyStatement> studyPolicyStatements = new ArrayList<StudyPolicyStatement>();
    Iterator iter = studyPolicyStatementRepository.findAll().iterator();
    CollectionUtils.addAll(studyPolicyStatements, iter);

    return studyPolicyStatements;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public NodeListTransferable(ArrayList nodeList, ArrayList fields, SpreadSheet spreadSheet, int[] rows,
        int[] cols, boolean nodeSelection) {
    this.nodeSelection = nodeSelection;
    try {/*from  w w w .  j  a va 2 s.  co  m*/
        nodeListDataFlavor = new DataFlavor(NODE_LIST_MIME_TYPE);
    } catch (ClassNotFoundException e) {
    }
    if (nodeSelection) {
        flavors = new DataFlavor[] { nodeListDataFlavor, DataFlavor.stringFlavor,
                DataFlavor.getTextPlainUnicodeFlavor() }; //TODO isRepresentationClassReader(||InputStream)||isFlavorTextType+flavor.getReaderForText()
        this.nodeList = nodeList;
        this.fields = fields;
    } else {
        flavors = new DataFlavor[] { DataFlavor.stringFlavor, DataFlavor.getTextPlainUnicodeFlavor() }; //TODO isRepresentationClassReader(||InputStream)||isFlavorTextType+flavor.getReaderForText()
        //sdata=nodeListToString(nodeList,spreadSheet,fields);
    }
    flavorSet = new HashSet();
    //Collections.addAll(flavorSet,flavors); //jdk 1.5
    //for (int i=0;i<flavors.length;i++) flavorSet.add(flavors[i]);
    CollectionUtils.addAll(flavorSet, flavors); //replaced JDK 1.5 code with this call
    this.spreadsheet = spreadSheet;
    this.rows = rows;
    this.cols = cols;
}

From source file:gov.nih.nci.caarray.validation.UniqueConstraintValidator.java

/**
 * {@inheritDoc}/* w  ww  . j  av a  2  s. c o m*/
 */
public void apply(PersistentClass pc) {
    if (this.uniqueConstraint.generateDDLConstraint()) {
        List<Column> columns = new ArrayList<Column>();
        for (UniqueConstraintField field : uniqueConstraint.fields()) {
            Property prop = pc.getProperty(field.name());
            CollectionUtils.addAll(columns, prop.getColumnIterator());
        }
        pc.getTable().createUniqueKey(columns);
    }
}

From source file:edu.isi.misd.scanner.network.registry.web.controller.UserRoleController.java

@RequestMapping(value = BASE_PATH, method = { RequestMethod.GET,
        RequestMethod.HEAD }, produces = HEADER_JSON_MEDIA_TYPE)
public @ResponseBody List<UserRole> getUserRoles(@RequestParam Map<String, String> paramMap) {
    Map<String, String> params = validateParameterMap(paramMap, REQUEST_PARAM_USER_NAME, REQUEST_PARAM_STUDY_ID,
            REQUEST_PARAM_SITE_ID, REQUEST_PARAM_NODE_ID, REQUEST_PARAM_DATASET_INSTANCE_ID);

    String userName = params.get(REQUEST_PARAM_USER_NAME);
    String studyId = params.get(REQUEST_PARAM_STUDY_ID);
    String siteId = params.get(REQUEST_PARAM_SITE_ID);
    String nodeId = params.get(REQUEST_PARAM_NODE_ID);
    String dataSetInstanceId = params.get(REQUEST_PARAM_DATASET_INSTANCE_ID);

    if (userName != null) {
        if (studyId != null) {
            return userRoleRepository.findByUserUserNameAndStudyRoleStudyStudyId(userName,
                    validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        } else if (siteId != null) {
            return userRoleRepository.findByUserUserNameAndStudyRoleSitePoliciesSiteSiteId(userName,
                    validateIntegerParameter(REQUEST_PARAM_SITE_ID, siteId));
        } else if (nodeId != null) {
            return userRoleRepository.findByUserUserNameAndStudyRoleSitePoliciesSiteNodesNodeId(userName,
                    validateIntegerParameter(REQUEST_PARAM_NODE_ID, nodeId));
        } else if (dataSetInstanceId != null) {
            return userRoleRepository
                    .findByUserUserNameAndStudyRoleSitePoliciesSiteNodesDataSetInstancesDataSetInstanceId(
                            userName,//  ww w.  ja  va  2s .c o  m
                            validateIntegerParameter(REQUEST_PARAM_DATASET_INSTANCE_ID, dataSetInstanceId));
        } else {
            return userRoleRepository.findByUserUserName(userName);
        }
    } else if (studyId != null) {
        if (siteId != null) {
            return userRoleRepository.findByStudyRoleStudyStudyIdAndStudyRoleSitePoliciesSiteSiteId(
                    validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId),
                    validateIntegerParameter(REQUEST_PARAM_SITE_ID, siteId));
        } else {
            return userRoleRepository
                    .findByStudyRoleStudyStudyId(validateIntegerParameter(REQUEST_PARAM_STUDY_ID, studyId));
        }
    } else if (siteId != null || nodeId != null || dataSetInstanceId != null) {
        throw new BadRequestException("Required parameter missing: " + REQUEST_PARAM_USER_NAME);
    } else {
        List<UserRole> roles = new ArrayList<UserRole>();
        Iterator iter = userRoleRepository.findAll().iterator();
        CollectionUtils.addAll(roles, iter);
        return roles;
    }
}

From source file:com.cyclopsgroup.tornado.hibernate.HqlLargeList.java

/**
 * Overwrite or implement method iterate()
 *
 * @see com.cyclopsgroup.waterview.LargeList#iterate(int, int, com.cyclopsgroup.waterview.LargeList.Sorting[])
 *//*from   w w  w .ja  v a  2  s.  c  om*/
public Iterator iterate(int startPosition, int maxRecords, Sorting[] sortings) throws Exception {
    if (StringUtils.isEmpty(hql)) {
        throw new IllegalStateException("query is still emtpy");
    }
    Session s = hibernate.getSession(dataSource);
    StringBuffer sb = new StringBuffer(hql);

    boolean first = true;
    for (int i = 0; i < sortings.length; i++) {
        Sorting sorting = sortings[i];
        if (first) {
            sb.append(" ORDER BY ");
            first = false;
        } else {
            sb.append(", ");
        }
        sb.append(sorting.getName());
        if (sorting.isDescending()) {
            sb.append(" DESC");
        }
    }

    Query q = s.createQuery(sb.toString());
    HashSet parameterNames = new HashSet();
    CollectionUtils.addAll(parameterNames, q.getNamedParameters());
    for (Iterator i = parameters.values().iterator(); i.hasNext();) {
        Parameter p = (Parameter) i.next();
        if (parameterNames.contains(p.getName())) {
            q.setParameter(p.getName(), p.getValue(), p.getType());
        }
    }
    q.setFirstResult(startPosition);
    if (maxRecords > 0) {
        q.setMaxResults(maxRecords);
    }
    return q.iterate();
}

From source file:com.rubenlaguna.en4j.mainmodule.NoteListTopComponent.java

private RepeatableTask createUpdateAllNotesTask() {
    Runnable runnable = new Runnable() {

        @Override/*  w w w  .jav  a  2 s  .c  o m*/
        @SuppressWarnings(value = "SleepWhileHoldingLock")
        public void run() {
            updateAllNotes();
            NoteListTopComponent.this.refresh();
        }

        private void updateAllNotes() {
            final Collection<Note> allNotesInDb = getAllNotesInDb();
            LOG.info("clear and repopulate allNotes list");

            final Collection<Note> toRemove = CollectionUtils.subtract(allNotes, allNotesInDb);
            final Collection<Note> toAdd = CollectionUtils.subtract(allNotesInDb, allNotes);

            long startLockList = System.currentTimeMillis();
            //allNotes.getReadWriteLock().writeLock().lock();
            try {
                // avoid removeAll as it would block allNotes for too long
                CollectionUtils.forAllDo(toRemove, new Closure() {
                    @Override
                    @SuppressWarnings("element-type-mismatch")
                    public void execute(Object input) {
                        allNotes.remove(input);
                    }
                });
                //avoid allNotes.addAll it could block allNotes for too long
                CollectionUtils.addAll(allNotes, toAdd.iterator());
            } finally {
                //allNotes.getReadWriteLock().writeLock().unlock();
            }
            long deltaListLock = System.currentTimeMillis() - startLockList;
            LOG.log(Level.INFO, "We locked the eventlist for {0} ms", deltaListLock);
            LOG.log(Level.INFO, "allNotes size: {0}  allNotesInDb size: {1}",
                    new Object[] { allNotes.size(), allNotesInDb.size() });
        }
    };
    return new RepeatableTask(runnable, 4000);
}

From source file:com.google.gdt.eclipse.designer.gxt.databinding.wizards.autobindings.GxtDatabindingProvider.java

public String performSubstitutions(String code, ImportsManager imports) throws Exception {
    // 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);
    ///*from  w  ww  .  jav  a2 s. co  m*/
    Collection<String> importList = Sets.newHashSet();
    //
    final List<PropertyAdapter> properties = Lists.newArrayList();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            m_packageName = m_firstPage.getPackageFragment().getElementName();
            CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements());
        }
    });
    //
    if (!ClassUtils.getPackageName(beanClassName).equals(m_packageName)) {
        importList.add(beanClassName);
    }
    beanClassName = 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, "%BeanFieldAccess%", beanFieldAccess);
    code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName));
    //
    boolean useGenerics = CoreUtils.useGenerics(m_javaProject);
    //
    StringBuffer fieldsCode = new StringBuffer();
    StringBuffer widgetsCode = new StringBuffer();
    StringBuffer bindingsCode = new StringBuffer();
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = m_propertyToEditor.get(property);
        GxtWidgetDescriptor widgetDescriptor = (GxtWidgetDescriptor) editorData[0];
        //
        String propertyName = property.getName();
        String widgetClassName = ClassUtils.getShortClassName(widgetDescriptor.getWidgetClass());
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        //
        if (useGenerics && widgetDescriptor.isGeneric()) {
            widgetClassName += "<" + convertTypes(property.getType().getName()) + ">";
        }
        //
        fieldsCode.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        //
        widgetsCode.append("\t\t" + widgetFieldName + " = new " + widgetClassName + "();\r\n");
        widgetsCode.append("\t\t" + widgetFieldAccess + ".setFieldLabel(\""
                + StringUtils.capitalize(propertyName) + "\");\r\n");
        widgetsCode.append("\t\t" + accessPrefix + "m_formPanel.add(" + widgetFieldAccess
                + ", new FormData(\"100%\"));\r\n");
        widgetsCode.append("\t\t//");
        //
        importList.add(widgetDescriptor.getBindingClass());
        bindingsCode.append("\t\tm_formBinding.addFieldBinding(new "
                + ClassUtils.getShortClassName(widgetDescriptor.getBindingClass()) + "(" + widgetFieldAccess
                + ",\"" + propertyName + "\"));\r\n");
        //
        importList.add(widgetDescriptor.getWidgetClass());
        //
        if (I.hasNext()) {
            fieldsCode.append("\r\n");
            widgetsCode.append("\r\n");
        }
    }
    //
    bindingsCode.append("\t\t//\r\n");
    bindingsCode.append("\t\tm_formBinding.bind(" + beanFieldAccess + ");");
    // replace template patterns
    code = StringUtils.replace(code, "%WidgetFields%", fieldsCode.toString());
    code = StringUtils.replace(code, "%Widgets%", widgetsCode.toString());
    code = StringUtils.replace(code, "%Bindings%", bindingsCode.toString());
    // add imports
    for (String qualifiedTypeName : importList) {
        imports.addImport(qualifiedTypeName);
    }
    //
    return code;
}