@Override
 protected void doPaste(Object targetObject, Object[] sourceObjects) {
   // Get the model
   IBundleModel model = getBundleModel();
   // Ensure the model is defined
   if (model == null) {
     return;
   }
   // Get the bundle
   IBundle bundle = model.getBundle();
   // Paste all source objects
   for (Object sourceObject : sourceObjects) {
     if (sourceObject instanceof ExportPackageObject) {
       ExportPackageObject exportPackageObject = (ExportPackageObject) sourceObject;
       // Export package object
       // Adjust all the source object transient field values to
       // acceptable values
       exportPackageObject.reconnect(model, fHeader, getVersionAttribute());
       // Add the object to the header
       if (fHeader == null) {
         // Export package header not defined yet
         // Define one
         // Value will get inserted into a new export package object
         // created by a factory
         // Value needs to be empty string so no export package
         // object is created as the initial value
         bundle.setHeader(getExportedPackageHeader(), ""); // $NON-NLS-1$
       }
       // Add the export package to the header
       fHeader.addPackage(exportPackageObject);
     }
   }
 }
 private HashMap<?, ?> createCurrentExportPackageMap() {
   // Dummy hash map created in order to return a defined but empty map
   HashMap<?, ?> packageFragments = new HashMap<>(0);
   // Get the model
   IPluginModelBase model = getModel();
   // Ensure model is defined
   if (model == null) {
     return packageFragments;
   }
   // Get the underlying resource
   IResource resource = model.getUnderlyingResource();
   // Ensure resource is defined
   if (resource == null) {
     return packageFragments;
   }
   // Get the project
   IProject project = resource.getProject();
   // Ensure the project is defined
   if (project == null) {
     return packageFragments;
   }
   // Ensure the project is a Java project
   try {
     if (project.hasNature(JavaCore.NATURE_ID) == false) {
       return packageFragments;
     }
   } catch (CoreException e) {
     return packageFragments;
   }
   // Get the Java project
   IJavaProject javaProject = JavaCore.create(project);
   // Ensure the Java project is defined
   if (javaProject == null) {
     return packageFragments;
   }
   // Get the current packages associated with the export package header
   Vector<?> currentExportPackages = null;
   if (fHeader == null) {
     currentExportPackages = new Vector<>();
   } else {
     currentExportPackages = fHeader.getPackageNames();
   }
   // Get a hashtable of all the package fragments that are allowed to
   // be added to the current export package header
   // Generally, all package fragments contained in the same Java project
   // as the plugin manifest file
   // No duplicates are allowed and all current packages are excluded
   return PDEJavaHelper.getPackageFragmentsHash(
       javaProject, currentExportPackages, allowJavaPackages());
 }
 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) {
   }
 }
 private void handleRemove() {
   Object[] removed = ((IStructuredSelection) fPackageViewer.getSelection()).toArray();
   for (Object removedObject : removed) {
     fHeader.removePackage((PackageObject) removedObject);
   }
 }
Пример #5
0
  private void executeAdd(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.add((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.add((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.add((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.add((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).addContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).add(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.add(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel pluginModel = (BundlePluginModel) aggModel;
              RequireBundleObject requireBundle = (RequireBundleObject) element;
              pluginBase = pluginModel.getPluginBase();
              String elementValue = requireBundle.getValue();
              IPluginImport importNode = null;
              if (pluginModel.getPluginFactory() instanceof BundlePluginModelBase)
                importNode =
                    ((BundlePluginModelBase) pluginModel.getPluginFactory())
                        .createImport(elementValue);
              String version =
                  ((RequireBundleObject) element).getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
              IManifestHeader header =
                  bundleModel.getBundle().getManifestHeader(Constants.REQUIRE_BUNDLE);
              int bundleManifestVersion =
                  BundlePluginBase.getBundleManifestVersion(
                      ((RequireBundleHeader) header).getBundle());
              boolean option =
                  (bundleManifestVersion > 1)
                      ? Constants.RESOLUTION_OPTIONAL.equals(
                          requireBundle.getDirective(Constants.RESOLUTION_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.OPTIONAL_ATTRIBUTE)); // $NON-NLS-1$;
              boolean exported =
                  (bundleManifestVersion > 1)
                      ? Constants.VISIBILITY_REEXPORT.equals(
                          requireBundle.getDirective(Constants.VISIBILITY_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.REPROVIDE_ATTRIBUTE)); // $NON-NLS-1$;
              if (importNode != null) {
                importNode.setVersion(version);
                importNode.setOptional(option);
                importNode.setReexported(exported);
              }
              if (pluginBase instanceof BundlePluginBase && importNode != null)
                ((BundlePluginBase) pluginBase).add(importNode);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }
Пример #6
0
  private void executeRemove(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.remove((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.remove((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.remove((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.remove((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).removeContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).remove(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.remove(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel mod = (BundlePluginModel) aggModel;
              pluginBase = mod.getPluginBase();
              IPluginImport[] imports = pluginBase.getImports();
              IPluginImport currentImport = null;
              for (IPluginImport pluginImport : imports) {
                String elementValue = ((RequireBundleObject) element).getValue();
                if (pluginImport.getId().equals(elementValue)) {
                  currentImport = pluginImport;
                  break;
                }
              }
              IPluginImport[] plugins = {currentImport};
              if (pluginBase instanceof BundlePluginBase && currentImport != null)
                ((BundlePluginBase) pluginBase).remove(plugins);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }