Ejemplo n.º 1
0
 /**
  * Extract the variable.
  *
  * @param event The execution event that contains the application context
  * @param name The variable name to extract.
  * @return The object from the application context, or <code>null</code> if it could not be found.
  */
 public static Object getVariable(ExecutionEvent event, String name) {
   if (event.getApplicationContext() instanceof IEvaluationContext) {
     Object var = ((IEvaluationContext) event.getApplicationContext()).getVariable(name);
     return var == IEvaluationContext.UNDEFINED_VARIABLE ? null : var;
   }
   return null;
 }
Ejemplo n.º 2
0
 @Override
 public Object execute(final ExecutionEvent event) throws ExecutionException {
   final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
   final IWorkbenchPart activePart = WorkbenchUIUtil.getActivePart(event.getApplicationContext());
   if (selection == null || activePart == null) {
     return null;
   }
   final ISourceUnit su = LTKSelectionUtil.getSingleSourceUnit(activePart);
   if (!(su instanceof IRSourceUnit)) {
     return null;
   }
   ExtractFunctionRefactoring refactoring = null;
   if (selection instanceof ITextSelection) {
     final ITextSelection textSelection = (ITextSelection) selection;
     refactoring =
         new ExtractFunctionRefactoring(
             (IRSourceUnit) su, new Region(textSelection.getOffset(), textSelection.getLength()));
   }
   if (refactoring != null) {
     final RefactoringWizardExecutionHelper executionHelper =
         new RefactoringWizardExecutionHelper(
             new ExtractFunctionWizard(refactoring), RefactoringSaveHelper.SAVE_NOTHING);
     executionHelper.perform(activePart.getSite().getShell());
   }
   //			}
   //			catch (final CoreException e) {
   //				StatusManager.getManager().handle(new Status(
   //						IStatus.ERROR, RUI.PLUGIN_ID, -1,
   //						Messages.InlineTemp_Wizard_title, e),
   //						StatusManager.LOG | StatusManager.SHOW);
   //			}
   return null;
 }
  /**
   * @see
   *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    toSelect = new ArrayList<EObject>();
    IEditorPart editor = RequirementUtils.getCurrentEditor();
    IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor);
    CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage();

    if (services != null
        && ((EvaluationContext) event.getApplicationContext()).getDefaultVariable()
            instanceof List<?>) {
      EditingDomain editingDomain = services.getEditingDomain(editor);
      // Get the current selection
      List<?> elements =
          ((List<?>) ((EvaluationContext) event.getApplicationContext()).getDefaultVariable());
      CompoundCommand compoundCmd =
          new CompoundCommand(Messages.getString("AddAttributeHandler.1")); // $NON-NLS-1$
      for (Object currObject : elements) {
        EObject parent = null;
        if (currObject instanceof Attribute) {
          parent = ((Attribute) currObject).eContainer();
          int newIndex = calculateIndex(parent, (EObject) currObject);

          Attribute toDuplicate = null;
          if (currObject instanceof AttributeLink) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateAttributeLink((AttributeLink) currObject);
          } else if (currObject instanceof ObjectAttribute) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateObjectAttribute((ObjectAttribute) currObject);
          }
          if (parent != null && toDuplicate != null) {
            toSelect.add(toDuplicate);
            compoundCmd.appendIfCanExecute(
                AddCommand.create(
                    editingDomain,
                    parent,
                    RequirementPackage.eINSTANCE.getRequirement_Attribute(),
                    toDuplicate,
                    newIndex));
          }
        }
      }
      if (!compoundCmd.isEmpty() && compoundCmd.canExecute()) {
        editingDomain.getCommandStack().execute(compoundCmd);
        page.setSelection(new StructuredSelection(toSelect));
      }
    }
    return null;
  }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());
    final List<IProject> projects;
    if (selection instanceof IStructuredSelection) {
      final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      projects = new ArrayList<>(structuredSelection.size());
      for (final Iterator<?> iter = structuredSelection.iterator(); iter.hasNext(); ) {
        final Object obj = iter.next();
        if (obj instanceof IAdaptable) {
          final IProject project = (IProject) ((IAdaptable) obj).getAdapter(IProject.class);
          if (project != null) {
            projects.add(project);
          }
        }
      }
    } else {
      return null;
    }

    final WorkspaceModifyOperation op =
        new WorkspaceModifyOperation() {

          @Override
          protected void execute(final IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            final SubMonitor m =
                SubMonitor.convert(monitor, TexUIMessages.TexProject_ConvertTask_label, 100);
            try {
              final SubMonitor mProjects = m.newChild(100).setWorkRemaining(projects.size());
              for (final IProject project : projects) {
                if (m.isCanceled()) {
                  throw new InterruptedException();
                }
                TexProjects.setupTexProject(project, mProjects.newChild(1));
              }
            } finally {
              m.done();
            }
          }
        };
    try {
      UIAccess.getActiveWorkbenchWindow(true).run(true, true, op);
    } catch (final InvocationTargetException e) {
      StatusManager.getManager()
          .handle(
              new Status(
                  IStatus.ERROR,
                  TexUI.PLUGIN_ID,
                  TexUIMessages.TexProject_ConvertTask_error_message,
                  e.getTargetException()));
    } catch (final InterruptedException e) {
      // cancelled
    }

    return null;
  }
  /** {@inheritDoc} */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    StructuredSelection selection =
        (StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
    AbstractRootEditor rootEditor = (AbstractRootEditor) HandlerUtil.getActiveEditor(event);
    RepositoryDefinition repositoryDefinition =
        rootEditor.getInputDefinition().getRepositoryDefinition();

    Object selectedObject = selection.getFirstElement();
    ExceptionSensorData dataToNavigateTo = null;
    if (selectedObject instanceof ExceptionSensorData) {
      dataToNavigateTo = (ExceptionSensorData) selectedObject;
    } else if (selectedObject instanceof InvocationSequenceData) {
      List<ExceptionSensorData> exceptions =
          ((InvocationSequenceData) selectedObject).getExceptionSensorDataObjects();
      if ((null != exceptions) && !exceptions.isEmpty()) {
        for (ExceptionSensorData exSensorData : exceptions) {
          if (0 != exSensorData.getMethodIdent()) {
            dataToNavigateTo = exSensorData;
            break;
          }
        }
      }
    }

    if (null != dataToNavigateTo) {
      ExceptionSensorData exceptionSensorData = dataToNavigateTo;

      // exit if the object does not carry the methodIdent
      if (null == exceptionSensorData.getThrowableType()) {
        return null;
      }

      InputDefinition inputDefinition =
          getInputDefinition(repositoryDefinition, exceptionSensorData);

      // open the view via command
      IHandlerService handlerService =
          (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
      ICommandService commandService =
          (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);

      Command command = commandService.getCommand(OpenViewHandler.COMMAND);
      ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event());
      IEvaluationContext context = (IEvaluationContext) executionEvent.getApplicationContext();
      context.addVariable(OpenViewHandler.INPUT, inputDefinition);

      try {
        command.executeWithChecks(executionEvent);
      } catch (NotDefinedException | NotEnabledException | NotHandledException e) {
        throw new ExecutionException("Error opening the exception type view.", e);
      }
    }
    return null;
  }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEvaluationContext context = (IEvaluationContext) event.getApplicationContext();

    /* Get the map */
    final IWorkbenchWindow window =
        (IWorkbenchWindow) context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
    final IWorkbenchPage activePage = window.getActivePage();

    /* set input to gtt tables */
    final IScenarioDataProvider dataProvider = KalypsoAFGUIFrameworkPlugin.getDataProvider();
    final IFolder scenarioFolder = (IFolder) dataProvider.getScenarioFolder();

    KalypsoCorePlugin.getDefault().getSelectionManager().clear();

    WorkflowHandlerUtils.setGttInput(
        activePage,
        "NaNodes",
        "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:NaNodes:gtt",
        Messages.getString("ResultOutputManagementTaskHandler_0"),
        scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    WorkflowHandlerUtils.setGttInput(
        activePage,
        "Catchments",
        "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:Catchments:gtt",
        Messages.getString("ResultOutputManagementTaskHandler_1"),
        scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    WorkflowHandlerUtils.setGttInput(
        activePage,
        "StorageChannels",
        "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:StorageChannels:gtt",
        Messages.getString("ResultOutputManagementTaskHandler_2"),
        scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    WorkflowHandlerUtils.setGftInput(
        activePage,
        "Outputs",
        "urn:org.kalypso.model.rrm.resultOutputManagement:workflow:Outputs:gft",
        Messages.getString("ResultOutputManagementTaskHandler_3"),
        scenarioFolder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    return null;
  }
Ejemplo n.º 7
0
  private IImageTrace getImage(ExecutionEvent event) {

    if (event == null) return null;
    final Object context = event.getApplicationContext();
    IImageTrace image = context instanceof IImageTrace ? (IImageTrace) context : null;

    if (image == null) {

      IPlottingSystem<?> system =
          context instanceof IPlottingSystem
              ? (IPlottingSystem<?>) context
              : (IPlottingSystem<?>)
                  EclipseUtils.getPage().getActivePart().getAdapter(IPlottingSystem.class);

      image = (IImageTrace) system.getTraces(IImageTrace.class).iterator().next();
    }

    return image;
  }
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
    final ISelection selection = WorkbenchUIUtil.getCurrentSelection(event.getApplicationContext());

    try {
      if (workbenchPart instanceof ITextEditor && selection instanceof ITextSelection) {
        final ITextEditor editor = (ITextEditor) workbenchPart;
        final IDocumentProvider documentProvider = editor.getDocumentProvider();
        if (documentProvider == null) {
          return null;
        }
        final IDocument document = documentProvider.getDocument(editor.getEditorInput());
        if (document == null) {
          return null;
        }
        final List<String> lines = LaunchShortcutUtil.getSelectedCodeLines(event);
        if (lines != null) {
          RCodeLaunching.runRCodeDirect(lines, false, null);
          final int newOffset =
              getNextLineOffset(document, ((ITextSelection) selection).getEndLine());
          if (newOffset >= 0) {
            editor.selectAndReveal(newOffset, 0);
          }
        }
        return null;
      }
    } catch (final CoreException e) {
      LaunchShortcutUtil.handleRLaunchException(
          e, RLaunchingMessages.RSelectionLaunch_error_message, event);
      return null;
    }

    LaunchShortcutUtil.handleUnsupportedExecution(event);
    return null;
  }
Ejemplo n.º 9
0
  @SuppressWarnings("unchecked")
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final MessageConsole b3Console = BeeLangConsoleUtils.getBeeLangConsole();
    final PrintStream b3ConsoleOutputStream = BeeLangConsoleUtils.getConsoleOutputStream(b3Console);
    try {
      b3ConsoleOutputStream.println("Running the main function...");
      EvaluationContext ctx = (EvaluationContext) event.getApplicationContext();
      List<ContentOutlineNode> nodes = (List<ContentOutlineNode>) ctx.getDefaultVariable();
      ContentOutlineNode node = nodes.get(0);
      Object result =
          node.getEObjectHandle()
              .readOnly(
                  new IUnitOfWork<Object, EObject>() {
                    // @Override
                    public Object exec(EObject state) throws Exception {
                      B3BuildEngine engine =
                          new B3BuildEngine(new ExecuteHandlerModule(b3ConsoleOutputStream));
                      try {
                        engine.defineBeeModel((BeeModel) state);
                      } catch (Throwable e) {
                        PrintStream b3ConsoleErrorStream =
                            BeeLangConsoleUtils.getConsoleErrorStream(b3Console);
                        try {
                          e.printStackTrace();
                          b3ConsoleErrorStream.println(
                              "Loading failed with error: "
                                  + e.getClass().getName().toString()
                                  + " : "
                                  + e.getMessage());
                          if (e.getCause() != null) {
                            b3ConsoleErrorStream.println("Caused by: " + e.getCause().getMessage());
                            return null;
                          }

                        } finally {
                          b3ConsoleErrorStream.close();
                        }
                      }
                      // get the resolution scope (in case a resolution is to be performed)
                      //
                      SharedScope resolutionScope = null;
                      // If resolving, run a resolution
                      if (isPerformResolve()) {
                        resolutionScope =
                            engine.getInjector().getInstance(B3BuildConstants.KEY_RESOLUTION_SCOPE);
                        resolutionScope.enter(); // !remember to call exit()

                        IStatus status = engine.resolveAllUnits();
                        if (!status.isOK()) {
                          PrintStream b3ConsoleErrorStream =
                              BeeLangConsoleUtils.getConsoleErrorStream(b3Console);
                          try {
                            // TODO: Better error reporting on failed resolution
                            b3ConsoleErrorStream.println("Resolution Failed with non OK status :");
                            b3ConsoleErrorStream.println(status.toString());

                          } finally {
                            b3ConsoleErrorStream.close();
                            // if(resolutionScope != null) // in case the error has to do with
                            // resolution scope
                            // resolutionScope.exit();
                            // resolutionScope = null;
                          }
                        }
                      }
                      // find a function called main (use the first found) and call it with a
                      // List<Object> argv
                      IFunction main = null;
                      for (IFunction f : ((BeeModel) state).getFunctions()) {
                        if ("main".equals(f.getName())) {
                          main = f;
                        }
                      }

                      if (main == null) return null;
                      final List<Object> argv = new ArrayList<Object>();
                      argv.add(engine);
                      try {
                        engine.callFunction(
                            // return engine.getContext().callFunction(
                            "main", new Object[] {argv}, new Type[] {List.class});
                      } catch (B3BackendException exprException) {
                        exprException.printStackTrace();
                        BExpression expr = exprException.getExpression();
                        int lineNumber = BeeLangUtils.getLineNumber(expr);

                        PrintStream b3ConsoleErrorStream =
                            BeeLangConsoleUtils.getConsoleErrorStream(b3Console);
                        try {
                          b3ConsoleErrorStream.println(exprException.getMessage());
                          b3ConsoleErrorStream.println(
                              "        at "
                                  + BeeLangUtils.closestNamedElement(expr)
                                  + "("
                                  + exprException.getLocationString()
                                  + ":"
                                  + lineNumber
                                  + ").");
                          if (exprException.getCause() != null) {
                            b3ConsoleErrorStream.println(
                                "Caused by: "
                                    + ((exprException.getCause().getMessage() == null)
                                        ? exprException.getCause().getClass().getName()
                                        : exprException.getCause().getMessage()));
                          }

                        } finally {
                          b3ConsoleErrorStream.close();
                        }

                      } catch (Throwable e) {
                        // Just print some errors
                        e.printStackTrace();
                        PrintStream b3ConsoleErrorStream =
                            BeeLangConsoleUtils.getConsoleErrorStream(b3Console);
                        try {
                          b3ConsoleErrorStream.println(e.getMessage());
                        } finally {
                          b3ConsoleErrorStream.close();
                        }
                      } finally {
                        if (resolutionScope != null) resolutionScope.exit();
                        resolutionScope = null;
                      }
                      return null;
                    }
                  });
      b3ConsoleOutputStream.println("Result = " + (result == null ? "null" : result.toString()));
      return null;
    } finally {
      b3ConsoleOutputStream.close();
    }
  }