Search in sources :

Example 1 with GetVFileContentsXmlMessage

use of jetbrains.communicator.core.transport.GetVFileContentsXmlMessage in project intellij-plugins by JetBrains.

the class Helper method fillVFileContent.

public static void fillVFileContent(final Transport transport, final User user, final VFile vFile, IDEFacade ideFacade) {
    if (user.isOnline()) {
        try {
            UIUtil.run(ideFacade, StringUtil.getMsg("GetVFileContents.title"), new Runnable() {

                @Override
                public void run() {
                    final Semaphore semaphore = new Semaphore(1);
                    try {
                        semaphore.acquire();
                        transport.sendXmlMessage(user, new GetVFileContentsXmlMessage(vFile) {

                            @Override
                            public void processResponse(Element responseElement) {
                                super.processResponse(responseElement);
                                semaphore.release();
                            }
                        });
                        semaphore.tryAcquire(getWaitTimeout(), TimeUnit.MILLISECONDS);
                    } catch (InterruptedException ignored) {
                    // noop
                    }
                }
            });
        } catch (CanceledException e) {
            LOG.info(e.getMessage(), e);
        }
        if (vFile.getContents() == null) {
            String secondParamForFailMessage = user.getDisplayName();
            String address = transport.getAddressString(user);
            if (!com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces(address)) {
                secondParamForFailMessage += " from " + address;
            }
            ideFacade.showMessage(StringUtil.FAILED_TITLE, StringUtil.getMsg("GetVFileContents.fail", vFile.getDisplayName(), secondParamForFailMessage));
        }
    }
}
Also used : CanceledException(jetbrains.communicator.ide.CanceledException) Element(org.jdom.Element) Semaphore(java.util.concurrent.Semaphore) GetVFileContentsXmlMessage(jetbrains.communicator.core.transport.GetVFileContentsXmlMessage)

Aggregations

Semaphore (java.util.concurrent.Semaphore)1 GetVFileContentsXmlMessage (jetbrains.communicator.core.transport.GetVFileContentsXmlMessage)1 CanceledException (jetbrains.communicator.ide.CanceledException)1 Element (org.jdom.Element)1