@Override
 public boolean canPaste(Clipboard clipboard) {
   Display d = getSection().getDisplay();
   Control c = d.getFocusControl();
   if (c instanceof Text) return true;
   return false;
 }
  private void createSectionToolbar(Section section, FormToolkit toolkit) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    // Cursor needs to be explicitly disposed
    toolbar.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            if (handCursor.isDisposed() == false) {
              handCursor.dispose();
            }
          }
        });
    fNewPluginAction = new NewPluginAction();
    fNewFragmentAction = new NewFragmentAction();
    toolBarManager.add(fNewPluginAction);
    toolBarManager.add(fNewFragmentAction);

    toolBarManager.update(true);
    section.setTextClient(toolbar);
  }
 private void handleAdd() {
   IPluginModelBase model = (IPluginModelBase) getPage().getModel();
   final IProject project = model.getUnderlyingResource().getProject();
   try {
     if (project.hasNature(JavaCore.NATURE_ID)) {
       ILabelProvider labelProvider = new JavaElementLabelProvider();
       final ConditionalListSelectionDialog dialog =
           new ConditionalListSelectionDialog(
               PDEPlugin.getActiveWorkbenchShell(),
               labelProvider,
               PDEUIMessages.ExportPackageSection_dialogButtonLabel);
       final Collection<?> pckgs = fHeader == null ? new Vector<>() : fHeader.getPackageNames();
       final boolean allowJava =
           "true".equals(getBundle().getHeader(ICoreConstants.ECLIPSE_JREBUNDLE)); // $NON-NLS-1$
       Runnable runnable =
           new Runnable() {
             @Override
             public void run() {
               ArrayList<IPackageFragment> elements = new ArrayList<>();
               ArrayList<IPackageFragment> conditional = new ArrayList<>();
               IPackageFragment[] fragments =
                   PDEJavaHelper.getPackageFragments(JavaCore.create(project), pckgs, allowJava);
               for (IPackageFragment fragment : fragments) {
                 try {
                   if (fragment.containsJavaResources()) {
                     elements.add(fragment);
                   } else {
                     conditional.add(fragment);
                   }
                 } catch (JavaModelException e) {
                 }
               }
               dialog.setElements(elements.toArray());
               dialog.setConditionalElements(conditional.toArray());
               dialog.setMultipleSelection(true);
               dialog.setMessage(PDEUIMessages.PackageSelectionDialog_label);
               dialog.setTitle(PDEUIMessages.ExportPackageSection_title);
               dialog.create();
               PlatformUI.getWorkbench()
                   .getHelpSystem()
                   .setHelp(dialog.getShell(), IHelpContextIds.EXPORT_PACKAGES);
               SWTUtil.setDialogSize(dialog, 400, 500);
             }
           };
       BusyIndicator.showWhile(Display.getCurrent(), runnable);
       if (dialog.open() == Window.OK) {
         Object[] selected = dialog.getResult();
         if (fHeader != null) {
           for (Object selectedObject : selected) {
             IPackageFragment candidate = (IPackageFragment) selectedObject;
             fHeader.addPackage(
                 new ExportPackageObject(fHeader, candidate, getVersionAttribute()));
           }
         } else {
           getBundle().setHeader(getExportedPackageHeader(), getValue(selected));
           // the way events get triggered, updateButtons isn't called
           if (selected.length > 0) getTablePart().setButtonEnabled(CALCULATE_USE_INDEX, true);
         }
       }
       labelProvider.dispose();
     }
   } catch (CoreException e) {
   }
 }
 @Override
 public boolean canPaste(Clipboard clipboard) {
   Display d = getSection().getDisplay();
   return d.getFocusControl() instanceof Text;
 }