use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DatabaseLaunchContributionItem method extractSelectedObjects.
protected Object[] extractSelectedObjects() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return NO_OBJECTS;
}
ISelection selection = window.getSelectionService().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structured = (IStructuredSelection) selection;
Object[] array = structured.toArray();
Object o = structured.getFirstElement();
if (o instanceof IEditorPart) {
IEditorPart part = (IEditorPart) o;
array[0] = part.getEditorInput();
}
return array;
}
if (selection instanceof ITextSelection) {
IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
IEditorPart activeEditor = activePage.getActiveEditor();
DBSObject databaseObject = DebugUI.extractDatabaseObject(activeEditor);
if (databaseObject != null) {
return new Object[] { databaseObject };
}
}
}
return NO_OBJECTS;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class ToggleProcedureBreakpointTarget method toggleLineBreakpoints.
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
IEditorPart editorPart = (IEditorPart) part;
IResource resource = extractResource(editorPart, selection);
if (resource == null) {
return;
}
DBSObject databaseObject = DebugUI.extractDatabaseObject(editorPart);
if (databaseObject == null) {
return;
}
DBNDatabaseNode node = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(new VoidProgressMonitor(), databaseObject, false);
if (node == null) {
return;
}
String nodeItemPath = node.getNodeItemPath();
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DBGConstants.MODEL_IDENTIFIER_DATABASE);
for (IBreakpoint breakpoint : breakpoints) {
if (breakpoint instanceof IDatabaseBreakpoint) {
IDatabaseBreakpoint databaseBreakpoint = (IDatabaseBreakpoint) breakpoint;
if (nodeItemPath.equals(databaseBreakpoint.getNodePath())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
DebugUITools.deleteBreakpoints(new IBreakpoint[] { breakpoint }, part.getSite().getShell(), null);
return;
}
}
}
}
int charstart = -1, charend = -1;
DBGBreakpointDescriptor breakpointDescriptor = GeneralUtils.adapt(databaseObject, DBGBreakpointDescriptor.class);
if (breakpointDescriptor == null) {
throw new CoreException(GeneralUtils.makeErrorStatus("Object '" + DBUtils.getObjectFullName(databaseObject, DBPEvaluationContext.UI) + "' doesn't support breakpoints"));
}
// create line breakpoint (doc line numbers start at 0)
new DatabaseLineBreakpoint(databaseObject, node, resource, breakpointDescriptor, lineNumber + 1, charstart, charend, true);
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DatabaseLaunchShortcut method launch.
@Override
public void launch(IEditorPart editor, String mode) {
IEditorSite editorSite = editor.getEditorSite();
workbenchPartSite = editorSite;
ISelection selection = editorSite.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
Object[] array = ((IStructuredSelection) selection).toArray();
searchAndLaunch(array, mode, getEditorEmptyMessage());
} else {
DBSObject databaseObject = DebugUI.extractDatabaseObject(editor);
if (databaseObject != null) {
Object[] array = new Object[] { databaseObject };
searchAndLaunch(array, mode, getEditorEmptyMessage());
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class PostgresRolePrivilegesEditor method updateCurrentPrivileges.
private void updateCurrentPrivileges(boolean grant, PostgrePrivilegeType privilegeType) {
if (ArrayUtils.isEmpty(currentObjects)) {
DBWorkbench.getPlatformUI().showError("Update privilege", "Can't update privilege - no current object");
return;
}
PostgrePrivilegeOwner databaseObject = getDatabaseObject();
for (int i = 0; i < currentObjects.length; i++) {
DBSObject currentObject = currentObjects[i];
PostgrePrivilege permission = currentPermissions[i];
if (permission == null) {
if (!grant) {
// No permission - nothing to revoke
continue;
}
if (isRoleEditor()) {
PostgrePrivilegeOwner permissionsOwner = (PostgrePrivilegeOwner) currentObject;
PostgrePrivilegeGrant.Kind kind;
String objectName;
if (permissionsOwner instanceof PostgreProcedure) {
if (((PostgreProcedure) permissionsOwner).getKind() == PostgreProcedureKind.p) {
kind = PostgrePrivilegeGrant.Kind.PROCEDURE;
} else {
kind = PostgrePrivilegeGrant.Kind.FUNCTION;
}
objectName = ((PostgreProcedure) permissionsOwner).getUniqueName();
} else {
if (permissionsOwner instanceof PostgreSchema) {
kind = PostgrePrivilegeGrant.Kind.SCHEMA;
} else if (permissionsOwner instanceof PostgreSequence) {
kind = PostgrePrivilegeGrant.Kind.SEQUENCE;
} else {
kind = PostgrePrivilegeGrant.Kind.TABLE;
}
objectName = permissionsOwner.getName();
}
permission = new PostgreRolePrivilege(databaseObject, kind, permissionsOwner.getSchema().getName(), objectName, Collections.emptyList());
} else {
String currentUser = databaseObject.getDataSource().getContainer().getActualConnectionConfiguration().getUserName();
PostgrePrivilegeGrant privGrant = new PostgrePrivilegeGrant(currentUser, currentObject.getName(), databaseObject.getDatabase().getName(), databaseObject.getSchema().getName(), databaseObject.getName(), privilegeType, false, false);
permission = new PostgreObjectPrivilege(databaseObject, currentObject.getName(), Collections.singletonList(privGrant));
}
// Add to map
currentPermissions[i] = permission;
permissionMap.put(permission.getName(), permission);
} else if (privilegeType != null) {
// Check for privilege was already granted for this object
boolean hasPriv = permission.getPermission(privilegeType) != PostgrePrivilege.NONE;
if (grant != hasPriv && !grant) {
permissionMap.remove(permission.getName());
}
}
// Add command
addChangeCommand(new PostgreCommandGrantPrivilege(databaseObject, grant, currentObject, permission, privilegeType == null ? null : new PostgrePrivilegeType[] { privilegeType }), new DBECommandReflector<PostgrePrivilegeOwner, PostgreCommandGrantPrivilege>() {
@Override
public void redoCommand(PostgreCommandGrantPrivilege cmd) {
// if (!privTable.isDisposed() && curCatalog == selectedCatalog && curTable == selectedTable) {
// privTable.checkPrivilege(privilege, isGrant);
// }
// updateLocalData(privilege, isGrant, curCatalog, curTable);
}
@Override
public void undoCommand(PostgreCommandGrantPrivilege cmd) {
// if (!privTable.isDisposed() && curCatalog == selectedCatalog && curTable == selectedTable) {
// privTable.checkPrivilege(privilege, !isGrant);
// }
// updateLocalData(privilege, !isGrant, curCatalog, curTable);
}
});
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DataFilterRegistry method makeObjectId.
public static String makeObjectId(DBSObject object) {
DBSObject[] path = DBUtils.getObjectPath(object, true);
StringBuilder objName = new StringBuilder();
for (DBSObject p : path) {
if (objName.length() > 0)
objName.append(OBJ_PATH_DELIMITER);
objName.append(p.getName());
}
return objName.toString();
}
Aggregations