Search in sources :

Example 6 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class SelectObjectDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    ObjectListControl<T> objectList = new ObjectListControl<T>(group, SWT.BORDER | (singleSelection ? SWT.SINGLE : SWT.MULTI), new ListContentProvider()) {

        @NotNull
        @Override
        protected String getListConfigId(List<Class<?>> classList) {
            return "ObjectsSelector";
        }

        @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());
        }
    };
    objectList.createProgressPanel();
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.minimumWidth = 300;
    objectList.setLayoutData(gd);
    objectList.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectedObjects.clear();
            selectedObjects.addAll(selection.toList());
            getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
        }
    });
    objectList.setDoubleClickHandler(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getButton(IDialogConstants.OK_ID).isEnabled()) {
                okPressed();
            }
        }
    });
    objectList.loadData();
    return group;
}
Also used : ObjectListControl(org.jkiss.dbeaver.ui.controls.itemlist.ObjectListControl) Composite(org.eclipse.swt.widgets.Composite) InvocationTargetException(java.lang.reflect.InvocationTargetException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 7 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class DialogUtils method loadFromFile.

public static boolean loadFromFile(final IValueController controller) {
    if (!(controller.getValue() instanceof DBDContent)) {
        log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
        return false;
    }
    Shell shell = UIUtils.getShell(controller.getValueSite());
    final File openFile = openFile(shell);
    if (openFile == null) {
        return false;
    }
    final DBDContent value = (DBDContent) controller.getValue();
    DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                DBDContentStorage storage;
                if (ContentUtils.isTextContent(value)) {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
                } else {
                    storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
                }
                value.updateContents(monitor, storage);
                controller.updateValue(value, true);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
    return true;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) ExternalContentStorage(org.jkiss.dbeaver.model.impl.ExternalContentStorage) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class GotoObjectDialog method fillContentProvider.

@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    DBSStructureAssistant structureAssistant = DBUtils.getAdapter(DBSStructureAssistant.class, context.getDataSource());
    if (structureAssistant == null) {
        return;
    }
    String nameMask = ((ObjectFilter) itemsFilter).getNameMask();
    DBRProgressMonitor monitor = RuntimeUtils.makeMonitor(progressMonitor);
    try {
        monitor.beginTask("Search for '" + nameMask + "'", 100);
        List<DBSObjectType> typesToSearch = new ArrayList<>();
        for (DBSObjectType type : structureAssistant.getSupportedObjectTypes()) {
            Class<? extends DBSObject> typeClass = type.getTypeClass();
            if (DBSEntityElement.class.isAssignableFrom(typeClass)) {
                // Skipp attributes (columns), methods, etc
                continue;
            }
            typesToSearch.add(type);
        }
        Collection<DBSObjectReference> result = structureAssistant.findObjectsByMask(monitor, container, typesToSearch.toArray(new DBSObjectType[typesToSearch.size()]), nameMask, false, true, 1000);
        DBPDataSourceContainer dsContainer = context.getDataSource().getContainer();
        for (DBSObjectReference ref : result) {
            DBSObjectFilter filter = dsContainer.getObjectFilter(ref.getObjectClass(), ref.getContainer(), true);
            if (filter == null || !filter.isEnabled() || filter.matches(ref.getName())) {
                contentProvider.add(ref, itemsFilter);
            }
        }
    } catch (DBException e) {
        throw new CoreException(GeneralUtils.makeExceptionStatus(e));
    } finally {
        monitor.done();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) CoreException(org.eclipse.core.runtime.CoreException) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 9 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class GenericStructureAssistant method findProceduresByMask.

private void findProceduresByMask(JDBCSession session, GenericCatalog catalog, GenericSchema schema, String procNameMask, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
    final GenericMetaObject procObject = getDataSource().getMetaObject(GenericConstants.OBJECT_PROCEDURE);
    DBRProgressMonitor monitor = session.getProgressMonitor();
    try (JDBCResultSet dbResult = session.getMetaData().getProcedures(catalog == null ? null : catalog.getName(), schema == null ? null : schema.getName(), procNameMask)) {
        while (dbResult.next()) {
            if (monitor.isCanceled()) {
                break;
            }
            String catalogName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_CAT);
            String schemaName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_SCHEM);
            String procName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_NAME);
            String uniqueName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.SPECIFIC_NAME);
            if (CommonUtils.isEmpty(procName)) {
                continue;
            }
            if (CommonUtils.isEmpty(uniqueName)) {
                uniqueName = procName;
            }
            objects.add(new ProcedureReference(findContainer(session.getProgressMonitor(), catalog, schema, catalogName, schemaName), catalogName, procName, uniqueName));
            if (objects.size() >= maxResults) {
                break;
            }
        }
    }
}
Also used : GenericMetaObject(org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 10 with DBRProgressMonitor

use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.

the class GenericStructureAssistant method findTablesByMask.

private void findTablesByMask(JDBCSession session, GenericCatalog catalog, GenericSchema schema, String tableNameMask, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
    final GenericMetaObject tableObject = getDataSource().getMetaObject(GenericConstants.OBJECT_TABLE);
    final DBRProgressMonitor monitor = session.getProgressMonitor();
    try (JDBCResultSet dbResult = session.getMetaData().getTables(catalog == null ? null : catalog.getName(), schema == null ? null : schema.getName(), tableNameMask, null)) {
        while (dbResult.next()) {
            if (monitor.isCanceled()) {
                break;
            }
            String catalogName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_CAT);
            String schemaName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_SCHEM);
            String tableName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_NAME);
            if (CommonUtils.isEmpty(tableName)) {
                continue;
            }
            objects.add(new TableReference(findContainer(session.getProgressMonitor(), catalog, schema, catalogName, schemaName), tableName, GenericUtils.safeGetString(tableObject, dbResult, JDBCConstants.REMARKS)));
            if (objects.size() >= maxResults) {
                break;
            }
        }
    }
}
Also used : GenericMetaObject(org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)79 DBException (org.jkiss.dbeaver.DBException)45 InvocationTargetException (java.lang.reflect.InvocationTargetException)36 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)30 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 ArrayList (java.util.ArrayList)8 IStatus (org.eclipse.core.runtime.IStatus)8 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)6 GridData (org.eclipse.swt.layout.GridData)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 List (java.util.List)5 NotNull (org.jkiss.code.NotNull)5 File (java.io.File)4 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4