use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class NavigatorHandlerObjectGoto method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = null;
DBSObject container = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DBPContextProvider) {
context = ((DBPContextProvider) activePart).getExecutionContext();
} else if (activePart instanceof INavigatorModelView) {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) element).getObject();
if (object != null) {
container = object;
while (container instanceof DBSFolder) {
container = container.getParentObject();
}
DBPDataSource dataSource = object.getDataSource();
if (dataSource != null) {
context = dataSource.getDefaultContext(true);
}
}
}
}
}
if (context == null) {
DBUserInterface.getInstance().showError("Go to object", "No active datasource");
return null;
}
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
dialog.open();
Object[] objectsToOpen = dialog.getResult();
if (!ArrayUtils.isEmpty(objectsToOpen)) {
Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
for (DBNDatabaseNode node : nodes) {
NavigatorUtils.openNavigatorNode(node, workbenchWindow);
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class NavigatorHandlerObjectOpen method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object element = iter.next();
DBNNode node = null;
if (element instanceof IResource) {
openResource((IResource) element, HandlerUtil.getActiveWorkbenchWindow(event));
continue;
} else if (element instanceof DBNNode) {
node = (DBNNode) element;
} else {
DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
if (object != null) {
node = getNodeByObject(object);
}
}
if (node != null) {
NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event));
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
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) {
Map<String, Object> options = DBPScriptObject.EMPTY_OPTIONS;
if (!showScript(workbenchWindow, commandTarget.getContext(), options, "Rename script")) {
commandTarget.getContext().resetChanges();
return false;
} else {
ObjectSaver renamer = new ObjectSaver(commandTarget.getContext(), options);
TasksJob.runTask("Rename object '" + object.getName() + "'", renamer);
}
} else {
for (DBECommand command : commandTarget.getContext().getFinalCommands()) {
// System.out.println(command);
}
}
return true;
}
}
}
} catch (Throwable e) {
DBUserInterface.getInstance().showError("Rename object", "Can't rename object '" + node.getNodeName() + "'", e);
return false;
}
return false;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class DataImportHandler method chooseProducer.
@Override
protected IDataTransferProducer chooseProducer(ExecutionEvent event, IDataTransferConsumer consumer) {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
final DBNNode rootNode = DBeaverCore.getInstance().getLiveProjects().size() == 1 ? navigatorModel.getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) : navigatorModel.getRoot();
DBNNode node = BrowseObjectDialog.selectObject(HandlerUtil.getActiveShell(event), "Select source container for '" + consumer.getTargetName() + "'", rootNode, null, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { DBSDataContainer.class });
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (object instanceof DBSDataContainer) {
return new DatabaseTransferProducer((DBSDataContainer) object);
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class DataExporterSQL method exportHeader.
@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
columns = getSite().getAttributes();
DBPNamedObject source = getSite().getSource();
if (source instanceof DBSObject) {
tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
} else {
throw new DBException("SQL export may be done only from table object");
}
rowCount = 0;
}
Aggregations