응용 프로그램을 닫기 위해 윈도우 오른쪽 상단 버튼을 어떻게 비활성화 할 수 있습니까?Eclipse 응용 프로그램에서 Eclipse rcp disable exit 버튼
고마워요이 직접하지 SWT에 의해, 기본 OS 윈도우 관리자에 의해 관리되기 때문에 내가 (같은이 회색하게) 당신이 그것을을 해제 할 수 있다고 생각하지 않습니다
응용 프로그램을 닫기 위해 윈도우 오른쪽 상단 버튼을 어떻게 비활성화 할 수 있습니까?Eclipse 응용 프로그램에서 Eclipse rcp disable exit 버튼
고마워요이 직접하지 SWT에 의해, 기본 OS 윈도우 관리자에 의해 관리되기 때문에 내가 (같은이 회색하게) 당신이 그것을을 해제 할 수 있다고 생각하지 않습니다
. false
에, 단순히 'event.doit
'을 설정 귀하의 경우에는
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();
}
}
:
당신은 어떤 close 이벤트, this snippet에서 같은 비트를 무시하기 위해,하지만 리스너를 추가 할 수 있습니다.
또 다른 가능성은 사용자가 응용 프로그램을 닫으려는 경우 응용 프로그램을 "아이콘 화"하는 것입니다. 즉, 응용 프로그램이 용지함 항목으로 이동되었음을 의미합니다. 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
HTH 재정이 나에게 많은 – picciopiccio
흥미로운 대안을 (바로 시간에 그것을 보지 않았다) 도움이됩니다. +1 – VonC
이것은 결국 거기에 나를 잡았지만 많은 일을했습니다. 클래스 변수 선언 (예 : fBlockIconifyEvent, fMinimizeFromClose 등)을 표시하지 않으며 그 중 일부는 필요하지 않습니다. 또한 ApplicationActionBarAdvisor에는 기본적으로 fillTrayItem이 없습니다. 그러나 이러한 결함으로 인해 필자는 필요한 포괄적 인 솔루션을 제공했습니다. –