use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class DiagramCreateWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite placeholder = UIUtils.createPlaceholder(parent, 1);
Composite configGroup = UIUtils.createControlGroup(placeholder, ERDUIMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
// $NON-NLS-1$
final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
projectNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
diagram.setName(projectNameText.getText());
updateState();
}
});
Label contentLabel = UIUtils.createControlLabel(configGroup, ERDUIMessages.wizard_page_diagram_create_label_init_content);
GridData gd = new GridData(GridData.BEGINNING);
gd.horizontalSpan = 2;
contentLabel.setLayoutData(gd);
final DBNProject rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject());
if (rootNode == null) {
setControl(placeholder);
return;
}
contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
gd.heightHint = 400;
contentTree.setLayoutData(gd);
CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
viewer.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isChecked(Object element) {
return false;
}
@Override
public boolean isGrayed(Object element) {
if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSTable) {
return false;
}
}
return true;
}
});
if (entitySelection != null) {
viewer.setSelection(entitySelection, true);
viewer.setCheckedElements(entitySelection.toArray());
}
setControl(placeholder);
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class SQLScriptTaskScriptSelectorDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
INavigatorFilter scriptFilter = new INavigatorFilter() {
@Override
public boolean filterFolders() {
return true;
}
@Override
public boolean isLeafObject(Object object) {
return object instanceof DBNResource && ((DBNResource) object).getResource() instanceof IFile;
}
@Override
public boolean select(Object element) {
return element instanceof DBNLocalFolder || element instanceof DBNResource || element instanceof TreeNodeSpecial;
}
};
scriptsTree = new DatabaseNavigatorTree(dialogArea, projectNode, SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, scriptFilter);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
scriptsTree.setLayoutData(gd);
scriptsTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeNodeSpecial) {
return true;
}
if (element instanceof DBNResource) {
return isResourceApplicable((DBNResource) element);
}
return false;
}
});
scriptsTree.getViewer().addSelectionChangedListener(event -> {
updateSelectedScripts();
});
scriptsTree.getViewer().expandToLevel(2);
scriptsTree.getViewer().getTree().setHeaderVisible(true);
createScriptColumns(scriptsTree.getViewer());
return dialogArea;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class PostgresRolePrivilegesEditor method createPartControl.
public void createPartControl(Composite parent) {
this.pageControl = new PageControl(parent);
SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
final TreeViewer treeViewer = roleOrObjectTable.getViewer();
treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {
@Override
public Font getFont(Object element) {
if (element instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof PostgreSchema) {
String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
for (String tableName : permissionMap.keySet()) {
if (tableName.startsWith(schemaPrefix)) {
return boldFont;
}
}
} else if (getObjectPermissions(object) != null) {
return boldFont;
}
}
return null;
}
});
treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
return false;
}
if (element instanceof DBNDatabaseFolder) {
try {
String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
if (elementTypeName == null) {
return false;
}
Class<?> childType = Class.forName(elementTypeName);
return PostgreTableReal.class.isAssignableFrom(childType) || PostgreSequence.class.isAssignableFrom(childType) || PostgreProcedure.class.isAssignableFrom(childType);
} catch (ClassNotFoundException e) {
return false;
}
}
return true;
}
});
{
permEditPanel = new Composite(composite, SWT.NONE);
permEditPanel.setLayout(new GridLayout(1, true));
permissionTable = new Table(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK);
permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
permissionTable.setHeaderVisible(true);
permissionTable.setLinesVisible(true);
UIUtils.createTableColumn(permissionTable, SWT.LEFT, PostgreMessages.dialog_create_table_column_name_permission);
UIUtils.createTableColumn(permissionTable, SWT.CENTER, PostgreMessages.dialog_create_table_column_name_with_garant);
UIUtils.createTableColumn(permissionTable, SWT.CENTER, PostgreMessages.dialog_create_table_column_name_with_hierarchy);
permissionTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
updateCurrentPrivileges(((TableItem) e.item).getChecked(), (PostgrePrivilegeType) e.item.getData());
}
}
});
permissionTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
super.mouseDown(e);
}
});
if (!isRoleEditor()) {
for (PostgrePrivilegeType pt : PostgrePrivilegeType.values()) {
if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
continue;
}
TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
privItem.setText(0, pt.name());
privItem.setData(pt);
}
}
Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
buttonPanel.setLayout(new RowLayout());
UIUtils.createPushButton(buttonPanel, PostgreMessages.dialog_create_push_button_grant_all, null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean hadNonChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (!item.getChecked())
hadNonChecked = true;
item.setChecked(true);
}
if (hadNonChecked)
updateCurrentPrivileges(true, null);
}
});
UIUtils.createPushButton(buttonPanel, PostgreMessages.dialog_create_push_button_revoke_all, null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean hadChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (item.getChecked())
hadChecked = true;
item.setChecked(false);
}
if (hadChecked) {
updateCurrentPrivileges(false, null);
}
}
});
objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
}
pageControl.createOrSubstituteProgressPanel(getSite());
updateObjectPermissions(null);
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class SQLToolTaskObjectSelectorDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
INavigatorFilter dsFilter = new INavigatorFilter() {
@Override
public boolean filterFolders() {
return true;
}
@Override
public boolean isLeafObject(Object object) {
return object instanceof DBNDatabaseItem && taskType.appliesTo(((DBNDatabaseItem) object).getObject());
}
@Override
public boolean select(Object element) {
if (element instanceof DBNProject || element instanceof DBNProjectDatabases) {
return true;
}
if (element instanceof DBNLocalFolder) {
for (DBNDataSource ds : ((DBNLocalFolder) element).getNestedDataSources()) {
if (taskType.isDriverApplicable(ds.getDataSourceContainer().getDriver()) && (!showConnected || ds.getDataSourceContainer().isConnected())) {
return true;
}
}
return false;
}
if (element instanceof DBNDataSource) {
if (showConnected && !((DBNDataSource) element).getDataSourceContainer().isConnected()) {
return false;
}
return taskType.isDriverApplicable(((DBNDataSource) element).getDataSourceContainer().getDriver());
}
if (element instanceof DBNDatabaseItem) {
DBSObject object = ((DBNDatabaseItem) element).getObject();
return (DBSObjectContainer.class.isAssignableFrom(object.getClass()) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(object.getClass())) || taskType.appliesTo(object));
} else if (element instanceof DBNDatabaseFolder) {
Class<? extends DBSObject> childrenClass = ((DBNDatabaseFolder) element).getChildrenClass();
return childrenClass != null && (DBSObjectContainer.class.isAssignableFrom(childrenClass) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(childrenClass)) || taskType.matchesType(childrenClass));
}
return element instanceof TreeNodeSpecial;
}
};
dataSourceTree = new DatabaseNavigatorTree(dialogArea, projectNode.getDatabases(), SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, dsFilter);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
dataSourceTree.setLayoutData(gd);
dataSourceTree.getViewer().addSelectionChangedListener(event -> {
updateSelectedObjects();
});
final Button showConnectedCheck = new Button(dialogArea, SWT.CHECK);
showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
showConnectedCheck.setSelection(showConnected);
showConnectedCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showConnected = showConnectedCheck.getSelection();
dataSourceTree.getViewer().refresh();
}
});
return dialogArea;
}
use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree in project dbeaver by serge-rider.
the class ObjectACLEditor method createPartControl.
public void createPartControl(Composite parent) {
this.pageControl = new PageControl(parent);
SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
final TreeViewer treeViewer = roleOrObjectTable.getViewer();
treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {
@Override
public Font getFont(Object element) {
if (element instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSSchema) {
String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
for (String tableName : privilegeMap.keySet()) {
if (tableName.startsWith(schemaPrefix)) {
return boldFont;
}
}
} else if (getObjectPermissions(object) != null) {
return boldFont;
}
}
return null;
}
});
treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
return false;
}
if (element instanceof DBNDatabaseFolder) {
try {
String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
if (elementTypeName == null) {
return false;
}
Class<?> childType = Class.forName(elementTypeName);
return DBAPrivilegeOwner.class.isAssignableFrom(childType);
} catch (ClassNotFoundException e) {
return false;
}
}
return true;
}
});
{
permEditPanel = new Composite(composite, SWT.NONE);
permEditPanel.setLayout(new GridLayout(1, true));
permissionTable = new ObjectListControl<DBAPrivilege>(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK, new ListContentProvider()) {
@Override
protected String getListConfigId(List<Class<?>> classList) {
return ObjectACLEditor.this.getClass().getName();
}
@Override
protected LoadingJob<Collection<DBAPrivilege>> createLoadService() {
return null;
}
};
permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/*
UIUtils.createTableColumn(permissionTable, SWT.LEFT, "Permission");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With GRANT");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With Hierarchy");
permissionTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
updateCurrentPrivileges(((TableItem) e.item).getChecked(), (DBAPrivilegeType) e.item.getData());
}
}
});
if (!isRoleEditor()) {
for (PRIVILEGE_TYPE pt : getACLManager().getPrivilegeTypes()) {
if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
continue;
}
TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
privItem.setText(0, pt.getName());
privItem.setData(pt);
}
}
*/
Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
buttonPanel.setLayout(new RowLayout());
UIUtils.createPushButton(buttonPanel, "Grant All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadNonChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (!item.getChecked()) hadNonChecked = true;
item.setChecked(true);
}
if (hadNonChecked) updateCurrentPrivileges(true, null);
*/
}
});
UIUtils.createPushButton(buttonPanel, "Revoke All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (item.getChecked()) hadChecked = true;
item.setChecked(false);
}
if (hadChecked) {
updateCurrentPrivileges(false, null);
}
*/
}
});
objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
}
pageControl.createOrSubstituteProgressPanel(getSite());
updateObjectPermissions(null);
}
Aggregations