Search in sources :

Example 6 with DBNProject

use of org.jkiss.dbeaver.model.navigator.DBNProject in project dbeaver by serge-rider.

the class SQLToolTaskWizardPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm previewSplitter = new SashForm(composite, SWT.VERTICAL);
    previewSplitter.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm settingsPanel = new SashForm(previewSplitter, SWT.HORIZONTAL);
    Group objectsPanel;
    {
        objectsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_objects, 2, GridData.FILL_BOTH, 0);
        objectsViewer = new TableViewer(objectsPanel, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        objectsViewer.setContentProvider(new ListContentProvider());
        objectsViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return DBUtils.getObjectFullName((DBPNamedObject) element, DBPEvaluationContext.UI);
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(DBValueFormatting.getObjectImage((DBPObject) element));
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 150;
        gd.widthHint = 200;
        final Table objectTable = objectsViewer.getTable();
        objectTable.setLayoutData(gd);
        ToolBar buttonsToolbar = new ToolBar(objectsPanel, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_add_string, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
                SQLToolTaskObjectSelectorDialog objectListDialog = new SQLToolTaskObjectSelectorDialog(getShell(), projectNode, (TaskTypeDescriptor) sqlWizard.getTaskType());
                if (objectListDialog.open() == IDialogConstants.OK_ID) {
                    for (DBSObject object : objectListDialog.getSelectedObjects()) {
                        if (!selectedObjects.contains(object)) {
                            selectedObjects.add(object);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_remove_string, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = objectsViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBSObject) {
                            selectedObjects.remove(element);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem[] moveButtons = new ToolItem[2];
        moveButtons[0] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBSObject prevScript = selectedObjects.get(selectionIndex - 1);
                    selectedObjects.set(selectionIndex - 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, prevScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 1);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
            }
        });
        moveButtons[1] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex < objectTable.getItemCount() - 1) {
                    DBSObject nextScript = selectedObjects.get(selectionIndex + 1);
                    selectedObjects.set(selectionIndex + 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, nextScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 0);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 2);
            }
        });
        objectsViewer.addSelectionChangedListener(event -> {
            int selectionIndex = objectTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveButtons[0].setEnabled(selectionIndex > 0);
            moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
        moveButtons[0].setEnabled(false);
        moveButtons[1].setEnabled(false);
    }
    {
        Group optionsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_settings, 1, GridData.FILL_BOTH, 0);
        taskOptionsViewer = new PropertyTreeViewer(optionsPanel, SWT.BORDER);
        taskOptionsViewer.addPropertyChangeListener(event -> updateScriptPreview());
    }
    Composite previewPanel = UIUtils.createComposite(previewSplitter, 1);
    previewPanel.setLayout(new FillLayout());
    serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        try {
            sqlPreviewPanel = serviceSQL.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), previewPanel, this, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_sql_panel_name, true, "");
        } catch (DBException e) {
            DBWorkbench.getPlatformUI().showError(TasksSQLUIMessages.sql_tool_task_wizard_page_settings_title_sql_preview_error, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_message_sql_preview_panel, e);
        }
    }
    Composite controlsPanel = UIUtils.createComposite(composite, 2);
    UIUtils.createDialogButton(controlsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_dialog_button_label_copy, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = serviceSQL.getSQLPanelText(sqlPreviewPanel);
            if (!CommonUtils.isEmpty(text)) {
                UIUtils.setClipboardContents(getShell().getDisplay(), TextTransfer.getInstance(), text);
            }
        }
    });
    getWizard().createTaskSaveButtons(controlsPanel, true, 1);
    loadSettings();
    if (taskOptionsViewer.getTree().getItemCount() == 0) {
        settingsPanel.setMaximizedControl(objectsPanel);
    }
    setControl(composite);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Nullable(org.jkiss.code.Nullable) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) TaskTypeDescriptor(org.jkiss.dbeaver.registry.task.TaskTypeDescriptor) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) ArrayList(java.util.ArrayList) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Log(org.jkiss.dbeaver.Log) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) SQLToolExecuteSettings(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteSettings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) List(java.util.List) SQLToolExecuteHandler(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteHandler) DBException(org.jkiss.dbeaver.DBException) TasksSQLUIMessages(org.jkiss.dbeaver.tasks.ui.sql.internal.TasksSQLUIMessages) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBException(org.jkiss.dbeaver.DBException) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 7 with DBNProject

use of org.jkiss.dbeaver.model.navigator.DBNProject in project dbeaver by serge-rider.

the class SQLScriptTaskPageSettings method loadSettings.

public void loadSettings() {
    SQLScriptExecuteSettings settings = sqlWizard.getSettings();
    List<String> scriptFiles = settings.getScriptFiles();
    for (String filePath : scriptFiles) {
        IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
        if (file == null) {
            log.debug("Script file '" + filePath + "' not found");
            continue;
        }
        DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
        if (currentProject == null) {
            log.debug("Project '" + file.getProject().getName() + "' not found");
            continue;
        }
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
        if (projectNode != null) {
            DBNResource resource = projectNode.findResource(file);
            if (resource != null) {
                selectedScripts.add(resource);
            }
        }
    }
    scriptsViewer.setInput(selectedScripts);
    for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
        DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
        DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
        if (dsNode != null) {
            selectedDataSources.add(dsNode);
        }
    }
    dataSourceViewer.setInput(selectedDataSources);
// if (!selectedDataSources.isEmpty()) {
// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
// }
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 8 with DBNProject

use of org.jkiss.dbeaver.model.navigator.DBNProject in project dbeaver by serge-rider.

the class NavigatorHandlerProjectSetActive method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNProject)) {
            return null;
        }
        DBNProject projectNode = (DBNProject) element;
        final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
        if (projectRegistry.getActiveProject() != projectNode.getProject()) {
            projectRegistry.setActiveProject(projectNode.getProject());
        }
    }
    return null;
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry)

Example 9 with DBNProject

use of org.jkiss.dbeaver.model.navigator.DBNProject in project dbeaver by serge-rider.

the class DiagramCreateWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    Composite configGroup = UIUtils.createControlGroup(placeholder, ERDMessages.wizard_page_diagram_create_group_settings, 2, GridData.FILL_BOTH, 0);
    //$NON-NLS-1$
    final Text projectNameText = UIUtils.createLabelText(configGroup, "Name", null);
    projectNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            diagram.setName(projectNameText.getText());
            updateState();
        }
    });
    Label contentLabel = UIUtils.createControlLabel(configGroup, ERDMessages.wizard_page_diagram_create_label_init_content);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 2;
    contentLabel.setLayoutData(gd);
    final DBNProject rootNode = DBeaverCore.getInstance().getNavigatorModel().getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject());
    if (rootNode == null) {
        setControl(placeholder);
        return;
    }
    contentTree = new DatabaseNavigatorTree(configGroup, rootNode.getDatabases(), SWT.SINGLE | SWT.CHECK);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    gd.heightHint = 400;
    contentTree.setLayoutData(gd);
    CheckboxTreeViewer viewer = (CheckboxTreeViewer) contentTree.getViewer();
    viewer.setCheckStateProvider(new ICheckStateProvider() {

        @Override
        public boolean isChecked(Object element) {
            return false;
        }

        @Override
        public boolean isGrayed(Object element) {
            if (element instanceof DBNDatabaseNode && !(element instanceof DBNDataSource)) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBSTable) {
                    return false;
                }
            }
            return true;
        }
    });
    setControl(placeholder);
}
Also used : DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 10 with DBNProject

use of org.jkiss.dbeaver.model.navigator.DBNProject in project dbeaver by serge-rider.

the class DatabaseConsumerPageMapping method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    final DatabaseConsumerSettings settings = getWizard().getPageSettings(this, DatabaseConsumerSettings.class);
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        // Target container
        Composite containerPanel = new Composite(composite, SWT.NONE);
        containerPanel.setLayout(new GridLayout(4, false));
        containerPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        UIUtils.createControlLabel(containerPanel, "Target container");
        containerIcon = new Label(containerPanel, SWT.NONE);
        containerIcon.setImage(DBeaverIcons.getImage(DBIcon.TYPE_UNKNOWN));
        containerName = new Text(containerPanel, SWT.BORDER | SWT.READ_ONLY);
        containerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        containerName.setText("");
        Button browseButton = new Button(containerPanel, SWT.PUSH);
        browseButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
        browseButton.setText("...");
        browseButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                IProject activeProject = DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
                if (activeProject != null) {
                    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
                    final DBNProject rootNode = navigatorModel.getRoot().getProject(activeProject);
                    DBNNode selectedNode = settings.getContainerNode();
                    if (selectedNode == null && !settings.getDataMappings().isEmpty()) {
                        // Use first source object as cur selection (it's better than nothing)
                        DBSDataContainer firstSource = settings.getDataMappings().keySet().iterator().next();
                        selectedNode = navigatorModel.getNodeByObject(firstSource);
                        while (selectedNode != null) {
                            if (selectedNode instanceof DBSWrapper && ((DBSWrapper) selectedNode).getObject() instanceof DBSObjectContainer) {
                                break;
                            } else {
                                selectedNode = selectedNode.getParentNode();
                            }
                        }
                    }
                    DBNNode node = BrowseObjectDialog.selectObject(getShell(), "Choose container", rootNode.getDatabases(), selectedNode, new Class[] { DBSObjectContainer.class }, null);
                    if (node instanceof DBNDatabaseNode) {
                        settings.setContainerNode((DBNDatabaseNode) node);
                        containerIcon.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
                        containerName.setText(settings.getContainerFullName());
                        // Reset mappings
                        for (DatabaseMappingContainer mappingContainer : settings.getDataMappings().values()) {
                            if (mappingContainer.getMappingType() == DatabaseMappingType.create) {
                                try {
                                    mappingContainer.refreshMappingType(getContainer(), DatabaseMappingType.create);
                                } catch (DBException e1) {
                                    log.error(e1);
                                }
                            }
                        }
                        mappingViewer.refresh();
                        updatePageCompletion();
                    }
                }
            }
        });
    }
    createMappingsTree(composite);
    {
        // Control buttons
        Composite buttonsPanel = new Composite(composite, SWT.NONE);
        buttonsPanel.setLayout(new GridLayout(4, false));
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final Button mapTableButton = new Button(buttonsPanel, SWT.PUSH);
        mapTableButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_TABLE));
        mapTableButton.setText("Existing table ...");
        mapTableButton.setEnabled(false);
        mapTableButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                mapExistingTable((DatabaseMappingContainer) getSelectedMapping());
            }
        });
        final Button createNewButton = new Button(buttonsPanel, SWT.PUSH);
        createNewButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_VIEW));
        createNewButton.setText("New table...");
        createNewButton.setEnabled(false);
        createNewButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                mapNewTable((DatabaseMappingContainer) getSelectedMapping());
            }
        });
        final Button columnsButton = new Button(buttonsPanel, SWT.PUSH);
        columnsButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_COLUMNS));
        columnsButton.setText("Columns' mappings ...");
        columnsButton.setEnabled(false);
        columnsButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DatabaseMappingObject selectedMapping = getSelectedMapping();
                mapColumns(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
            }
        });
        final Button ddlButton = new Button(buttonsPanel, SWT.PUSH);
        ddlButton.setImage(DBeaverIcons.getImage(UIIcon.SQL_TEXT));
        ddlButton.setText("DDL ...");
        ddlButton.setEnabled(false);
        ddlButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DatabaseMappingObject selectedMapping = getSelectedMapping();
                showDDL(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
            }
        });
        mappingViewer.getTree().addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                try {
                    boolean updated = false;
                    Object element = null;
                    if (e.character == SWT.CR) {
                    //Object element = mappingViewer.getStructuredSelection().getFirstElement();
                    //mappingViewer.editElement(element, 1);
                    } else if (e.character == SWT.DEL) {
                        for (TreeItem item : mappingViewer.getTree().getSelection()) {
                            element = item.getData();
                            if (element instanceof DatabaseMappingAttribute) {
                                DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) element;
                                attribute.setMappingType(DatabaseMappingType.skip);
                            } else if (element instanceof DatabaseMappingContainer) {
                                DatabaseMappingContainer container = (DatabaseMappingContainer) element;
                                container.refreshMappingType(getContainer(), DatabaseMappingType.skip);
                            }
                        }
                        updated = true;
                    } else if (e.character == SWT.SPACE) {
                        for (TreeItem item : mappingViewer.getTree().getSelection()) {
                            element = item.getData();
                            if (element instanceof DatabaseMappingAttribute) {
                                DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
                                attribute.setMappingType(DatabaseMappingType.existing);
                                attribute.updateMappingType(VoidProgressMonitor.INSTANCE);
                            } else if (element instanceof DatabaseMappingContainer) {
                                DatabaseMappingContainer container = (DatabaseMappingContainer) element;
                                setMappingTarget(container, container.getSource().getName());
                            }
                        }
                        updated = true;
                    }
                    if (updated) {
                        mappingViewer.refresh();
                        updatePageCompletion();
                        if (element instanceof DatabaseMappingContainer) {
                            // Select next container
                            @SuppressWarnings("unchecked") List<DatabaseMappingContainer> model = (List<DatabaseMappingContainer>) mappingViewer.getInput();
                            int curIndex = model.indexOf(element);
                            if (curIndex < model.size() - 1) {
                                mappingViewer.setSelection(new StructuredSelection(model.get(curIndex + 1)), true);
                            }
                        }
                    }
                } catch (DBException e1) {
                    UIUtils.showDatabaseError(getShell(), "Mapping error", "Error mapping table", e1);
                }
            }
        });
        mappingViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                DatabaseMappingObject mapping = getSelectedMapping();
                mapTableButton.setEnabled(mapping instanceof DatabaseMappingContainer);
                createNewButton.setEnabled(mapping instanceof DatabaseMappingContainer && settings.getContainerNode() != null);
                final boolean hasMappings = (mapping instanceof DatabaseMappingContainer && mapping.getMappingType() != DatabaseMappingType.unspecified) || (mapping instanceof DatabaseMappingAttribute && ((DatabaseMappingAttribute) mapping).getParent().getMappingType() != DatabaseMappingType.unspecified);
                columnsButton.setEnabled(hasMappings);
                ddlButton.setEnabled(hasMappings);
            }
        });
        mappingViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent event) {
                DatabaseMappingObject selectedMapping = getSelectedMapping();
                if (selectedMapping != null) {
                    if (selectedMapping instanceof DatabaseMappingContainer) {
                    /*
                            if (selectedMapping.getMappingType() == DatabaseMappingType.unspecified) {
                                mapExistingTable((DatabaseMappingContainer) selectedMapping);
                            } else {
                                mapColumns((DatabaseMappingContainer) selectedMapping);
                            }
*/
                    }
                }
            }
        });
    }
    {
        Composite hintPanel = new Composite(composite, SWT.NONE);
        hintPanel.setLayout(new GridLayout(3, false));
        hintPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        new Label(hintPanel, SWT.NONE).setText("* DEL - skip column(s)  SPACE - map column(s)");
    }
    setControl(composite);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IProject(org.eclipse.core.resources.IProject) GridData(org.eclipse.swt.layout.GridData)

Aggregations

DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)16 GridData (org.eclipse.swt.layout.GridData)7 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)5 List (java.util.List)4 ISelection (org.eclipse.jface.viewers.ISelection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 DBException (org.jkiss.dbeaver.DBException)4 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)4 ArrayList (java.util.ArrayList)3 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)3 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3