コード例 #1
0
 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);
     }
   }
 }
コード例 #2
0
  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());
    }
  }