Search in sources :

Example 1 with DBEObjectRenamer

use of org.jkiss.dbeaver.model.edit.DBEObjectRenamer in project dbeaver by serge-rider.

the class NavigatorHandlerObjectRename method renameDatabaseObject.

public static boolean renameDatabaseObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node, String newName) {
    try {
        if (node.getParentNode() instanceof DBNContainer) {
            final DBNContainer container = (DBNContainer) node.getParentNode();
            DBSObject object = node.getObject();
            if (object != null) {
                DBEObjectRenamer objectRenamer = EntityEditorsRegistry.getInstance().getObjectManager(object.getClass(), DBEObjectRenamer.class);
                if (objectRenamer != null) {
                    CommandTarget commandTarget = getCommandTarget(workbenchWindow, container, object.getClass(), false);
                    objectRenamer.renameObject(commandTarget.getContext(), object, newName);
                    if (object.isPersisted() && commandTarget.getEditor() == null) {
                        if (!showScript(workbenchWindow, commandTarget.getContext(), "Rename script")) {
                            commandTarget.getContext().resetChanges();
                            return false;
                        } else {
                            ObjectSaver renamer = new ObjectSaver(commandTarget.getContext());
                            TasksJob.runTask("Rename object '" + object.getName() + "'", renamer);
                        }
                    } else {
                        for (DBECommand command : commandTarget.getContext().getFinalCommands()) {
                        //System.out.println(command);
                        }
                    }
                    return true;
                }
            }
        }
    } catch (Throwable e) {
        UIUtils.showErrorDialog(workbenchWindow.getShell(), "Rename object", "Can't rename object '" + node.getNodeName() + "'", e);
        return false;
    }
    return false;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBNContainer(org.jkiss.dbeaver.model.navigator.DBNContainer) DBEObjectRenamer(org.jkiss.dbeaver.model.edit.DBEObjectRenamer)

Aggregations

DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)1 DBEObjectRenamer (org.jkiss.dbeaver.model.edit.DBEObjectRenamer)1 DBNContainer (org.jkiss.dbeaver.model.navigator.DBNContainer)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1