use of com.cubrid.cubridmanager.ui.common.control.UserManagementWizard in project cubrid-manager by CUBRID.
the class UserManagementTableViewerSorter method createDialogArea.
/**
* Create dialog area content
*
* @param parent the parent composite
* @return the control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
Label tipLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
tipLabel.setText(Messages.msgUserManagementList);
tipLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
// create CUBRID Manager user information table
String[] columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnDbAuth, Messages.tblColumnBrokerAuth, Messages.tblColumnMonitorAuth };
final ServerType serverType = server.getServerInfo().getServerType();
if (serverType == ServerType.DATABASE) {
columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnDbAuth, Messages.tblColumnMonitorAuth };
} else if (serverType == ServerType.BROKER) {
columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnBrokerAuth, Messages.tblColumnMonitorAuth };
}
tableViewer = CommonUITool.createCommonTableViewer(composite, new UserManagementTableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
userManageTable = tableViewer.getTable();
initialTableModel();
tableViewer.setInput(serverUserInfoTableList);
for (int i = 0; i < userManageTable.getColumnCount(); i++) {
userManageTable.getColumn(i).pack();
}
userManageTable.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("rawtypes")
public void widgetSelected(SelectionEvent event) {
if (userManageTable.getSelectionCount() > 0) {
StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
boolean isHasAdmin = false;
if (selection != null && !selection.isEmpty()) {
Iterator it = selection.iterator();
while (it.hasNext()) {
Map map = (Map) it.next();
if (map.get("0").equals("admin")) {
isHasAdmin = true;
break;
}
}
}
deleteButton.setEnabled(!isHasAdmin);
} else {
deleteButton.setEnabled(false);
}
if (userManageTable.getSelectionCount() == 1) {
editButton.setEnabled(true);
} else {
editButton.setEnabled(false);
}
}
});
// create button
Composite buttonComp = new Composite(composite, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.spacing = 5;
buttonComp.setLayout(rowLayout);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalAlignment = GridData.END;
buttonComp.setLayoutData(gridData);
Button addButton = new Button(buttonComp, SWT.PUSH);
addButton.setText(Messages.btnAdd);
addButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
UserManagementWizard userManagementWizard = new UserManagementWizard(server, null, serverUserInfoList);
CMWizardDialog dialog = new CMWizardDialog(getShell(), userManagementWizard);
int returnCode = dialog.open();
if (returnCode == IDialogConstants.OK_ID) {
ServerUserInfo userInfo = userManagementWizard.getServerUserInfo();
Map<String, Object> map = new HashMap<String, Object>();
map.put("0", userInfo.getUserName());
if (serverType == ServerType.BOTH) {
map.put("1", userInfo.getDbCreateAuthType().getText());
map.put("2", userInfo.getCasAuth().getText());
map.put("3", userInfo.getStatusMonitorAuth().getText());
map.put("4", userInfo);
}
if (serverType == ServerType.DATABASE) {
map.put("1", userInfo.getDbCreateAuthType().getText());
map.put("2", userInfo.getStatusMonitorAuth().getText());
map.put("3", userInfo);
} else if (serverType == ServerType.BROKER) {
map.put("1", userInfo.getCasAuth().getText());
map.put("2", userInfo.getStatusMonitorAuth().getText());
map.put("3", userInfo);
}
serverUserInfoTableList.add(map);
serverUserInfoList.add(userInfo);
tableViewer.refresh();
for (int i = 0; i < userManageTable.getColumnCount(); i++) {
userManageTable.getColumn(i).pack();
}
}
}
});
editButton = new Button(buttonComp, SWT.PUSH);
editButton.setText(Messages.btnEdit);
editButton.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void widgetSelected(SelectionEvent event) {
StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
ServerUserInfo serverUserInfo = null;
if (selection != null && !selection.isEmpty()) {
Map map = (Map) selection.getFirstElement();
if (serverType == ServerType.BOTH) {
serverUserInfo = (ServerUserInfo) map.get("4");
} else {
serverUserInfo = (ServerUserInfo) map.get("3");
}
UserManagementWizard userManagementWizard = new UserManagementWizard(server, serverUserInfo, serverUserInfoList);
CMWizardDialog dialog = new CMWizardDialog(getShell(), userManagementWizard);
int returnCode = dialog.open();
if (returnCode == IDialogConstants.OK_ID) {
ServerUserInfo userInfo = userManagementWizard.getServerUserInfo();
map.put("0", userInfo.getUserName());
if (serverType == ServerType.BOTH) {
map.put("1", userInfo.getDbCreateAuthType().getText());
map.put("2", userInfo.getCasAuth().getText());
map.put("3", userInfo.getStatusMonitorAuth().getText());
map.put("4", userInfo);
}
if (serverType == ServerType.DATABASE) {
map.put("1", userInfo.getDbCreateAuthType().getText());
map.put("2", userInfo.getStatusMonitorAuth().getText());
map.put("3", userInfo);
} else if (serverType == ServerType.BROKER) {
map.put("1", userInfo.getCasAuth().getText());
map.put("2", userInfo.getStatusMonitorAuth().getText());
map.put("3", userInfo);
}
tableViewer.refresh();
for (int i = 0; i < userManageTable.getColumnCount(); i++) {
userManageTable.getColumn(i).pack();
}
}
}
}
});
editButton.setEnabled(userManageTable.getSelectionCount() == 1);
deleteButton = new Button(buttonComp, SWT.PUSH);
deleteButton.setText(Messages.btnDelete);
deleteButton.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("rawtypes")
public void widgetSelected(SelectionEvent event) {
boolean isDelete = CommonUITool.openConfirmBox(getShell(), Messages.msgDeleteUserConfirm);
if (!isDelete) {
return;
}
StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
if (selection != null && !selection.isEmpty()) {
Map[] userInfoMapArr = new Map[selection.size()];
Iterator it = selection.iterator();
int i = 0;
while (it.hasNext()) {
Map map = (Map) it.next();
userInfoMapArr[i] = map;
i++;
}
deleteUser(userInfoMapArr);
}
tableViewer.refresh();
}
});
deleteButton.setEnabled(userManageTable.getSelectionCount() == 1);
setTitle(Messages.titleUserManagementDialog);
setMessage(Messages.msgUserManagementDialog);
return parentComp;
}
Aggregations