Search in sources :

Example 1 with DBDLabelValuePair

use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by serge-rider.

the class FilterValueEditDialog method okPressed.

@Override
protected void okPressed() {
    if (table != null) {
        java.util.List<Object> values = new ArrayList<>();
        for (DBDLabelValuePair item : getMultiValues()) {
            if (table.getChecked(item)) {
                values.add(item.getValue());
            }
        }
        value = values.toArray();
    } else if (editor != null) {
        try {
            value = editor.extractEditorValue();
        } catch (DBException e) {
            log.error("Can't get editor value", e);
        }
    } else {
        value = textControl.getText();
    }
    super.okPressed();
}
Also used : DBException(org.jkiss.dbeaver.DBException) java.util(java.util) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 2 with DBDLabelValuePair

use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by serge-rider.

the class FilterValueEditDialog method createMultiValueSelector.

private void createMultiValueSelector(Composite composite) {
    table = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION);
    table.getTable().setLinesVisible(true);
    table.getTable().setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 300;
    table.getTable().setLayoutData(gd);
    table.setContentProvider(new ListContentProvider());
    ViewerColumnController columnController = new ViewerColumnController(getClass().getName(), table);
    columnController.addColumn("Value", "Value", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return attr.getValueHandler().getValueDisplayString(attr, ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
        }
    });
    columnController.addColumn("Description", "Row description (composed from dictionary columns)", SWT.LEFT, true, true, new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DBDLabelValuePair) element).getLabel();
        }
    });
    columnController.createColumns();
    MenuManager menuMgr = new MenuManager();
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            UIUtils.fillDefaultTableContextMenu(manager, table.getTable());
            manager.add(new Separator());
            manager.add(new Action("Select &All") {

                @Override
                public void run() {
                    for (DBDLabelValuePair row : getMultiValues()) {
                        table.setChecked(row, true);
                    }
                }
            });
            manager.add(new Action("Select &None") {

                @Override
                public void run() {
                    for (DBDLabelValuePair row : getMultiValues()) {
                        table.setChecked(row, false);
                    }
                }
            });
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    table.getTable().setMenu(menuMgr.createContextMenu(table.getTable()));
    if (attr.getDataKind() == DBPDataKind.STRING) {
        // Create filter text
        final Text valueFilterText = new Text(composite, SWT.BORDER);
        valueFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        valueFilterText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                filterPattern = valueFilterText.getText();
                if (filterPattern.isEmpty()) {
                    filterPattern = null;
                }
                loadValues();
            }
        });
    }
    filterPattern = null;
    loadValues();
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) ModifyListener(org.eclipse.swt.events.ModifyListener) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 3 with DBDLabelValuePair

use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.

the class AbstractMockValueGenerator method generateValue.

@Override
public Object generateValue(DBRProgressMonitor monitor) throws DBException, IOException {
    if (isFirstRun) {
        isFirstRun = false;
        isUnique = DBUtils.checkUnique(monitor, dbsEntity, attribute);
        if (isUnique && (attribute instanceof DBSAttributeEnumerable)) {
            uniqueValues = new HashSet<>();
            Collection<DBDLabelValuePair> valuePairs = readColumnValues(monitor, dbsEntity.getDataSource(), (DBSAttributeEnumerable) attribute, UNIQUE_VALUES_SET_SIZE);
            for (DBDLabelValuePair pair : valuePairs) {
                uniqueValues.add(pair.getValue());
            }
        }
    }
    if (isUnique) {
        int attempts = 0;
        Object value = null;
        while (value == null || uniqueValues.contains(value)) {
            if (attempts > UNIQUE_VALUE_GEN_ATTEMPTS) {
                throw new DBException("\n      Can't generate appropriate unique value for the '" + attribute.getName() + "' <" + attribute.getFullTypeName() + "> attribute.\n" + "      Try to change the generator or its parameters.\n");
            }
            if (monitor.isCanceled()) {
                return null;
            }
            value = generateOneValue(monitor);
            attempts++;
        }
        uniqueValues.add(value);
        return value;
    } else {
        return generateOneValue(monitor);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSAttributeEnumerable(org.jkiss.dbeaver.model.struct.DBSAttributeEnumerable) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 4 with DBDLabelValuePair

use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.

the class FKGenerator method generateOneValue.

@Override
public Object generateOneValue(DBRProgressMonitor monitor) throws DBException, IOException {
    if (refValues == null) {
        refValues = new ArrayList<>();
        List<DBSEntityReferrer> attributeReferrers = DBUtils.getAttributeReferrers(monitor, (DBSEntityAttribute) attribute);
        // TODO only the first
        DBSEntityReferrer fk = attributeReferrers.get(0);
        List<? extends DBSEntityAttributeRef> references = ((DBSEntityReferrer) fk).getAttributeReferences(monitor);
        DBSTableForeignKeyColumn column = null;
        for (DBSEntityAttributeRef ref : references) {
            if (((DBPNamedObject) ref).getName().equals(attribute.getName())) {
                column = (DBSTableForeignKeyColumn) ref;
            }
        }
        if (column == null) {
            throw new DBException("Can't find reference column for '" + attribute.getName() + "'");
        }
        int numberRefRecords = DBUtils.checkUnique(monitor, dbsEntity, attribute) ? UNIQ_REF_RECORDS_LIMIT : REF_RECORDS_LIMIT;
        Collection<DBDLabelValuePair> values = readColumnValues(monitor, fk.getDataSource(), (DBSAttributeEnumerable) column.getReferencedColumn(), numberRefRecords);
        for (DBDLabelValuePair value : values) {
            refValues.add(value.getValue());
        }
    }
    return refValues.get(random.nextInt(refValues.size()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTableForeignKeyColumn(org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKeyColumn) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 5 with DBDLabelValuePair

use of org.jkiss.dbeaver.model.data.DBDLabelValuePair in project dbeaver by dbeaver.

the class FilterValueEditDialog method okPressed.

@Override
protected void okPressed() {
    if (handler.table != null) {
        java.util.List<Object> values = new ArrayList<>();
        for (DBDLabelValuePair item : handler.getMultiValues()) {
            if (((TableItem) handler.table.testFindItem(item)).getChecked()) {
                values.add(item.getValue());
            }
        }
        value = values.toArray();
    } else if (handler.editor != null) {
        try {
            value = handler.editor.extractEditorValue();
        } catch (DBException e) {
            log.error("Can't get editor value", e);
        }
    } else {
        value = handler.textControl.getText();
    }
    super.okPressed();
}
Also used : DBException(org.jkiss.dbeaver.DBException) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Aggregations

DBDLabelValuePair (org.jkiss.dbeaver.model.data.DBDLabelValuePair)19 DBException (org.jkiss.dbeaver.DBException)8 GridData (org.eclipse.swt.layout.GridData)7 ViewerColumnController (org.jkiss.dbeaver.ui.controls.ViewerColumnController)6 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 Pattern (java.util.regex.Pattern)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 TableItem (org.eclipse.swt.widgets.TableItem)4 java.util (java.util)3 ListContentProvider (org.jkiss.dbeaver.ui.controls.ListContentProvider)3 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Action (org.eclipse.jface.action.Action)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 Nullable (org.jkiss.code.Nullable)2 DBDAttributeConstraint (org.jkiss.dbeaver.model.data.DBDAttributeConstraint)2 DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)2 DBSEntityAssociation (org.jkiss.dbeaver.model.struct.DBSEntityAssociation)2