Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.IProgressMonitor


    if (computeSubtypes) {
      // Note by construction there always is a focus type here
      IType focusType = getType();
      boolean focusIsObject = focusType.getElementName().equals(new String(IIndexConstants.OBJECT));
      int amountOfWorkForSubtypes = focusIsObject ? 5 : 80; // percentage of work needed to get possible subtypes
      IProgressMonitor possibleSubtypesMonitor =
        this.hierarchy.progressMonitor == null ?
          null :
          new SubProgressMonitor(this.hierarchy.progressMonitor, amountOfWorkForSubtypes);
      HashSet localTypes = new HashSet(10); // contains the paths that have potential subtypes that are local/anonymous types
      String[] allPossibleSubtypes;
      if (((Member)focusType).getOuterMostLocalContext() == null) {
        // top level or member type
        allPossibleSubtypes = this.determinePossibleSubTypes(localTypes, possibleSubtypesMonitor);
      } else {
        // local or anonymous type
        allPossibleSubtypes = CharOperation.NO_STRINGS;
      }
      if (allPossibleSubtypes != null) {
        IProgressMonitor buildMonitor =
          this.hierarchy.progressMonitor == null ?
            null :
            new SubProgressMonitor(this.hierarchy.progressMonitor, 100 - amountOfWorkForSubtypes);
        this.hierarchy.initialize(allPossibleSubtypes.length);
        buildFromPotentialSubtypes(allPossibleSubtypes, localTypes, buildMonitor);
View Full Code Here


        excludePath = ((IJavaElement) this.unitToSkip).getPath().toString();
      } else {
        excludePath = null;
      }

      IProgressMonitor progressMonitor = new IProgressMonitor() {
        boolean isCanceled = false;
        public void beginTask(String n, int totalWork) {
          // implements interface method
        }
        public void done() {
View Full Code Here

            CharOperation.toLowerCase(
              CharOperation.subarray(prefix, lastDotIndex + 1, prefix.length));
        }
      }

      IProgressMonitor progressMonitor = new IProgressMonitor() {
        boolean isCanceled = false;
        public void beginTask(String name, int totalWork) {
          // implements interface method
        }
        public void done() {
View Full Code Here

            if (VERBOSE)
              Util.verbose("CANCELED concurrent job - " + searchJob); //$NON-NLS-1$
            throw new OperationCanceledException();
 
          case IJob.WaitUntilReady :
            IProgressMonitor subProgress = null;
            try {
              int totalWork = 1000;
              if (progress != null) {
                subProgress = new SubProgressMonitor(progress, concurrentJobWork * 8 / 10);
                subProgress.beginTask("", totalWork); //$NON-NLS-1$
                concurrentJobWork = concurrentJobWork * 2 / 10;
              }
              // use local variable to avoid potential NPE (see bug 20435 NPE when searching java method
              // and bug 42760 NullPointerException in JobManager when searching)
              Thread t = this.processingThread;
              int originalPriority = t == null ? -1 : t.getPriority();
              try {
                if (t != null)
                  t.setPriority(Thread.currentThread().getPriority());
                synchronized(this) {
                  this.awaitingClients++;
                }
                IJob previousJob = null;
                int awaitingJobsCount;
                int lastJobsCount = totalWork;
                float lastWorked = 0;
                float totalWorked = 0;
                while ((awaitingJobsCount = awaitingJobsCount()) > 0) {
                  if (subProgress != null && subProgress.isCanceled())
                    throw new OperationCanceledException();
                  IJob currentJob = currentJob();
                  // currentJob can be null when jobs have been added to the queue but job manager is not enabled
                  if (currentJob != null && currentJob != previousJob) {
                    if (VERBOSE)
                      Util.verbose("-> NOT READY - waiting until ready - " + searchJob);//$NON-NLS-1$
                    if (subProgress != null) {
                      subProgress.subTask(
                        Messages.bind(Messages.manager_filesToIndex, Integer.toString(awaitingJobsCount)));
                      // ratio of the amount of work relative to the total work
                      float ratio = awaitingJobsCount < totalWork ? 1 : ((float) totalWork) / awaitingJobsCount;
                      if (lastJobsCount > awaitingJobsCount) {
                        totalWorked += (lastJobsCount - awaitingJobsCount) * ratio;
                      } else {
                        // more jobs were added, just increment by the ratio
                        totalWorked += ratio;
                      }
                      if (totalWorked - lastWorked >= 1) {
                        subProgress.worked((int) (totalWorked - lastWorked));
                        lastWorked = totalWorked;
                      }
                      lastJobsCount = awaitingJobsCount;
                    }
                    previousJob = currentJob;
                  }
                  try {
                    if (VERBOSE)
                      Util.verbose("-> GOING TO SLEEP - " + searchJob);//$NON-NLS-1$
                    Thread.sleep(50);
                  } catch (InterruptedException e) {
                    // ignore
                  }
                }
              } finally {
                synchronized(this) {
                  this.awaitingClients--;
                }
                if (t != null && originalPriority > -1 && t.isAlive())
                  t.setPriority(originalPriority);
              }
            } finally {
              if (subProgress != null)
                subProgress.done();
            }
        }
      }
      status = searchJob.execute(progress == null ? null : new SubProgressMonitor(progress, concurrentJobWork));
    } finally {
View Full Code Here

     *             Thrown when the creation failed.
     * @throws InterruptedException
     *             Thrown when the operation was canceled.
     */
    public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException {
        IProgressMonitor monitorInternal = monitor;
        if (monitorInternal == null) {
            monitorInternal = new NullProgressMonitor();
        }

        monitorInternal.beginTask(NewWizardMessages.NewTypeWizardPage_operationdesc, 8);

        IPackageFragmentRoot root = getPackageFragmentRoot();
        IPackageFragment pack = getPackageFragment();
        if (pack == null) {
            pack = root.getPackageFragment(""); //$NON-NLS-1$
        }

        if (!pack.exists()) {
            String packName = pack.getElementName();
            pack = root.createPackageFragment(packName, true, new SubProgressMonitor(monitorInternal, 1));
        } else {
            monitorInternal.worked(1);
        }

        boolean needsSave;
        ICompilationUnit connectedCU = null;

        try {
            String typeName = getTypeNameWithoutParameters();

            boolean isInnerClass = isEnclosingTypeSelected();

            IType createdType;
            ImportsManager imports;
            int indent = 0;

            Set<String> existingImports;

            String lineDelimiter = null;
            if (!isInnerClass) {
                lineDelimiter = StubUtility.getLineDelimiterUsed(pack.getJavaProject());

                String cuName = getCompilationUnitName(typeName);
                ICompilationUnit parentCU = pack.createCompilationUnit(cuName, "", false, new SubProgressMonitor(monitorInternal, 2)); //$NON-NLS-1$
                // create a working copy with a new owner

                needsSave = true;
                parentCU.becomeWorkingCopy(new SubProgressMonitor(monitorInternal, 1)); // cu is now a (primary) working copy
                connectedCU = parentCU;

                IBuffer buffer = parentCU.getBuffer();

                String simpleTypeStub = constructSimpleTypeStub();
                String cuContent = constructCUContent(parentCU, simpleTypeStub, lineDelimiter);
                buffer.setContents(cuContent);

                CompilationUnit astRoot = createASTForImports(parentCU);
                existingImports = getExistingImports(astRoot);

                imports = new ImportsManager(astRoot);
                // add an import that will be removed again. Having this import solves 14661
                imports.addImport(JavaModelUtil.concatenateName(pack.getElementName(), typeName));

                String typeContent = constructTypeStub(parentCU, imports, lineDelimiter);

                int index = cuContent.lastIndexOf(simpleTypeStub);
                if (index == -1) {
                    AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) astRoot.types().get(0);
                    int start = ((ASTNode) typeNode.modifiers().get(0)).getStartPosition();
                    int end = typeNode.getStartPosition() + typeNode.getLength();
                    buffer.replace(start, end - start, typeContent);
                } else {
                    buffer.replace(index, simpleTypeStub.length(), typeContent);
                }

                createdType = parentCU.getType(typeName);
            } else {
                IType enclosingType = getEnclosingType();

                ICompilationUnit parentCU = enclosingType.getCompilationUnit();

                needsSave = !parentCU.isWorkingCopy();
                parentCU.becomeWorkingCopy(new SubProgressMonitor(monitorInternal, 1)); // cu is now for sure (primary) a working copy
                connectedCU = parentCU;

                CompilationUnit astRoot = createASTForImports(parentCU);
                imports = new ImportsManager(astRoot);
                existingImports = getExistingImports(astRoot);

                // add imports that will be removed again. Having the imports solves 14661
                IType[] topLevelTypes = parentCU.getTypes();
                for (int i = 0; i < topLevelTypes.length; i++) {
                    imports.addImport(topLevelTypes[i].getFullyQualifiedName('.'));
                }

                lineDelimiter = StubUtility.getLineDelimiterUsed(enclosingType);
                StringBuffer content = new StringBuffer();

                String comment = getTypeComment(parentCU, lineDelimiter);
                if (comment != null) {
                    content.append(comment);
                    content.append(lineDelimiter);
                }

                content.append(constructTypeStub(parentCU, imports, lineDelimiter));
                IJavaElement sibling = null;
                if (enclosingType.isEnum()) {
                    IField[] fields = enclosingType.getFields();
                    if (fields.length > 0) {
                        for (int i = 0, max = fields.length; i < max; i++) {
                            if (!fields[i].isEnumConstant()) {
                                sibling = fields[i];
                                break;
                            }
                        }
                    }
                } else {
                    IJavaElement[] elems = enclosingType.getChildren();
                    sibling = elems.length > 0 ? elems[0] : null;
                }

                createdType = enclosingType.createType(content.toString(), sibling, false, new SubProgressMonitor(monitorInternal, 2));

                indent = StubUtility.getIndentUsed(enclosingType) + 1;
            }
            if (monitorInternal.isCanceled()) {
                throw new InterruptedException();
            }

            // add imports for superclass/interfaces, so types can be resolved correctly

            ICompilationUnit cu = createdType.getCompilationUnit();

            imports.create(false, new SubProgressMonitor(monitorInternal, 1));

            JavaModelUtil.reconcile(cu);

            if (monitorInternal.isCanceled()) {
                throw new InterruptedException();
            }

            // set up again
            CompilationUnit astRoot = createASTForImports(imports.getCompilationUnit());
            imports = new ImportsManager(astRoot);

            createTypeMembers(createdType, imports, new SubProgressMonitor(monitorInternal, 1));

            // add imports
            imports.create(false, new SubProgressMonitor(monitorInternal, 1));

            removeUnusedImports(cu, existingImports, false);

            JavaModelUtil.reconcile(cu);

            ISourceRange range = createdType.getSourceRange();

            IBuffer buf = cu.getBuffer();
            String originalContent = buf.getText(range.getOffset(), range.getLength());

            String formattedContent = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, originalContent, indent, lineDelimiter, pack.getJavaProject());
            formattedContent = Strings.trimLeadingTabsAndSpaces(formattedContent);
            buf.replace(range.getOffset(), range.getLength(), formattedContent);
            if (!isInnerClass) {
                String fileComment = getFileComment(cu);
                if (fileComment != null && fileComment.length() > 0) {
                    buf.replace(0, 0, fileComment + lineDelimiter);
                }
            }
            fCreatedType = createdType;

            if (needsSave) {
                cu.commitWorkingCopy(true, new SubProgressMonitor(monitorInternal, 1));
            } else {
                monitorInternal.worked(1);
            }

        } finally {
            if (connectedCU != null) {
                connectedCU.discardWorkingCopy();
            }
            monitorInternal.done();
        }
    }
View Full Code Here

     */
    public IRunnableWithProgress getRunnable() {
        return new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    IProgressMonitor monitorInternal = monitor;
                    if (monitorInternal == null) {
                        monitorInternal = new NullProgressMonitor();
                    }
                    createType(monitorInternal);
                } catch (CoreException e) {
View Full Code Here

              final List<CloudService> addedServices = wizard.getCloudServicesToCreate();
              writeToManifest[0] = wizard.persistManifestChanges();
              configuration[0] = wizard.getDeploymentConfiguration();

              if (addedServices != null && !addedServices.isEmpty()) {
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, addedServices.size());
                try {
                  server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),
                      subMonitor);
                }
                catch (CoreException e) {
                  // Do not let service creation errors
                  // stop the application deployment
                  CloudFoundryPlugin.log(e);
                }
                finally {
                  subMonitor.done();
                }
              }

            }
            else {
              cancelled[0] = true;
            }
          }
          catch (Throwable t) {
            // Any error in the wizard should result in the module
            // being deleted (i.e. cancelled)
            cancelled[0] = true;
            status[0] = CloudFoundryPlugin.getErrorStatus(t);
          }
        }
      });

      if (cancelled[0]) {
        if (!status[0].isOK()) {
          CloudFoundryPlugin.logError("Failed to deploy application due to: " + status[0].getMessage(), //$NON-NLS-1$
              status[0].getException());
        }
        throw new OperationCanceledException();
      }
      else {
        if (status[0].isOK()) {
          status[0] = appModule.validateDeploymentInfo();
        }
        if (!status[0].isOK()) {
          throw new CoreException(status[0]);
        }
        else if (writeToManifest[0]) {

          IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
          try {
            new ManifestParser(appModule, server).write(subMonitor, oldInfo);
          }
          catch (Throwable ce) {
            // Do not let this error propagate, as failing to write
            // to the manifest should not stop the app's deployment
            CloudFoundryPlugin.logError(ce);
          }
          finally {
            subMonitor.done();
          }
        }

        return configuration[0];
      }
View Full Code Here

    this.serverType = serverType;
    this.verifyPath = "conf"; //$NON-NLS-1$
  }

  public IServer getExistingServer() {
    IProgressMonitor monitor = new NullProgressMonitor();
    try {
      IServerType st = ServerCore.findServerType(serverType);
      if (st == null) {
        return null;
      }
View Full Code Here

        {
            if (sigil.exists()) {
                entries = getCachedClassPath(sigil);
               
                if ( entries == null ) {
                    IProgressMonitor monitor = ThreadProgressMonitor.getProgressMonitor();
                    entries = sigil.findExternalClasspath(monitor).toArray(new IClasspathEntry[0]);
                   
                    cacheClassPath(sigil, entries);
                }
            }
View Full Code Here

    /**
     * @return
     */
    private IProgressMonitor getMonitor()
    {
        IProgressMonitor monitor = ThreadProgressMonitor.getProgressMonitor();

        if (monitor == null)
        {
            monitor = Job.getJobManager().createProgressGroup();
        }
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.IProgressMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.