use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by dbeaver.
the class SQLGeneratorConfigurationRegistry method getApplicableGenerators.
public List<SQLGeneratorDescriptor> getApplicableGenerators(Collection<?> objects, Object context) {
List<SQLGeneratorDescriptor> result = new ArrayList<>();
for (SQLGeneratorDescriptor gen : generators) {
for (Object object : objects) {
if (object instanceof DBPObject && gen.appliesTo((DBPObject) object, context)) {
if (gen.isMultiObject() && objects.size() < 2) {
continue;
}
result.add(gen);
break;
}
}
}
result.sort(Comparator.comparingInt(SQLGeneratorDescriptor::getOrder));
return result;
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
the class SQLGeneratorContributor method getContributionItems.
// ////////////////////////////////////////////////////////
// Contributors
@Override
protected IContributionItem[] getContributionItems() {
IWorkbenchPart part = UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart();
IStructuredSelection structuredSelection = NavigatorUtils.getSelectionFromPart(part);
if (structuredSelection == null || structuredSelection.isEmpty()) {
return new IContributionItem[0];
}
List<IContributionItem> menu = new ArrayList<>();
if (structuredSelection instanceof IResultSetSelection) {
// Results
makeResultSetContributions(menu, (IResultSetSelection) structuredSelection);
} else {
List<DBPObject> objects = new ArrayList<>();
for (Object obj : structuredSelection.toList()) {
DBSObject adaptedObject = GeneralUtils.adapt(obj, DBSObject.class);
if (adaptedObject != null) {
objects.add(adaptedObject);
} else if (obj instanceof DBSWrapper) {
objects.add(((DBSWrapper) obj).getObject());
} else if (obj instanceof DBPObject) {
objects.add((DBPObject) obj);
}
}
List<SQLGeneratorDescriptor> generators = SQLGeneratorConfigurationRegistry.getInstance().getApplicableGenerators(objects, structuredSelection);
int lastGrand = 0;
for (SQLGeneratorDescriptor gen : generators) {
int order = gen.getOrder();
if (order > 0 && order / 1000 > lastGrand) {
menu.add(new Separator());
}
lastGrand = order / 1000;
menu.add(makeAction(gen.getLabel(), gen, objects));
}
}
return menu.toArray(new IContributionItem[0]);
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
the class ObjectListDialog method createObjectSelector.
@NotNull
protected static <T extends DBPObject> DatabaseObjectListControl<T> createObjectSelector(Composite group, boolean singleSelection, String listId, List<T> selectedObjects, DBRRunnableWithResult<List<T>> objectReader) {
return new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {
private Font boldFont;
private ISearchExecutor searcher = new SearcherFilter();
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return listId;
}
@Override
protected LoadingJob<Collection<T>> createLoadService() {
return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {
@Override
public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
objectReader.run(monitor);
return objectReader.getResult();
}
@Override
public Object getFamily() {
return ObjectListDialog.class;
}
}, new ObjectsLoadVisualizer() {
@Override
public void completeLoading(Collection<T> items) {
super.completeLoading(items);
performSearch(SearchType.NONE);
getItemsViewer().getControl().setFocus();
}
});
}
protected CellLabelProvider getColumnLabelProvider(ObjectColumn objectColumn) {
return new ObjectLabelProvider(objectColumn);
}
@Override
protected Object getObjectValue(T item) {
if (item instanceof DBSWrapper) {
return ((DBSWrapper) item).getObject();
}
return super.getObjectValue(item);
}
@Override
protected DBPImage getObjectImage(T item) {
if (item instanceof DBNDatabaseNode) {
return ((DBNDatabaseNode) item).getNodeIcon();
}
return null;
}
@Override
protected void setListData(Collection<T> items, boolean append) {
super.setListData(items, append);
if (selectedObjects != null) {
getItemsViewer().setSelection(new StructuredSelection(selectedObjects), true);
}
}
@Override
public void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
addColumnConfigAction(contributionManager);
}
protected void addSearchAction(IContributionManager contributionManager) {
contributionManager.add(new Action("Filter objects", DBeaverIcons.getImageDescriptor(UIIcon.SEARCH)) {
@Override
public void run() {
performSearch(SearchType.NONE);
}
});
}
@Override
protected ISearchExecutor getSearchRunner() {
return searcher;
}
class ObjectLabelProvider extends ObjectColumnLabelProvider implements IFontProvider {
ObjectLabelProvider(ObjectColumn objectColumn) {
super(objectColumn);
}
@Override
public Font getFont(Object element) {
if (selectedObjects.contains(element)) {
if (boldFont == null) {
boldFont = UIUtils.makeBoldFont(group.getFont());
group.addDisposeListener(e -> boldFont.dispose());
}
return boldFont;
}
return null;
}
}
};
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.model.DBPObject in project dbeaver by serge-rider.
the class SQLGeneratorConfigurationRegistry method getApplicableGenerators.
public List<SQLGeneratorDescriptor> getApplicableGenerators(Collection<?> objects, Object context) {
List<SQLGeneratorDescriptor> result = new ArrayList<>();
for (SQLGeneratorDescriptor gen : generators) {
for (Object object : objects) {
if (object instanceof DBPObject && gen.appliesTo((DBPObject) object, context)) {
if (gen.isMultiObject() && objects.size() < 2) {
continue;
}
result.add(gen);
break;
}
}
}
result.sort(Comparator.comparingInt(SQLGeneratorDescriptor::getOrder));
return result;
}
Aggregations