use of org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer 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.controls.folders.ITabbedFolderContainer in project dbeaver by serge-rider.
the class EntityEditor method addEditorTab.
private boolean addEditorTab(EntityEditorDescriptor descriptor) {
try {
IEditorPart editor = descriptor.createEditor();
if (editor == null) {
return false;
}
IEditorInput nestedInput = descriptor.getNestedEditorInput(getEditorInput());
final Class<? extends IEditorActionBarContributor> contributorClass = descriptor.getContributorClass();
if (contributorClass != null) {
addActionsContributor(editor, contributorClass);
}
int index = addPage(editor, nestedInput);
setPageText(index, descriptor.getName());
if (descriptor.getIcon() != null) {
setPageImage(index, DBeaverIcons.getImage(descriptor.getIcon()));
}
if (!CommonUtils.isEmpty(descriptor.getDescription())) {
setPageToolTip(index, descriptor.getDescription());
}
editorMap.put(descriptor.getId(), editor);
if (editor instanceof ITabbedFolderContainer) {
((ITabbedFolderContainer) editor).addFolderListener(folderListener);
}
return true;
} catch (Exception ex) {
//$NON-NLS-1$
log.error("Error adding nested editor", ex);
return false;
}
}
use of org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer in project dbeaver by serge-rider.
the class EntityEditor method createPages.
@Override
protected void createPages() {
final IDatabaseEditorInput editorInput = getEditorInput();
if (editorInput instanceof DatabaseLazyEditorInput) {
try {
addPage(new ProgressEditorPart(this), editorInput);
setPageText(0, "Initializing ...");
setActivePage(0);
} catch (PartInitException e) {
log.error(e);
}
return;
} else if (editorInput instanceof ErrorEditorInput) {
ErrorEditorInput errorInput = (ErrorEditorInput) editorInput;
try {
addPage(new ErrorEditorPartEx(errorInput.getError()), errorInput);
setPageImage(0, UIUtils.getShardImage(ISharedImages.IMG_OBJS_ERROR_TSK));
setPageText(0, "Error");
setActivePage(0);
} catch (PartInitException e) {
log.error(e);
}
return;
}
// Command listener
commandListener = new DBECommandAdapter() {
@Override
public void onCommandChange(DBECommand command) {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
firePropertyChange(IEditorPart.PROP_DIRTY);
}
});
}
};
DBECommandContext commandContext = getCommandContext();
if (commandContext != null) {
commandContext.addCommandListener(commandListener);
}
// Property listener
addPropertyListener(new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (propId == IEditorPart.PROP_DIRTY) {
EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_DIRTY);
EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_CAN_UNDO);
EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_CAN_REDO);
}
}
});
super.createPages();
DBSObject databaseObject = editorInput.getDatabaseObject();
EditorDefaults editorDefaults = null;
if (databaseObject == null) {
// Weird
log.debug("Null database object in EntityEditor");
} else {
synchronized (defaultPageMap) {
editorDefaults = defaultPageMap.get(databaseObject.getClass().getName());
}
EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
// Add object editor page
EntityEditorDescriptor defaultEditor = editorsRegistry.getMainEntityEditor(databaseObject);
hasPropertiesEditor = false;
if (defaultEditor != null) {
hasPropertiesEditor = addEditorTab(defaultEditor);
}
if (hasPropertiesEditor) {
DBNNode node = editorInput.getNavigatorNode();
int propEditorIndex = getPageCount() - 1;
setPageText(propEditorIndex, CoreMessages.editors_entity_properties_text);
setPageToolTip(propEditorIndex, node.getNodeType() + CoreMessages.editors_entity_properties_tooltip_suffix);
setPageImage(propEditorIndex, DBeaverIcons.getImage(node.getNodeIconDefault()));
}
}
// Add contributed pages
addContributions(EntityEditorDescriptor.POSITION_PROPS);
addContributions(EntityEditorDescriptor.POSITION_START);
addContributions(EntityEditorDescriptor.POSITION_MIDDLE);
// Add contributed pages
addContributions(EntityEditorDescriptor.POSITION_END);
String defPageId = editorInput.getDefaultPageId();
String defFolderId = editorInput.getDefaultFolderId();
if (defPageId == null && editorDefaults != null) {
defPageId = editorDefaults.pageId;
}
if (defPageId != null) {
IEditorPart defEditorPage = editorMap.get(defPageId);
if (defEditorPage != null) {
setActiveEditor(defEditorPage);
}
} else {
setActiveEditor(getEditor(0));
}
this.activeEditor = getActiveEditor();
if (activeEditor instanceof ITabbedFolderContainer) {
if (defFolderId == null && editorDefaults != null) {
defFolderId = editorDefaults.folderId;
}
if (defFolderId != null) {
((ITabbedFolderContainer) activeEditor).switchFolder(defFolderId);
}
}
UIUtils.setHelp(getContainer(), IHelpContextIds.CTX_ENTITY_EDITOR);
}
Aggregations