Search in sources :

Example 1 with IRpcResultCallback

use of org.erlide.runtime.rpc.IRpcResultCallback in project erlide_eclipse by erlang.

the class ErlSearchQuery method run.

@Override
public IStatus run(final IProgressMonitor monitor) throws OperationCanceledException {
    final Object locker = new Object();
    final IRpcResultCallback callback = new IRpcResultCallback() {

        @Override
        public void start(final OtpErlangObject msg) {
            if (fSearchResult != null) {
                fSearchResult.removeAll();
            }
            final OtpErlangLong progressMaxL = (OtpErlangLong) msg;
            int progressMax;
            try {
                progressMax = progressMaxL.intValue();
            } catch (final OtpErlangRangeException e) {
                progressMax = 10;
            }
            monitor.beginTask("Searching", progressMax);
        }

        @Override
        public void stop(final OtpErlangObject msg) {
            monitor.done();
            stopped = true;
            synchronized (locker) {
                locker.notifyAll();
            }
        }

        @Override
        public void progress(final OtpErlangObject msg) {
            final OtpErlangTuple t = (OtpErlangTuple) msg;
            final OtpErlangPid backgroundSearchPid = (OtpErlangPid) t.elementAt(0);
            final OtpErlangLong progressL = (OtpErlangLong) t.elementAt(1);
            final OtpErlangObject resultO = t.elementAt(2);
            int progress = 1;
            try {
                progress = progressL.intValue();
                final List<ModuleLineFunctionArityRef> result = Lists.newArrayList();
                SearchUtil.addSearchResult(result, resultO);
                addMatches(result);
            } catch (final OtpErlangRangeException e) {
            }
            monitor.worked(progress);
            if (monitor.isCanceled()) {
                try {
                    ErlangEngine.getInstance().getSearchServerService().cancelSearch(backgroundSearchPid);
                } catch (final RpcException e) {
                }
            }
        }
    };
    try {
        final ErlSearchScope reducedScope = pattern.reduceScope(scope);
        ErlangEngine.getInstance().getSearchServerService().startFindRefs(pattern, reducedScope, ErlangEngine.getInstance().getStateDir(), callback, false);
    } catch (final RpcException e) {
        return new Status(IStatus.ERROR, ErlideUIPlugin.PLUGIN_ID, "Search error", e);
    }
    while (!stopped) {
        synchronized (locker) {
            try {
                if (!stopped) {
                    locker.wait();
                }
            } catch (final InterruptedException e) {
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IRpcResultCallback(org.erlide.runtime.rpc.IRpcResultCallback) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Aggregations

OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)1 ModuleLineFunctionArityRef (org.erlide.engine.services.search.ModuleLineFunctionArityRef)1 IRpcResultCallback (org.erlide.runtime.rpc.IRpcResultCallback)1 RpcException (org.erlide.runtime.rpc.RpcException)1