Example #1
0
 public void run() {
   Job job = createJob();
   job.setUser(true);
   job.setProperty(
       IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PSEARCH_OBJ.createImage());
   job.schedule();
 }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    Job job =
        new Job(getJobName()) {

          @Override
          protected IStatus run(IProgressMonitor monitor) {
            int i = 0;
            while (i < MAX_ATTEMPTS) {
              refreshAll(monitor);
              cleanAll(monitor);

              List<IMarker> errorMarkers = getErrorMarkers();
              if (errorMarkers.isEmpty()) {
                buildAll(monitor);
                return Status.OK_STATUS;
              }

              boolean hasOtherProblems = wsHasProblemsThatCantBeSolvedByCleanRefresh(errorMarkers);
              if (hasOtherProblems) {
                return new Status(
                    IStatus.ERROR,
                    Activator.PLUGIN_ID,
                    "Workspace has problems that can't be solved by clean-refresh",
                    null);
              }

              monitor.worked(1);
              i++;
            }
            return new Status(
                IStatus.ERROR,
                Activator.PLUGIN_ID,
                "Workspace problems were not resolved within "
                    + MAX_ATTEMPTS
                    + " clean-refresh attempts",
                null);
          }
        };
    job.setUser(true);
    job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
    job.schedule();
    return "Done";
  }
  /** {@inheritDoc} */
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException {
    final StructuredSelection selection =
        (StructuredSelection) HandlerUtil.getCurrentSelection(event);

    if (selection.isEmpty()) {
      return null;
    }

    final int size = selection.size();
    MessageBox confirmDelete =
        new MessageBox(HandlerUtil.getActiveShell(event), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
    confirmDelete.setText("Confirm Delete");
    confirmDelete.setMessage(
        "Are you sure you want to delete the "
            + size
            + " selected environment"
            + ((size > 1) ? "s" : "")
            + "?");
    boolean confirmed = SWT.OK == confirmDelete.open();

    if (confirmed) {
      Job deleteEnvironmentsJob =
          new Job("Delete Environment(s) Job") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
              List<Status> statuses = new ArrayList<>();
              for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
                Object selected = it.next();
                if (selected instanceof IEnvironmentProvider) {
                  CmrRepositoryDefinition repositoryDefinition =
                      ((IEnvironmentProvider) selected).getCmrRepositoryDefinition();
                  Environment environment = ((IEnvironmentProvider) selected).getEnvironment();

                  try {
                    if (repositoryDefinition.getOnlineStatus() != OnlineStatus.OFFLINE) {
                      repositoryDefinition
                          .getConfigurationInterfaceService()
                          .deleteEnvironment(environment);

                      InspectIT.getDefault()
                          .getInspectITConfigurationInterfaceManager()
                          .environmentDeleted(environment, repositoryDefinition);
                    }
                  } catch (BusinessException e) {
                    statuses.add(
                        new Status(
                            IStatus.ERROR,
                            InspectIT.ID,
                            "Error deleting environment "
                                + environment.getName()
                                + " from the CMR.",
                            e));
                  }
                }
              }

              if (CollectionUtils.isNotEmpty(statuses)) {
                if (1 == statuses.size()) {
                  return statuses.iterator().next();
                } else {
                  return new MultiStatus(
                      InspectIT.ID,
                      IStatus.OK,
                      statuses.toArray(new Status[statuses.size()]),
                      "Delete of several environments failed.",
                      null);
                }
              } else {
                return Status.OK_STATUS;
              }
            }
          };
      deleteEnvironmentsJob.setUser(true);
      deleteEnvironmentsJob.setProperty(
          IProgressConstants.ICON_PROPERTY,
          InspectIT.getDefault().getImageDescriptor(InspectITImages.IMG_BLOCK));
      deleteEnvironmentsJob.schedule();
    }

    return null;
  }
  private void internalExecute(final Resource resource, final Shell shell) {
    if (resource != null) {
      final JdbcSource source = JdbcUtil.findJdbcSource(resource);
      if (source != null) {
        final List emfTables = RelationalUtil.findTables(resource);
        final Map tblStats = createTableInfos(emfTables);
        if (tblStats != null && tblStats.size() > 0) {
          CostAnalysisDialog dialog =
              new CostAnalysisDialog(
                  shell,
                  InternalModelerJdbcUiPluginConstants.Util.getString(
                      "CostAnalysisAction.taskDescription"), //$NON-NLS-1$
                  InternalModelerJdbcUiPluginConstants.Util.getString(
                      "CostAnalysisAction.passwordPrompt",
                      new Object[] {source.getUrl(), source.getUsername()}),
                  null,
                  null); //$NON-NLS-1$
          dialog.open();

          final String password = dialog.getValue();
          if (password != null) {
            final Job job =
                new Job(
                    InternalModelerJdbcUiPluginConstants.Util.getString(
                        "CostAnalysisAction.jobDescription")) { //$NON-NLS-1$
                  @Override
                  protected IStatus run(IProgressMonitor monitor) {
                    try {
                      monitor.beginTask(
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.taskDescription"),
                          calculateNumberOfWorkIncrements(tblStats.values())); // $NON-NLS-1$

                      CostAnalyzer costAnalyzer =
                          CostAnalyzerFactory.getCostAnalyzerFactory()
                              .getCostAnalyzer(source, password);
                      // log output to standard out
                      // costAnalyzer.setOutputStream(System.out);
                      costAnalyzer.collectStatistics(tblStats, monitor);

                      if (!monitor.isCanceled()) {
                        populateEmfColumnStatistics(emfTables, tblStats);
                      }

                      monitor.done();

                      if (monitor.isCanceled()) {
                        return Status.CANCEL_STATUS;
                      }

                      return new Status(
                          IStatus.OK,
                          ModelerJdbcUiConstants.PLUGIN_ID,
                          IStatus.OK,
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.statusFinished", emfTables.size()),
                          null); //$NON-NLS-1$
                    } catch (Exception e) {
                      InternalModelerJdbcUiPluginConstants.Util.log(e);
                      return new Status(
                          IStatus.ERROR,
                          ModelerJdbcUiConstants.PLUGIN_ID,
                          IStatus.ERROR,
                          InternalModelerJdbcUiPluginConstants.Util.getString(
                              "CostAnalysisAction.errorMessage"),
                          e); //$NON-NLS-1$
                    } finally {
                    }
                  }
                };

            job.setSystem(false);
            job.setUser(true);
            job.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
            // start as soon as possible
            job.schedule();
          }
        } else {
          MessageDialog.openInformation(
              shell,
              InternalModelerJdbcUiPluginConstants.Util.getString(
                  "CostAnalysisAction.taskDescription"),
              InternalModelerJdbcUiPluginConstants.Util.getString(
                  "CostAnalysisAction.noValidTablesMessage")); //$NON-NLS-1$ //$NON-NLS-2$
        }
      }
    }
  }
  /** Create the update job that handles the updatesInfo. */
  private void createUpdateJob() {
    updateJob =
        new WorkbenchJob(ProgressMessages.ProgressContentProvider_UpdateProgressJob) {
          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            synchronized (updateScheduled) {
              // updates requested while we are running should cause it to
              // be rescheduled
              updateScheduled.value = false;
            }
            // Abort the job if there isn't anything
            if (collectors.length == 0) {
              return Status.CANCEL_STATUS;
            }

            if (currentInfo.updateAll) {
              synchronized (updateLock) {
                currentInfo.reset();
              }
              for (int i = 0; i < collectors.length; i++) {
                collectors[i].refresh();
              }

            } else {
              // Lock while getting local copies of the caches.
              Object[] updateItems;
              Object[] additionItems;
              Object[] deletionItems;
              synchronized (updateLock) {
                currentInfo.processForUpdate();

                updateItems = currentInfo.refreshes.toArray();
                additionItems = currentInfo.additions.toArray();
                deletionItems = currentInfo.deletions.toArray();

                currentInfo.reset();
              }

              for (int v = 0; v < collectors.length; v++) {
                IProgressUpdateCollector collector = collectors[v];

                if (updateItems.length > 0) {
                  collector.refresh(updateItems);
                }
                if (additionItems.length > 0) {
                  collector.add(additionItems);
                }
                if (deletionItems.length > 0) {
                  collector.remove(deletionItems);
                }
              }
            }

            return Status.OK_STATUS;
          }

          @Override
          protected void canceling() {
            synchronized (updateScheduled) {
              updateScheduled.value = false;
            }
          }
        };
    updateJob.setSystem(true);
    updateJob.setPriority(Job.DECORATE);
    updateJob.setProperty(ProgressManagerUtil.INFRASTRUCTURE_PROPERTY, new Object());
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ptp.rtsystem.IRuntimeSystem#startup(org.eclipse.core.runtime
   * .IProgressMonitor)
   */
  public void startup(IProgressMonitor monitor) throws CoreException {
    SubMonitor subMon = SubMonitor.convert(monitor, 100);

    synchronized (this) {
      startupMonitor = subMon;
    }

    initialize();

    subMon.subTask(Messages.AbstractToolRuntimeSystem_1);

    DebugUtil.trace(
        DebugUtil.RTS_TRACING,
        "RTS {0}: startup",
        getResourceManager().getConfiguration().getName()); // $NON-NLS-1$

    try {
      remoteServices =
          PTPRemoteCorePlugin.getDefault()
              .getRemoteServices(
                  getResourceManager().getControlConfiguration().getRemoteServicesId(),
                  subMon.newChild(10));
      if (remoteServices == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                RMCorePlugin.PLUGIN_ID,
                Messages.AbstractToolRuntimeSystem_Exception_NoRemoteServices));
      }

      IRemoteConnectionManager connectionManager = remoteServices.getConnectionManager();
      Assert.isNotNull(connectionManager);

      subMon.worked(10);
      subMon.subTask(Messages.AbstractToolRuntimeSystem_2);

      connection =
          connectionManager.getConnection(
              getResourceManager().getControlConfiguration().getConnectionName());
      if (connection == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                RMCorePlugin.PLUGIN_ID,
                Messages.AbstractToolRuntimeSystem_Exception_NoConnection));
      }

      if (!connection.isOpen()) {
        try {
          connection.open(subMon.newChild(50));
        } catch (RemoteConnectionException e) {
          throw new CoreException(
              new Status(IStatus.ERROR, RMCorePlugin.PLUGIN_ID, e.getMessage()));
        }
      }

      if (subMon.isCanceled()) {
        connection.close();
        return;
      }

      try {
        doStartup(subMon.newChild(40));
      } catch (CoreException e) {
        connection.close();
        throw e;
      }

      if (subMon.isCanceled()) {
        connection.close();
        return;
      }

      /*
       * Wait for discover job to complete so we can check it's status and
       * throw an exception if it fails.
       */
      Job discoverJob = createDiscoverJob();
      if (discoverJob != null) {
        /*
         * Disable error messages being displayed on job's progress
         * monitor. These are handled by the progress service starting
         * the RM.
         */
        discoverJob.setProperty(
            IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
        discoverJob.schedule();
        try {
          discoverJob.join();
        } catch (InterruptedException e) {
          // Just check result
        }
        IStatus status = discoverJob.getResult();
        if (!status.isOK()) {
          throw new CoreException(status);
        }
      }

      if (jobQueueThread == null) {
        jobQueueThread =
            new Thread(
                new JobRunner(), Messages.AbstractToolRuntimeSystem_JobQueueManagerThreadTitle);
        jobQueueThread.start();
      }

      /*
       * Register for connection events
       */
      connection.addConnectionChangeListener(fConnectionChangeHandler);

      fireRuntimeRunningStateEvent(eventFactory.newRuntimeRunningStateEvent());
    } finally {
      synchronized (this) {
        startupMonitor = null;
      }
      if (monitor != null) {
        monitor.done();
      }
    }
  }