コード例 #1
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {

    String genId = event.getParameter("com.opcoach.gendoc.generateDocument.generatorID");

    ISelection sel = HandlerUtil.getCurrentSelection(event);
    if (sel instanceof IStructuredSelection) {
      Object selected = ((IStructuredSelection) sel).getFirstElement();
      if (selected instanceof EObject) {
        // Can get the path of current object and initialize the gendoc
        // generator.
        GeneratorDesc gd = OPCGendocActivator.getDocumentGeneratorRegistry().get(genId);
        generateDocument((EObject) selected, gd);
      }
    }

    return null;
  }
コード例 #2
0
  public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    OPCGendocActivator activator = OPCGendocActivator.getDefault();

    IGendocDiagnostician diagnostician =
        GendocServices.getDefault().getService(IGendocDiagnostician.class);
    diagnostician.init();
    IProgressMonitorService monitorService =
        (IProgressMonitorService)
            GendocServices.getDefault().getService(IProgressMonitorService.class);
    monitorService.setMonitor(monitor);

    try {

      GendocProcess gendocProcess = new GendocProcess();

      EMFModelLoaderService service =
          new EMFModelLoaderService() {
            @Override
            public EObject getModel(URI path) throws ModelNotFoundException {
              return source;
            }
          };
      service.setServiceId("IEMFModelLoaderService");
      GendocServices.getDefault().setService(IEMFModelLoaderService.class, service);

      IConfigurationService conf =
          GendocServices.getDefault().getService(IConfigurationService.class);
      conf.setOutput(getOutpuPath());
      URL templateUrl = gd.getTemplateURL();

      String resultFile = gendocProcess.runProcess(templateUrl);

      handleDiagnostic(
          diagnostician.getResultDiagnostic(),
          "The file has been generated but contains errors :\n",
          resultFile);
    } catch (GenDocException e) {
      activator
          .getLog()
          .log(new Status(IStatus.ERROR, OPCGendocActivator.PLUGIN_ID, e.getUIMessage(), e));
      diagnostician.addDiagnostic(
          new BasicDiagnostic(
              Diagnostic.ERROR, OPCGendocActivator.PLUGIN_ID, 0, e.getUIMessage(), null));
      handleDiagnostic(
          diagnostician.getResultDiagnostic(), "An error occured during generation.", null);
    } catch (Throwable t) {
      activator
          .getLog()
          .log(new Status(IStatus.ERROR, OPCGendocActivator.PLUGIN_ID, t.getMessage(), t));
      diagnostician.addDiagnostic(
          new BasicDiagnostic(
              Diagnostic.ERROR,
              OPCGendocActivator.PLUGIN_ID,
              0,
              t.getMessage(),
              t.getStackTrace()));
      handleDiagnostic(
          diagnostician.getResultDiagnostic(),
          "An unexpected error occured during the generation.",
          null);
    } finally {
      GendocServices.getDefault().clear();
    }
  }