use of com.cubrid.common.ui.spi.TableViewerSorter in project cubrid-manager by CUBRID.
the class EditUserDialog method createAuthComposite.
/**
* Create auth composite
*
* @return the composite
*/
private Composite createAuthComposite() {
final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
composite.setLayout(layout);
Label classTableDescLabel = new Label(composite, SWT.NONE);
classTableDescLabel.setText(Messages.lblUnAuthorizedTable);
final String[] columnNameArr = new String[] { Messages.tblColClassName, Messages.tblColClassSchematype, Messages.tblColClassOwner, Messages.tblColClassType };
classTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
classTableViewer.setInput(classListData);
classTable = classTableViewer.getTable();
classTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
final Composite cmpControl = new Composite(composite, SWT.NONE);
final GridData gdCmpControl = new GridData(SWT.CENTER, SWT.FILL, false, false);
cmpControl.setLayoutData(gdCmpControl);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
cmpControl.setLayout(gridLayout);
grantButton = new Button(cmpControl, SWT.LEFT);
grantButton.setEnabled(false);
grantButton.setText(Messages.addClassButtonName);
grantButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = classTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int i : idx) {
String className = classTable.getItem(i).getText(0);
for (Map<String, String> map : classListData) {
if (map.get("0").equals(className)) {
classListData.remove(map);
break;
}
}
ClassAuthorizations classAuthorizations = classGrantMap.get(className);
if (classAuthorizations == null) {
classAuthorizations = new ClassAuthorizations();
classAuthorizations.setClassName(className);
classAuthorizations.setSelectPriv(true);
}
authListData.add(getItemAuthMap(classAuthorizations));
}
classTableViewer.refresh();
authTableViewer.refresh();
if (authTableViewer.getTable().getColumn(0) != null) {
authTableViewer.getTable().getColumn(0).pack();
}
setAuthBtnEnableDisable();
}
});
revokeButton = new Button(cmpControl, SWT.NONE);
revokeButton.setEnabled(false);
revokeButton.setText(Messages.deleteClassButtonName);
revokeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = authTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int id : idx) {
String tableName = authTable.getItem(id).getText(0);
for (ClassInfo bean : allClassInfoList) {
if (tableName.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
CommonUITool.openErrorBox(parentComp.getShell(), Messages.errRemoveSysClass);
return;
} else {
Map<String, String> map = new HashMap<String, String>();
map.put("0", bean.getClassName());
map.put("1", bean.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", bean.getOwnerName());
map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
classListData.add(map);
}
}
}
for (Map<String, Object> map : authListData) {
String className = (String) map.get("0");
if (tableName.equals(className)) {
authListData.remove(map);
break;
}
}
}
authTableViewer.refresh();
classTableViewer.refresh();
setAuthBtnEnableDisable();
}
});
Label authTableDescLabel = new Label(composite, SWT.NONE);
authTableDescLabel.setText(Messages.lblAuthorizedTable);
final String[] authColumnNameArr = new String[] { Messages.tblColAuthTable, Messages.tblColAuthSelect, Messages.tblColAuthInsert, Messages.tblColAuthUpdate, Messages.tblColAuthDelete, Messages.tblColAuthAlter, Messages.tblColAuthIndex, Messages.tblColAuthExecute, Messages.tblColAuthGrantselect, Messages.tblColAuthGrantinsert, Messages.tblColAuthGrantupdate, Messages.tblColAuthGrantdelete, Messages.tblColAuthGrantalter, Messages.tblColAuthGrantindex, Messages.tblColAuthGrantexecute };
authTableViewer = createCommonTableViewer(composite, authColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
authTableViewer.setLabelProvider(new AuthTableLabelProvider());
authTableViewer.setInput(authListData);
authTable = authTableViewer.getTable();
CellEditor[] editors = new CellEditor[15];
editors[0] = null;
for (int i = 1; i < 15; i++) {
editors[i] = new CheckboxCellEditor(authTable, SWT.READ_ONLY);
}
authTableViewer.setColumnProperties(authColumnNameArr);
authTableViewer.setCellEditors(editors);
authTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
boolean isDbaAuthority = database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
if (isDbaAuthority) {
return true;
}
/*Can't grant/revoke for current login user*/
if (StringUtil.isEqual(userName, currentUserInfo.getName())) {
return false;
}
String name = (String) map.get("0");
for (ClassInfo bean : allClassInfoList) {
if (name.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
return false;
} else if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
return true;
}
}
}
ClassAuthorizations authorizations = currentUserAuthorizations.get(name);
if (authorizations == null || authorizations.isAllPriv() || authorizations.isPriv(property)) {
return true;
} else {
return false;
}
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
return Boolean.valueOf((Boolean) map.get("" + i));
}
}
return null;
}
@SuppressWarnings("unchecked")
public void modify(Object element, String property, Object value) {
Object elementData;
elementData = element;
if (element instanceof Item) {
elementData = ((Item) element).getData();
}
String key = "";
Map<String, Object> map = (Map<String, Object>) elementData;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
key = "" + i;
break;
}
}
if (value instanceof Boolean) {
map.put(key, ((Boolean) value).booleanValue());
}
authTableViewer.refresh();
}
});
authTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
}
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
authTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
setAuthBtnEnableDisable();
}
});
return composite;
}
use of com.cubrid.common.ui.spi.TableViewerSorter in project cubrid-manager by CUBRID.
the class EditUserDialog method createCommonTableViewer.
/**
* Create common tableViewer
*
* @param parent the parent composite
* @param columnNameArr the column name array
* @param gridData the GridData
* @return the tableviewer
*/
public TableViewer createCommonTableViewer(Composite parent, final String[] columnNameArr, GridData gridData) {
final TableViewer tableViewer = new TableViewer(parent, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION);
tableViewer.setContentProvider(new TableContentProvider());
tableViewer.setLabelProvider(new AuthTableLabelProvider());
tableViewer.setSorter(new TableViewerSorter());
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLayoutData(gridData);
for (int i = 0; i < columnNameArr.length; i++) {
final TableColumn tblColumn = new TableColumn(tableViewer.getTable(), SWT.CHECK);
if (i != 0) {
tblColumn.setImage(CommonUIPlugin.getImage("icons/unchecked.gif"));
}
tblColumn.setData(false);
tblColumn.setText(columnNameArr[i]);
final int num = i;
tblColumn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
TableColumn column = (TableColumn) event.widget;
if (num == 0) {
int sortIndex = 0;
for (int j = 0; j < columnNameArr.length; j++) {
sortIndex = j;
if (column.getText().equals(columnNameArr[j])) {
break;
}
}
TableViewerSorter sorter = ((TableViewerSorter) tableViewer.getSorter());
if (sorter == null) {
return;
}
sorter.doSort(sortIndex);
tableViewer.getTable().setSortColumn(column);
tableViewer.getTable().setSortDirection(sorter.isAsc() ? SWT.UP : SWT.DOWN);
tableViewer.refresh();
for (int k = 0; k < tableViewer.getTable().getColumnCount(); k++) {
tableViewer.getTable().getColumn(k).pack();
}
return;
}
if ((Boolean) tblColumn.getData()) {
column.setImage(CommonUIPlugin.getImage("icons/unchecked.gif"));
column.setData(false);
for (int v = 0; v < column.getParent().getItemCount(); v++) {
Map<String, Object> map = authListData.get(v);
if (isSystemClass((String) map.get("0"))) {
map.put(num + "", false);
}
}
} else {
column.setImage(CommonUIPlugin.getImage("icons/checked.gif"));
column.setData(true);
for (int v = 0; v < column.getParent().getItemCount(); v++) {
Map<String, Object> map = authListData.get(v);
if (isSystemClass((String) map.get("0"))) {
map.put(num + "", true);
}
}
}
tableViewer.refresh();
}
});
tblColumn.pack();
}
return tableViewer;
}
use of com.cubrid.common.ui.spi.TableViewerSorter in project cubrid-manager by CUBRID.
the class VolumeSizeValidator method createTable.
/**
* Create volume table area
*
* @param parent the parent composite
*/
private void createTable(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
composite.setLayoutData(gridData);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
composite.setLayout(layout);
Label tipLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
tipLabel.setText(Messages.msgVolumeList);
tipLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
gridData = new GridData(GridData.FILL_HORIZONTAL);
tipLabel.setLayoutData(gridData);
addVolumeButton = new Button(composite, SWT.NONE);
addVolumeButton.setText(Messages.btnAddVolume);
addVolumeButton.setEnabled(false);
addVolumeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String volumeName = volumeNameText.getText();
String volumeType = volumeTypeCombo.getText();
String volumeSize = volumeSizeText.getText();
String pageNumber = String.valueOf(CreateDatabaseWizard.calcVolumePageNum(volumeSize, pageSize));
String volumePath = volumePathText.getText();
Map<String, String> map = new HashMap<String, String>();
map.put("0", volumeName);
map.put("1", volumeType);
map.put("2", volumeSize);
map.put("3", pageNumber);
map.put("4", volumePath);
volumeTableList.add(map);
volumeTableViewer.refresh();
for (int i = 0; i < volumeTable.getColumnCount(); i++) {
volumeTable.getColumn(i).pack();
}
changeVolumeName();
changeAutoVolumeButton();
}
});
deleteVolumeButton = new Button(composite, SWT.NONE);
deleteVolumeButton.setText(Messages.btnDelVolume);
deleteVolumeButton.setEnabled(false);
deleteVolumeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
StructuredSelection selection = (StructuredSelection) volumeTableViewer.getSelection();
if (selection != null && !selection.isEmpty()) {
volumeTableList.removeAll(selection.toList());
}
volumeTableViewer.refresh();
deleteVolumeButton.setEnabled(volumeTable.getSelectionCount() > 0);
changeAutoVolumeButton();
changeVolumeName();
}
});
final String[] columnNameArr = new String[] { Messages.tblColumnVolName, Messages.tblColumnVolType, Messages.tblColumnVolSize, Messages.tblColumnVolPath };
volumeTableViewer = CommonUITool.createCommonTableViewer(parent, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 4, 1, -1, -1));
volumeTableViewer.setLabelProvider(new VolumeInfoTableProvider());
volumeTableViewer.setInput(volumeTableList);
volumeTable = volumeTableViewer.getTable();
for (int i = 0; i < volumeTable.getColumnCount(); i++) {
volumeTable.getColumn(i).pack();
}
volumeTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
deleteVolumeButton.setEnabled(volumeTable.getSelectionCount() > 0);
}
});
// Create the cell editors
CellEditor[] editors = new CellEditor[4];
editors[0] = new TextCellEditor(volumeTable);
editors[1] = new ComboBoxCellEditor(volumeTable, VOLUME_TYPES, SWT.READ_ONLY);
editors[2] = new TextCellEditor(volumeTable);
editors[3] = null;
editors[0].setValidator(new VolumeNameValidator(volumeTableViewer));
editors[0].addListener(new ICellEditorListener() {
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
if (!newValidState) {
VolumeInfoPage.this.setErrorMessage(Messages.errVolumeName);
} else {
VolumeInfoPage.this.setErrorMessage(null);
}
}
public void cancelEditor() {
VolumeInfoPage.this.setErrorMessage(null);
}
public void applyEditorValue() {
VolumeInfoPage.this.setErrorMessage(null);
}
});
editors[2].setValidator(new VolumeSizeValidator());
editors[2].addListener(new ICellEditorListener() {
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
if (!newValidState) {
VolumeInfoPage.this.setErrorMessage(Messages.errVolumeSize);
} else {
VolumeInfoPage.this.setErrorMessage(null);
}
}
public void cancelEditor() {
VolumeInfoPage.this.setErrorMessage(null);
}
public void applyEditorValue() {
VolumeInfoPage.this.setErrorMessage(null);
}
});
volumeTableViewer.setCellEditors(editors);
volumeTableViewer.setColumnProperties(PROPS);
volumeTableViewer.setCellModifier(new VolumnCellEditor(this, volumeTableViewer));
}
use of com.cubrid.common.ui.spi.TableViewerSorter in project cubrid-manager by CUBRID.
the class BackupDatabaseDialog method createBackupHistoryComp.
/**
*
* Create backup history information tab composite
*
* @return the composite
*/
private Composite createBackupHistoryComp() {
Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
composite.setLayout(layout);
Label tipLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
tipLabel.setText(Messages.msgBackupHistoryList);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
tipLabel.setLayoutData(gridData);
final String[] columnNameArr = new String[] { Messages.tblColumnBackupLevel, Messages.tblColumnBackupDate, Messages.tblColumnSize, Messages.tblColumnBackupPath };
TableViewer historyTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, 400, 200));
historyTableViewer.setInput(getBackupHistoryInfoList());
Table historyTable = historyTableViewer.getTable();
for (int i = 0; i < historyTable.getColumnCount(); i++) {
historyTable.getColumn(i).pack();
}
return composite;
}
use of com.cubrid.common.ui.spi.TableViewerSorter in project cubrid-manager by CUBRID.
the class LoadDatabaseDialog method createDbUnloadInfoTable.
/**
*
* Create database unload information table
*
* @param parent the parent composite
*/
private void createDbUnloadInfoTable(Composite parent) {
final String[] columnNameArr = new String[] { Messages.tblColumnLoadType, Messages.tblColumnPath, Messages.tblColumnDate };
tableViewer = (CheckboxTableViewer) CommonUITool.createCheckBoxTableViewer(parent, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, 100));
tableViewer.addCheckStateListener(new ICheckStateListener() {
@SuppressWarnings("unchecked")
public void checkStateChanged(CheckStateChangedEvent event) {
Map<String, String> map = (Map<String, String>) event.getElement();
String checkedType = map.get("0");
String checkedPath = map.get("1");
String checkedDate = map.get("2");
if (event.getChecked()) {
for (int i = 0, n = unloadInfoTable.getItemCount(); i < n; i++) {
if (unloadInfoTable.getItem(i).getChecked()) {
String type = unloadInfoTable.getItem(i).getText(0);
String path = unloadInfoTable.getItem(i).getText(1);
String date = unloadInfoTable.getItem(i).getText(2);
if (checkedType.equals(type) && checkedPath.equals(path) && checkedDate.equals(date)) {
continue;
}
if (checkedType.equals(type)) {
unloadInfoTable.getItem(i).setChecked(false);
}
}
}
}
valid();
}
});
unloadInfoTable = tableViewer.getTable();
}
Aggregations