Search in sources :

Example 1 with EditDictionaryPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.

the class FilterValueEditPopup method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    DBSEntityReferrer descReferrer = ResultSetUtils.getEnumerableConstraint(filter.getAttribute());
    Composite group = (Composite) super.createDialogArea(parent);
    {
        Composite labelComposite = UIUtils.createComposite(group, 2);
        labelComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        Label controlLabel = UIUtils.createControlLabel(labelComposite, "Choose value(s) to filter by");
        controlLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        if (descReferrer instanceof DBSEntityAssociation) {
            Link hintLabel = UIUtils.createLink(labelComposite, "(<a>Define Description</a>)", new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    EditDictionaryPage editDictionaryPage = new EditDictionaryPage(((DBSEntityAssociation) descReferrer).getAssociatedEntity());
                    if (editDictionaryPage.edit(parent.getShell())) {
                        filter.loadValues(null);
                    }
                }
            });
            hintLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
        } else {
            UIUtils.createEmptyLabel(labelComposite, 1, 1);
        }
    }
    Text filterTextbox = filter.addFilterTextbox(group);
    filterTextbox.setFocus();
    filterTextbox.addTraverseListener(e -> {
        Table table = filter.getTableViewer().getTable();
        if (e.detail == SWT.TRAVERSE_ARROW_PREVIOUS || e.detail == SWT.TRAVERSE_ARROW_NEXT) {
            if (table.getSelectionIndex() < 0 && table.getItemCount() > 0) {
                table.setSelection(0);
            }
            table.setFocus();
        } else if (e.detail == SWT.TRAVERSE_RETURN) {
            applyFilterValue();
        }
    });
    UIUtils.addEmptyTextHint(filterTextbox, text -> "Type partial value to search");
    Composite tableComposite = UIUtils.createComposite(group, 1);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 300;
    tableComposite.setLayoutData(gd);
    filter.setupTable(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | (filter.getOperator() == DBCLogicalOperator.IN ? SWT.CHECK : SWT.NONE), true, descReferrer != null, new GridData(GridData.FILL_BOTH));
    Table table = filter.getTableViewer().getTable();
    TableViewerColumn resultsetColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Value"));
    resultsetColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return filter.getAttribute().getValueHandler().getValueDisplayString(filter.getAttribute(), ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
        }
    });
    TableViewerColumn descColumn;
    if (descReferrer != null) {
        descColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Description"));
        descColumn.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return ((DBDLabelValuePair) element).getLabel();
            }
        });
    }
    filter.getTableViewer().addSelectionChangedListener(event -> {
        value = filter.getFilterValue();
    // okPressed();
    });
    filter.getTableViewer().addDoubleClickListener(event -> applyFilterValue());
    filter.setFilterPattern(null);
    filter.loadValues(() -> UIUtils.asyncExec(() -> UIUtils.packColumns(table, false)));
    filter.createFilterButton(ResultSetMessages.sql_editor_resultset_filter_panel_btn_apply, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            applyFilterValue();
        }
    });
    closeOnFocusLost(filterTextbox, table);
    return tableComposite;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage) DBSEntityAssociation(org.jkiss.dbeaver.model.struct.DBSEntityAssociation) DBSEntityReferrer(org.jkiss.dbeaver.model.struct.DBSEntityReferrer) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Example 2 with EditDictionaryPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by dbeaver.

the class ReferenceValueEditor method createEditorSelector.

public boolean createEditorSelector(final Composite parent) {
    if (!(valueController instanceof IAttributeController) || valueController.isReadOnly()) {
        return false;
    }
    refConstraint = getEnumerableConstraint();
    if (refConstraint == null) {
        return false;
    }
    if (refConstraint instanceof DBSEntityAssociation) {
        final DBSEntityAssociation association = (DBSEntityAssociation) refConstraint;
        if (association.getReferencedConstraint() != null) {
            final DBSEntity refTable = association.getReferencedConstraint().getParentObject();
            Composite labelGroup = UIUtils.createPlaceholder(parent, 2);
            labelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            Link dictLabel = UIUtils.createLink(labelGroup, NLS.bind(CoreMessages.dialog_value_view_label_dictionary, refTable.getName()), new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // Open
                    final IWorkbenchWindow window = valueController.getValueSite().getWorkbenchWindow();
                    DBeaverUI.runInUI(window, new DBRRunnableWithProgress() {

                        @Override
                        public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            DBNDatabaseNode tableNode = NavigatorUtils.getNodeByObject(monitor, refTable, true);
                            if (tableNode != null) {
                                NavigatorHandlerObjectOpen.openEntityEditor(tableNode, DatabaseDataEditor.class.getName(), window);
                            }
                        }
                    });
                }
            });
            dictLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            Link hintLabel = UIUtils.createLink(labelGroup, "(<a>Define Description</a>)", new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    EditDictionaryPage editDictionaryPage = new EditDictionaryPage("Dictionary structure", refTable);
                    if (editDictionaryPage.edit(parent.getShell())) {
                        loaderJob.schedule();
                    }
                }
            });
            hintLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
        }
    }
    editorSelector = new Table(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    editorSelector.setLinesVisible(true);
    editorSelector.setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 150;
    // gd.widthHint = 300;
    // gd.grabExcessVerticalSpace = true;
    // gd.grabExcessHorizontalSpace = true;
    editorSelector.setLayoutData(gd);
    UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_value);
    UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_description);
    UIUtils.packColumns(editorSelector);
    editorSelector.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selection = editorSelector.getSelection();
            if (selection != null && selection.length > 0) {
                Object value = selection[0].getData();
                // editorControl.setText(selection[0].getText());
                try {
                    valueEditor.primeEditorValue(value);
                } catch (DBException e1) {
                    log.error(e1);
                }
            }
        }
    });
    Control control = valueEditor.getControl();
    ModifyListener modifyListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            Object curEditorValue;
            try {
                curEditorValue = valueEditor.extractEditorValue();
            } catch (DBException e1) {
                log.error(e1);
                return;
            }
            // Try to select current value in the table
            final String curTextValue = valueController.getValueHandler().getValueDisplayString(((IAttributeController) valueController).getBinding(), curEditorValue, DBDDisplayFormat.UI);
            boolean valueFound = false;
            for (TableItem item : editorSelector.getItems()) {
                if (item.getText(0).equals(curTextValue)) {
                    editorSelector.select(editorSelector.indexOf(item));
                    editorSelector.showItem(item);
                    valueFound = true;
                    break;
                }
            }
            if (!valueFound) {
                // Read dictionary
                if (loaderJob.getState() == Job.RUNNING) {
                    // Cancel it and create new one
                    loaderJob.cancel();
                    loaderJob = new SelectorLoaderJob();
                }
                loaderJob.setPattern(curEditorValue);
                if (loaderJob.getState() != Job.WAITING) {
                    loaderJob.schedule(100);
                }
            }
        }
    };
    if (control instanceof Text) {
        ((Text) control).addModifyListener(modifyListener);
    } else if (control instanceof StyledText) {
        ((StyledText) control).addModifyListener(modifyListener);
    }
    loaderJob = new SelectorLoaderJob();
    final Object curValue = valueController.getValue();
    if (curValue instanceof Number) {
        loaderJob.setPattern(curValue);
    }
    loaderJob.schedule(500);
    return true;
}
Also used : DBException(org.jkiss.dbeaver.DBException) ModifyListener(org.eclipse.swt.events.ModifyListener) EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseDataEditor(org.jkiss.dbeaver.ui.editors.data.DatabaseDataEditor) StyledText(org.eclipse.swt.custom.StyledText) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 3 with EditDictionaryPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.

the class ReferenceValueEditor method createEditorSelector.

public boolean createEditorSelector(final Composite parent) {
    if (!(valueController instanceof IAttributeController) || valueController.isReadOnly()) {
        return false;
    }
    refConstraint = getEnumerableConstraint();
    if (refConstraint == null) {
        return false;
    }
    if (refConstraint instanceof DBSEntityAssociation) {
        final DBSEntityAssociation association = (DBSEntityAssociation) refConstraint;
        if (association.getReferencedConstraint() != null) {
            final DBSEntity refTable = association.getReferencedConstraint().getParentObject();
            Composite labelGroup = UIUtils.createPlaceholder(parent, 2);
            labelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            Link dictLabel = UIUtils.createLink(labelGroup, NLS.bind(ResultSetMessages.dialog_value_view_label_dictionary, refTable.getName()), new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // Open
                    final IWorkbenchWindow window = valueController.getValueSite().getWorkbenchWindow();
                    UIUtils.runInUI(window, monitor -> {
                        DBNDatabaseNode tableNode = DBNUtils.getNodeByObject(monitor, refTable, true);
                        if (tableNode != null) {
                            NavigatorHandlerObjectOpen.openEntityEditor(tableNode, DatabaseDataEditor.class.getName(), window);
                        }
                    });
                }
            });
            dictLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            Link hintLabel = UIUtils.createLink(labelGroup, "(<a>Define Description</a>)", new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    EditDictionaryPage editDictionaryPage = new EditDictionaryPage(refTable);
                    if (editDictionaryPage.edit(parent.getShell())) {
                        reloadSelectorValues(null, true);
                    }
                }
            });
            hintLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
        }
    }
    editorSelector = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    editorSelector.setLinesVisible(true);
    editorSelector.setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 150;
    // gd.widthHint = 300;
    // gd.grabExcessVerticalSpace = true;
    // gd.grabExcessHorizontalSpace = true;
    editorSelector.setLayoutData(gd);
    TreeColumn valueColumn = UIUtils.createTreeColumn(editorSelector, SWT.LEFT, ResultSetMessages.dialog_value_view_column_value);
    valueColumn.setData(Boolean.TRUE);
    TreeColumn descColumn = UIUtils.createTreeColumn(editorSelector, SWT.LEFT, ResultSetMessages.dialog_value_view_column_description);
    descColumn.setData(Boolean.FALSE);
    SortListener sortListener = new SortListener();
    valueColumn.addListener(SWT.Selection, sortListener);
    descColumn.addListener(SWT.Selection, sortListener);
    editorSelector.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] selection = editorSelector.getSelection();
            if (selection != null && selection.length > 0) {
                Object value = selection[0].getData();
                // editorControl.setText(selection[0].getText());
                try {
                    valueEditor.primeEditorValue(value);
                } catch (DBException e1) {
                    log.error(e1);
                }
            }
        }
    });
    {
        MenuManager menuMgr = new MenuManager();
        menuMgr.addMenuListener(manager -> {
            manager.add(new CopyAction());
            manager.add(new Separator());
        });
        menuMgr.setRemoveAllWhenShown(true);
        this.editorSelector.setMenu(menuMgr.createContextMenu(this.editorSelector));
        this.editorSelector.addDisposeListener(e -> menuMgr.dispose());
    }
    Control control = valueEditor.getControl();
    ModifyListener modifyListener = e -> {
        Object curEditorValue;
        try {
            curEditorValue = valueEditor.extractEditorValue();
        } catch (DBException e1) {
            log.error(e1);
            return;
        }
        // Try to select current value in the table
        final String curTextValue = valueController.getValueHandler().getValueDisplayString(((IAttributeController) valueController).getBinding(), curEditorValue, DBDDisplayFormat.EDIT);
        boolean valueFound = false;
        if (curTextValue != null) {
            TreeItem[] items = editorSelector.getItems();
            for (int i = 0; i < items.length; i++) {
                TreeItem item = items[i];
                if (curTextValue.equalsIgnoreCase(item.getText(0)) || curTextValue.equalsIgnoreCase(item.getText(1))) {
                    editorSelector.select(item);
                    editorSelector.showItem(item);
                    // editorSelector.setTopIndex(i);
                    valueFound = true;
                    break;
                }
            }
        }
        if (!valueFound) {
            // Read dictionary
            reloadSelectorValues(curEditorValue, false);
        }
    };
    if (control instanceof Text) {
        ((Text) control).addModifyListener(modifyListener);
    } else if (control instanceof StyledText) {
        ((StyledText) control).addModifyListener(modifyListener);
    }
    if (refConstraint instanceof DBSEntityAssociation) {
        final Text valueFilterText = new Text(parent, SWT.BORDER);
        valueFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        valueFilterText.addModifyListener(e -> {
            String filterPattern = valueFilterText.getText();
            reloadSelectorValues(filterPattern, false);
        });
        valueFilterText.addPaintListener(e -> {
            if (valueFilterText.isEnabled() && valueFilterText.getCharCount() == 0) {
                e.gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
                e.gc.drawText("Type part of dictionary value to search", 2, 0, true);
                e.gc.setFont(null);
            }
        });
    }
    final Object curValue = valueController.getValue();
    reloadSelectorValues(curValue, false);
    return true;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) org.jkiss.dbeaver.model.data(org.jkiss.dbeaver.model.data) Nullable(org.jkiss.code.Nullable) DatabaseDataEditor(org.jkiss.dbeaver.ui.editors.data.DatabaseDataEditor) ArrayList(java.util.ArrayList) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) UIUtils(org.jkiss.dbeaver.ui.UIUtils) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) AbstractLoadService(org.jkiss.dbeaver.model.runtime.load.AbstractLoadService) ResultSetUtils(org.jkiss.dbeaver.ui.controls.resultset.ResultSetUtils) IValueController(org.jkiss.dbeaver.ui.data.IValueController) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) Separator(org.eclipse.jface.action.Separator) org.jkiss.dbeaver.model.struct(org.jkiss.dbeaver.model.struct) NLS(org.eclipse.osgi.util.NLS) DBUtils(org.jkiss.dbeaver.model.DBUtils) MenuManager(org.eclipse.jface.action.MenuManager) Collection(java.util.Collection) org.eclipse.swt.widgets(org.eclipse.swt.widgets) Action(org.eclipse.jface.action.Action) ProgressLoaderVisualizer(org.jkiss.dbeaver.ui.controls.ProgressLoaderVisualizer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) DBExecUtils(org.jkiss.dbeaver.model.exec.DBExecUtils) NavigatorHandlerObjectOpen(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectOpen) DBException(org.jkiss.dbeaver.DBException) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LoadingJob(org.jkiss.dbeaver.ui.LoadingJob) DBException(org.jkiss.dbeaver.DBException) ModifyListener(org.eclipse.swt.events.ModifyListener) EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StyledText(org.eclipse.swt.custom.StyledText) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator)

Example 4 with EditDictionaryPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.

the class EditVirtualEntityDialog method createDictionaryPage.

private void createDictionaryPage(TabFolder tabFolder) {
    if (entity != null) {
        editDictionaryPage = new EditDictionaryPage(entity);
        editDictionaryPage.createControl(tabFolder);
        TabItem dictItem = new TabItem(tabFolder, SWT.NONE);
        dictItem.setText("Dictionary");
        dictItem.setImage(DBeaverIcons.getImage(DBIcon.TREE_PACKAGE));
        dictItem.setControl(editDictionaryPage.getControl());
        dictItem.setData(InitPage.DICTIONARY);
    }
}
Also used : EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage)

Example 5 with EditDictionaryPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.

the class VirtualStructureEditor method createDictionaryPage.

private void createDictionaryPage(TabFolder tabFolder) {
    if (entity != null) {
        editDictionaryPage = new EditDictionaryPage(entity);
        editDictionaryPage.createControl(tabFolder);
        TabItem dictItem = new TabItem(tabFolder, SWT.NONE);
        dictItem.setText(DataEditorsMessages.virtual_structure_editor_dictionary_page_text);
        dictItem.setControl(editDictionaryPage.getControl());
        dictItem.setData(EditVirtualEntityDialog.InitPage.DICTIONARY);
    }
}
Also used : EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage)

Aggregations

EditDictionaryPage (org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 StyledText (org.eclipse.swt.custom.StyledText)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DBException (org.jkiss.dbeaver.DBException)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 IAttributeController (org.jkiss.dbeaver.ui.data.IAttributeController)2 DatabaseDataEditor (org.jkiss.dbeaver.ui.editors.data.DatabaseDataEditor)2 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 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1