Search in sources :

Example 6 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.

the class SQLScriptTaskPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    SQLScriptExecuteSettings dtSettings = getWizard().getSettings();
    SashForm mainGroup = new SashForm(composite, SWT.NONE);
    mainGroup.setSashWidth(5);
    mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
    {
        Composite filesGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_files, 2, GridData.FILL_BOTH, 0);
        scriptsViewer = new TableViewer(filesGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        scriptsViewer.setContentProvider(new ListContentProvider());
        scriptsViewer.getTable().setHeaderVisible(true);
        scriptsViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return ((DBNResource) element).getResource().getProjectRelativePath().toString();
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DBNResource) element).getNodeIconDefault());
            }
        });
        scriptsViewer.addDoubleClickListener(event -> {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            IResource resource = ((DBNResource) selection.getFirstElement()).getResource();
            if (resource != null) {
                DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
                if (handler != null) {
                    try {
                        handler.openResource(resource);
                    } catch (Exception e) {
                        log.error("Failed to open resource " + resource, e);
                    }
                }
            }
        });
        // GridData gd = new GridData(GridData.FILL_BOTH);
        // gd.heightHint = 300;
        // gd.widthHint = 400;
        // scriptsViewer.getTable().setLayoutData(gd);
        SQLScriptTaskScriptSelectorDialog.createScriptColumns(scriptsViewer);
        final Table scriptTable = scriptsViewer.getTable();
        scriptTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        ToolBar buttonsToolbar = new ToolBar(filesGroup, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_script, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SQLScriptTaskScriptSelectorDialog dialog = new SQLScriptTaskScriptSelectorDialog(getShell(), projectNode);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    for (DBNResource script : dialog.getSelectedScripts()) {
                        if (!selectedScripts.contains(script)) {
                            selectedScripts.add(script);
                        }
                    }
                    refreshScripts();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_script, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = scriptsViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBNResource) {
                            selectedScripts.remove(element);
                        }
                    }
                    refreshScripts();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = scriptTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBNResource prevScript = selectedScripts.get(selectionIndex - 1);
                    selectedScripts.set(selectionIndex - 1, selectedScripts.get(selectionIndex));
                    selectedScripts.set(selectionIndex, prevScript);
                    refreshScripts();
                }
            }
        });
        ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = scriptTable.getSelectionIndex();
                if (selectionIndex < scriptTable.getItemCount() - 1) {
                    DBNResource nextScript = selectedScripts.get(selectionIndex + 1);
                    selectedScripts.set(selectionIndex + 1, selectedScripts.get(selectionIndex));
                    selectedScripts.set(selectionIndex, nextScript);
                    refreshScripts();
                }
            }
        });
        scriptsViewer.addSelectionChangedListener(event -> {
            int selectionIndex = scriptTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveUpItem.setEnabled(selectionIndex > 0);
            moveDownItem.setEnabled(selectionIndex < scriptTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
    }
    {
        Composite connectionsGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_connections, 2, GridData.FILL_BOTH, 0);
        dataSourceViewer = new TableViewer(connectionsGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        dataSourceViewer.setContentProvider(new ListContentProvider());
        // dataSourceViewer.getTable().setHeaderVisible(true);
        dataSourceViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return ((DBNDataSource) element).getNodeName();
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DBNDataSource) element).getNodeIcon());
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 400;
        dataSourceViewer.getTable().setLayoutData(gd);
        final Table dsTable = dataSourceViewer.getTable();
        dsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        ToolBar buttonsToolbar = new ToolBar(connectionsGroup, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_data_source, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SQLScriptTaskDataSourceSelectorDialog dialog = new SQLScriptTaskDataSourceSelectorDialog(getShell(), projectNode);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    for (DBNDataSource ds : dialog.getSelectedDataSources()) {
                        if (!selectedDataSources.contains(ds)) {
                            selectedDataSources.add(ds);
                        }
                    }
                    refreshDataSources();
                    updatePageCompletion();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_data_source, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = dataSourceViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBNDataSource) {
                            selectedDataSources.remove(element);
                        }
                    }
                    refreshDataSources();
                    updatePageCompletion();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = dsTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBNDataSource prevScript = selectedDataSources.get(selectionIndex - 1);
                    selectedDataSources.set(selectionIndex - 1, selectedDataSources.get(selectionIndex));
                    selectedDataSources.set(selectionIndex, prevScript);
                    refreshDataSources();
                }
            }
        });
        ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = dsTable.getSelectionIndex();
                if (selectionIndex < dsTable.getItemCount() - 1) {
                    DBNDataSource nextScript = selectedDataSources.get(selectionIndex + 1);
                    selectedDataSources.set(selectionIndex + 1, selectedDataSources.get(selectionIndex));
                    selectedDataSources.set(selectionIndex, nextScript);
                    refreshScripts();
                }
            }
        });
        dataSourceViewer.addSelectionChangedListener(event -> {
            int selectionIndex = dsTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveUpItem.setEnabled(selectionIndex > 0);
            moveDownItem.setEnabled(selectionIndex < dsTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
    }
    {
        Composite settingsGroup = UIUtils.createControlGroup(composite, DTMessages.sql_script_task_page_settings_group_script, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        ignoreErrorsCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_ignore_errors, "", dtSettings.isIgnoreErrors(), 1);
        dumpQueryCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_dump_results, "", dtSettings.isDumpQueryResultsToLog(), 1);
        dumpQueryCheck.setEnabled(false);
        autoCommitCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_auto_commit, "", dtSettings.isAutoCommit(), 1);
    }
    getWizard().createTaskSaveButtons(composite, true, 1);
    loadSettings();
    setControl(composite);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) java.util(java.util) SashForm(org.eclipse.swt.custom.SashForm) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DTMessages(org.jkiss.dbeaver.tools.transfer.internal.DTMessages) DTUIMessages(org.jkiss.dbeaver.tools.transfer.ui.internal.DTUIMessages) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) List(java.util.List) IResource(org.eclipse.core.resources.IResource) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) SashForm(org.eclipse.swt.custom.SashForm) GridData(org.eclipse.swt.layout.GridData) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource)

Example 7 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.

the class NavigatorHandlerObjectCreateNew method fillCreateMenuItems.

// If site is null then we need only item count. BAD CODE.
public static List<IContributionItem> fillCreateMenuItems(@Nullable IWorkbenchPartSite site, DBNNode node) {
    List<IContributionItem> createActions = new ArrayList<>();
    if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases) {
        IContributionItem item = makeCreateContributionItem(site, DBPDataSourceContainer.class.getName(), ModelMessages.model_navigator_Connection, UIIcon.SQL_NEW_CONNECTION, false);
        createActions.add(item);
    }
    if (node instanceof DBNDatabaseNode) {
        addDatabaseNodeCreateItems(site, createActions, (DBNDatabaseNode) node);
    }
    if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases || node instanceof DBNDataSource) {
        createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_LOCAL_FOLDER));
    } else if (node instanceof DBNResource) {
        final DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
        IResource resource = ((DBNResource) node).getResource();
        if (resource instanceof IProject) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_PROJECT));
        }
        DBPResourceHandler handler = workspace.getResourceHandler(resource);
        if (handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 0) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FILE));
        }
        if (handler != null && (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FOLDER));
        }
        if (resource instanceof IContainer) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FILE_LINK));
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FOLDER_LINK));
        }
    }
    if (site != null) {
        if (!createActions.isEmpty() && !(createActions.get(createActions.size() - 1) instanceof Separator)) {
            createActions.add(new Separator());
        }
        createActions.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.FILE_NEW, "Other ...", null));
    }
    return createActions;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) IContainer(org.eclipse.core.resources.IContainer) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) Separator(org.eclipse.jface.action.Separator)

Example 8 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.

the class DBNResource method refreshResourceState.

public void refreshResourceState(Object source) {
    DBPResourceHandler newHandler = getModel().getPlatform().getWorkspace().getResourceHandler(resource);
    if (newHandler != handler) {
        handler = newHandler;
    }
    if (handler != null) {
        handler.updateNavigatorNode(this, resource);
    } else {
        log.error("Can't find handler for resource " + resource.getFullPath());
    }
    getModel().fireNodeEvent(new DBNEvent(source, DBNEvent.Action.UPDATE, this));
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 9 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.

the class DiagramCreateWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        Collection<DBNNode> initialContent = pageContent.getInitialContent();
        List<DBSObject> rootObjects = new ArrayList<>();
        for (DBNNode node : initialContent) {
            if (node instanceof DBNDatabaseNode) {
                rootObjects.add(((DBNDatabaseNode) node).getObject());
            }
        }
        DiagramCreator creator = new DiagramCreator(rootObjects);
        UIUtils.run(getContainer(), true, true, creator);
        DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(creator.diagramFile);
        if (handler != null) {
            handler.openResource(creator.diagramFile);
        }
    } catch (InterruptedException ex) {
        return false;
    } catch (Throwable ex) {
        if (ex instanceof InvocationTargetException) {
            ex = ((InvocationTargetException) ex).getTargetException();
        }
        DBWorkbench.getPlatformUI().showError("Create error", "Cannot create diagram", ex);
        return false;
    }
    return true;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by serge-rider.

the class SQLScriptTaskPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    SQLScriptExecuteSettings dtSettings = getWizard().getSettings();
    SashForm mainGroup = new SashForm(composite, SWT.NONE);
    mainGroup.setSashWidth(5);
    mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
    {
        Composite filesGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_files, 2, GridData.FILL_BOTH, 0);
        scriptsViewer = new TableViewer(filesGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        scriptsViewer.setContentProvider(new ListContentProvider());
        scriptsViewer.getTable().setHeaderVisible(true);
        scriptsViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return ((DBNResource) element).getResource().getProjectRelativePath().toString();
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DBNResource) element).getNodeIconDefault());
            }
        });
        scriptsViewer.addDoubleClickListener(event -> {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            IResource resource = ((DBNResource) selection.getFirstElement()).getResource();
            if (resource != null) {
                DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
                if (handler != null) {
                    try {
                        handler.openResource(resource);
                    } catch (Exception e) {
                        log.error("Failed to open resource " + resource, e);
                    }
                }
            }
        });
        // GridData gd = new GridData(GridData.FILL_BOTH);
        // gd.heightHint = 300;
        // gd.widthHint = 400;
        // scriptsViewer.getTable().setLayoutData(gd);
        SQLScriptTaskScriptSelectorDialog.createScriptColumns(scriptsViewer);
        final Table scriptTable = scriptsViewer.getTable();
        scriptTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        ToolBar buttonsToolbar = new ToolBar(filesGroup, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_script, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SQLScriptTaskScriptSelectorDialog dialog = new SQLScriptTaskScriptSelectorDialog(getShell(), projectNode);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    for (DBNResource script : dialog.getSelectedScripts()) {
                        if (!selectedScripts.contains(script)) {
                            selectedScripts.add(script);
                        }
                    }
                    refreshScripts();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_script, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = scriptsViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBNResource) {
                            selectedScripts.remove(element);
                        }
                    }
                    refreshScripts();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = scriptTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBNResource prevScript = selectedScripts.get(selectionIndex - 1);
                    selectedScripts.set(selectionIndex - 1, selectedScripts.get(selectionIndex));
                    selectedScripts.set(selectionIndex, prevScript);
                    refreshScripts();
                }
            }
        });
        ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = scriptTable.getSelectionIndex();
                if (selectionIndex < scriptTable.getItemCount() - 1) {
                    DBNResource nextScript = selectedScripts.get(selectionIndex + 1);
                    selectedScripts.set(selectionIndex + 1, selectedScripts.get(selectionIndex));
                    selectedScripts.set(selectionIndex, nextScript);
                    refreshScripts();
                }
            }
        });
        scriptsViewer.addSelectionChangedListener(event -> {
            int selectionIndex = scriptTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveUpItem.setEnabled(selectionIndex > 0);
            moveDownItem.setEnabled(selectionIndex < scriptTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
    }
    {
        Composite connectionsGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_connections, 2, GridData.FILL_BOTH, 0);
        dataSourceViewer = new TableViewer(connectionsGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        dataSourceViewer.setContentProvider(new ListContentProvider());
        // dataSourceViewer.getTable().setHeaderVisible(true);
        dataSourceViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return ((DBNDataSource) element).getNodeName();
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(((DBNDataSource) element).getNodeIcon());
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 400;
        dataSourceViewer.getTable().setLayoutData(gd);
        final Table dsTable = dataSourceViewer.getTable();
        dsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        ToolBar buttonsToolbar = new ToolBar(connectionsGroup, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_data_source, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                SQLScriptTaskDataSourceSelectorDialog dialog = new SQLScriptTaskDataSourceSelectorDialog(getShell(), projectNode);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    for (DBNDataSource ds : dialog.getSelectedDataSources()) {
                        if (!selectedDataSources.contains(ds)) {
                            selectedDataSources.add(ds);
                        }
                    }
                    refreshDataSources();
                    updatePageCompletion();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_data_source, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = dataSourceViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBNDataSource) {
                            selectedDataSources.remove(element);
                        }
                    }
                    refreshDataSources();
                    updatePageCompletion();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = dsTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBNDataSource prevScript = selectedDataSources.get(selectionIndex - 1);
                    selectedDataSources.set(selectionIndex - 1, selectedDataSources.get(selectionIndex));
                    selectedDataSources.set(selectionIndex, prevScript);
                    refreshDataSources();
                }
            }
        });
        ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = dsTable.getSelectionIndex();
                if (selectionIndex < dsTable.getItemCount() - 1) {
                    DBNDataSource nextScript = selectedDataSources.get(selectionIndex + 1);
                    selectedDataSources.set(selectionIndex + 1, selectedDataSources.get(selectionIndex));
                    selectedDataSources.set(selectionIndex, nextScript);
                    refreshScripts();
                }
            }
        });
        dataSourceViewer.addSelectionChangedListener(event -> {
            int selectionIndex = dsTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveUpItem.setEnabled(selectionIndex > 0);
            moveDownItem.setEnabled(selectionIndex < dsTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
    }
    {
        Composite settingsGroup = UIUtils.createControlGroup(composite, DTMessages.sql_script_task_page_settings_group_script, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        ignoreErrorsCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_ignore_errors, "", dtSettings.isIgnoreErrors(), 1);
        dumpQueryCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_dump_results, "", dtSettings.isDumpQueryResultsToLog(), 1);
        dumpQueryCheck.setEnabled(false);
        autoCommitCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_auto_commit, "", dtSettings.isAutoCommit(), 1);
    }
    getWizard().createTaskSaveButtons(composite, true, 1);
    loadSettings();
    setControl(composite);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) java.util(java.util) SashForm(org.eclipse.swt.custom.SashForm) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DTMessages(org.jkiss.dbeaver.tools.transfer.internal.DTMessages) DTUIMessages(org.jkiss.dbeaver.tools.transfer.ui.internal.DTUIMessages) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) List(java.util.List) IResource(org.eclipse.core.resources.IResource) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) SashForm(org.eclipse.swt.custom.SashForm) GridData(org.eclipse.swt.layout.GridData) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource)

Aggregations

DBPResourceHandler (org.jkiss.dbeaver.model.app.DBPResourceHandler)16 IResource (org.eclipse.core.resources.IResource)8 IProject (org.eclipse.core.resources.IProject)6 ArrayList (java.util.ArrayList)4 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)4 DBPResourceCreator (org.jkiss.dbeaver.model.app.DBPResourceCreator)4 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 List (java.util.List)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 Separator (org.eclipse.jface.action.Separator)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 SWT (org.eclipse.swt.SWT)2 SashForm (org.eclipse.swt.custom.SashForm)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2