use of org.jkiss.dbeaver.ui.IRefreshablePart in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView;
if (workbenchPart instanceof INavigatorModelView) {
navigatorView = (INavigatorModelView) workbenchPart;
} else {
navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
}
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.jkiss.dbeaver.ui.IRefreshablePart in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView = GeneralUtils.adapt(workbenchPart, INavigatorModelView.class);
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.jkiss.dbeaver.ui.IRefreshablePart in project dbeaver by dbeaver.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView = GeneralUtils.adapt(workbenchPart, INavigatorModelView.class);
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.jkiss.dbeaver.ui.IRefreshablePart in project dbeaver by dbeaver.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView;
if (workbenchPart instanceof INavigatorModelView) {
navigatorView = (INavigatorModelView) workbenchPart;
} else {
navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
}
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.jkiss.dbeaver.ui.IRefreshablePart in project dbeaver by serge-rider.
the class NavigatorHandlerObjectOpen method openEntityEditor.
public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable String defaultFolderId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow, boolean activate) {
if (selectedNode instanceof DBNDataSource) {
final DBPDataSourceContainer dataSourceContainer = ((DBNDataSource) selectedNode).getDataSourceContainer();
openConnectionEditor(workbenchWindow, dataSourceContainer);
return null;
}
try {
if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
if (defaultFolderId == null) {
defaultFolderId = selectedNode.getNodeType();
}
selectedNode = selectedNode.getParentNode();
}
IEditorPart editor = findEntityEditor(workbenchWindow, selectedNode);
if (editor != null) {
boolean settingsChanged = false;
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof DatabaseEditorInput) {
settingsChanged = setInputAttributes((DatabaseEditorInput<?>) editorInput, defaultPageId, defaultFolderId, attributes);
}
if (editor instanceof EntityEditor && defaultPageId != null) {
// Set active page
IEditorPart pageEditor = ((EntityEditor) editor).getPageEditor(defaultPageId);
if (pageEditor != null && pageEditor != ((EntityEditor) editor).getActiveEditor()) {
((EntityEditor) editor).setActiveEditor(pageEditor);
}
}
if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
// Activate default folder
if (((ITabbedFolderContainer) editor).switchFolder(defaultFolderId)) {
settingsChanged = true;
}
}
if (settingsChanged) {
if (editor instanceof IRefreshablePart) {
((IRefreshablePart) editor).refreshPart(selectedNode, true);
}
}
if (workbenchWindow.getActivePage().getActiveEditor() != editor || activate) {
workbenchWindow.getActivePage().activate(editor);
}
return editor;
}
if (selectedNode instanceof DBNDatabaseNode) {
DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
DBSObject databaseObject = dnNode.getObject();
if (databaseObject != null) {
if (!databaseObject.isPersisted()) {
return null;
}
try {
DBUtils.getOrOpenDefaultContext(databaseObject, false);
} catch (DBCException ignored) {
return null;
}
if (selectedNode instanceof DBNDatabaseObject) {
DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
if (!objectNode.isPersisted()) {
return null;
}
ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
} else {
DatabaseNodeEditorInput editorInput = new DatabaseNodeEditorInput(dnNode);
if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
refreshDatabaseNode(dnNode);
}
setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
}
} else {
DBWorkbench.getPlatformUI().showError("No object", "Node has no associated database object");
return null;
}
} else {
NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
}
} catch (Exception ex) {
DBWorkbench.getPlatformUI().showError(UINavigatorMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
return null;
}
}
Aggregations