这是 OLE 对象。在 OLE 中,保存菜单被禁用,但是可以通过save()方法保存对象,如下所示:
oleClientSite.save(new File(fileName), true);
如果对象被修改,还有 isDirty() 方法返回 true 您需要添加自己的菜单才能让用户保存文件。
private void addMenu(OleFrame frame, String menuName) {
final Shell shell = frame.getShell();
Menu menuBar = shell.getMenuBar();
if (menuBar == null) {
menuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menuBar);
}
MenuItem fileMenu = new MenuItem(menuBar, SWT.CASCADE);
fileMenu.setText(menuName);
Menu menuFile = new Menu(fileMenu);
fileMenu.setMenu(menuFile);
frame.setFileMenus(new MenuItem[]{fileMenu});
MenuItem menuFileOpen = new MenuItem(menuFile, SWT.CASCADE);
menuFileOpen.setText("Save ...");
menuFileOpen.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
oleClientSite.save(new File(fileName), true);
}
});
MenuItem menuFileExit = new MenuItem(menuFile, SWT.CASCADE);
menuFileExit.setText("Quit");
menuFileExit.addSelectionListener(new SelectionAdapter() {
shell.dispose();
}
});
}
.....
display = new Display();
shell = new Shell(display);
shell.setSize(1000, 700);
shell.setLayout(new FillLayout());
oleFrame = new OleFrame(shell, SWT.NONE);
oleClientSite = new OleClientSite(oleFrame, SWT.NONE, new File(fileName));
oleClientSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
addMenu(oleFrame);
更多细节在这里 - http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet262。爪哇
在这里http://www.eclipse.org/swt/snippets/