use of org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry in project dbeaver by dbeaver.
the class NavigatorHandlerObjectCreateBase method createNewObject.
protected boolean createNewObject(final IWorkbenchWindow workbenchWindow, DBNNode element, DBNDatabaseNode copyFrom) {
try {
DBNContainer container = null;
if (element instanceof DBNContainer && !(element instanceof DBNDataSource)) {
container = (DBNContainer) element;
} else {
DBNNode parentNode = element.getParentNode();
if (parentNode instanceof DBNContainer) {
container = (DBNContainer) parentNode;
}
}
if (container == null) {
throw new DBException("Can't detect container for '" + element.getNodeName() + "'");
}
Class<?> childType = container.getChildrenClass();
if (childType == null) {
throw new DBException("Can't determine child element type for container '" + container + "'");
}
if (childType == IProject.class) {
return NavigatorHandlerProjectCreate.createNewProject(workbenchWindow);
}
DBSObject sourceObject = copyFrom == null ? null : copyFrom.getObject();
// Do not check for type - manager must do it. Potentially we can copy anything into anything.
// if (sourceObject != null && !childType.isAssignableFrom(sourceObject.getClass())) {
// throw new DBException("Can't create '" + childType.getName() + "' from '" + sourceObject.getClass().getName() + "'");
// }
final EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
DBEObjectManager<?> objectManager = editorsRegistry.getObjectManager(childType);
if (objectManager == null) {
throw new DBException("Object manager not found for type '" + childType.getName() + "'");
}
DBEObjectMaker objectMaker = (DBEObjectMaker) objectManager;
DBPDataSource dataSource = container instanceof DBNDatabaseNode ? ((DBNDatabaseNode) container).getDataSource() : null;
final boolean openEditor = dataSource != null && (objectMaker.getMakerOptions(dataSource) & DBEObjectMaker.FEATURE_EDITOR_ON_CREATE) != 0;
CommandTarget commandTarget = getCommandTarget(workbenchWindow, container, childType, openEditor);
// Parent is model object - not node
final Object parentObject = container.getValueObject();
if (parentObject instanceof DBPObject) {
createDatabaseObject(commandTarget, objectMaker, (DBPObject) parentObject, sourceObject);
} else {
throw new DBException("Parent object type is not supported: " + parentObject);
}
} catch (Throwable e) {
DBUserInterface.getInstance().showError("Create object", null, e);
return false;
}
return true;
}
use of org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateBase method createNewObject.
protected boolean createNewObject(final IWorkbenchWindow workbenchWindow, DBNNode element, DBNDatabaseNode copyFrom) {
try {
DBNContainer container = null;
if (element instanceof DBNContainer) {
container = (DBNContainer) element;
} else {
DBNNode parentNode = element.getParentNode();
if (parentNode instanceof DBNContainer) {
container = (DBNContainer) parentNode;
}
}
if (container == null) {
throw new DBException("Can't detect container for '" + element.getNodeName() + "'");
}
Class<?> childType = container.getChildrenClass();
if (childType == null) {
throw new DBException("Can't determine child element type for container '" + container + "'");
}
if (childType == IProject.class) {
return NavigatorHandlerProjectCreate.createNewProject(workbenchWindow);
}
DBSObject sourceObject = copyFrom == null ? null : copyFrom.getObject();
// Do not check for type - manager must do it. Potentially we can copy anything into anything.
// if (sourceObject != null && !childType.isAssignableFrom(sourceObject.getClass())) {
// throw new DBException("Can't create '" + childType.getName() + "' from '" + sourceObject.getClass().getName() + "'");
// }
final EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
DBEObjectManager<?> objectManager = editorsRegistry.getObjectManager(childType);
if (objectManager == null) {
throw new DBException("Object manager not found for type '" + childType.getName() + "'");
}
DBEObjectMaker objectMaker = (DBEObjectMaker) objectManager;
final boolean openEditor = (objectMaker.getMakerOptions() & DBEObjectMaker.FEATURE_EDITOR_ON_CREATE) != 0;
CommandTarget commandTarget = getCommandTarget(workbenchWindow, container, childType, openEditor);
final Object parentObject = container.getValueObject();
createDatabaseObject(commandTarget, objectMaker, parentObject, sourceObject);
} catch (Throwable e) {
UIUtils.showErrorDialog(workbenchWindow.getShell(), "Create object", null, e);
return false;
}
return true;
}
use of org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry in project dbeaver by dbeaver.
the class EntityEditor method addContributions.
private void addContributions(String position) {
EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
final DBSObject databaseObject = getEditorInput().getDatabaseObject();
DBPObject object;
if (databaseObject instanceof DBPDataSourceContainer && databaseObject.getDataSource() != null) {
object = databaseObject.getDataSource();
} else {
object = databaseObject;
}
List<EntityEditorDescriptor> descriptors = editorsRegistry.getEntityEditors(object, this, position);
for (EntityEditorDescriptor descriptor : descriptors) {
if (descriptor.getType() == EntityEditorDescriptor.Type.editor) {
addEditorTab(descriptor);
}
}
}
use of org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry in project dbeaver by dbeaver.
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(() -> firePropertyChange(IEditorPart.PROP_DIRTY));
}
};
DBECommandContext commandContext = getCommandContext();
if (commandContext != null) {
commandContext.addCommandListener(commandListener);
}
// Property listener
addPropertyListener((source, 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, this);
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