use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class NavigatorHandlerObjectCreateCopy method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell activeShell = HandlerUtil.getActiveShell(event);
Control focusControl = activeShell.getDisplay().getFocusControl();
if (focusControl instanceof Text) {
((Text) focusControl).paste();
return null;
} else if (focusControl instanceof StyledText) {
((StyledText) focusControl).paste();
return null;
} else if (focusControl instanceof Combo) {
((Combo) focusControl).paste();
return null;
}
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode curNode = NavigatorUtils.getSelectedNode(selection);
if (curNode != null) {
Clipboard clipboard = new Clipboard(Display.getDefault());
try {
@SuppressWarnings("unchecked") Collection<DBNNode> cbNodes = (Collection<DBNNode>) clipboard.getContents(TreeNodeTransfer.getInstance());
if (cbNodes != null) {
for (DBNNode nodeObject : cbNodes) {
if (nodeObject instanceof DBNDatabaseNode) {
createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), curNode, ((DBNDatabaseNode) nodeObject));
} else if (nodeObject instanceof DBNResource && curNode instanceof DBNResource) {
pasteResource((DBNResource) nodeObject, (DBNResource) curNode);
}
}
} else if (curNode instanceof DBNResource) {
String[] files = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (files != null) {
for (String fileName : files) {
final File file = new File(fileName);
if (file.exists()) {
pasteResource(file, (DBNResource) curNode);
}
}
} else {
log.debug("Paste error: unsupported clipboard format. File or folder were expected.");
Display.getCurrent().beep();
}
} else {
log.debug("Paste error: clipboard contains data in unsupported format");
Display.getCurrent().beep();
}
} finally {
clipboard.dispose();
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class TabbedFolderPageNode method isRefreshingEvent.
private boolean isRefreshingEvent(DBNEvent event) {
if (!(event.getSource() instanceof DBPEvent)) {
return false;
}
DBPEvent dbEvent = (DBPEvent) event.getSource();
if (dbEvent.getData() == DBPEvent.REORDER) {
DBNNode rootNode = getRootNode();
// Reorder of child elements
return rootNode instanceof DBNDatabaseNode && dbEvent.getObject() == ((DBNDatabaseNode) rootNode).getValueObject();
}
Object itemsInput = itemControl.getItemsViewer().getInput();
return itemsInput instanceof Collection && ((Collection) itemsInput).contains(dbEvent.getObject());
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class NavigatorHandlerSetDefaultObject method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection) selection;
Object element = structSelection.getFirstElement();
if (element instanceof DBNDatabaseNode) {
markObjectAsActive((DBNDatabaseNode) element, activeEditor);
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
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 dbeaver.
the class PostgreFDWConfigWizard method generateScript.
List<DBEPersistAction> generateScript(DBRProgressMonitor monitor) throws DBException {
PostgreDatabase database = getDatabase();
PostgreDataSource curDataSource = database.getDataSource();
List<DBEPersistAction> actions = new ArrayList<>();
PostgreFDWConfigWizard.FDWInfo selectedFDW = getSelectedFDW();
PropertySourceCustom propertySource = getFdwPropertySource();
Map<String, Object> propValues = propertySource.getPropertiesWithDefaults();
String serverId = getFdwServerId();
actions.add(new SQLDatabasePersistActionComment(curDataSource, "CREATE EXTENSION " + selectedFDW.getId()));
{
StringBuilder script = new StringBuilder();
script.append("CREATE SERVER ").append(serverId).append("\n\tFOREIGN DATA WRAPPER ").append(selectedFDW.getId()).append("\n\tOPTIONS(");
boolean firstProp = true;
for (Map.Entry<String, Object> pe : propValues.entrySet()) {
String propName = CommonUtils.toString(pe.getKey());
String propValue = CommonUtils.toString(pe.getValue());
if (CommonUtils.isEmpty(propName) || CommonUtils.isEmpty(propValue)) {
continue;
}
if (!firstProp)
script.append(", ");
script.append(propName).append(" '").append(propValue).append("'");
firstProp = false;
}
script.append(")");
actions.add(new SQLDatabasePersistAction("Create extension", script.toString()));
}
actions.add(new SQLDatabasePersistAction("CREATE USER MAPPING FOR CURRENT_USER SERVER " + serverId));
// Now tables
DBECommandContext commandContext = new SimpleCommandContext(getExecutionContext(), false);
try {
PostgreFDWConfigWizard.FDWInfo fdwInfo = getSelectedFDW();
Map<String, Object> options = new HashMap<>();
options.put(SQLObjectEditor.OPTION_SKIP_CONFIGURATION, true);
PostgreForeignTableManager tableManager = new PostgreForeignTableManager();
PostgreTableColumnManager columnManager = new PostgreTableColumnManager();
for (DBNDatabaseNode tableNode : getSelectedEntities()) {
DBSEntity entity = (DBSEntity) tableNode.getObject();
PostgreTableForeign pgTable = (PostgreTableForeign) tableManager.createNewObject(monitor, commandContext, getSelectedSchema(), null, options);
if (pgTable == null) {
log.error("Internal error while creating new table");
continue;
}
pgTable.setName(entity.getName());
pgTable.setForeignServerName(serverId);
pgTable.setForeignOptions(new String[0]);
for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
// Cache data types
PostgreSchema catalogSchema = database.getCatalogSchema(monitor);
if (catalogSchema != null) {
catalogSchema.getDataTypes(monitor);
}
String defTypeName = DBStructUtils.mapTargetDataType(database, attr, true);
String plainTargetTypeName = SQLUtils.stripColumnTypeModifiers(defTypeName);
PostgreDataType dataType = database.getDataType(monitor, plainTargetTypeName);
if (dataType == null) {
log.error("Data type '" + plainTargetTypeName + "' not found. Skip column mapping.");
continue;
}
PostgreTableColumn newColumn = columnManager.createNewObject(monitor, commandContext, pgTable, null, options);
assert newColumn != null;
newColumn.setName(attr.getName());
newColumn.setDataType(dataType);
}
DBEPersistAction[] tableDDL = tableManager.getTableDDL(monitor, pgTable, options);
Collections.addAll(actions, tableDDL);
}
} finally {
commandContext.resetChanges(true);
}
// CREATE SERVER clickhouse_svr FOREIGN DATA WRAPPER clickhousedb_fdw OPTIONS(dbname 'default', driver '/usr/local/lib/odbc/libclickhouseodbc.so', host '46.101.202.143');
return actions;
}
Aggregations