/* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
  */
 @Override
 protected Control createDialogArea(Composite parent) {
   setTitle(
       NLS.bind(
           SnippetMessages.getString(
               "SelectImportsDialog.Manage_the_Java_Snippet_Editor_Imports_for___{0}__1"),
           new String[] {fEditor.getEditorInput().getName()})); // $NON-NLS-1$
   setMessage(
       NLS.bind(
           SnippetMessages.getString("SelectImportsDialog.add_remove_imports"),
           new String[] {fEditor.getEditorInput().getName()})); // $NON-NLS-1$
   Composite outer = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH);
   GridLayout gl = (GridLayout) outer.getLayout();
   gl.marginLeft = 7;
   gl.marginTop = 0;
   gl.marginBottom = 0;
   SWTFactory.createLabel(
       outer, SnippetMessages.getString("SelectImportsDialog.imports_heading"), 2); // $NON-NLS-1$
   fImportsTable = new Table(outer, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
   GridData gd = new GridData(GridData.FILL_HORIZONTAL);
   gd.heightHint = 150;
   fImportsTable.setLayoutData(gd);
   fImportsViewer = new TableViewer(fImportsTable);
   fImportsViewer.setLabelProvider(new FilterLabelProvider());
   fImportsViewer.setComparator(new FilterViewerComparator());
   fImportContentProvider = new ImportsContentProvider(fImportsViewer);
   fImportsViewer.setContentProvider(fImportContentProvider);
   // input just needs to be non-null
   fImportsViewer.setInput(this);
   fImportsViewer.addSelectionChangedListener(
       new ISelectionChangedListener() {
         @Override
         public void selectionChanged(SelectionChangedEvent event) {
           ISelection selection = event.getSelection();
           if (selection.isEmpty()) {
             fRemoveImportsButton.setEnabled(false);
           } else {
             fRemoveImportsButton.setEnabled(true);
           }
         }
       });
   createImportButtons(outer);
   applyDialogFont(outer);
   return parent;
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#okPressed()
  */
 @Override
 protected void okPressed() {
   String[] imports = null;
   Object[] results = fImportContentProvider.getElements(null);
   if (results != null && results.length > 0) {
     imports = new String[results.length];
     for (int i = 0; i < results.length; i++) {
       Filter imprt = (Filter) results[i];
       imports[i] = imprt.getName();
     }
   }
   fEditor.setImports(imports);
   super.okPressed();
 }
 private void addPackage() {
   Shell shell = fAddPackageButton.getDisplay().getActiveShell();
   ElementListSelectionDialog dialog = null;
   try {
     IJavaProject project = fEditor.getJavaProject();
     List<IJavaElement> projects = new ArrayList<IJavaElement>();
     projects.add(project);
     IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots();
     for (int i = 0; i < roots.length; i++) {
       IPackageFragmentRoot root = roots[i];
       projects.add(root.getParent());
     }
     dialog =
         JDIDebugUIPlugin.createAllPackagesDialog(
             shell, projects.toArray(new IJavaProject[projects.size()]), false);
   } catch (JavaModelException jme) {
     String title =
         SnippetMessages.getString("SelectImportsDialog.Add_package_as_import_7"); // $NON-NLS-1$
     String message =
         SnippetMessages.getString(
             "SelectImportsDialog.Could_not_open_package_selection_dialog_8"); //$NON-NLS-1$
     ExceptionHandler.handle(jme, title, message);
     return;
   }
   if (dialog == null) {
     return;
   }
   dialog.setTitle(
       SnippetMessages.getString("SelectImportsDialog.Add_package_as_import_7")); // $NON-NLS-1$
   dialog.setMessage(
       SnippetMessages.getString(
           "SelectImportsDialog.&Select_a_package_to_add_as_an_Import_10")); //$NON-NLS-1$
   dialog.setMultipleSelection(true);
   if (dialog.open() == IDialogConstants.CANCEL_ID) {
     return;
   }
   Object[] packages = dialog.getResult();
   if (packages != null) {
     for (int i = 0; i < packages.length; i++) {
       IJavaElement pkg = (IJavaElement) packages[i];
       String filter = pkg.getElementName();
       filter += ".*"; // $NON-NLS-1$
       fImportContentProvider.addImport(filter);
     }
   }
 }
  private void addType() {
    Shell shell = fAddTypeButton.getDisplay().getActiveShell();
    SelectionDialog dialog = null;
    try {
      dialog =
          JavaUI.createTypeDialog(
              shell,
              PlatformUI.getWorkbench().getProgressService(),
              SearchEngine.createJavaSearchScope(
                  new IJavaElement[] {fEditor.getJavaProject()}, true),
              IJavaElementSearchConstants.CONSIDER_ALL_TYPES,
              false);
    } catch (JavaModelException jme) {
      String title =
          SnippetMessages.getString("SelectImportsDialog.Add_Type_as_Import_12"); // $NON-NLS-1$
      String message =
          SnippetMessages.getString(
              "SelectImportsDialog.Could_not_open_class_selection_dialog_13"); //$NON-NLS-1$
      ExceptionHandler.handle(jme, title, message);
      return;
    }

    dialog.setTitle(
        SnippetMessages.getString("SelectImportsDialog.Add_Type_as_Import_12")); // $NON-NLS-1$
    dialog.setMessage(
        SnippetMessages.getString(
            "SelectImportsDialog.&Select_a_type_to_add_to_add_as_an_import_15")); //$NON-NLS-1$
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
      return;
    }

    Object[] types = dialog.getResult();
    if (types != null && types.length > 0) {
      IType type = (IType) types[0];
      fImportContentProvider.addImport(type.getFullyQualifiedName());
    }
  }
 public SelectImportsDialog(JavaSnippetEditor editor, String[] imports) {
   super(editor.getShell());
   fEditor = editor;
   fImports = imports;
 }