use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class StreamProducerPageSettings method updateSingleConsumer.
private void updateSingleConsumer(DBRProgressMonitor monitor, DataTransferPipe pipe, File file) {
final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
final StreamTransferProducer oldProducer = pipe.getProducer() instanceof StreamTransferProducer ? (StreamTransferProducer) pipe.getProducer() : null;
final StreamTransferProducer newProducer = new StreamTransferProducer(new StreamEntityMapping(file));
pipe.setProducer(newProducer);
producerSettings.updateProducerSettingsFromStream(monitor, newProducer, getWizard().getSettings());
IDataTransferSettings consumerSettings = getWizard().getSettings().getNodeSettings(getWizard().getSettings().getConsumer());
if (consumerSettings instanceof DatabaseConsumerSettings) {
DatabaseConsumerSettings settings = (DatabaseConsumerSettings) consumerSettings;
DatabaseMappingContainer mapping = new DatabaseMappingContainer(settings, newProducer.getDatabaseObject());
if (pipe.getConsumer() != null && pipe.getConsumer().getDatabaseObject() instanceof DBSDataManipulator) {
DBSDataManipulator databaseObject = (DBSDataManipulator) pipe.getConsumer().getDatabaseObject();
DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, databaseObject.getParentObject(), false);
if (databaseNode != null) {
settings.setContainerNode(databaseNode);
}
mapping.setTarget(databaseObject);
} else {
mapping.setTarget(null);
mapping.setTargetName(generateTableName(newProducer.getInputFile()));
}
if (oldProducer != null) {
// Remove old mapping because we're just replaced file
DatabaseMappingContainer oldMappingContainer = settings.getDataMappings().remove(oldProducer.getDatabaseObject());
if (oldMappingContainer != null && oldMappingContainer.getSource() instanceof StreamEntityMapping) {
StreamEntityMapping oldEntityMapping = (StreamEntityMapping) oldMappingContainer.getSource();
// Copy mappings from old producer if columns are the same
if (oldEntityMapping.isSameColumns(newProducer.getEntityMapping())) {
StreamEntityMapping entityMapping = new StreamEntityMapping(file);
settings.addDataMappings(getWizard().getRunnableContext(), entityMapping, new DatabaseMappingContainer(oldMappingContainer, entityMapping));
StreamTransferProducer producer = new StreamTransferProducer(entityMapping);
pipe.setProducer(producer);
producerSettings.updateProducerSettingsFromStream(monitor, producer, getWizard().getSettings());
return;
}
}
}
settings.addDataMappings(getWizard().getRunnableContext(), newProducer.getDatabaseObject(), mapping);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DataTransferPagePipes method createInputsTable.
private void createInputsTable(Composite composite) {
Composite panel = UIUtils.createComposite(composite, 1);
// UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
inputsTable.getTable().setLinesVisible(true);
inputsTable.getTable().setHeaderVisible(true);
inputsTable.setContentProvider(new ListContentProvider());
UIUtils.createTableContextMenu(inputsTable.getTable(), null);
DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject element = (DBSObject) cell.getElement();
if (cell.getColumnIndex() == 0) {
DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
cell.setImage(DBeaverIcons.getImage(icon));
cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
} else if (element.getDescription() != null) {
cell.setText(element.getDescription());
}
}
};
{
TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
columnName.setLabelProvider(labelProvider);
columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
columnDesc.setLabelProvider(labelProvider);
columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class SearchDataPage method saveTreeState.
protected void saveTreeState() {
// Object sources
StringBuilder sourcesString = new StringBuilder();
for (DBNNode node : selectorPanel.getCheckedNodes()) {
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
if (sourcesString.length() > 0) {
// $NON-NLS-1$
sourcesString.append("|");
}
sourcesString.append(node.getNodeItemPath());
}
}
searchStateCache.put(getClass(), sourcesString.toString());
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class ItemListControl method fillCustomActions.
@Override
public void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
final DBNNode rootNode = getRootNode();
if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {
@Override
public void run() {
NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
}
});
}
addColumnConfigAction(contributionManager);
IWorkbenchSite workbenchSite = getWorkbenchSite();
if (rootNode instanceof DBNDatabaseFolder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
{
if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
} else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {
{
setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
}
@Override
public void run() {
super.run();
}
@Override
public IMenuCreator getMenuCreator() {
return new MenuCreator(control -> {
List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
MenuManager menuManager = new MenuManager();
for (IContributionItem cc : items) {
menuManager.add(cc);
}
return menuManager;
});
}
});
}
}
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
}
if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
boolean hasReorder = false;
List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
for (Class<?> chilType : childrenTypes) {
if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
hasReorder = true;
break;
}
}
if (hasReorder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
}
}
if (rootNode instanceof DBNDatabaseNode) {
// Expand/collapse
final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
if (!inlineMetas.isEmpty()) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
}
}
// Save/revert
if (workbenchSite instanceof MultiPageEditorSite) {
final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
if (editor instanceof EntityEditor) {
contributionManager.add(new Separator());
DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
}
}
}
Aggregations