Search in sources :

Example 1 with DatabaseObjectListControl

use of org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl 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;
            }
        }
    };
}
Also used : ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DBPImage(org.jkiss.dbeaver.model.DBPImage) NotNull(org.jkiss.code.NotNull) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) Collection(java.util.Collection) IContributionManager(org.eclipse.jface.action.IContributionManager) Action(org.eclipse.jface.action.Action) IFontProvider(org.eclipse.jface.viewers.IFontProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBPObject(org.jkiss.dbeaver.model.DBPObject) AbstractPopupPanel(org.jkiss.dbeaver.ui.dialogs.AbstractPopupPanel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Action(org.eclipse.jface.action.Action) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) Font(org.eclipse.swt.graphics.Font) InvocationTargetException(java.lang.reflect.InvocationTargetException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IContributionManager(org.eclipse.jface.action.IContributionManager) NotNull(org.jkiss.code.NotNull)

Example 2 with DatabaseObjectListControl

use of org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl in project dbeaver by dbeaver.

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;
            }
        }
    };
}
Also used : ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DBPImage(org.jkiss.dbeaver.model.DBPImage) NotNull(org.jkiss.code.NotNull) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) Collection(java.util.Collection) IContributionManager(org.eclipse.jface.action.IContributionManager) Action(org.eclipse.jface.action.Action) IFontProvider(org.eclipse.jface.viewers.IFontProvider) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBPObject(org.jkiss.dbeaver.model.DBPObject) AbstractPopupPanel(org.jkiss.dbeaver.ui.dialogs.AbstractPopupPanel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Action(org.eclipse.jface.action.Action) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseObjectListControl(org.jkiss.dbeaver.ui.navigator.itemlist.DatabaseObjectListControl) Font(org.eclipse.swt.graphics.Font) InvocationTargetException(java.lang.reflect.InvocationTargetException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IContributionManager(org.eclipse.jface.action.IContributionManager) NotNull(org.jkiss.code.NotNull)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Action (org.eclipse.jface.action.Action)2 IContributionManager (org.eclipse.jface.action.IContributionManager)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)2 IFontProvider (org.eclipse.jface.viewers.IFontProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 SWT (org.eclipse.swt.SWT)2 Font (org.eclipse.swt.graphics.Font)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Control (org.eclipse.swt.widgets.Control)2 Shell (org.eclipse.swt.widgets.Shell)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2