3
A
回答
2
我不認爲你可以禁用它(如使其灰色),因爲它是由底層操作系統窗口管理器直接管理,而不是由SWT。
您可以添加,雖然監聽器,以忽略任何關閉事件,有點像this snippet:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class Snippet99 {
public static void main (String [] args) {
Display display = new Display();
final Shell shell = new Shell (display);
shell.addListener (SWT.Close, new Listener() {
public void handleEvent (Event event) {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox (shell, style);
messageBox.setText ("Information");
messageBox.setMessage ("Close the shell?");
event.doit = messageBox.open() == SWT.YES;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
在你的情況,只需設置「event.doit
」到false
。
4
如果用戶想要關閉應用程序,另一種可能是「圖標化」應用程序,這意味着應用程序被移入托盤項目中。將以下內容添加到ApplicationWorkbenchWindowAdvisor:
a。覆蓋postWindowOpen
public void postWindowOpen() { Shell shell = getWindowConfigurer().getWindow().getShell(); boolean trayEnabled = false; trayEnabled = enableTray(); }
b。執行托盤支持
/* Enable System-Tray Support */ private boolean enableTray() { /* Avoid that this is being called redundantly */ if (this.fTrayEnabled) { return true; } /* Only enable for Primary Window */ IWorkbenchWindow primaryWindow = PlatformUI.getWorkbench().getWorkbenchWindows()[0]; if (primaryWindow == null || !primaryWindow.equals(getWindowConfigurer().getWindow())) { return false; } final Shell shell = primaryWindow.getShell(); final Tray tray = shell.getDisplay().getSystemTray(); /* Tray not support on the OS */ if (tray == null) { return false; } /* Create Item in Tray */ this.fTrayItem = new TrayItem(tray, SWT.NONE); this.fTrayItem.setToolTipText(Platform.getProduct().getName()); this.fTrayEnabled = true; this.fTrayItem.setVisible(false); /* Apply Image */ this.fTrayItem.setImage(trayIcon); /* Minimize to Tray on Shell Iconify if set */ this.fTrayShellListener = new ShellAdapter() { @Override public void shellIconified(final ShellEvent e) { if (!ApplicationWorkbenchWindowAdvisor.this.fBlockIconifyEvent && ApplicationWorkbenchWindowAdvisor.this.fMinimizeFromClose) { moveToTray(shell); } } }; shell.addShellListener(this.fTrayShellListener); /* Show Menu on Selection */ this.fTrayItem.addListener(SWT.MenuDetect, new Listener() { public void handleEvent(final Event event) { MenuManager trayMenu = new MenuManager(); /* Restore */ trayMenu.add(new ContributionItem() { @Override public void fill(final Menu menu, final int index) { MenuItem restoreItem = new MenuItem(menu, SWT.PUSH); restoreItem.setText("Restore from Tray"); restoreItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { restoreFromTray(shell); } }); menu.setDefaultItem(restoreItem); } }); /* Separator */ trayMenu.add(new Separator()); /* Other Items */ ApplicationWorkbenchWindowAdvisor.this.fActionBarAdvisor.fillTrayItem(trayMenu); Menu menu = trayMenu.createContextMenu(shell); menu.setVisible(true); } }); /* Handle DefaultSelection */ this.fTrayItem.addListener(SWT.DefaultSelection, new Listener() { public void handleEvent(final Event event) { /* Restore from Tray */ if (!shell.isVisible()) { restoreFromTray(shell); } else { moveToTray(shell); } } }); return true; } /* Move to System Tray */ private void moveToTray(final Shell shell) { this.fTrayItem.setVisible(true); this.fBlockIconifyEvent = true; try { shell.setVisible(false); } finally { this.fBlockIconifyEvent = false; } this.fMinimizedToTray = true; /** * @param shell */ public void restoreFromTray(final Shell shell) { /* Restore Shell */ shell.setVisible(true); shell.setActive(); shell.layout(true); /* Un-Minimize if minimized */ if (shell.getMinimized()) { shell.setMinimized(false); } this.fTrayItem.setVisible(false); if (this.fTrayTeasing) { this.fTrayItem.setImage(this.trayImage); } this.fTrayTeasing = false; this.fMinimizedToTray = false; } /* Disable System-Tray Support */ private void disableTray() { /* Avoid that this is being called redundantly */ if (!this.fTrayEnabled) { return; } /* First make sure to have the Window restored */ restoreFromTray(getWindowConfigurer().getWindow().getShell()); this.fTrayEnabled = false; this.fMinimizedToTray = false; if (this.fTrayItem != null) { this.fTrayItem.dispose(); } if (this.fTrayShellListener != null) { getWindowConfigurer().getWindow().getShell().removeShellListener(this.fTrayShellListener); } }
c。覆蓋preWindowShellClose
@Override public boolean preWindowShellClose() { final res = true ; this.fMinimizeFromClose = true; getWindowConfigurer().getWindow().getShell().notifyListeners(SWT.Iconify, new Event()); res = false; this.fMinimizeFromClose = false; return res; }
HTH 湯姆
相關問題
- 1. 等待在eclipse rcp應用程序退出時運行作業
- 2. 在我的eclipse rcp應用程序中禁用「Reset Perspective ...」菜單
- 3. Eclipse RCP應用程序(Indigo)上的Java退出代碼13
- 4. 在Eclipse RCP應用程序中重用Eclipse Run菜單
- 5. 工具欄的自定義按鈕Eclipse RCP應用程序
- 6. Eclipse RCP中的應用程序設計
- 7. Eclipse RCP應用程序中的NoClassDefFoundError
- 8. jruby中的Eclipse RCP應用程序
- 9. 獲取在Eclipse RCP應用程序
- 10. 使用OSGi Eclipse RCP應用程序
- 11. 使用Eclipse遠程調試「eclipse RCP應用程序」
- 12. Eclipse RCP的禁用EditorReference/IEditorPart
- 13. Eclipse RCP應用程序調試
- 14. rcp eclipse應用程序的位置
- 15. MVC的Eclipse RCP應用程序
- 16. Eclipse RCP應用程序無法啓動
- 17. Eclipse RCP應用程序無法啓動
- 18. 從Eclipse RCP應用程序製作jar
- 19. 如何更新Eclipse RCP應用程序?
- 20. Spring Rans的Eclipse RCP應用程序
- 21. Eclipse 4中的常見Eclipse 4插件RCP應用程序
- 22. WP7 PhoneGap應用程序後退按鈕退出應用程序
- 23. 使用Eclipse Classic開發Eclipse RCP應用程序
- 24. RCP應用程序和進度視圖在Eclipse RCP
- 25. 如何在Eclipse RCP應用程序中使用用戶輸入?
- 26. 如何在Eclipse RCP應用程序中禁用快速訪問TextField
- 27. 沒有Eclipse GUI的Eclipse RCP應用程序
- 28. 將Eclipse插件添加到Eclipse RCP應用程序
- 29. 向上按鈕退出應用程序?
- 30. 退出應用程序按鈕android
謝謝了很多,這幫助了我很多 – picciopiccio 2011-01-15 11:04:07
有趣的選擇(沒有看到它馬上在時間)。 +1 – VonC 2011-01-15 12:55:35
這讓我終於到了那裏,但它花了很多工作。你不顯示你的類變量的聲明(如fBlockIconifyEvent,fMinimizeFromClose等),其中一些不是必需的。 ApplicationActionBarAdvisor中也沒有默認的fillTrayItem。儘管如此,這些缺陷給了我所需的全面解決方案。 – 2013-01-03 17:00:51