Search in sources :

Example 36 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project translationstudio8 by heartsome.

the class LockRepeatedSegmentHandler method lockTMSegmentOFEditor.

/**
	 * 专门处理以 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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 37 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project mechanoid by robotoworks.

the class NewMechanoidElementWizard method performFinish.

@Override
public boolean performFinish() {
    final IPath newFilePath = createNewResourceFilePath();
    onBeforeCreateElementResource();
    WorkspaceModifyDelegatingOperation op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                mNewResource = createElementResource(monitor, newFilePath);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    });
    try {
        getContainer().run(true, true, op);
        selectAndReveal(mNewResource);
        openResource(mNewResource);
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), Messages.NewMechanoidElementWizard_Dialog_CreateResourceError_Title, realException.getMessage());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) WorkspaceModifyDelegatingOperation(org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 38 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project flux by eclipse.

the class AuthFailureReporter method newValue.

@Override
public void newValue(Observable<ConnectionStatus> o, ConnectionStatus v) {
    if (v.isAuthFailure()) {
        UIJob job = new UIJob("Flux Error Reporter") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                MessageDialog.openError(null, "Flux Connection Failed", "Flux Web Socket handshake failed. Most likely this means " + "your Flux credentials are invalid.");
                return Status.OK_STATUS;
            }
        };
        job.schedule();
    //We only report this error once. 
    // since this error is all we handle... there's no point to continue listening  
    } else if (v.isConnected()) {
        //This means credentials must be valid and this listener now useless.
        dispose();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob)

Example 39 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project flux by eclipse.

the class LiveEditConnector method dispose.

public void dispose() {
    this.liveEditCoordinator.removeLiveEditConnector(liveEditConnector);
    this.repository.removeRepositoryListener(repositoryListener);
    FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener);
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener);
    WorkbenchJob jw = new WorkbenchJob("Removing listener") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window != null) {
                window.getActivePage().removePartListener(partListener);
            }
            return Status.OK_STATUS;
        }
    };
    jw.setSystem(true);
    jw.schedule();
    for (IDocument document : documentMappings.values()) {
        if (document != null) {
            document.removeDocumentListener(documentListener);
        }
    }
    resourceMappings.clear();
    documentMappings.clear();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) IDocument(org.eclipse.jface.text.IDocument)

Example 40 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.

the class ReplaceInvocationsRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 20);
    fChangeManager = new TextChangeManager();
    RefactoringStatus result = new RefactoringStatus();
    fSourceProvider = resolveSourceProvider(fMethodBinding, result);
    if (result.hasFatalError())
        return result;
    result.merge(fSourceProvider.checkActivation());
    if (result.hasFatalError())
        return result;
    fSourceProvider.initialize();
    fTargetProvider.initialize();
    pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching);
    RefactoringStatus searchStatus = new RefactoringStatus();
    String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName()));
    ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
    ICompilationUnit[] units = fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1));
    binaryRefs.addErrorIfNecessary(searchStatus);
    if (searchStatus.hasFatalError()) {
        result.merge(searchStatus);
        return result;
    }
    IFile[] filesToBeModified = getFilesToBeModified(units);
    result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext()));
    if (result.hasFatalError())
        return result;
    result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)));
    checkOverridden(result, new SubProgressMonitor(pm, 4));
    IProgressMonitor sub = new SubProgressMonitor(pm, 15);
    //$NON-NLS-1$
    sub.beginTask("", units.length * 3);
    for (int c = 0; c < units.length; c++) {
        ICompilationUnit unit = units[c];
        sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit)));
        CallInliner inliner = null;
        try {
            boolean added = false;
            MultiTextEdit root = new MultiTextEdit();
            CompilationUnitChange change = (CompilationUnitChange) fChangeManager.get(unit);
            change.setEdit(root);
            BodyDeclaration[] bodies = fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1));
            if (bodies.length == 0)
                continue;
            inliner = new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider);
            for (int b = 0; b < bodies.length; b++) {
                BodyDeclaration body = bodies[b];
                inliner.initialize(body);
                RefactoringStatus nestedInvocations = new RefactoringStatus();
                ASTNode[] invocations = removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2)));
                for (int i = 0; i < invocations.length; i++) {
                    ASTNode invocation = invocations[i];
                    result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity()));
                    if (result.hasFatalError())
                        break;
                    if (result.getSeverity() < fTargetProvider.getStatusSeverity()) {
                        added = true;
                        TextEditGroup group = new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline);
                        change.addTextEditGroup(group);
                        result.merge(inliner.perform(group));
                    }
                }
                // do this after we have inlined the method calls. We still want
                // to generate the modifications.
                result.merge(nestedInvocations);
            }
            if (!added) {
                fChangeManager.remove(unit);
            } else {
                root.addChild(inliner.getModifications());
                ImportRewrite rewrite = inliner.getImportEdit();
                if (rewrite.hasRecordedChanges()) {
                    TextEdit edit = rewrite.rewriteImports(null);
                    if (edit instanceof MultiTextEdit ? ((MultiTextEdit) edit).getChildrenSize() > 0 : true) {
                        root.addChild(edit);
                        change.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] { edit }));
                    }
                }
            }
        } finally {
            if (inliner != null)
                inliner.dispose();
        }
        sub.worked(1);
        if (sub.isCanceled())
            throw new OperationCanceledException();
    }
    result.merge(searchStatus);
    sub.done();
    pm.done();
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ReferencesInBinaryContext(org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) TextEditGroup(org.eclipse.text.edits.TextEditGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)530 InvocationTargetException (java.lang.reflect.InvocationTargetException)181 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)162 CoreException (org.eclipse.core.runtime.CoreException)134 Job (org.eclipse.core.runtime.jobs.Job)133 IStatus (org.eclipse.core.runtime.IStatus)110 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)83 Status (org.eclipse.core.runtime.Status)81 ArrayList (java.util.ArrayList)80 IOException (java.io.IOException)69 IFile (org.eclipse.core.resources.IFile)60 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)58 File (java.io.File)56 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)54 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)50 ITask (com.cubrid.common.core.task.ITask)49 IProject (org.eclipse.core.resources.IProject)43 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)37