Search in sources :

Example 21 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SpreadsheetPresentation method openValueEditor.

@Override
@Nullable
public Control openValueEditor(final boolean inline) {
    // The control that will be the editor must be a child of the Table
    DBDAttributeBinding attr = getFocusAttribute();
    ResultSetRow row = getFocusRow();
    if (attr == null || row == null) {
        return null;
    }
    if (!inline) {
        for (Iterator<SpreadsheetValueController> iterator = openEditors.keySet().iterator(); iterator.hasNext(); ) {
            SpreadsheetValueController valueController = iterator.next();
            if (attr == valueController.getBinding() && row == valueController.getCurRow()) {
                IValueEditorStandalone editor = openEditors.get(valueController);
                if (editor.getControl() != null && !editor.getControl().isDisposed()) {
                    editor.showValueEditor();
                    return null;
                } else {
                    // Remove disposed editor from the list
                    iterator.remove();
                }
            }
        }
    }
    //        if (controller.isAttributeReadOnly(attr) && inline) {
    //            // No inline editors for readonly columns
    //            return null;
    //        }
    Composite placeholder = null;
    if (inline) {
        if (controller.isReadOnly()) {
            return null;
        }
        spreadsheet.cancelInlineEditor();
        placeholder = new Composite(spreadsheet, SWT.NONE);
        placeholder.setFont(spreadsheet.getFont());
        placeholder.setLayout(new FillLayout());
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.horizontalIndent = 0;
        gd.verticalIndent = 0;
        gd.grabExcessHorizontalSpace = true;
        gd.grabExcessVerticalSpace = true;
        placeholder.setLayoutData(gd);
        controller.lockActionsByControl(placeholder);
    }
    SpreadsheetValueController valueController = new SpreadsheetValueController(controller, attr, row, inline ? IValueController.EditType.INLINE : IValueController.EditType.EDITOR, placeholder);
    IValueController.EditType[] supportedEditTypes = valueController.getValueManager().getSupportedEditTypes();
    if (supportedEditTypes.length == 0) {
        if (placeholder != null) {
            placeholder.dispose();
        }
        return null;
    }
    /*
        if (inline &&
            (!ArrayUtils.contains(supportedEditTypes, IValueController.EditType.INLINE) || controller.isAttributeReadOnly(attr)) &&
            ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL))
        {
            // Inline editor isn't supported but panel viewer is
            // Enable panel
            if (!isPreviewVisible()) {
                togglePreview();
            }
            placeholder.dispose();

            return null;
        }
*/
    final IValueEditor editor;
    try {
        editor = valueController.getValueManager().createEditor(valueController);
    } catch (Exception e) {
        UIUtils.showErrorDialog(spreadsheet.getShell(), "Cannot edit value", null, e);
        return null;
    }
    if (editor != null) {
        editor.createControl();
    }
    if (editor instanceof IValueEditorStandalone) {
        valueController.registerEditor((IValueEditorStandalone) editor);
        // show dialog in separate job to avoid block
        new UIJob("Open separate editor") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                ((IValueEditorStandalone) editor).showValueEditor();
                return Status.OK_STATUS;
            }
        }.schedule();
    //((IValueEditorStandalone)editor).showValueEditor();
    } else {
        // Set editable value
        if (editor != null) {
            try {
                editor.primeEditorValue(valueController.getValue());
            } catch (DBException e) {
                log.error(e);
            }
            editor.setDirty(false);
        }
    }
    if (inline) {
        if (editor != null) {
            spreadsheet.showCellEditor(placeholder);
            return editor.getControl();
        } else {
            // No editor was created so just drop placeholder
            placeholder.dispose();
            // Probably we can just show preview panel
            if (ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL)) {
                // Inline editor isn't supported but panel viewer is
                // Enable panel
                controller.activatePanel(ViewValuePanel.PANEL_ID, true, true);
                return null;
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) IValueEditor(org.jkiss.dbeaver.ui.data.IValueEditor) DBException(org.jkiss.dbeaver.DBException) MalformedURLException(java.net.MalformedURLException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) IValueEditorStandalone(org.jkiss.dbeaver.ui.data.IValueEditorStandalone) Nullable(org.jkiss.code.Nullable)

Example 22 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SpreadsheetPresentation method getAdapter.

@Override
public <T> T getAdapter(Class<T> adapter) {
    if (adapter == IPropertySheetPage.class) {
        // Show cell properties
        PropertyPageStandard page = new PropertyPageStandard();
        page.setPropertySourceProvider(new IPropertySourceProvider() {

            @Nullable
            @Override
            public IPropertySource getPropertySource(Object object) {
                if (object instanceof GridCell) {
                    GridCell cell = (GridCell) object;
                    boolean recordMode = controller.isRecordMode();
                    final DBDAttributeBinding attr = (DBDAttributeBinding) (recordMode ? cell.row : cell.col);
                    final ResultSetRow row = (ResultSetRow) (recordMode ? cell.col : cell.row);
                    final SpreadsheetValueController valueController = new SpreadsheetValueController(controller, attr, row, IValueController.EditType.NONE, null);
                    PropertyCollector props = new PropertyCollector(valueController.getBinding().getAttribute(), false);
                    props.collectProperties();
                    valueController.getValueManager().contributeProperties(props, valueController);
                    return new PropertySourceDelegate(props);
                }
                return null;
            }
        });
        return adapter.cast(page);
    } else if (adapter == IFindReplaceTarget.class) {
        return adapter.cast(findReplaceTarget);
    }
    return null;
}
Also used : PropertyPageStandard(org.jkiss.dbeaver.ui.controls.PropertyPageStandard) IPropertySourceProvider(org.eclipse.ui.views.properties.IPropertySourceProvider) PropertySourceDelegate(org.jkiss.dbeaver.ui.properties.PropertySourceDelegate) PropertyCollector(org.jkiss.dbeaver.runtime.properties.PropertyCollector) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) GridCell(org.jkiss.dbeaver.ui.controls.lightgrid.GridCell) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) Nullable(org.jkiss.code.Nullable)

Example 23 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DB2BaseTableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<DB2Table> getScriptListener() {
    final int nbExtraColumns = getNumberExtraResultingColumns();
    return new SQLScriptStatusDialog<DB2Table>(getShell(), getTitle() + " " + DB2Messages.dialog_table_tools_progress, null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText(DB2Messages.dialog_table_tools_result);
            for (int i = 0; i < nbExtraColumns; i++) {
                new TreeColumn(objectTree, SWT.NONE);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull DB2Table db2Table, Exception exception) {
            TreeItem treeItem = getTreeItem(db2Table);
            if (exception == null) {
                treeItem.setText(1, DB2Messages.dialog_table_tools_success_title);
            } else {
                treeItem.setText(1, exception.getMessage());
            }
            UIUtils.packColumns(treeItem.getParent(), false, null);
        }

        // DF: This method is for tools that return resultsets
        @Override
        public void processObjectResults(@NotNull DB2Table db2Table, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (resultSet == null) {
                return;
            }
            // Retrive column names
            JDBCResultSetMetaDataImpl rsMetaData = (JDBCResultSetMetaDataImpl) resultSet.getMeta();
            try {
                TreeItem treeItem = getTreeItem(db2Table);
                Font f = UIUtils.makeBoldFont(treeItem.getFont());
                if (treeItem != null) {
                    // Display the column names
                    TreeItem subItem = null;
                    subItem = new TreeItem(treeItem, SWT.NONE);
                    subItem.setFont(f);
                    for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
                        subItem.setText(i, rsMetaData.getColumnName(i + 1));
                        subItem.setGrayed(true);
                    }
                    // Display the data for each row
                    while (resultSet.nextRow()) {
                        subItem = new TreeItem(treeItem, SWT.NONE);
                        for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
                            subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
                        }
                    }
                    treeItem.setExpanded(true);
                }
            } catch (SQLException e) {
                throw new DBCException(e.getMessage());
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCResultSetMetaDataImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCResultSetMetaDataImpl) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) Font(org.eclipse.swt.graphics.Font) DB2Table(org.jkiss.dbeaver.ext.db2.model.DB2Table) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 24 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DB2TableUniqueKeyCache method fetchObjectRow.

@Nullable
@Override
protected DB2TableKeyColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableUniqueKey object, JDBCResultSet dbResult) throws SQLException, DBException {
    String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
    DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
    if (tableColumn == null) {
        log.debug("Column '" + colName + "' not found in table '" + db2Table.getFullyQualifiedName(DBPEvaluationContext.UI) + "' ??");
        return null;
    } else {
        return new DB2TableKeyColumn[] { new DB2TableKeyColumn(object, tableColumn, JDBCUtils.safeGetInt(dbResult, "COLSEQ")) };
    }
}
Also used : DB2TableKeyColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn) DB2TableColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableColumn) Nullable(org.jkiss.code.Nullable)

Example 25 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class DB2TableCheckConstraintCache method fetchObjectRow.

@Nullable
@Override
protected DB2TableCheckConstraintColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableCheckConstraint object, JDBCResultSet dbResult) throws SQLException, DBException {
    String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
    DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
    DB2TableCheckConstraintColUsage usage = CommonUtils.valueOf(DB2TableCheckConstraintColUsage.class, JDBCUtils.safeGetString(dbResult, "USAGE"));
    if (tableColumn == null) {
        log.debug("Column '" + colName + "' not found in table '" + db2Table.getFullyQualifiedName(DBPEvaluationContext.UI) + "' ??");
        return null;
    } else {
        return new DB2TableCheckConstraintColumn[] { new DB2TableCheckConstraintColumn(object, tableColumn, usage) };
    }
}
Also used : DB2TableColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableColumn) DB2TableCheckConstraintColUsage(org.jkiss.dbeaver.ext.db2.model.dict.DB2TableCheckConstraintColUsage) DB2TableCheckConstraintColumn(org.jkiss.dbeaver.ext.db2.model.DB2TableCheckConstraintColumn) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2