/**
   * @param candidates Array of IFeatureModel
   * @param monitor
   * @throws CoreException
   */
  public void doAdd(Object[] candidates) throws CoreException {
    // Category to add features to
    String categoryName = null;
    ISelection selection = fCategoryViewer.getSelection();
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
      Object element = ((IStructuredSelection) selection).getFirstElement();
      if (element instanceof ISiteCategoryDefinition) {
        categoryName = ((ISiteCategoryDefinition) element).getName();
      } else if (element instanceof SiteFeatureAdapter) {
        categoryName = ((SiteFeatureAdapter) element).category;
      }
    }
    //
    ISiteFeature[] added = new ISiteFeature[candidates.length];
    for (int i = 0; i < candidates.length; i++) {
      IFeatureModel candidate = (IFeatureModel) candidates[i];
      ISiteFeature child = createSiteFeature(fModel, candidate);
      if (categoryName != null) {
        addCategory(child, categoryName);
      }
      added[i] = child;
    }

    // Update model
    fModel.getSite().addFeatures(added);
    // Select last added feature
    if (added.length > 0) {
      if (categoryName != null) {
        expandCategory(categoryName);
      }
      fCategoryViewer.setSelection(
          new StructuredSelection(new SiteFeatureAdapter(categoryName, added[added.length - 1])),
          true);
    }
  }
  protected void fillContextMenu(IMenuManager manager) {
    Action removeAction =
        new Action(PDEUIMessages.CategorySection_remove) {
          public void run() {
            doGlobalAction(ActionFactory.DELETE.getId());
          }
        };
    removeAction.setEnabled(isEditable());
    manager.add(removeAction);
    getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);

    ISelection selection = fCategoryViewer.getSelection();
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
      final ISiteFeature[] features = getFeaturesFromSelection((IStructuredSelection) selection);
      if (features.length > 0) {
        manager.add(new Separator());
        Action synchronizeAction = new SynchronizePropertiesAction(features, fModel);
        manager.add(synchronizeAction);
        Action buildAction =
            new Action(PDEUIMessages.CategorySection_build) {
              public void run() {
                ((SiteEditor) getPage().getPDEEditor()).handleBuild(features);
              }
            };
        buildAction.setEnabled(isEditable());
        manager.add(buildAction);
      }
    }
  }
  /** Refreshes the local resources that are selected in the view. */
  private void refreshLocal() {
    final ISelectionProvider selectionProvider = fView.getSite().getSelectionProvider();
    if (selectionProvider == null) return;

    ISelection selection = selectionProvider.getSelection();
    if (!(selection instanceof IStructuredSelection)) return;

    RefreshAction refreshAction = new RefreshAction(fView.getSite());
    if (selection.isEmpty()) refreshAction.refreshAll();
    else {
      refreshAction.selectionChanged((IStructuredSelection) selection);
      refreshAction.run();
    }
  }
  /**
   * Returns true if given structured selection matches the conditions specified in the registry for
   * this action.
   */
  private boolean isEnabledFor(ISelection sel) {
    Object obj = sel;
    int count = sel.isEmpty() ? 0 : 1;

    if (verifySelectionCount(count) == false) {
      return false;
    }

    // Compare selection to enablement expression.
    if (enablementExpression != null) {
      return enablementExpression.isEnabledFor(obj);
    }

    // Compare selection to class requirements.
    if (classes.isEmpty()) {
      return true;
    }
    if (obj instanceof IAdaptable) {
      IAdaptable element = (IAdaptable) obj;
      if (verifyElement(element) == false) {
        return false;
      }
    } else {
      return false;
    }

    return true;
  }
 private void updateRemoveButtons(boolean updateRemove, boolean updateRemoveAll) {
   TablePart tablePart = getTablePart();
   Table table = tablePart.getTableViewer().getTable();
   TableItem[] tableSelection = table.getSelection();
   if (updateRemove) {
     ISelection selection = getViewerSelection();
     tablePart.setButtonEnabled(
         3,
         isEditable()
             && !selection.isEmpty()
             && selection instanceof IStructuredSelection
             && ((IStructuredSelection) selection).getFirstElement() instanceof IProductPlugin);
   }
   int count = fPluginTable.getTable().getItemCount();
   if (updateRemoveAll) tablePart.setButtonEnabled(4, isEditable() && count > 0);
   tablePart.setButtonEnabled(2, isEditable() && count > 0);
   tablePart.setButtonEnabled(5, isEditable() && tableSelection.length == 1);
 }
 @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);
   }
 }
예제 #7
0
 /** Tests if the current workbench selection is a suitable container to use. */
 private void initialize() {
   if (selection != null
       && selection.isEmpty() == false
       && selection instanceof IStructuredSelection) {
     IStructuredSelection ssel = (IStructuredSelection) selection;
     if (ssel.size() > 1) {
       return;
     }
     Object obj = ssel.getFirstElement();
     if (obj instanceof IResource) {
       IContainer container;
       if (obj instanceof IContainer) {
         container = (IContainer) obj;
       } else {
         container = ((IResource) obj).getParent();
       }
       containerText.setText(container.getFullPath().toString());
     }
   }
   fileText.setText("new.gaml");
 }
 private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
   if (available) fAddButton.setEnabled(!theSelection.isEmpty());
   else fRemoveButton.setEnabled(!theSelection.isEmpty());
 }