Search in sources :

Example 1 with DBSObjectCache

use of org.jkiss.dbeaver.model.struct.cache.DBSObjectCache in project dbeaver by dbeaver.

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);
        }
*/
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectCache(org.jkiss.dbeaver.model.struct.cache.DBSObjectCache) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker)

Example 2 with DBSObjectCache

use of org.jkiss.dbeaver.model.struct.cache.DBSObjectCache 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);
        }
*/
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObjectCache(org.jkiss.dbeaver.model.struct.cache.DBSObjectCache) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker)

Aggregations

DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBPObject (org.jkiss.dbeaver.model.DBPObject)2 DBEObjectMaker (org.jkiss.dbeaver.model.edit.DBEObjectMaker)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DBSObjectCache (org.jkiss.dbeaver.model.struct.cache.DBSObjectCache)2