【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-ArchiveEditorActionGroup.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package cn.com.chengang.sms.archive;
import static cn.com.chengang.sms.system.ImagesContext.FIRST;
import static cn.com.chengang.sms.system.ImagesContext.LAST;
import static cn.com.chengang.sms.system.ImagesContext.NEXT;
import static cn.com.chengang.sms.system.ImagesContext.NOTE;
import static cn.com.chengang.sms.system.ImagesContext.PREV;
import static cn.com.chengang.sms.system.ImagesContext.REMOVE;
import static cn.com.chengang.sms.system.ImagesContext.REPORT;
import java.util.List;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.actions.ActionGroup;
import cn.com.chengang.sms.Activator;
import cn.com.chengang.sms.archive.wizard.ArchiveWizard;
import cn.com.chengang.sms.db.DbOperate;
import cn.com.chengang.sms.db.QueryInfo;
import cn.com.chengang.sms.model.IUser;
import cn.com.chengang.sms.preferences.DBPreferencePage;
import cn.com.chengang.sms.system.ImagesContext;
import cn.com.chengang.sms.system.SmsFactory;
public class ArchiveEditorActionGroup extends ActionGroup {
private TableViewer tv;
private DbOperate db = SmsFactory.getDbOperate();
private QueryInfo queryInfo = new QueryInfo();
private Action addAction = new AddAction();
private Action modifyAction = new ModifyAction();
private Action removeAction = new RemoveAction();
private Action firstAction = new FirstAction();
private Action prevAction = new PrevAction();
private Action nextAction = new NextAction();
private Action lastAction = new LastAction();
public ArchiveEditorActionGroup(TableViewer tv) {
this.tv = tv;
queryInfo.currentPage = 1;
// queryInfo.pageSize = Constants.ARCHIVE_EDITOR_RS_NUM;//表示每页显示记录数的常数
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
String str = ps.getString(DBPreferencePage.ARCHIVE_EDITOR_RS_NUM_KEY);
queryInfo.pageSize = Integer.parseInt(str);
}
public void fillActionToolBars(ToolBarManager toolBarManager) {
toolBarManager.add(createActionContrItem(addAction));
toolBarManager.add(createActionContrItem(modifyAction));
toolBarManager.add(createActionContrItem(removeAction));
toolBarManager.add(createActionContrItem(firstAction));
toolBarManager.add(createActionContrItem(prevAction));
toolBarManager.add(createActionContrItem(nextAction));
toolBarManager.add(createActionContrItem(lastAction));
// 更新工具栏。没有这一句,工具栏上会没有任何显示
toolBarManager.update(true);
}
// 为了同时显示图像文字,用ActionContributionItem包装一下Action
private ActionContributionItem createActionContrItem(IAction action) {
ActionContributionItem aci = new ActionContributionItem(action);
aci.setMode(ActionContributionItem.MODE_FORCE_TEXT);// 显示图像+文字
return aci;
}
private class AddAction extends Action {
public AddAction() {
setText("新增");
setHoverImageDescriptor(ImagesContext.getImageDescriptor(REPORT));
}
public void run() {
ArchiveWizard wizard = new ArchiveWizard();
WizardDialog dialog = new WizardDialog(null, wizard);
dialog.setPageSize(-1, 120); // dialog大小,-1是指让宽度自动调整
if (dialog.open() == IDialogConstants.OK_ID) {
IUser user = wizard.getUser();
if (db.insertUser(user)) {
MessageDialog.openInformation(null, "", "成功插入");
IUser o = db.getUser(user.getUserId());
tv.add(o);
List list = (List) tv.getInput();
list.add(o);
} else {
MessageDialog.openError(null, "", "记录插入失败");
}
}
}
}
private class ModifyAction extends Action {
public ModifyAction() {
setText("修改");
setHoverImageDescriptor(ImagesContext.getImageDescriptor(NOTE));
}
public