use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class PostgreFDWConfigWizardPageFinal method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createComposite(parent, 1);
{
Group settingsGroup = UIUtils.createControlGroup(composite, "Script", 1, GridData.FILL_BOTH, 0);
Composite sqlPanelPH = new Composite(settingsGroup, SWT.NONE);
sqlPanelPH.setLayoutData(new GridData(GridData.FILL_BOTH));
sqlPanelPH.setLayout(new FillLayout());
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
try {
sqlPanel = service.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), sqlPanelPH, getWizard(), "FDW Script", true, "");
} catch (DBException e) {
log.debug(e);
setErrorMessage(e.getMessage());
}
}
Composite buttonsPanel = UIUtils.createComposite(settingsGroup, 2);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createDialogButton(buttonsPanel, "Copy", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIUtils.setClipboardContents(buttonsPanel.getDisplay(), TextTransfer.getInstance(), scriptText);
}
});
UIUtils.createDialogButton(buttonsPanel, "Save ...", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final File saveFile = DialogUtils.selectFileForSave(buttonsPanel.getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, null);
if (saveFile != null) {
try {
IOUtils.writeFileFromString(saveFile, scriptText);
} catch (IOException e1) {
DBWorkbench.getPlatformUI().showError("Save scritp to file", "Error saving script to file " + saveFile.getAbsolutePath(), e1);
}
}
}
});
}
setControl(composite);
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class SavePreviewDialog method createDetailsContents.
@Override
protected Control createDetailsContents(Composite composite) {
Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(1, true));
group.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite previewFrame = new Composite(group, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 250;
previewFrame.setLayoutData(gd);
previewFrame.setLayout(new FillLayout());
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
try {
sqlPanel = serviceSQL.createSQLPanel(viewer.getSite(), previewFrame, viewer, UINavigatorMessages.editors_entity_dialog_preview_title, true, "");
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Can't create SQL panel", "Error creating SQL panel", e);
}
}
populateSQL();
return previewFrame;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class NavigatorViewBase method createNavigatorTree.
private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
// Create tree
final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
createTreeColumns(navigatorTree);
navigatorTree.getViewer().addSelectionChangedListener(event -> onSelectionChange((IStructuredSelection) event.getSelection()));
navigatorTree.getViewer().getTree().addListener(SWT.MouseDoubleClick, event -> {
event.doit = false;
});
navigatorTree.getViewer().getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
super.mouseDoubleClick(e);
}
@Override
public void mouseDown(MouseEvent e) {
super.mouseDown(e);
}
@Override
public void mouseUp(MouseEvent e) {
super.mouseUp(e);
}
});
navigatorTree.getViewer().addDoubleClickListener(event -> {
TreeViewer viewer = tree.getViewer();
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
for (Object node : selection.toArray()) {
// Object node = selection.getFirstElement();
if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
toggleNode(viewer, node);
} else if (node instanceof DBNDataSource) {
NavigatorPreferences.DoubleClickBehavior dsBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK), NavigatorPreferences.DoubleClickBehavior.EDIT);
if (dsBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
toggleNode(viewer, node);
} else {
DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
switch(dsBehaviorDefault) {
case EDIT:
NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, UIUtils.getActiveWorkbenchWindow());
break;
case CONNECT:
{
UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
if (serviceConnections != null) {
if (dataSource.isConnected()) {
serviceConnections.disconnectDataSource(dataSource);
} else {
serviceConnections.connectDataSource(dataSource, null);
}
}
break;
}
case SQL_EDITOR:
{
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openRecentScript(dataSource);
}
break;
}
case SQL_EDITOR_NEW:
{
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
serviceSQL.openNewScript(dataSource);
}
break;
}
}
}
} else if (node instanceof TreeNodeSpecial) {
((TreeNodeSpecial) node).handleDefaultAction(navigatorTree);
} else {
String defaultEditorPageId = null;
NavigatorPreferences.DoubleClickBehavior dcBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
defaultEditorPageId = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE);
}
boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
if (hasChildren && dcBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
toggleNode(viewer, node);
} else {
Map<String, Object> parameters = null;
if (!CommonUtils.isEmpty(defaultEditorPageId)) {
parameters = Collections.singletonMap(MultiPageDatabaseEditor.PARAMETER_ACTIVE_PAGE, defaultEditorPageId);
}
NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, parameters, getSite());
}
}
}
});
// Hook context menu
NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
// Add drag and drop support
NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
DBWorkbench.getPlatform().getPreferenceStore().addPropertyChangeListener(this);
return navigatorTree;
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.
the class DatabaseConsumerPageMapping method showDDL.
private void showDDL(DatabaseMappingContainer mapping) {
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
final DBSObjectContainer container = settings.getContainer();
if (container == null) {
return;
}
DBPDataSource dataSource = container.getDataSource();
final DBEPersistAction[][] ddl = new DBEPersistAction[1][];
try {
getWizard().getRunnableContext().run(true, true, monitor -> {
monitor.beginTask(DTUIMessages.database_consumer_page_mapping_monitor_task, 1);
try {
DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
ddl[0] = DatabaseTransferUtils.generateTargetTableDDL(monitor, executionContext, container, mapping);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
monitor.done();
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_target_DDL, DTUIMessages.database_consumer_page_mapping_message_error_generating_target_DDL, e);
return;
} catch (InterruptedException e) {
return;
}
DBEPersistAction[] persistActions = ddl[0];
if (ArrayUtils.isEmpty(persistActions)) {
UIUtils.showMessageBox(getShell(), "No schema changes", "No changes are needed for this mapping", SWT.ICON_INFORMATION);
return;
}
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
String sql = SQLUtils.generateScript(dataSource, persistActions, false);
int result = serviceSQL.openSQLViewer(DBUtils.getDefaultContext(container, true), DTUIMessages.database_consumer_page_mapping_sqlviewer_title, null, sql, dataSource.getContainer().hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA), false);
if (result == IDialogConstants.PROCEED_ID) {
if (UIUtils.confirmAction(getShell(), "Create target objects", "Database metadata will be modified by creating new table(s) and column(s).\nAre you sure you want to proceed?")) {
// Create target objects
if (applySchemaChanges(dataSource, mapping, persistActions)) {
autoAssignMappings();
updateMappingsAndButtons();
}
}
}
}
}
use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by serge-rider.
the class PostgreFDWConfigWizardPageFinal method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createComposite(parent, 1);
{
Group settingsGroup = UIUtils.createControlGroup(composite, "Script", 1, GridData.FILL_BOTH, 0);
Composite sqlPanelPH = new Composite(settingsGroup, SWT.NONE);
sqlPanelPH.setLayoutData(new GridData(GridData.FILL_BOTH));
sqlPanelPH.setLayout(new FillLayout());
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
try {
sqlPanel = service.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), sqlPanelPH, getWizard(), "FDW Script", true, "");
} catch (DBException e) {
log.debug(e);
setErrorMessage(e.getMessage());
}
}
Composite buttonsPanel = UIUtils.createComposite(settingsGroup, 2);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createDialogButton(buttonsPanel, "Copy", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIUtils.setClipboardContents(buttonsPanel.getDisplay(), TextTransfer.getInstance(), scriptText);
}
});
UIUtils.createDialogButton(buttonsPanel, "Save ...", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final File saveFile = DialogUtils.selectFileForSave(buttonsPanel.getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, null);
if (saveFile != null) {
try {
IOUtils.writeFileFromString(saveFile, scriptText);
} catch (IOException e1) {
DBWorkbench.getPlatformUI().showError("Save scritp to file", "Error saving script to file " + saveFile.getAbsolutePath(), e1);
}
}
}
});
}
setControl(composite);
}
Aggregations