private void updateButtons() {
    Object[] selected = ((IStructuredSelection) fPackageViewer.getSelection()).toArray();

    TablePart tablePart = getTablePart();
    tablePart.setButtonEnabled(ADD_INDEX, canAddExportedPackages());
    tablePart.setButtonEnabled(REMOVE_INDEX, isEditable() && selected.length > 0);
    tablePart.setButtonEnabled(PROPERTIES_INDEX, shouldEnableProperties(selected));
    tablePart.setButtonEnabled(
        CALCULATE_USE_INDEX, isEditable() && fPackageViewer.getTable().getItemCount() > 0);
  }
 private void handleAdd() {
   IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection();
   if (ssel.size() > 0) {
     Table table = fAvailableListViewer.getTable();
     int index = table.getSelectionIndices()[0];
     doAdd(ssel.toList());
     table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1);
     pageChanged(true, false);
   }
 }
 private void handleDelete() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() > 0) {
     Object[] objects = ssel.toArray();
     IProductPlugin[] plugins = new IProductPlugin[objects.length];
     System.arraycopy(objects, 0, plugins, 0, objects.length);
     getProduct().removePlugins(plugins);
     updateRemoveButtons(true, true);
   }
 }
  private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
    updateCount();
    int availableCount = fAvailableListViewer.getTable().getItemCount();
    int importCount = fImportListViewer.getTable().getItemCount();

    if (doAddEnablement) updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
    if (doRemoveEnablement) updateSelectionBasedEnablement(fImportListViewer.getSelection(), false);

    fAddAllButton.setEnabled(availableCount > 0);
    fRemoveAllButton.setEnabled(importCount > 0);
    fAddRequiredButton.setEnabled(importCount > 0);
  }
 private void handleProperties() {
   IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
   if (ssel.size() == 1) {
     IProductPlugin plugin = (IProductPlugin) ssel.toArray()[0];
     VersionDialog dialog =
         new VersionDialog(PDEPlugin.getActiveWorkbenchShell(), isEditable(), plugin.getVersion());
     dialog.create();
     SWTUtil.setDialogSize(dialog, 400, 200);
     if (dialog.open() == Window.OK) {
       plugin.setVersion(dialog.getVersion());
     }
   }
 }
 @Override
 protected void fillContextMenu(IMenuManager manager) {
   ISelection selection = fPackageViewer.getSelection();
   manager.add(fAddAction);
   boolean singleSelection =
       selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1;
   if (singleSelection) manager.add(fGoToAction);
   manager.add(new Separator());
   if (!selection.isEmpty()) manager.add(fRemoveAction);
   getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
   if (singleSelection)
     manager.add(
         new Action(PDEUIMessages.ExportPackageSection_findReferences) {
           @Override
           public void run() {
             doSearch(fPackageViewer.getSelection());
           }
         });
   if (shouldEnableProperties(((IStructuredSelection) fPackageViewer.getSelection()).toArray())) {
     manager.add(new Separator());
     manager.add(fPropertiesAction);
   }
 }
 private void handleRemove() {
   LinkedList<NameVersionDescriptor> bundles = new LinkedList<NameVersionDescriptor>();
   bundles.addAll(Arrays.asList(getTargetDefinition().getImplicitDependencies()));
   Object[] removeBundles = ((IStructuredSelection) fElementViewer.getSelection()).toArray();
   if (removeBundles.length > 0) {
     for (int i = 0; i < removeBundles.length; i++) {
       if (removeBundles[i] instanceof NameVersionDescriptor) {
         bundles.remove(removeBundles[i]);
       }
     }
     getTargetDefinition()
         .setImplicitDependencies(bundles.toArray((new NameVersionDescriptor[bundles.size()])));
     fElementViewer.refresh();
     updateImpButtons();
   }
 }
 private void handleOpenProperties() {
   Object[] selected = ((IStructuredSelection) fPackageViewer.getSelection()).toArray();
   ExportPackageObject first = (ExportPackageObject) selected[0];
   DependencyPropertiesDialog dialog = new DependencyPropertiesDialog(isEditable(), first);
   dialog.create();
   PlatformUI.getWorkbench()
       .getHelpSystem()
       .setHelp(dialog.getShell(), IHelpContextIds.EXPORTED_PACKAGE_PROPERTIES);
   SWTUtil.setDialogSize(dialog, 400, -1);
   if (selected.length == 1) dialog.setTitle(((ExportPackageObject) selected[0]).getName());
   else dialog.setTitle(PDEUIMessages.ExportPackageSection_props);
   if (dialog.open() == Window.OK && isEditable()) {
     String newVersion = dialog.getVersion();
     for (Object selectedObject : selected) {
       ExportPackageObject object = (ExportPackageObject) selectedObject;
       if (!newVersion.equals(object.getVersion())) object.setVersion(newVersion);
     }
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#fillContextMenu(org.eclipse.jface.action.IMenuManager)
   */
  protected void fillContextMenu(IMenuManager manager) {
    IStructuredSelection ssel = (IStructuredSelection) fPluginTable.getSelection();
    if (ssel == null) return;

    Action openAction =
        new Action(PDEUIMessages.PluginSection_open) {
          public void run() {
            handleDoubleClick((IStructuredSelection) fPluginTable.getSelection());
          }
        };
    openAction.setEnabled(isEditable() && ssel.size() == 1);
    manager.add(openAction);

    manager.add(new Separator());

    Action removeAction =
        new Action(PDEUIMessages.PluginSection_remove) {
          public void run() {
            handleDelete();
          }
        };
    removeAction.setEnabled(isEditable() && ssel.size() > 0);
    manager.add(removeAction);

    Action removeAll =
        new Action(PDEUIMessages.PluginSection_removeAll) {
          public void run() {
            handleRemoveAll();
          }
        };
    removeAll.setEnabled(isEditable());
    manager.add(removeAll);

    manager.add(new Separator());

    getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
  }
 private void handleRemove() {
   Object[] removed = ((IStructuredSelection) fPackageViewer.getSelection()).toArray();
   for (Object removedObject : removed) {
     fHeader.removePackage((PackageObject) removedObject);
   }
 }
 private void updateImpButtons() {
   boolean empty = fElementViewer.getSelection().isEmpty();
   fRemoveButton.setEnabled(!empty);
   boolean hasElements = fElementViewer.getTable().getItemCount() > 0;
   fRemoveAllButton.setEnabled(hasElements);
 }