Java Code Examples for org.eclipse.core.runtime.SubProgressMonitor#worked()

The following examples show how to use org.eclipse.core.runtime.SubProgressMonitor#worked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InferTypeArgumentsConstraintsSolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void chooseTypes(ConstraintVariable2[] allConstraintVariables, SubProgressMonitor pm) {
	pm.beginTask("", allConstraintVariables.length); //$NON-NLS-1$
	for (int i= 0; i < allConstraintVariables.length; i++) {
		ConstraintVariable2 cv= allConstraintVariables[i];

		TypeEquivalenceSet set= cv.getTypeEquivalenceSet();
		if (set == null)
			continue; //TODO: should not happen iff all unused constraint variables got pruned
		//TODO: should calculate only once per EquivalenceRepresentative; can throw away estimate TypeSet afterwards
		TType type= chooseSingleType((TypeSet) cv.getTypeEstimate()); //TODO: is null for Universe TypeSet
		setChosenType(cv, type);

		if (cv instanceof CollectionElementVariable2) {
			CollectionElementVariable2 elementCv= (CollectionElementVariable2) cv;
			fUpdate.addDeclaration(elementCv);
		}

		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();
	}
	pm.done();
}
 
Example 2
Source File: InferTypeArgumentsConstraintsSolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void runSolver(SubProgressMonitor pm) {
	pm.beginTask("", fWorkList.size() * 3); //$NON-NLS-1$
	while (! fWorkList.isEmpty()) {
		// Get a variable whose type estimate has changed
		ConstraintVariable2 cv= fWorkList.removeFirst();
		List<ITypeConstraint2> usedIn= fTCModel.getUsedIn(cv);
		processConstraints(usedIn);
		pm.worked(1);
		if (pm.isCanceled())
			throw new OperationCanceledException();
	}
	pm.done();
}
 
Example 3
Source File: Implementors.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds IMethod instances on the specified IType instances with identical signatures
 * as the specified IMethod parameter.
 *
 * @param method The method to find "equals" of.
 * @param types The types in which the search is performed.
 *
 * @return An array of methods which match the method parameter.
 */
private IJavaElement[] findMethods(IMethod method, IType[] types,
    IProgressMonitor progressMonitor) {
    Collection<IMethod> foundMethods = new ArrayList<IMethod>();

    SubProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor,
            10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
    subProgressMonitor.beginTask("", types.length); //$NON-NLS-1$

    try {
        for (int i = 0; i < types.length; i++) {
            IType type = types[i];
            IMethod[] methods = type.findMethods(method);

            if (methods != null) {
                for (int j = 0; j < methods.length; j++) {
                    foundMethods.add(methods[j]);
                }
            }

            subProgressMonitor.worked(1);
        }
    } finally {
        subProgressMonitor.done();
    }

    return foundMethods.toArray(new IJavaElement[foundMethods.size()]);
}
 
Example 4
Source File: EquinoxApplicationProcessor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void processLocal ( final IFolder output, final IProgressMonitor parentMonitor ) throws Exception
{
    final IProgressMonitor monitor = new SubProgressMonitor ( parentMonitor, 13 );

    // create context

    final OscarContext ctx = createContext ();

    // generate common content

    new SecurityProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new JdbcUserServiceModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventStoragePostgresModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventStorageJdbcModuleProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventInjectorJdbcProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new EventInjectorPostgresProcessor ( this.app, ctx ).process ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    new ConnectionProcessor ( this.app, ctx ).process ();
    new ExporterProcessor ( this.app, ctx ).process ();

    // generate based on processors

    final Collection<OscarProcessor> processors = createProcessors ();
    monitor.worked ( 1 ); // COUNT:1
    {
        final SubProgressMonitor subMonitor = new SubProgressMonitor ( monitor, 1 ); // COUNT:1
        subMonitor.beginTask ( "Process application modules", processors.size () );

        for ( final OscarProcessor processor : processors )
        {
            processor.process ( ctx, this.app, subMonitor );
            subMonitor.worked ( 1 );
        }
        subMonitor.done ();
    }

    // generate custom content

    processForContext ( ctx, output, monitor );

    // write out oscar context

    final OscarWriter writer = new OscarWriter ( ctx.getData (), ctx.getIgnoreFields () );
    monitor.worked ( 1 ); // COUNT:1

    final IFile file = output.getFile ( "configuration.oscar" ); //$NON-NLS-1$
    try ( FileOutputStream fos = new FileOutputStream ( file.getRawLocation ().toOSString () ) )
    {
        writer.write ( fos );
    }
    monitor.worked ( 1 ); // COUNT:1

    final IFile jsonFile = output.getFile ( "data.json" ); //$NON-NLS-1$
    try ( final FileOutputStream fos = new FileOutputStream ( jsonFile.getRawLocation ().toOSString () ) )
    {
        OscarWriter.writeData ( ctx.getData (), fos );
    }
    monitor.worked ( 1 ); // COUNT:1

    // write out profile
    new P2ProfileProcessor ( this.app ).process ( output.getLocation ().toFile (), monitor );
    monitor.worked ( 1 ); // COUNT:1

    // refresh
    output.refreshLocal ( IResource.DEPTH_INFINITE, monitor );

    monitor.done ();
}
 
Example 5
Source File: ExtractClassRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus updateReferences(IType type, ParameterObjectFactory pof, IProgressMonitor pm) throws CoreException {
	RefactoringStatus status= new RefactoringStatus();
	pm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_updating_references, 100);
	try {
		pm.worked(10);
		if (pm.isCanceled())
			throw new OperationCanceledException();
		List<IField> validIFields= new ArrayList<IField>();
		for (Iterator<FieldInfo> iterator= fVariables.values().iterator(); iterator.hasNext();) {
			FieldInfo info= iterator.next();
			if (isCreateField(info))
				validIFields.add(info.ifield);
		}
		if (validIFields.size() == 0) {
			status.addWarning(RefactoringCoreMessages.ExtractClassRefactoring_warning_no_fields_moved, JavaStatusContext.create(type));
			return status;
		}
		SearchPattern pattern= RefactoringSearchEngine.createOrPattern(validIFields.toArray(new IField[validIFields.size()]), IJavaSearchConstants.ALL_OCCURRENCES);
		SearchResultGroup[] results= RefactoringSearchEngine.search(pattern, RefactoringScopeFactory.create(type), pm, status);
		SubProgressMonitor spm= new SubProgressMonitor(pm, 90);
		spm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_updating_references, results.length * 10);
		try {
			for (int i= 0; i < results.length; i++) {
				SearchResultGroup group= results[i];
				ICompilationUnit unit= group.getCompilationUnit();

				CompilationUnitRewrite cuRewrite;
				if (unit.equals(fBaseCURewrite.getCu()))
					cuRewrite= fBaseCURewrite;
				else
					cuRewrite= new CompilationUnitRewrite(unit);
				spm.worked(1);

				status.merge(replaceReferences(pof, group, cuRewrite));
				if (cuRewrite != fBaseCURewrite) //Change for fBaseCURewrite will be generated later
					fChangeManager.manage(unit, cuRewrite.createChange(true, new SubProgressMonitor(spm, 9)));
				if (spm.isCanceled())
					throw new OperationCanceledException();
			}
		} finally {
			spm.done();
		}
	} finally {
		pm.done();
	}
	return status;
}
 
Example 6
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the necessary source code for the refactoring.
 *
 * @param monitor
 *            the progress monitor to use
 * @return
 *            the resulting status
 */
private RefactoringStatus createNecessarySourceCode(final IProgressMonitor monitor) {
	final RefactoringStatus status= new RefactoringStatus();
	try {
		monitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, 240);
		final IPackageFragmentRoot root= getPackageFragmentRoot();
		if (root != null && fSourceFolder != null && fJavaProject != null) {
			try {
				final SubProgressMonitor subMonitor= new SubProgressMonitor(monitor, 40, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
				final IJavaElement[] elements= root.getChildren();
				final List<IPackageFragment> list= new ArrayList<IPackageFragment>(elements.length);
				try {
					subMonitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, elements.length);
					for (int index= 0; index < elements.length; index++) {
						final IJavaElement element= elements[index];
						if (!fProcessedFragments.contains(element) && !element.getElementName().equals(META_INF_FRAGMENT))
							list.add((IPackageFragment) element);
						subMonitor.worked(1);
					}
				} finally {
					subMonitor.done();
				}
				if (!list.isEmpty()) {
					fProcessedFragments.addAll(list);
					final URI uri= fSourceFolder.getRawLocationURI();
					if (uri != null) {
						final IPackageFragmentRoot sourceFolder= fJavaProject.getPackageFragmentRoot(fSourceFolder);
						IWorkspaceRunnable runnable= null;
						if (canUseSourceAttachment()) {
							runnable= new SourceCreationOperation(uri, list) {

								private IPackageFragment fFragment= null;

								@Override
								protected final void createCompilationUnit(final IFileStore store, final String name, final String content, final IProgressMonitor pm) throws CoreException {
									fFragment.createCompilationUnit(name, content, true, pm);
								}

								@Override
								protected final void createPackageFragment(final IFileStore store, final String name, final IProgressMonitor pm) throws CoreException {
									fFragment= sourceFolder.createPackageFragment(name, true, pm);
								}
							};
						} else {
							runnable= new StubCreationOperation(uri, list, true) {

								private IPackageFragment fFragment= null;

								@Override
								protected final void createCompilationUnit(final IFileStore store, final String name, final String content, final IProgressMonitor pm) throws CoreException {
									fFragment.createCompilationUnit(name, content, true, pm);
								}

								@Override
								protected final void createPackageFragment(final IFileStore store, final String name, final IProgressMonitor pm) throws CoreException {
									fFragment= sourceFolder.createPackageFragment(name, true, pm);
								}
							};
						}
						try {
							runnable.run(new SubProgressMonitor(monitor, 150, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
						} finally {
							fSourceFolder.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
						}
					}
				}
			} catch (CoreException exception) {
				status.addFatalError(exception.getLocalizedMessage());
			}
		}
	} finally {
		monitor.done();
	}
	return status;
}
 
Example 7
Source File: LockRepeatedSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
private LockTMSegment lockTMSegment(final List<IFile> iFileList, boolean isLockTM100Segment,
		boolean isLockTM101Segment, IProgressMonitor monitor) {
	SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(),
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	subMonitor.beginTask("", 10);
	subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
	XLFHandler xlfHandler = null;
	singleNattable = null;
	Display.getDefault().syncExec(new Runnable() {
		public void run() {
			IEditorReference[] editorRefer = window.getActivePage().findEditors(
					new FileEditorInput(iFileList.get(0)), XLIFF_EDITOR_ID,
					IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
			if (editorRefer.length > 0) {
				singleNattable = ((XLIFFEditorImplWithNatTable) editorRefer[0].getEditor(true));
			}
		}
	});
	if (singleNattable != null) {
		xlfHandler = singleNattable.getXLFHandler();
	}

	if (xlfHandler == null) {
		xlfHandler = new XLFHandler();
		for (final IFile iFile : iFileList) {
			File file = iFile.getLocation().toFile();
			try {
				Map<String, Object> resultMap = xlfHandler.openFile(file);
				if (resultMap == null
						|| Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap
								.get(Constant.RETURNVALUE_RESULT)) {
					// 打开文件失败。
					Display.getDefault().syncExec(new Runnable() {
						public void run() {
							MessageDialog.openInformation(shell, Messages
									.getString("translation.LockRepeatedSegmentHandler.msgTitle"), MessageFormat
									.format(Messages.getString("translation.LockRepeatedSegmentHandler.msg2"),
											iFile.getLocation().toOSString()));
						}
					});
					list.remove(iFile);
					return null;
				}
			} catch (Exception e) {
				LOGGER.error("", e);
				e.printStackTrace();
			}
			if (!monitorWork(monitor, 1)) {
				return null;
			}
		}
	} else {
		subMonitor.worked(1);
	}

	List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
	LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
	lts.setLockedContextMatch(isLockTM101Segment);
	lts.setLockedFullMatch(isLockTM100Segment);
	// 查记忆库并锁定,占剩下的 9/10。
	SubProgressMonitor subSubMonitor = new SubProgressMonitor(subMonitor, 9,
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	if (!lts.executeTranslation(subSubMonitor)) {
		isCancel = true;
		subSubMonitor.done();
		subMonitor.done();
		return null;
	}
	subSubMonitor.done();
	subMonitor.done();

	if (singleNattable != null) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				singleNattable.getTable().redraw();
			}
		});
	}
	Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
	if (needLockRowIdMap.size() > 0) {
		lockTU(xlfHandler, needLockRowIdMap);
	}
	return lts;
}
 
Example 8
Source File: LockRepeatedSegmentHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private LockTMSegment lockTMSegment(final List<IFile> iFileList, boolean isLockTM100Segment,
		boolean isLockTM101Segment, IProgressMonitor monitor) {
	SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(),
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	subMonitor.beginTask("", 10);
	subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));
	XLFHandler xlfHandler = null;
	singleNattable = null;
	Display.getDefault().syncExec(new Runnable() {
		public void run() {
			IEditorReference[] editorRefer = window.getActivePage().findEditors(
					new FileEditorInput(iFileList.get(0)), XLIFF_EDITOR_ID,
					IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
			if (editorRefer.length > 0) {
				singleNattable = ((XLIFFEditorImplWithNatTable) editorRefer[0].getEditor(true));
			}
		}
	});
	if (singleNattable != null) {
		xlfHandler = singleNattable.getXLFHandler();
	}

	if (xlfHandler == null) {
		xlfHandler = new XLFHandler();
		for (final IFile iFile : iFileList) {
			File file = iFile.getLocation().toFile();
			try {
				Map<String, Object> resultMap = xlfHandler.openFile(file);
				if (resultMap == null
						|| Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap
								.get(Constant.RETURNVALUE_RESULT)) {
					// 打开文件失败。
					Display.getDefault().syncExec(new Runnable() {
						public void run() {
							MessageDialog.openInformation(shell, Messages
									.getString("translation.LockRepeatedSegmentHandler.msgTitle"), MessageFormat
									.format(Messages.getString("translation.LockRepeatedSegmentHandler.msg2"),
											iFile.getLocation().toOSString()));
						}
					});
					list.remove(iFile);
					return null;
				}
			} catch (Exception e) {
				LOGGER.error("", e);
				e.printStackTrace();
			}
			if (!monitorWork(monitor, 1)) {
				return null;
			}
		}
	} else {
		subMonitor.worked(1);
	}

	List<String> filesPath = ResourceUtils.IFilesToOsPath(iFileList);
	LockTMSegment lts = new LockTMSegment(xlfHandler, tmMatcher, filesPath, curProject);
	lts.setLockedContextMatch(isLockTM101Segment);
	lts.setLockedFullMatch(isLockTM100Segment);
	// 查记忆库并锁定,占剩下的 9/10。
	SubProgressMonitor subSubMonitor = new SubProgressMonitor(subMonitor, 9,
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	if (!lts.executeTranslation(subSubMonitor)) {
		isCancel = true;
		subSubMonitor.done();
		subMonitor.done();
		return null;
	}
	subSubMonitor.done();
	subMonitor.done();

	if (singleNattable != null) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				singleNattable.getTable().redraw();
			}
		});
	}
	Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
	if (needLockRowIdMap.size() > 0) {
		lockTU(xlfHandler, needLockRowIdMap);
	}
	return lts;
}