use of org.jkiss.dbeaver.model.struct.DBSObjectSelector in project dbeaver by serge-rider.
the class NavigatorActionSetActiveObject method run.
@Override
public void run(IAction action) {
if (selection instanceof IStructuredSelection) {
DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
if (selectedNode instanceof DBNDatabaseNode) {
final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
if (activeContainer != null) {
TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
activeContainer.setDefaultObject(monitor, databaseNode.getObject());
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectSelector in project dbeaver by serge-rider.
the class DataSourceManagementToolbar method changeDataBaseSelection.
private void changeDataBaseSelection() {
if (databaseCombo == null || databaseCombo.isDisposed() || databaseCombo.getSelectionIndex() < 0) {
return;
}
DBPDataSourceContainer dsContainer = getDataSourceContainer();
final String newName = databaseCombo.getItemText(databaseCombo.getSelectionIndex());
if (dsContainer != null && dsContainer.isConnected()) {
final DBPDataSource dataSource = dsContainer.getDataSource();
new AbstractJob("Change active database") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
DBSObjectContainer oc = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
DBSObjectSelector os = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (os != null) {
final DBSObject defObject = os.getDefaultObject();
if (defObject instanceof DBSObjectContainer) {
// USe seconds level of active object
DBSObjectSelector os2 = DBUtils.getAdapter(DBSObjectSelector.class, defObject);
if (os2 != null && os2.supportsDefaultChange()) {
oc = (DBSObjectContainer) defObject;
os = os2;
}
}
}
if (oc != null && os != null && os.supportsDefaultChange()) {
DBSObject newChild = oc.getChild(monitor, newName);
if (newChild != null) {
os.setDefaultObject(monitor, newChild);
} else {
throw new DBException(MessageFormat.format(CoreMessages.toolbar_datasource_selector_error_database_not_found, newName));
}
} else {
throw new DBException(CoreMessages.toolbar_datasource_selector_error_database_change_not_supported);
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectSelector in project dbeaver by dbeaver.
the class DataSourceManagementToolbar method changeDataBaseSelection.
private void changeDataBaseSelection(DBNDatabaseNode node) {
DBPDataSourceContainer dsContainer = getDataSourceContainer();
final String newName = node.getNodeName();
if (dsContainer != null && dsContainer.isConnected()) {
final DBPDataSource dataSource = dsContainer.getDataSource();
new AbstractJob("Change active database") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
DBSObjectContainer oc = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
DBSObjectSelector os = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (os != null) {
final DBSObject defObject = os.getDefaultObject();
if (defObject instanceof DBSObjectContainer) {
// USe seconds level of active object
DBSObjectSelector os2 = DBUtils.getAdapter(DBSObjectSelector.class, defObject);
if (os2 != null && os2.supportsDefaultChange()) {
oc = (DBSObjectContainer) defObject;
os = os2;
}
}
}
if (oc != null && os != null && os.supportsDefaultChange()) {
DBSObject newChild = oc.getChild(monitor, newName);
if (newChild != null) {
os.setDefaultObject(monitor, newChild);
} else {
throw new DBException(MessageFormat.format(CoreMessages.toolbar_datasource_selector_error_database_not_found, newName));
}
} else {
throw new DBException(CoreMessages.toolbar_datasource_selector_error_database_change_not_supported);
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectSelector in project dbeaver by serge-rider.
the class NavigatorUtils method isDefaultElement.
public static boolean isDefaultElement(Object element) {
if (element instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) element).getObject();
DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, object);
if (activeContainer != null) {
return activeContainer.getDefaultObject() == object;
}
} else if (element instanceof DBNProject) {
if (((DBNProject) element).getProject() == DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) {
return true;
}
}
return false;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectSelector in project dbeaver by serge-rider.
the class NavigatorUtils method createContextMenu.
public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final IMenuListener menuListener) {
final Control control = viewer.getControl();
final MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(control);
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
}
@Override
public void menuShown(MenuEvent e) {
Menu m = (Menu) e.widget;
DBNNode node = getSelectedNode(viewer.getSelection());
if (node != null && !node.isLocked() && node.allowsOpen()) {
String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, CoreCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
for (MenuItem item : m.getItems()) {
Object itemData = item.getData();
if (itemData instanceof IContributionItem) {
String contribId = ((IContributionItem) itemData).getId();
if (contribId != null && contribId.equals(commandID)) {
m.setDefaultItem(item);
}
}
}
}
}
});
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager) {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new GroupMarker(MB_NAVIGATOR_ADDITIONS));
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
final DBNNode selectedNode = getSelectedNode(viewer);
if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
// Add "Set active object" menu
if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
if (activeContainer != null && activeContainer.supportsDefaultChange()) {
DBSObject activeChild;
activeChild = activeContainer.getDefaultObject();
if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
// + databaseNode.getNodeType();
String text = "Set Active ";
// Fill context menu
IAction action = ActionUtils.makeAction(new NavigatorActionSetActiveObject(), workbenchSite, selection, text, null, null);
manager.add(action);
}
}
}
}
manager.add(new Separator());
manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
// Add properties button
if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
}
if (selectedNode.isPersisted()) {
// Add refresh button
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
}
}
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuMgr.dispose();
}
});
return menuMgr;
}
Aggregations