📄 eusermanager.java
字号:
package efly.clientframe.feature.enterprise;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import efly.clientframe.core.PrivilegeInfo;
import efly.clientframe.core.Privileger;
import efly.clientframe.extension.ConfigurableUI;
/**
* @author efly
* @version 1.0.0,12/13/02
*/
public final class EUserManager
extends ConfigurableUI
implements Enterprise, Privileger {
private Shell dialog;
private static final String TITLE = "用户管理";
private Image bar_image;
private final static String BAR_IMAGE = "images/horizontal_bar.jpg";
/**
* @see efly.clientframe.extension.ConfigurableUI#createMenuItems()
*/
protected MenuItem[] createMenuItems() {
MenuItem[] items = new MenuItem[1];
Menu menu = acquireMenu("管理(&M)");
items[0] = new MenuItem(menu, SWT.CASCADE);
items[0].setText(TITLE + "\tF2");
items[0].setAccelerator(SWT.F2);
items[0].addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
dialog = createDialog();
dialog.open();
}
});
return items;
}
/**
* @see efly.clientframe.extension.Plugable#createToolBars()
*/
protected ToolBar[] createToolBars() {
return null;
}
/**
* @see efly.clientframe.core.Privileger#iniPrivileges()
*/
public PrivilegeInfo[] iniPrivileges() {
return null;
}
/**
* @see efly.clientframe.core.Extension#initialize()
*/
public void initialize() {
}
/**
* @see efly.clientframe.core.Extension#postLocate()
*/
public void postLocate() {
}
/**
* @see efly.clientframe.core.Extension#terminate()
*/
public void terminate() {
System.out.println("dipose bar image");
bar_image.dispose();
}
private Shell createDialog() {
if (dialog != null)
return dialog;
dialog = new Shell(getShell(), SWT.APPLICATION_MODAL | SWT.CLOSE);
dialog.setText(TITLE);
dialog.setImage(getIcon());
dialog.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
e.doit = false;
dialog.setVisible(false);
}
});
createPanel(dialog);
int w = bar_image.getBounds().width * 5 / 3;
int h = w * getShell().getSize().y / getShell().getSize().x;
dialog.setSize(w, h);
center(dialog);
dialog.open();
return dialog;
}
private void createPanel(Composite parent) {
FormLayout layout = new FormLayout();
layout.marginWidth = 5;
layout.marginHeight = 5;
parent.setLayout(layout);
final Tree root = new Tree(parent, SWT.BORDER | SWT.SINGLE);
final Composite userInfo = new Composite(parent, SWT.NONE);
bar_image = new Image(getDisplay(), BAR_IMAGE);
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
Button apply = new Button(parent, SWT.PUSH);
apply.setText("应用");
Button ok = new Button(parent, SWT.PUSH);
ok.setText("确定");
Button cancel = new Button(parent, SWT.PUSH);
cancel.setText("取消");
userInfo.setLayout(new FormLayout());
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(40, 0);
data.bottom = new FormAttachment(separator, -5, SWT.TOP);
root.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(40, 5);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(separator, -5, SWT.TOP);
userInfo.setLayoutData(data);
data = new FormData();
data.bottom = new FormAttachment(apply, -5, SWT.TOP);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
separator.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 10);
data.bottom = new FormAttachment(100, -5);
apply.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -10);
data.bottom = new FormAttachment(100, -5);
cancel.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(cancel, -10, SWT.LEFT);
data.bottom = new FormAttachment(100, -5);
ok.setLayoutData(data);
apply.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
apply();
}
});
ok.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ok();
}
});
cancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
cancel();
}
});
//机构,部门,用户组,用户
final Menu menu = new Menu(root);
final MenuItem[] popItems = new MenuItem[5];
root.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
updateEUserCompound(root);
}
});
root.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event e) {
if (e.button == 3) {
refreshMenuItem(root, popItems);
}
}
});
popItems[0] = new MenuItem(menu, SWT.PUSH);
popItems[0].setText("增加机构");
addPopItemListener(
userInfo,
popItems[0],
root,
EUserCompound.ORGANIZATION,
"名称");
popItems[1] = new MenuItem(menu, SWT.PUSH);
popItems[1].setText("增加部门");
addPopItemListener(
userInfo,
popItems[1],
root,
EUserCompound.DEPARTMENT,
"名称");
popItems[2] = new MenuItem(menu, SWT.PUSH);
popItems[2].setText("增加用户组");
addPopItemListener(
userInfo,
popItems[2],
root,
EUserCompound.USER_GROUP,
"名称");
popItems[3] = new MenuItem(menu, SWT.PUSH);
popItems[3].setText("增加用户");
addPopItemListener(
userInfo,
popItems[3],
root,
EUserCompound.INDIVIDUAL,
"姓名");
new MenuItem(menu, SWT.SEPARATOR);
popItems[4] = new MenuItem(menu, SWT.PUSH);
popItems[4].setText("删除");
popItems[4].addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
TreeItem[] items = root.getSelection();
items[0].dispose();
}
});
refreshMenuItem(root, popItems);
root.setMenu(menu);
}
/**
* Method cancel.
*/
private void cancel() {
}
/**
* Method ok.
*/
private void ok() {
}
/**
* Method apply.
*/
private void apply() {
FontDialog dialog1=new FontDialog(dialog);
dialog1.open();
System.out.println(dialog1.getFontData().getName());
}
private void iterateItemNode(TreeItem node) {
EUserItemNode eNode = (EUserItemNode) node;
eNode.getEUserCompound().hide();
TreeItem[] subNodes = node.getItems();
for (int i = 0; i < subNodes.length; i++)
iterateItemNode(subNodes[i]);
}
/**
* Method updateEUserCompound.
* @param root
*/
private void updateEUserCompound(Tree root) {
TreeItem[] subNodes = root.getItems();
TreeItem[] selected = root.getSelection();
for (int i = 0; i < subNodes.length; i++) {
iterateItemNode(subNodes[i]);
}
EUserItemNode sel = (EUserItemNode) selected[0];
sel.getEUserCompound().show();
}
private void addPopItemListener(
final Composite parent,
MenuItem menuItem,
final Tree root,
final int compoundType,
final String text) {
if (compoundType == EUserCompound.ORGANIZATION) {
menuItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
final TreeItem[] org = new TreeItem[1];
EUserCompound eUserComp =
new EUserCPanel(
parent,
bar_image,
EUserCompound.ORGANIZATION);
eUserComp.layout();
try {
org[0] = new EUserItemNode(root, eUserComp);
org[0].setText(text);
root.setSelection(org);
} catch (EUserNodeException enne) {
System.err.println(enne);
}
eUserComp.addEUserNodeListener(new EUserNodeListener() {
public void fireNodeNameChanged(String name) {
org[0].setText(name);
}
});
updateEUserCompound(root);
}
});
} else {
menuItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
final TreeItem[] items = new TreeItem[1];
EUserCompound eUserComp =
new EUserCPanel(parent, bar_image, compoundType);
eUserComp.layout();
try {
TreeItem parent = root.getSelection()[0];
items[0] = new EUserItemNode(parent, eUserComp);
items[0].setText(text);
root.setSelection(items);
} catch (EUserNodeException enne) {
System.err.println(enne);
}
eUserComp.addEUserNodeListener(new EUserNodeListener() {
public void fireNodeNameChanged(String name) {
items[0].setText(name);
}
});
updateEUserCompound(root);
}
});
}
}
private void refreshMenuItem(Tree root, MenuItem[] popItems) {
TreeItem[] selects = root.getSelection();
popItems[1].setEnabled(false);
popItems[2].setEnabled(false);
popItems[3].setEnabled(false);
popItems[4].setEnabled(false);
if (selects.length == 0) {
return;
} else {
popItems[4].setEnabled(true);
EUserItemNode select = (EUserItemNode) selects[0];
if (select.getGenericType() == EUserCompound.ORGANIZATION) {
popItems[1].setEnabled(true);
} else if (select.getGenericType() == EUserCompound.DEPARTMENT) {
popItems[1].setEnabled(true);
popItems[2].setEnabled(true);
popItems[3].setEnabled(true);
} else if (select.getGenericType() == EUserCompound.USER_GROUP) {
popItems[3].setEnabled(true);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -