Search in sources :

Example 1 with DatabaseObjectListControl

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

the class SelectObjectDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    final DatabaseObjectListControl<T> objectList = new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {

        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 {
                    return objects;
                }

                @Override
                public Object getFamily() {
                    return SelectObjectDialog.this;
                }
            }, new ObjectsLoadVisualizer() {

                @Override
                public void completeLoading(Collection<T> items) {
                    super.completeLoading(items);
                    performSearch(ISearchContextProvider.SearchType.NONE);
                    getItemsViewer().getControl().setFocus();
                    closeOnFocusLost(getItemsViewer().getControl(), getSearchTextControl());
                }
            });
        }

        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
        protected 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(ISearchContextProvider.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)) {
                    return boldFont;
                }
                return null;
            }
        }
    };
    objectList.createProgressPanel();
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.minimumWidth = 300;
    objectList.setLayoutData(gd);
    objectList.getSelectionProvider().addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        selectedObjects.clear();
        selectedObjects.addAll(selection.toList());
        if (!isModeless()) {
            getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
        }
    });
    objectList.setDoubleClickHandler(event -> {
        if (isModeless() || getButton(IDialogConstants.OK_ID).isEnabled()) {
            okPressed();
        }
    });
    objectList.loadData();
    return group;
}
Also used : 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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseObjectListControl(org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl) Font(org.eclipse.swt.graphics.Font) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) ArrayList(java.util.ArrayList) List(java.util.List) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) Composite(org.eclipse.swt.widgets.Composite) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContributionManager(org.eclipse.jface.action.IContributionManager)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Action (org.eclipse.jface.action.Action)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SWT (org.eclipse.swt.SWT)1 Font (org.eclipse.swt.graphics.Font)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 DBPObject (org.jkiss.dbeaver.model.DBPObject)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)1 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)1 DatabaseObjectListControl (org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl)1