1
랩 파트를 대상 플랫폼으로 랩 1.4가 포함 된 RCP/RAP-App을 작성하고 있습니다. rcp에서 plugin.xml의 menuContribution과 save 명령의 SaveHandler를 통해 구성된 저장 버튼이 있습니다. 이제 랩 앱에서이 버튼을 다운로드 버튼으로 사용하고 싶습니다.다운로드 링크로 도구 모음 버튼을 사용하는 방법
랩 파트를 대상 플랫폼으로 랩 1.4가 포함 된 RCP/RAP-App을 작성하고 있습니다. rcp에서 plugin.xml의 menuContribution과 save 명령의 SaveHandler를 통해 구성된 저장 버튼이 있습니다. 이제 랩 앱에서이 버튼을 다운로드 버튼으로 사용하고 싶습니다.다운로드 링크로 도구 모음 버튼을 사용하는 방법
나는 그것을 얻었습니다.
DownloadServiceHandler를 작성하고 save-command의 핸들러에 download-URL이있는 보이지 않는 브라우저를 만들었습니다. 단계별로
모든 작업 단계 :
도구 모음에서 저장 버튼은 plugin.xml에 구성됩니다 : 방법의 postWindowCreate에서
public class DownloadServiceHandler implements IServiceHandler
{
public void service() throws IOException, ServletException
{
final String fileName = RWT.getRequest().getParameter("filename");
final byte[] download = getYourFileContent().getBytes();
// Send the file in the response
final HttpServletResponse response = RWT.getResponse();
response.setContentType("application/octet-stream");
response.setContentLength(download.length);
final String contentDisposition = "attachment; filename=\"" + fileName + "\"";
response.setHeader("Content-Disposition", contentDisposition);
response.getOutputStream().write(download);
}
}
:
<extension
point="org.eclipse.ui.commands">
<command
id="pgui.rcp.command.save"
name="Save">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="pgui.rcp.toolbar1">
<command
commandId="pgui.rcp.command.save"
icon="icons/filesave_16.png"
id="pgui.rcp.button.save"
style="push"
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="pgui.handler.SaveHandler"
commandId="pgui.rcp.command.save">
</handler>
</extension>
은 내가 DownloadServiceHandler를 생성 ApplicationWorkbenchWindowAdvisor에 DownloadServiceHandler를 등록했습니다.
private void registerDownloadHandler()
{
final IServiceManager manager = RWT.getServiceManager();
final IServiceHandler handler = new DownloadServiceHandler();
manager.registerServiceHandler("downloadServiceHandler", handler);
}
SaveHandler의 execute-method에서 보이지 않는 브라우저를 만들고 URL과 파일 이름 및 등록 된 DownloadServiceHandler를 설정합니다.
final Browser browser = new Browser(shell, SWT.NONE);
browser.setSize(0, 0);
browser.setUrl(createDownloadUrl(fileName));
.
.
private String createDownloadUrl(final String fileName)
{
final StringBuilder url = new StringBuilder();
url.append(RWT.getRequest().getContextPath());
url.append(RWT.getRequest().getServletPath());
url.append("?");
url.append(IServiceHandler.REQUEST_PARAM);
url.append("=downloadServiceHandler");
url.append("&filename=");
url.append(fileName);
return RWT.getResponse().encodeURL(url.toString());
}