📄 exitaction.java
字号:
package com.niis.myprice.action;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import com.niis.myprice.domain.DataTree;
import com.niis.myprice.util.message.Messages;
public class ExitAction extends Action {
private final IWorkbenchWindow window;
private int instanceNum = 0;
public ExitAction(IWorkbenchWindow window, String label) {
this.window = window;
setText(label);
// The id is used to refer to the action in a menu or toolbar
setId(ICommandIds.CMD_EXIT);
// Associate the action with a pre-defined command, to allow key bindings.
setActionDefinitionId(ICommandIds.CMD_EXIT);
// setImageDescriptor(tt.Activator.getImageDescriptor("/icons/sample2.gif"));
}
public void run() {
if (DataTree.getDt().isModified()) {
Shell shell = window.getShell();
String title = Messages.getString("common.promptmessage");
String msg =Messages.getString("ApplicationWorkbenchWindowAdvisor.prompt");
MessageDialog dialog = new MessageDialog(shell, title, null, // accept
msg, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
IDialogConstants.NO_LABEL,IDialogConstants.CANCEL_LABEL }, 0); // yes is the default
int result = dialog.open();
switch(result){
case 0://yes
DataTree.getDt().save();
break;
case 1://no
break;
case 2://cancel
return;
default:break;
}
}
ActionFactory.QUIT.create(window).run();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -