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;
}
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;
}
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());
}
}
};
}
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")) };
}
}
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) };
}
}
Aggregations