use of org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput in project dbeaver by serge-rider.
the class NavigatorHandlerObjectOpen method openEntityEditor.
public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow) {
if (selectedNode instanceof DBNDataSource) {
final DataSourceDescriptor dataSourceContainer = (DataSourceDescriptor) ((DBNDataSource) selectedNode).getDataSourceContainer();
openConnectionEditor(workbenchWindow, dataSourceContainer);
return null;
}
if (!selectedNode.isPersisted()) {
log.debug("Node '" + selectedNode.getNodeName() + "' s not persisted. Open not possible.");
return null;
}
try {
String defaultFolderId = null;
if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
defaultFolderId = selectedNode.getNodeType();
selectedNode = selectedNode.getParentNode();
}
DatabaseEditorInputFactory.setLookupEditor(true);
try {
for (IEditorReference ref : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorInput editorInput;
try {
editorInput = ref.getEditorInput();
} catch (Throwable e) {
continue;
}
if (editorInput instanceof INavigatorEditorInput) {
boolean matches;
if (editorInput instanceof DatabaseLazyEditorInput) {
matches = selectedNode.getNodeItemPath().equals(((DatabaseLazyEditorInput) editorInput).getNodePath());
} else {
matches = ((INavigatorEditorInput) editorInput).getNavigatorNode() == selectedNode;
}
if (matches) {
final IEditorPart editor = ref.getEditor(true);
if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
// Activate default folder
((ITabbedFolderContainer) editor).switchFolder(defaultFolderId);
}
workbenchWindow.getActivePage().activate(editor);
return editor;
}
}
}
} finally {
DatabaseEditorInputFactory.setLookupEditor(false);
}
if (selectedNode instanceof DBNDatabaseObject) {
DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
} else if (selectedNode instanceof DBNDatabaseNode) {
DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
if (dnNode.getObject() != null) {
EntityEditorInput editorInput = new EntityEditorInput(dnNode);
if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
if (dnNode.getObject() instanceof DBSObjectContainer) {
// do not auto-refresh object containers (too expensive)
} else {
refreshDatabaseNode(dnNode);
}
}
setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
} else {
UIUtils.showErrorDialog(workbenchWindow.getShell(), "No object", "Node do not has associated database object");
return null;
}
} else {
NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
}
} catch (Exception ex) {
UIUtils.showErrorDialog(workbenchWindow.getShell(), CoreMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
return null;
}
}
use of org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput in project dbeaver by serge-rider.
the class NodeEditorInputFactory method createElement.
@Override
public IAdaptable createElement(IMemento memento) {
// Get the node path.
final String nodePath = memento.getString(TAG_NODE);
if (nodePath == null) {
return null;
}
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
try {
final DBNNode node = navigatorModel.getNodeByPath(VoidProgressMonitor.INSTANCE, nodePath);
if (node != null) {
return new NodeEditorInput(node);
}
} catch (DBException e) {
log.error("Error opening node '" + nodePath + "'", e);
return null;
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput in project dbeaver by serge-rider.
the class AbstractResourceHandler method openResource.
@Override
public void openResource(@NotNull IResource resource) throws CoreException, DBException {
if (resource instanceof IFolder) {
DBNResource node = DBeaverCore.getInstance().getNavigatorModel().getNodeByResource(resource);
if (node != null) {
NodeEditorInput nodeInput = new NodeEditorInput(node);
DBeaverUI.getActiveWorkbenchWindow().getActivePage().openEditor(nodeInput, FolderEditor.class.getName());
}
}
//throw new DBException("Resource open is not implemented");
}
Aggregations