use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by serge-rider.
the class DataSourceInvalidateHandler method showConnectionLostDialog.
public static void showConnectionLostDialog(final Shell shell, final String message, final DBException error) {
//log.debug(message);
Runnable runnable = new Runnable() {
@Override
public void run() {
// Display the dialog
DBPDataSource dataSource = error.getDataSource();
if (dataSource == null) {
throw new IllegalStateException("No data source in error");
}
String title = "Connection with [" + dataSource.getContainer().getName() + "] lost";
ConnectionRecoverDialog dialog = new ConnectionRecoverDialog(shell, title, message == null ? title : message, error);
dialog.open();
}
};
DBeaverUI.syncExec(runnable);
}
use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by serge-rider.
the class GenerateMultiSQLDialog method getContextFromObjects.
protected static <T extends DBSObject> DBCExecutionContext getContextFromObjects(@NotNull Collection<T> objects, boolean meta) {
Iterator<T> iterator = objects.iterator();
if (iterator.hasNext()) {
T object = iterator.next();
DBPDataSource dataSource = object.getDataSource();
return dataSource == null ? null : dataSource.getDefaultContext(meta);
}
return null;
}
use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by serge-rider.
the class GenerateSQLDialog method getSQLText.
@Override
protected String getSQLText() {
DBPDataSource dataSource = executionContext.getDataSource();
if (dataSource instanceof SQLDataSource) {
String lineSeparator = GeneralUtils.getDefaultLineSeparator();
String scriptDelimiter = ((SQLDataSource) dataSource).getSQLDialect().getScriptDelimiter() + lineSeparator;
String[] scriptLines = generateSQLScript();
StringBuilder sql = new StringBuilder(scriptLines.length * 64);
for (String line : scriptLines) {
sql.append(line).append(scriptDelimiter);
}
// Cut last line separator
if (sql.length() > lineSeparator.length()) {
sql.setLength(sql.length() - lineSeparator.length());
}
return sql.toString();
} else {
return SQLUtils.generateCommentLine(dataSource, "Non-SQL data source");
}
}
use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method showDDL.
private void showDDL(DatabaseMappingContainer mapping) {
final DatabaseConsumerSettings settings = getWizard().getPageSettings(DatabaseConsumerPageMapping.this, DatabaseConsumerSettings.class);
final DBSObjectContainer container = settings.getContainer();
if (container == null) {
return;
}
DBPDataSource dataSource = container.getDataSource();
try {
final String ddl = DatabaseTransferConsumer.generateTargetTableDDL(VoidProgressMonitor.INSTANCE, dataSource, container, mapping);
ViewSQLDialog dialog = new ViewSQLDialog(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), dataSource.getDefaultContext(true), "Target DDL", null, ddl);
dialog.open();
} catch (DBException e) {
UIUtils.showErrorDialog(getShell(), "Target DDL", "Error generatiung target DDL", e);
}
}
use of org.jkiss.dbeaver.model.DBPDataSource in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method createMappingsTree.
private void createMappingsTree(Composite composite) {
// Mapping table
mappingViewer = new TreeViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
mappingViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
mappingViewer.getTree().setLinesVisible(true);
mappingViewer.getTree().setHeaderVisible(true);
TreeViewerColumn columnSource = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnSource.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI));
if (mapping.getIcon() != null) {
cell.setImage(DBeaverIcons.getImage(mapping.getIcon()));
}
super.update(cell);
}
});
columnSource.getColumn().setText("Source");
TreeViewerColumn columnTarget = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnTarget.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(mapping.getTargetName());
if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
} else {
cell.setBackground(null);
}
super.update(cell);
}
});
columnTarget.getColumn().setText("Target");
columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
try {
return createTargetEditor(element);
} catch (DBException e) {
setErrorMessage(e.getMessage());
return null;
}
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
return mapping.getSource().getName();
}
if (mapping instanceof DatabaseMappingContainer) {
if (mapping.getMappingType() == DatabaseMappingType.existing) {
return ((DatabaseMappingContainer) mapping).getTarget();
}
return mapping.getTargetName();
} else {
if (mapping.getMappingType() == DatabaseMappingType.existing) {
return ((DatabaseMappingAttribute) mapping).getTarget();
}
return mapping.getTargetName();
}
}
@Override
protected void setValue(final Object element, Object value) {
try {
final DatabaseConsumerSettings settings = getWizard().getPageSettings(DatabaseConsumerPageMapping.this, DatabaseConsumerSettings.class);
String name = CommonUtils.toString(value);
DBPDataSource dataSource = settings.getTargetDataSource((DatabaseMappingObject) element);
if (!name.equals(DatabaseMappingAttribute.TARGET_NAME_SKIP) && !name.equals(TARGET_NAME_BROWSE) && dataSource != null) {
name = DBObjectNameCaseTransformer.transformName(dataSource, name);
}
setMappingTarget((DatabaseMappingObject) element, name);
//mappingViewer.setSelection(mappingViewer.getSelection());
mappingViewer.update(element, null);
updatePageCompletion();
} catch (DBException e) {
UIUtils.showDatabaseError(getShell(), "Mapping error", "Error setting target table", e);
}
}
});
//TreeViewerEditor.create(mappingViewer, new TreeViewerFocusCellManager(), ColumnViewerEditor.TABBING_CYCLE_IN_ROW);
TreeViewerColumn columnMapping = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnMapping.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(mapping.getMappingType().name());
super.update(cell);
}
});
columnMapping.getColumn().setText("Mapping");
columnMapping.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
List<String> mappingTypes = new ArrayList<>();
mappingTypes.add(DatabaseMappingType.skip.name());
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
if (mapping instanceof DatabaseMappingAttribute) {
mappingTypes.add(((DatabaseMappingAttribute) mapping).getParent().getMappingType().name());
} else {
mappingTypes.add(mapping.getMappingType().name());
}
return new CustomComboBoxCellEditor(mappingViewer.getTree(), mappingTypes.toArray(new String[mappingTypes.size()]), SWT.DROP_DOWN | SWT.READ_ONLY);
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
return mapping.getMappingType().name();
}
@Override
protected void setValue(Object element, Object value) {
try {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
DatabaseMappingType mappingType = DatabaseMappingType.valueOf(value.toString());
if (mapping instanceof DatabaseMappingAttribute) {
((DatabaseMappingAttribute) mapping).setMappingType(mappingType);
} else {
((DatabaseMappingContainer) mapping).refreshMappingType(getWizard().getContainer(), mappingType);
}
mappingViewer.refresh();
setErrorMessage(null);
} catch (DBException e) {
setErrorMessage(e.getMessage());
}
}
});
mappingViewer.setContentProvider(new TreeContentProvider() {
@Override
public boolean hasChildren(Object element) {
return element instanceof DatabaseMappingContainer;
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DatabaseMappingContainer) {
return ((DatabaseMappingContainer) parentElement).getAttributeMappings(getContainer()).toArray();
}
return null;
}
});
}
Aggregations