public static IPath[] chooseExclusionPattern(
      Shell shell,
      IContainer currentSourceFolder,
      String title,
      String message,
      IPath initialPath,
      boolean multiSelection) {
    Class[] acceptedClasses = new Class[] {IFolder.class, IFile.class};
    ISelectionStatusValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, multiSelection);
    ViewerFilter filter = new TypedViewerFilter(acceptedClasses);

    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();

    IResource initialElement = null;
    if (initialPath != null) {
      IContainer curr = currentSourceFolder;
      int nSegments = initialPath.segmentCount();
      for (int i = 0; i < nSegments; i++) {
        IResource elem = curr.findMember(initialPath.segment(i));
        if (elem != null) {
          initialElement = elem;
        }
        if (elem instanceof IContainer) {
          curr = (IContainer) elem;
        } else {
          break;
        }
      }
    }

    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, lp, cp);
    dialog.setTitle(title);
    dialog.setValidator(validator);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    dialog.setInput(currentSourceFolder);
    dialog.setInitialSelection(initialElement);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setHelpAvailable(false);

    if (dialog.open() == Window.OK) {
      Object[] objects = dialog.getResult();
      int existingSegments = currentSourceFolder.getFullPath().segmentCount();

      IPath[] resArr = new IPath[objects.length];
      for (int i = 0; i < objects.length; i++) {
        IResource currRes = (IResource) objects[i];
        IPath path = currRes.getFullPath().removeFirstSegments(existingSegments).makeRelative();
        if (currRes instanceof IContainer) {
          path = path.addTrailingSeparator();
        }
        resArr[i] = path;
      }
      return resArr;
    }
    return null;
  }
  /**
   * View directory selection dialog.<br>
   * It is called when you press p> [Detail] search folder the "Browse" button.<br>
   * Set the path to the folder you want to display a tree dialog to select a folder, the selected.
   * <br>
   *
   * @return Folder path
   */
  private IFolder folderBrowse() {
    String directryPath = StringUtil.getText(searchTargetText);

    // Create dialog
    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            null, new WorkbenchLabelProvider(), new WorkbenchContentProvider());

    // Set the resources that are displayed in the dialog
    IProject project = PluginUtil.getProject(directryPath);
    dialog.setInput(getDialogInput(project));
    dialog.setMessage(getDialogMessage(project));
    dialog.setTitle(ResourceUtil.DIR_SELECT_TITLE);
    dialog.setHelpAvailable(false);

    // If the folder name has already been entered into the textbox initial
    // value
    if (!StringUtil.isEmpty(directryPath)) {
      IContainer container = ResourcesPlugin.getWorkspace().getRoot();
      dialog.setInitialSelection(PluginUtil.createIFolder(container, directryPath));
    }
    // Add ViewerFileter
    dialog.addFilter(
        new ViewerFilter() {

          /** {@inheritDoc} */
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IFolder) {
              return true;
            } else if (element instanceof IFile) {
              return false;
            }
            return true;
          }
        });

    // Open the dialog.
    if (dialog.open() == Window.OK) {
      Object result = dialog.getFirstResult();
      if (result instanceof IFolder) {
        return (IFolder) result;
      }
    }
    return null;
  }
  /**
   * View the file selection dialog.<br>
   * Called when the know-how of creating XML files "Browse" button is pressed.<br>
   *
   * @return File
   */
  private IFolder folderBrowse() {
    String filePath = page.outputFilePath();
    String filePathExcludeProjectName = page.getOutputFilePathExcludeProjectName();
    if (CmnStringUtil.isEmpty(filePath)) {
      return null;
    }
    // Create dialog
    final ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            PluginUtil.getActiveWorkbenchShell(),
            new WorkbenchLabelProvider(),
            new WorkbenchContentProvider());

    // Set the resources that are displayed in the dialog
    //        IProject project = PluginUtil.getProject(filePath);
    //        this.page.getSelectionProject();
    IProject selectionProject = this.page.getSelectionProject();
    dialog.setInput(selectionProject);
    dialog.setMessage(getDialogMessage(this.page.getSelectionProject()));
    dialog.setTitle(ResourceUtil.selectOutput);
    dialog.setHelpAvailable(false);
    // Add ViewerFileter
    dialog.addFilter(
        new ViewerFilter() {
          /** {@inheritDoc} */
          @Override
          public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IFolder) {
              return true;
            }
            return false;
          }
        });
    //        dialog.getFirstResult();
    // Open the dialog.
    if (dialog.open() == Window.OK) {
      Object result = dialog.getFirstResult();
      if (result instanceof IFolder) {
        return (IFolder) result;
      }
    }

    return null;
  }
  /**
   *
   *
   * <pre>
   *  The method executes the creation :
   *  - opens a selection dialog to choose a {@link ConnectableElement} reference as a role by the {@link CollaborationUse} type
   *  - created a dependency between the selected role and the {@link ConnectableElement} that will be bind to it
   *
   * {@inheritDoc}
   * </pre>
   */
  @Override
  protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info)
      throws ExecutionException {

    if (!canExecute()) {
      throw new ExecutionException(Messages.RoleBindingCreateCommand_INVALID_ARGS_MSG);
    }

    // Retrieve the graphical source of the binding.
    // This differs from the semantic source of the binding which is a role of the
    // CollaborationUse type.
    CollaborationUse graphicalSource = (CollaborationUse) getSource();

    // Create and open the selection dialog
    ComposedAdapterFactory adapterFactory =
        new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    Shell currentShell = new Shell(Display.getCurrent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            currentShell,
            new AdapterFactoryLabelProvider(adapterFactory),
            new CollaborationRoleTreeContentProvider());

    try {
      // Set dialog parameters
      dialog.setTitle(Messages.RoleBindingRoleSelectionDialog_Title);
      dialog.setMessage(Messages.RoleBindingRoleSelectionDialog_Message);
      dialog.setAllowMultiple(false);
      dialog.setHelpAvailable(false);
      // The source CollaborationUse is set as input for the selection dialog,
      // the CollaborationRoleTreeContentProvider provides the roles that can possibly be
      // selected.
      dialog.setInput(graphicalSource);

      dialog.open();
    } finally {
      adapterFactory.dispose();
    }

    // If a ConnectableElement has been selected, complete command execution
    // using selection as the "newly created" element and make the edited
    // Collaboration reference it in the CollaborationRoles eReference.
    if (dialog.getReturnCode() == ElementTreeSelectionDialog.OK) {

      ConnectableElement roleToBind = (ConnectableElement) dialog.getFirstResult();
      // Create a Dependency (the binding) between selected role and a ConnectableElement
      // (the target)
      Dependency newBinding = UMLFactory.eINSTANCE.createDependency();
      getContainer().getPackagedElements().add(newBinding);
      newBinding.getClients().add(roleToBind);
      newBinding.setName("binding_" + roleToBind.getName() + "_" + getTarget().getName());
      newBinding.getSuppliers().add(getTarget());
      graphicalSource.getRoleBindings().add(newBinding);

      doConfigure(newBinding, monitor, info);

      ((CreateElementRequest) getRequest()).setNewElement(newBinding);

      return CommandResult.newOKCommandResult(newBinding);
    }

    // No role selected: abort element creation
    return CommandResult.newCancelledCommandResult();
  }
  @Override
  protected String browse(final SapphireRenderingContext context) {
    final Property property = property();
    final List<Path> roots = getBasePaths();
    String selectedAbsolutePath = null;

    final List<String> extensions;

    if (this.fileExtensionService == null) {
      extensions = this.staticFileExtensionsList;
    } else {
      extensions = this.fileExtensionService.extensions();
    }

    if (enclosed()) {
      final List<IContainer> baseContainers = new ArrayList<IContainer>();

      for (Path path : roots) {
        final IContainer baseContainer = getWorkspaceContainer(path.toFile());

        if (baseContainer != null) {
          baseContainers.add(baseContainer);
        } else {
          break;
        }
      }

      final ITreeContentProvider contentProvider;
      final ILabelProvider labelProvider;
      final ViewerComparator viewerComparator;
      final Object input;

      if (roots.size() == baseContainers.size()) {
        // All paths are in the Eclipse Workspace. Use the available content and label
        // providers.

        contentProvider = new WorkspaceContentProvider(baseContainers);
        labelProvider = new WorkbenchLabelProvider();
        viewerComparator = new ResourceComparator();
        input = ResourcesPlugin.getWorkspace().getRoot();
      } else {
        // At least one of the roots is not in the Eclipse Workspace. Use custom file
        // system content and label providers.

        contentProvider = new FileSystemContentProvider(roots);
        labelProvider = new FileSystemLabelProvider(context);
        viewerComparator = new FileSystemNodeComparator();
        input = new Object();
      }

      final ElementTreeSelectionDialog dialog =
          new ElementTreeSelectionDialog(context.getShell(), labelProvider, contentProvider);

      dialog.setTitle(property.definition().getLabel(false, CapitalizationType.TITLE_STYLE, false));
      dialog.setMessage(
          createBrowseDialogMessage(
              property.definition().getLabel(true, CapitalizationType.NO_CAPS, false)));
      dialog.setAllowMultiple(false);
      dialog.setHelpAvailable(false);
      dialog.setInput(input);
      dialog.setComparator(viewerComparator);

      final Path currentPathAbsolute = convertToAbsolute((Path) ((Value<?>) property).content());

      if (currentPathAbsolute != null) {
        Object initialSelection = null;

        if (contentProvider instanceof WorkspaceContentProvider) {
          final URI uri = currentPathAbsolute.toFile().toURI();
          final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();

          final IFile[] files = wsroot.findFilesForLocationURI(uri);

          if (files.length > 0) {
            final IFile file = files[0];

            if (file.exists()) {
              initialSelection = file;
            }
          }

          if (initialSelection == null) {
            final IContainer[] containers = wsroot.findContainersForLocationURI(uri);

            if (containers.length > 0) {
              final IContainer container = containers[0];

              if (container.exists()) {
                initialSelection = container;
              }
            }
          }
        } else {
          initialSelection =
              ((FileSystemContentProvider) contentProvider).find(currentPathAbsolute);
        }

        if (initialSelection != null) {
          dialog.setInitialSelection(initialSelection);
        }
      }

      if (this.type == FileSystemResourceType.FILE) {
        dialog.setValidator(new FileSelectionStatusValidator());
      } else if (this.type == FileSystemResourceType.FOLDER) {
        dialog.addFilter(new ContainersOnlyViewerFilter());
      }

      if (!extensions.isEmpty()) {
        dialog.addFilter(new ExtensionBasedViewerFilter(extensions));
      }

      if (dialog.open() == Window.OK) {
        final Object firstResult = dialog.getFirstResult();

        if (firstResult instanceof IResource) {
          selectedAbsolutePath = ((IResource) firstResult).getLocation().toString();
        } else {
          selectedAbsolutePath = ((FileSystemNode) firstResult).getFile().getPath();
        }
      }
    } else if (this.type == FileSystemResourceType.FOLDER) {
      final DirectoryDialog dialog = new DirectoryDialog(context.getShell());
      dialog.setText(
          property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false));
      dialog.setMessage(
          createBrowseDialogMessage(
              property.definition().getLabel(true, CapitalizationType.NO_CAPS, false)));

      final Value<?> value = (Value<?>) property;
      final Path path = (Path) value.content();

      if (path != null) {
        dialog.setFilterPath(path.toOSString());
      } else if (roots.size() > 0) {
        dialog.setFilterPath(roots.get(0).toOSString());
      }

      selectedAbsolutePath = dialog.open();
    } else {
      final FileDialog dialog = new FileDialog(context.getShell());
      dialog.setText(
          property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false));

      final Value<?> value = (Value<?>) property;
      final Path path = (Path) value.content();

      if (path != null && path.segmentCount() > 1) {
        dialog.setFilterPath(path.removeLastSegments(1).toOSString());
        dialog.setFileName(path.lastSegment());
      } else if (roots.size() > 0) {
        dialog.setFilterPath(roots.get(0).toOSString());
      }

      if (!extensions.isEmpty()) {
        final StringBuilder buf = new StringBuilder();

        for (String extension : extensions) {
          if (buf.length() > 0) {
            buf.append(';');
          }

          buf.append("*.");
          buf.append(extension);
        }

        dialog.setFilterExtensions(new String[] {buf.toString()});
      }

      selectedAbsolutePath = dialog.open();
    }

    if (selectedAbsolutePath != null) {
      final Path relativePath = convertToRelative(new Path(selectedAbsolutePath));

      if (relativePath != null) {
        String result = relativePath.toPortableString();

        if (this.includeLeadingSlash) {
          result = "/" + result;
        }

        return result;
      }
    }

    return null;
  }
  /**
   * Opens a selection dialog that allows to select a source container.
   *
   * @return returns the selected package fragment root or <code>null</code> if the dialog has been
   *     canceled. The caller typically sets the result to the container input field.
   *     <p>Clients can override this method if they want to offer a different dialog.
   * @since 3.2
   */
  protected IPackageFragmentRoot chooseContainer() {
    IJavaElement initElement = getPackageFragmentRoot();
    Class<?>[] acceptedClasses = new Class[] {IPackageFragmentRoot.class, IJavaProject.class};
    TypedElementSelectionValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, false) {
          @Override
          public boolean isSelectedValid(Object element) {
            try {
              if (element instanceof IJavaProject) {
                IJavaProject jproject = (IJavaProject) element;
                IPath path = jproject.getProject().getFullPath();
                return (jproject.findPackageFragmentRoot(path) != null);
              } else if (element instanceof IPackageFragmentRoot) {
                return (((IPackageFragmentRoot) element).getKind()
                    == IPackageFragmentRoot.K_SOURCE);
              }
              return true;
            } catch (JavaModelException e) {
              JavaPlugin.log(e.getStatus()); // just log, no UI in validation
            }
            return false;
          }
        };

    acceptedClasses =
        new Class[] {IJavaModel.class, IPackageFragmentRoot.class, IJavaProject.class};
    ViewerFilter filter =
        new TypedViewerFilter(acceptedClasses) {
          @Override
          public boolean select(Viewer viewer, Object parent, Object element) {
            if (element instanceof IPackageFragmentRoot) {
              try {
                return (((IPackageFragmentRoot) element).getKind()
                    == IPackageFragmentRoot.K_SOURCE);
              } catch (JavaModelException e) {
                JavaPlugin.log(e.getStatus()); // just log, no UI in validation
                return false;
              }
            }
            return super.select(viewer, parent, element);
          }
        };

    StandardJavaElementContentProvider provider = new StandardJavaElementContentProvider();
    ILabelProvider labelProvider =
        new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(getShell(), labelProvider, provider);
    dialog.setValidator(validator);
    dialog.setComparator(new JavaElementComparator());
    dialog.setTitle(NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_title);
    dialog.setMessage(
        NewWizardMessages.NewContainerWizardPage_ChooseSourceContainerDialog_description);
    dialog.addFilter(filter);
    dialog.setInput(JavaCore.create(fWorkspaceRoot));
    dialog.setInitialSelection(initElement);
    dialog.setHelpAvailable(false);

    if (dialog.open() == Window.OK) {
      Object element = dialog.getFirstResult();
      if (element instanceof IJavaProject) {
        IJavaProject jproject = (IJavaProject) element;
        return jproject.getPackageFragmentRoot(jproject.getProject());
      } else if (element instanceof IPackageFragmentRoot) {
        return (IPackageFragmentRoot) element;
      }
      return null;
    }
    return null;
  }