@Override
  protected IContributionItem[] getItems() {

    Object selection = contextProvider.getContext().get(ESelectionService.class).getSelection();
    if (!(selection instanceof IBindingManager) || !((IBindingManager) selection).wIsSet("self"))
      return new IContributionItem[0];

    IBindingManager bm = (IBindingManager) selection;
    String languageURI = bm.wGet("self").wGetLanguageKit().getURI();

    Map<GuardedAction, String> actionsMap = new HashMap<GuardedAction, String>();
    IResourceRegistry<Resource> registry = ActionsRegistry.instance();
    for (IResource resource : registry.getResources(false)) {
      LanguageActionFactory actionsModule = resource.getEntity();
      URI targetLanguage = actionsModule.getTargetLanguage();
      if (DataTypeUtils.getDataKind(targetLanguage).isString()
          && !languageURI.equals(targetLanguage.getValue())) continue;

      for (GuardedAction guardedAction :
          Matcher.findAll(
              ActionsEntityDescriptorEnum.GuardedAction, getActions(actionsModule), false)) {
        String actionName = guardedAction.getName().getValue();
        String functionUri = resource.getURI() + '#' + actionName;
        actionsMap.put(guardedAction, functionUri);
      }
    }

    List<IAction> actions = new ArrayList<IAction>();
    List<GuardedAction> guardedActions = new ArrayList<GuardedAction>(actionsMap.keySet());
    Collections.sort(
        guardedActions,
        new Comparator<GuardedAction>() {
          public int compare(GuardedAction a1, GuardedAction a2) {
            return a1.getName().getValue().compareTo(a2.getName().getValue());
          }
        });

    for (GuardedAction guardedAction : guardedActions) {
      String actionName = guardedAction.getName().getValue();
      String functionUri = actionsMap.get(guardedAction);
      IUpdatableAction action =
          contextProvider
              .getActionRegistry()
              .getActionFactory()
              .createActionCallAction(
                  actionName, isAnalyze(), guardedAction.getEnablerPredicate(), functionUri);
      action.update();
      actions.add(action);
    }

    List<IContributionItem> items = new ArrayList<IContributionItem>();
    HierarchicalFillMenuStrategy.instance()
        .fillMenu(
            ActionListContainer.create(items),
            ActionSet.create(actions.toArray(new IAction[actions.size()])),
            0,
            actions.size());

    return items.toArray(new IContributionItem[items.size()]);
  }
Ejemplo n.º 2
0
  @Override
  @Execute
  public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
      IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
      if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer)) {
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart focusPart =
            (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);

        String textContents = Clipboard.instance().getTextContents();
        Command command = focusPart.getCommand(TextualRequest.createInsertRequest(textContents));

        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        if (command instanceof ITextCommand) {
          TextTransactionCommand transactionCommand = new TextTransactionCommand();
          transactionCommand.setModel(focusEntity);
          transactionCommand.merge((ITextCommand) command);
          transactionCommand.setLabel(getLabel(bm));
          commandStack.execute(transactionCommand);
        } else {
          command.setLabel(getLabel(bm) + " text");
          commandStack.execute(command);
        }
        return;
      }
    }
    super.execute(bm);
  }
 protected void apply(IEntityIterator<?> iterator) {
   IBindingManager bm = getBindings();
   ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
   bm.wEnterScope(resettableScope);
   for (IEntity e : iterator) {
     bm.setResult(e);
     resettableScope.commit();
   }
   resettableScope.rollback();
   bm.wExitScope();
 }
Ejemplo n.º 4
0
 @Override
 @CanExecute
 public boolean canExecute(
     @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
   try {
     if (bm.wIsSet("viewer") && Clipboard.instance().getInternalOrNativeEntityContents() == null) {
       IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
       if (ClipboardUtils.hasTextFocus(viewer) || ClipboardUtils.hasTextSeletion(viewer))
         return true;
     }
     return super.canExecute(bm);
   } catch (Exception e) {
     return false;
   }
 }
Ejemplo n.º 5
0
  public static void moveArtifactsIntoWorkspace(IEntity artifacts, IBindingManager bm) {
    switch (artifacts.wGetEntityDescriptor().getOrdinal()) {
      case ArtifactsEntityDescriptorEnum.Workspace_ord:
        Projects projectsPoint = (Projects) bm.wGet("projectsPoint");
        if (projectsPoint == null) throw new IllegalArgumentException("projectsPoint is undefined");

        IEntityIterator<Project> projectIterator = IteratorFactory.childIterator();
        projectIterator.reset(((Workspace) artifacts).getProjects());
        for (Project project : projectIterator) {
          projectIterator.remove();
          projectsPoint.add(project);
        }
        break;
      case ArtifactsEntityDescriptorEnum.Artifacts_ord:
        Artifacts packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        IEntityIterator<Artifact> artifactIterator = IteratorFactory.childIterator();
        artifactIterator.reset(artifacts);
        for (Artifact artifact : artifactIterator) {
          artifactIterator.remove();
          packagesPoint.add(artifact);
        }
        break;
      case ArtifactsEntityDescriptorEnum.PackageArtifact_ord:
      case ArtifactsEntityDescriptorEnum.FolderArtifact_ord:
        packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        packagesPoint.add((Artifact) artifacts);
        break;
      case ArtifactsEntityDescriptorEnum.FileArtifact_ord:
        Artifacts packageArtifactsPoint = (Artifacts) bm.wGet("packageArtifactsPoint");
        if (packageArtifactsPoint == null)
          throw new IllegalArgumentException("packageArtifactsPoint is undefined");

        packageArtifactsPoint.add((FileArtifact) artifacts);
        break;
    }
  }