private void createProjectViewerField(Composite parent) {
    projectViewer = new WorkspaceViewer(parent, SWT.BORDER);
    projectViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    projectViewer.getViewer().addFilter(getFilter());
    projectViewer
        .getViewer()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {

              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                String targetLocation = null;
                IStructuredSelection selection =
                    (IStructuredSelection) projectViewer.getSelectionProvider().getSelection();
                if (selection.getFirstElement() == null
                    || !(selection.getFirstElement() instanceof IContainer)) {
                  setErrorMessage(SELECT_THE_LOCATION_OF_THE_GENERATED_PAGE);
                } else {
                  setErrorMessage(null);
                  IContainer container = ((IContainer) selection.getFirstElement());
                  targetLocation = container.getFullPath().toString();
                  getModel().setTargetLocation(targetLocation);
                }
                checkPageStatus();
              }
            });
    projectViewer.getViewer().expandToLevel(2);
  }
  protected Object getApropriateFolderForAction(String folderName) {
    Object[] expandedElements = projectViewer.getViewer().getExpandedElements();
    if (expandedElements == null || expandedElements.length == 0) {
      return null;
    }
    ITreeContentProvider contentProvider =
        (ITreeContentProvider) projectViewer.getViewer().getContentProvider();
    IResource sourceResource = getModel().getSourceResource();
    if (sourceResource != null) {
      String[] segments = sourceResource.getLocation().segments();
      for (String segment : segments) {
        if (segment.equals(folderName)) {
          return sourceResource;
        }
      }
    }

    // backup variant if selection is on different artifact type or on
    // project level
    try {
      if (sourceResource != null) {
        IProject project = sourceResource.getProject();
        Object[] children = contentProvider.getChildren(project);
        for (Object object : children) {
          IResource r = (IResource) object;
          if ((r instanceof IFolder) && r.getName().equals(folderName)) {
            return r;
          }
        }
      } else {
        return null;
      }
    } catch (NullPointerException e) {
      // project is not selected, return null
    }
    return null;
  }
 private void setPreselectedElement() {
   projectViewer.getViewer().setSelection(getPreselectedElement(), true);
 }