use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method showPreview.
private void showPreview(DatabaseMappingContainer mappingContainer) {
DataTransferPipe pipe = getPipe(mappingContainer);
DataTransferSettings dtSettings = getWizard().getSettings();
PreviewMappingDialog previewDialog = new PreviewMappingDialog(getShell(), pipe, mappingContainer, dtSettings);
previewDialog.open();
}
use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method activatePage.
@Override
public void activatePage() {
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
// Detect producer container (e.g. schema)
DBSObjectContainer producerContainer = null;
for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
if (pipe.getProducer() != null) {
DBSObject producerObject = pipe.getProducer().getDatabaseObject();
if (producerObject instanceof DBSDataContainer) {
DBSObject container = producerObject.getParentObject();
if (container instanceof DBSObjectContainer) {
producerContainer = (DBSObjectContainer) container;
}
}
}
}
settings.loadNode(getWizard().getRunnableContext(), getWizard().getSettings(), producerContainer);
DBNDatabaseNode containerNode = settings.getContainerNode();
if (containerNode != null) {
try {
containerPanel.checkValidContainerNode(containerNode);
containerPanel.setContainerInfo(containerNode);
} catch (DBException e) {
setErrorMessage(e.getMessage());
}
}
boolean newMappings = false;
{
// Load columns model. Update it only if mapping have different set of source columns
// Otherwise we keep current mappings (to allow wizard page navigation without loosing mappings)
List<DatabaseMappingContainer> model = new ArrayList<>();
for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
if (pipe.getProducer() == null || !(pipe.getProducer().getDatabaseObject() instanceof DBSDataContainer)) {
continue;
}
DBSDataContainer sourceDataContainer = (DBSDataContainer) pipe.getProducer().getDatabaseObject();
DatabaseMappingContainer mapping = settings.getDataMapping(sourceDataContainer);
{
// Create new mapping for source object
DatabaseMappingContainer newMapping;
if (pipe.getConsumer() instanceof DatabaseTransferConsumer && ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject() != null) {
try {
newMapping = new DatabaseMappingContainer(getWizard().getRunnableContext(), getDatabaseConsumerSettings(), sourceDataContainer, ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject());
} catch (DBException e) {
setMessage(e.getMessage(), IMessageProvider.ERROR);
newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
}
} else {
newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
}
newMapping.getAttributeMappings(getWizard().getRunnableContext());
// Update current mapping if it differs from new one
if (mapping == null || !mapping.isSameMapping(newMapping)) {
mapping = newMapping;
settings.addDataMappings(getWizard().getRunnableContext(), sourceDataContainer, mapping);
}
}
model.add(mapping);
newMappings = mapping.getMappingType() == DatabaseMappingType.unspecified;
}
mappingViewer.setInput(model);
if (!model.isEmpty()) {
// Select first element
mappingViewer.setSelection(new StructuredSelection(model.get(0)));
}
if (newMappings) {
autoAssignMappings();
}
Tree table = mappingViewer.getTree();
int totalWidth = table.getClientArea().width;
TreeColumn[] columns = table.getColumns();
columns[0].setWidth(totalWidth * 40 / 100);
columns[1].setWidth(totalWidth * 40 / 100);
columns[2].setWidth(totalWidth * 20 / 100);
}
updatePageCompletion();
}
use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method getPipe.
private DataTransferPipe getPipe(DatabaseMappingContainer mappingContainer) {
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
if (pipe.getProducer() == null) {
continue;
}
DBSDataContainer sourceObject = (DBSDataContainer) pipe.getProducer().getDatabaseObject();
DatabaseMappingContainer mapping = settings.getDataMapping(sourceObject);
if (mapping == mappingContainer) {
return pipe;
}
}
return null;
}
use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.
the class DatabaseProducerPageInputObjects method activatePage.
@Override
public void activatePage() {
// final DatabaseProducerSettings settings = getWizard().getPageSettings(this, DatabaseProducerSettings.class);
DataTransferSettings settings = getWizard().getSettings();
mappingTable.removeAll();
for (DataTransferPipe pipe : settings.getDataPipes()) {
TableItem item = new TableItem(mappingTable, SWT.NONE);
item.setData(pipe);
updateItemData(item, pipe);
}
updatePageCompletion();
}
use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.
the class DatabaseProducerPageInputObjects method autoAssignMappings.
private void autoAssignMappings(List<DBSObject> containerObjects) {
boolean chooseConsumer = getWizard().getSettings().isConsumerOptional();
for (TableItem item : mappingTable.getItems()) {
DataTransferPipe pipe = (DataTransferPipe) item.getData();
if ((chooseConsumer && (pipe.getConsumer() == null || pipe.getConsumer().getDatabaseObject() == null)) || (!chooseConsumer && (pipe.getProducer() == null || pipe.getProducer().getDatabaseObject() == null))) {
DBSObject objectToMap = chooseConsumer ? pipe.getProducer().getDatabaseObject() : pipe.getConsumer().getDatabaseObject();
if (objectToMap == null) {
continue;
}
DBSObject object = DBUtils.findObject(containerObjects, objectToMap.getName());
if (object != null) {
if (chooseConsumer) {
if (object instanceof DBSDataManipulator) {
pipe.setConsumer(new DatabaseTransferConsumer((DBSDataManipulator) object));
}
} else {
if (object instanceof DBSDataContainer) {
pipe.setProducer(new DatabaseTransferProducer((DBSDataContainer) object));
}
}
updateItemData(item, pipe);
}
}
}
updatePageCompletion();
}
Aggregations