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

The following examples show how to use org.eclipse.core.runtime.SubProgressMonitor#done() . 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: TaskRunner.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public void run ( final RunnerContext ctx, final IProgressMonitor monitor )
{
    monitor.beginTask ( "Executing task", this.task.getExecute ().size () );

    for ( final Execute execute : this.task.getExecute () )
    {
        final Executable runnable = convert ( execute, ctx );

        // inject sub progress monitor
        final SubProgressMonitor sm = new SubProgressMonitor ( monitor, 1 );
        ctx.getMap ().put ( KEY_PROGRESS_MONITOR, sm );

        runnable.run ( ctx );

        // remove sub progress monitor
        ctx.getMap ().remove ( KEY_PROGRESS_MONITOR );
        // step is complete
        sm.done ();
    }

    monitor.done ();
}
 
Example 2
Source File: DatabaseDataAccess.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.te.core.tmxdata.AbstractTmxDataAccess#deleteDupaicate(org.eclipse.core.runtime.IProgressMonitor,
 *      boolean)
 */
@Override
public boolean deleteDupaicate(IProgressMonitor monitor, boolean ignoreTag, boolean ignoreCase) {
	DatabaseAccessUtils deleteUtil = new DatabaseAccessUtils(facade, currSrcLang, currTgtLang, ignoreTag,
			ignoreCase);
	try {
		monitor.beginTask("", 100);
		SubProgressMonitor subFilerJob = new SubProgressMonitor(monitor, 40);
		subFilerJob.setTaskName(Messages.getString("core.fileAccess.filterDupliacteSegment"));
		List<Integer> tuids = deleteUtil.getId4DulicateDelete(subFilerJob);
		subFilerJob.done();
		SubProgressMonitor subdeleteJob = new SubProgressMonitor(monitor, 60);
		subdeleteJob.setTaskName(Messages.getString("core.fileAccess.deleteDuplicateSegment"));
		facade.deleteTuByIds(tuids, currSrcLang, currTgtLang, System.getProperty("user.name"), subdeleteJob);
		subdeleteJob.done();
	} catch (SQLException e) {
		LOGGER.error("", e);
	} finally {
		monitor.done();
	}
	return false;
}
 
Example 3
Source File: TmxLargeFileDataAccess.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 删除相同原文不同译文的TU,删除时如果TU中只有2个TUV,则直接删除TU;如果TU中有超过2个TUV则只删除当前TUV
 * @param ignoreTag
 * @return ;
 */

public boolean deleteSameSrcDiffTgt(IProgressMonitor monitor, boolean ignoreTag, boolean ignoreCase) {
	monitor.beginTask("", 100);
	SubProgressMonitor subFilerJob = new SubProgressMonitor(monitor, 40);
	subFilerJob.setTaskName(Messages.getString("core.fileAccess.filterSameSrcDiffTgtSegment"));
	TmxFilterQueryUtil filterQuery = new TmxFilterQueryUtil(container, super.currSrcLang, super.currTgtLang);
	filterQuery.setIngoreTag(ignoreTag);
	filterQuery.setIgnoreCase(ignoreCase);
	List<String> filterResultList = filterQuery.getSrcSameButTgtDiff4DeleteIds(subFilerJob);
	subFilerJob.done();
	if (filterResultList.size() == 0) {
		return false;
	}

	SubProgressMonitor subDeleteJob = new SubProgressMonitor(monitor, 60);
	subDeleteJob.setTaskName(Messages.getString("core.fileAccess.deleteSameSrcDiffTgtSegment"));
	deleteTus(filterResultList.toArray(new String[] {}), subDeleteJob);
	subDeleteJob.done();

	return true;

}
 
Example 4
Source File: TmxLargeFileDataAccess.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 删除重复文本段 删除重复的TU,原文和译文相同。删除时如果TU中只有2个TUV,则直接删除TU;如果TU中有超过2个TUV则只删除当前TUV 保留最新的TUV
 * @return ;
 */
public boolean deleteDupaicate(IProgressMonitor monitor, boolean ignoreTag, boolean ignoreCase) {
	monitor.beginTask("", 100);
	SubProgressMonitor subFilerJob = new SubProgressMonitor(monitor, 40);
	subFilerJob.setTaskName(Messages.getString("core.fileAccess.filterDupliacteSegment"));
	TmxFilterQueryUtil filterQuery = new TmxFilterQueryUtil(container, super.currSrcLang, super.currTgtLang);
	filterQuery.setIngoreTag(ignoreTag);
	filterQuery.setIgnoreCase(ignoreCase);
	List<String> filterResultList = filterQuery.getDuplicate4DeleteIds(subFilerJob);
	subFilerJob.done();
	if (filterResultList.size() == 0) {
		return false;
	}

	SubProgressMonitor subDeleteJob = new SubProgressMonitor(monitor, 60);
	subDeleteJob.setTaskName(Messages.getString("core.fileAccess.deleteDuplicateSegment"));
	deleteTus(filterResultList.toArray(new String[] {}), subDeleteJob);
	subDeleteJob.done();

	return true;
}
 
Example 5
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Change[] cleanUpProject(IJavaProject project, CleanUpTarget[] targets, ICleanUp[] cleanUps, IProgressMonitor monitor) throws CoreException {
	CleanUpFixpointIterator iter= new CleanUpFixpointIterator(targets, cleanUps);

	SubProgressMonitor subMonitor= new SubProgressMonitor(monitor, 2 * targets.length * cleanUps.length);
	subMonitor.beginTask("", targets.length); //$NON-NLS-1$
	subMonitor.subTask(Messages.format(FixMessages.CleanUpRefactoring_Parser_Startup_message, BasicElementLabels.getResourceName(project.getProject())));
	try {
		while (iter.hasNext()) {
			iter.next(subMonitor);
		}

		return iter.getResult();
	} finally {
		iter.dispose();
		subMonitor.done();
	}
}
 
Example 6
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkPostConditions(SubProgressMonitor monitor) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();

	ICleanUp[] cleanUps= getCleanUps();
	monitor.beginTask("", cleanUps.length); //$NON-NLS-1$
	monitor.subTask(FixMessages.CleanUpRefactoring_checkingPostConditions_message);
	try {
		for (int j= 0; j < cleanUps.length; j++) {
			result.merge(cleanUps[j].checkPostConditions(new SubProgressMonitor(monitor, 1)));
		}
	} finally {
		monitor.done();
	}
	return result;
}
 
Example 7
Source File: DatabaseDataAccess.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.te.core.tmxdata.AbstractTmxDataAccess#batchAddTmxNote(org.eclipse.core.runtime.IProgressMonitor,
 *      java.lang.String, java.lang.String)
 */
@Override
public void batchAddTmxNote(IProgressMonitor monitor, String content, String filter) {
	monitor.beginTask("", 100);
	SubProgressMonitor filterJob = new SubProgressMonitor(monitor, 30);
	filterJob.beginTask("", 100);
	List<Integer> ids = new ArrayList<Integer>();
	try {
		if (TeCoreConstant.FILTERID_allSeg.equals(filter)) {// 应用到整个数据库
			ids = container.getDbOp().getAfterFilterTuPk(null, null, null);

		} else {// 应用到当前过滤结果
			for (String str : super.tuIdentifiers) {
				ids.add(Integer.parseInt(str));
			}
		}
		filterJob.done();
		SubProgressMonitor addJob = new SubProgressMonitor(monitor, 70);
		facade.beginTransaction();
		if (facade.batchAddTuNotes(content, ids, addJob)) {
			facade.commit();
		}
		addJob.done();
	} catch (SQLException e) {
		try {
			facade.rollback();
		} catch (SQLException e1) {
			LOGGER.error("", e1);
		}
		LOGGER.error("", e);

	} finally {
		monitor.done();
	}
}
 
Example 8
Source File: DatabaseDataAccess.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 * @see net.heartsome.cat.te.core.tmxdata.AbstractTmxDataAccess#batchAddTmxProp(org.eclipse.core.runtime.IProgressMonitor,
 *      java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public void batchAddTmxProp(IProgressMonitor monitor, String type, String content, String filter) {
	monitor.beginTask("", 100);
	SubProgressMonitor filterJob = new SubProgressMonitor(monitor, 30);
	filterJob.beginTask("", 100);
	List<Integer> ids = new ArrayList<Integer>();
	try {
		if (TeCoreConstant.FILTERID_allSeg.equals(filter)) {// 应用到整个数据库
			ids = container.getDbOp().getAfterFilterTuPk(null, null, null);

		} else {// 应用到当前过滤结果
			for (String str : super.tuIdentifiers) {
				ids.add(Integer.parseInt(str));
			}
		}
		filterJob.done();
		SubProgressMonitor addJob = new SubProgressMonitor(monitor, 70);
		facade.beginTransaction();
		if (facade.batchAddTuProps(type, content, ids, addJob)) {
			facade.commit();
		}
		addJob.done();
	} catch (SQLException e) {
		try {
			facade.rollback();
		} catch (SQLException e1) {
			LOGGER.error("", e1);
		}
		LOGGER.error("", e);

	} finally {
		monitor.done();
	}

}
 
Example 9
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 10
Source File: RenameAnalyzeUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static ICompilationUnit[] createNewWorkingCopies(ICompilationUnit[] compilationUnitsToModify, TextChangeManager manager, WorkingCopyOwner owner, SubProgressMonitor pm) throws CoreException {
	pm.beginTask("", compilationUnitsToModify.length); //$NON-NLS-1$
	ICompilationUnit[] newWorkingCopies= new ICompilationUnit[compilationUnitsToModify.length];
	for (int i= 0; i < compilationUnitsToModify.length; i++) {
		ICompilationUnit cu= compilationUnitsToModify[i];
		newWorkingCopies[i]= createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1));
	}
	pm.done();
	return newWorkingCopies;
}
 
Example 11
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 12
Source File: RenameAnalyzeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
static ICompilationUnit[] createNewWorkingCopies(ICompilationUnit[] compilationUnitsToModify, TextChangeManager manager, WorkingCopyOwner owner, SubProgressMonitor pm) throws CoreException {
	pm.beginTask("", compilationUnitsToModify.length); //$NON-NLS-1$
	ICompilationUnit[] newWorkingCopies= new ICompilationUnit[compilationUnitsToModify.length];
	for (int i= 0; i < compilationUnitsToModify.length; i++) {
		ICompilationUnit cu= compilationUnitsToModify[i];
		newWorkingCopies[i]= createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1));
	}
	pm.done();
	return newWorkingCopies;
}
 
Example 13
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 14
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 15
Source File: LockRepeatedSegmentHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 专门处理以 nattble 形式打开的文件
 * @param iFileList
 * @param isLockTM100Segment
 * @param isLockTM101Segment
 * @param monitor
 * @return ;
 */
private LockTMSegment lockTMSegmentOFEditor(List<IFile> iFileList, boolean isLockTM100Segment,
		boolean isLockTM101Segment, IProgressMonitor monitor) {
	XLFHandler xlfHandler = nattable.getXLFHandler();
	SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(),
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	subMonitor.beginTask("", 10);
	subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));

	// 解析文件,占 1/10,这里是直接获取编辑器的XLFHandler,故不需解析
	if (!monitorWork(subMonitor, 1)) {
		return null;
	}

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

	if (nattable != null) {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				nattable.getTable().redraw();
			}
		});
	}
	Map<String, List<String>> needLockRowIdMap = lts.getNeedLockRowIdMap();
	if (needLockRowIdMap.size() > 0) {
		lockTU(xlfHandler, needLockRowIdMap);
	}
	return lts;
}
 
Example 16
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 17
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;
}
 
Example 18
Source File: PyOutlineSelectionDialog.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IStatus run(IProgressMonitor monitor) {
    rootWithParents = root.createCopy(null);

    if (nodeToModel == null) {
        //Step 2: create mapping: classdef to hierarchy model.
        nodeToModel = new HashMap<SimpleNode, HierarchyNodeModel>();
        List<Tuple<ClassDef, DataAndImageTreeNode<Object>>> gathered = new ArrayList<Tuple<ClassDef, DataAndImageTreeNode<Object>>>();
        gatherClasses(rootWithParents, monitor, gathered);
        monitor.beginTask("Calculate parents", gathered.size() + 1);

        IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
        IPyRefactoring2 r2 = (IPyRefactoring2) pyRefactoring;

        for (Tuple<ClassDef, DataAndImageTreeNode<Object>> t : gathered) {
            SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1);
            try {
                ClassDef classDef = t.o1;
                PySelection ps = new PySelection(pyEdit.getDocument(), classDef.name.beginLine - 1,
                        classDef.name.beginColumn - 1);
                try {
                    RefactoringRequest refactoringRequest = PyRefactorAction.createRefactoringRequest(
                            subProgressMonitor, pyEdit, ps);
                    HierarchyNodeModel model = r2.findClassHierarchy(refactoringRequest, true);
                    nodeToModel.put(((OutlineEntry) t.o2.data).node, model);
                } catch (MisconfigurationException e) {
                    Log.log(e);
                }
            } finally {
                subProgressMonitor.done();
            }
        }
    }

    if (!monitor.isCanceled()) {
        fillHierarchy(rootWithParents);
    }

    if (!monitor.isCanceled()) {
        uiJobSetRootWithParentsInput.setPriority(Job.INTERACTIVE);
        uiJobSetRootWithParentsInput.schedule();
    } else {
        //Will be recalculated if asked again!
        rootWithParents = null;
    }
    monitor.done();

    return Status.OK_STATUS;
}
 
Example 19
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 20
Source File: LockRepeatedSegmentHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 专门处理以 nattble 形式打开的文件
 * @param iFileList
 * @param isLockTM100Segment
 * @param isLockTM101Segment
 * @param monitor
 * @return ;
 */
private LockTMSegment lockTMSegmentOFEditor(List<IFile> iFileList, boolean isLockTM100Segment,
		boolean isLockTM101Segment, IProgressMonitor monitor) {
	XLFHandler xlfHandler = nattable.getXLFHandler();
	SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, iFileList.size(),
			SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
	subMonitor.beginTask("", 10);
	subMonitor.setTaskName(Messages.getString("translation.LockRepeatedSegmentHandler.task2"));

	// 解析文件,占 1/10,这里是直接获取编辑器的XLFHandler,故不需解析
	if (!monitorWork(subMonitor, 1)) {
		return null;
	}

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

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