use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
the class PropertySourceEditable method setPropertyValue.
@Override
@SuppressWarnings("unchecked")
public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
if (prop.getValueTransformer() != null) {
newValue = prop.getValueTransformer().transform(editableValue, newValue);
}
final Object oldValue = getPropertyValue(monitor, editableValue, prop, true);
if (!updatePropertyValue(monitor, editableValue, prop, newValue, false)) {
return;
}
if (commandContext != null) {
if (lastCommand == null || lastCommand.getObject() != editableValue || lastCommand.property != prop || !commandContext.isDirty()) {
// Last command is not applicable (check for isDirty because command queue might be reverted)
final DBEObjectEditor<DBPObject> objectEditor = getObjectEditor(DBEObjectEditor.class);
if (objectEditor == null) {
log.error("Can't obtain object editor for " + getEditableValue());
return;
}
final DBEPropertyHandler<DBPObject> propertyHandler = objectEditor.makePropertyHandler((DBPObject) editableValue, prop);
PropertyChangeCommand curCommand = new PropertyChangeCommand((DBPObject) editableValue, prop, propertyHandler, oldValue, newValue);
commandContext.addCommand(curCommand, commandReflector);
lastCommand = curCommand;
} else {
lastCommand.setNewValue(newValue);
commandContext.updateCommand(lastCommand, commandReflector);
}
}
// To update name-based cache
if (prop.isNameProperty() && editableValue instanceof DBSObject) {
DBEObjectMaker objectManager = getObjectEditor(DBEObjectMaker.class);
if (objectManager != null) {
DBSObjectCache cache = objectManager.getObjectsCache((DBSObject) editableValue);
if (cache != null && cache.isFullyCached()) {
List<? extends DBSObject> cachedObjects = CommonUtils.copyList(cache.getCachedObjects());
cache.setCache(cachedObjects);
}
}
}
/*
// Notify listeners
for (IPropertySourceListener listener : listeners) {
listener.handlePropertyChange(editableValue, prop, newValue);
}
*/
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
the class SessionManagerViewer method loadPlainTextDetails.
private void loadPlainTextDetails(DBAServerSessionDetails data, StyledText styledText) {
SessionDetailsLoadService loadingService = new SessionDetailsLoadService(data);
LoadingJob.createService(loadingService, new ProgressLoaderVisualizer<Collection<DBPObject>>(loadingService, styledText) {
@Override
public void completeLoading(Collection<DBPObject> dbpObjects) {
StringBuilder text = new StringBuilder();
for (DBPObject item : dbpObjects) {
if (item instanceof DBPObjectWithDescription) {
text.append(((DBPObjectWithDescription) item).getDescription());
text.append(GeneralUtils.getDefaultLineSeparator());
}
}
styledText.setText(text.toString());
}
}).schedule();
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by dbeaver.
the class SQLStructEditor method getNestedOrderedCommands.
protected Collection<NestedObjectCommand> getNestedOrderedCommands(final StructCreateCommand structCommand) {
List<NestedObjectCommand> nestedCommands = new ArrayList<>(structCommand.getObjectCommands().values());
nestedCommands.sort((o1, o2) -> {
final DBPObject object1 = o1.getObject();
final DBPObject object2 = o2.getObject();
if (object1 == structCommand.getObject()) {
return 1;
} else if (object2 == structCommand.getObject()) {
return -1;
}
int order1 = -1, order2 = 1;
Class<?>[] childTypes = getChildTypes();
for (int i = 0, childTypesLength = childTypes.length; i < childTypesLength; i++) {
Class<?> childType = childTypes[i];
if (childType.isAssignableFrom(object1.getClass())) {
order1 = i;
}
if (childType.isAssignableFrom(object2.getClass())) {
order2 = i;
}
}
return order1 - order2;
});
return nestedCommands;
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by dbeaver.
the class SessionManagerViewer method loadPlainTextDetails.
private void loadPlainTextDetails(DBAServerSessionDetails data, StyledText styledText) {
SessionDetailsLoadService loadingService = new SessionDetailsLoadService(data);
LoadingJob.createService(loadingService, new ProgressLoaderVisualizer<Collection<DBPObject>>(loadingService, styledText) {
@Override
public void completeLoading(Collection<DBPObject> dbpObjects) {
StringBuilder text = new StringBuilder();
for (DBPObject item : dbpObjects) {
if (item instanceof DBPObjectWithDescription) {
text.append(((DBPObjectWithDescription) item).getDescription());
text.append(GeneralUtils.getDefaultLineSeparator());
}
}
styledText.setText(text.toString());
}
}).schedule();
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by dbeaver.
the class NavigatorHandlerObjectCreateBase method createNewObject.
protected boolean createNewObject(final IWorkbenchWindow workbenchWindow, DBNNode element, @Nullable Class<?> newObjectType, DBNDatabaseNode copyFrom, boolean isFolder) {
try {
DBNNode container = null;
if (isFolder || (element instanceof DBNContainer && !(element instanceof DBNDataSource))) {
container = element;
} else {
DBNNode parentNode = element.getParentNode();
if (parentNode instanceof DBNContainer) {
container = parentNode;
}
}
if (container == null) {
throw new DBException("Can't detect container for '" + element.getNodeName() + "'");
}
if (container instanceof DBNDatabaseNode && ObjectPropertyTester.isMetadataChangeDisabled((DBNDatabaseNode) container)) {
throw new DBException("Object create not available in simple view mode");
}
if (newObjectType == null) {
Class<?> childType = container instanceof DBNContainer ? ((DBNContainer) container).getChildrenClass() : null;
if (childType == null) {
throw new DBException("Can't determine child element type for container '" + container + "'");
}
newObjectType = childType;
}
if (newObjectType == IProject.class) {
return NavigatorHandlerProjectCreate.createNewProject(workbenchWindow);
}
DBSObject sourceObject = copyFrom == null ? null : copyFrom.getObject();
final Object parentObject;
if (container instanceof DBNDatabaseNode) {
parentObject = ((DBNDatabaseNode) container).getValueObject();
} else if (container instanceof DBNProject) {
parentObject = ((DBNProject) container).getProject();
} else if (container instanceof DBNProjectDatabases) {
parentObject = container.getOwnerProject();
} else if (container instanceof DBNLocalFolder) {
parentObject = ((DBNLocalFolder) container).getFolder();
} else {
parentObject = null;
}
// Check that child nodes are read an cached
if (container.hasChildren(false) || parentObject instanceof DBSInstanceLazy) {
try {
DBNNode finalContainer = container;
UIUtils.runInProgressService(monitor -> {
try {
if (finalContainer.hasChildren(false)) {
finalContainer.getChildren(monitor);
}
if (parentObject instanceof DBSInstanceLazy) {
((DBSInstanceLazy) parentObject).checkInstanceConnection(monitor);
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("New object", "Error creating new object", e);
} catch (InterruptedException e) {
// ignore
}
}
DBEObjectManager<?> objectManager = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(newObjectType);
if (objectManager == null) {
throw new DBException("Object manager not found for type '" + newObjectType.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, newObjectType, openEditor);
// Parent is model object - not node
Map<String, Object> options = new HashMap<>();
options.put(DBEObjectMaker.OPTION_CONTAINER, container);
options.put(DBEObjectMaker.OPTION_OBJECT_TYPE, newObjectType);
createDatabaseObject(commandTarget, objectMaker, parentObject instanceof DBPObject ? (DBPObject) parentObject : null, sourceObject, options);
} catch (Throwable e) {
DBWorkbench.getPlatformUI().showError("Create object", null, e);
return false;
}
return true;
}
Aggregations