Search in sources :

Example 1 with ActiveWizardDialog

use of org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog in project dbeaver by serge-rider.

the class DataTransferHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    IStructuredSelection ss = (IStructuredSelection) selection;
    final List<IDataTransferProducer> producers = new ArrayList<>();
    final List<IDataTransferConsumer> consumers = new ArrayList<>();
    for (Iterator<?> iter = ss.iterator(); iter.hasNext(); ) {
        Object object = iter.next();
        IDataTransferNode node = adaptTransferNode(object);
        if (node instanceof IDataTransferProducer) {
            producers.add((IDataTransferProducer) node);
        } else if (node instanceof IDataTransferConsumer) {
            consumers.add((IDataTransferConsumer) node);
        }
    }
    if (!consumers.isEmpty()) {
        // We need to choose producer for consumers
        for (IDataTransferConsumer consumer : consumers) {
            IDataTransferProducer producer = chooseProducer(event, consumer);
            if (producer == null) {
                return null;
            }
            producers.add(producer);
        }
    }
    // Run transfer wizard
    if (!producers.isEmpty() || !consumers.isEmpty()) {
        ActiveWizardDialog dialog = new ActiveWizardDialog(workbenchWindow, new DataTransferWizard(producers.toArray(new IDataTransferProducer[producers.size()]), consumers.toArray(new IDataTransferConsumer[consumers.size()])));
        dialog.open();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferNode(org.jkiss.dbeaver.tools.transfer.IDataTransferNode) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)

Example 2 with ActiveWizardDialog

use of org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog in project dbeaver by serge-rider.

the class ResultSetViewer method fillContextMenu.

@Override
public void fillContextMenu(@NotNull IMenuManager manager, @Nullable final DBDAttributeBinding attr, @Nullable final ResultSetRow row) {
    final DBPDataSource dataSource = getDataSource();
    // Custom oldValue items
    final ResultSetValueController valueController;
    final Object value;
    if (attr != null && row != null) {
        valueController = new ResultSetValueController(this, attr, row, IValueController.EditType.NONE, null);
        value = valueController.getValue();
    } else {
        valueController = null;
        value = null;
    }
    {
        {
            // Standard items
            manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_CUT));
            manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_COPY));
            MenuManager extCopyMenu = new MenuManager(ActionUtils.findCommandName(ResultSetCopySpecialHandler.CMD_COPY_SPECIAL));
            extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCopySpecialHandler.CMD_COPY_SPECIAL));
            extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COPY_COLUMN_NAMES));
            if (row != null) {
                extCopyMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COPY_ROW_NAMES));
            }
            manager.add(extCopyMenu);
            if (valueController != null) {
                manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_PASTE));
                manager.add(ActionUtils.makeCommandContribution(site, CoreCommands.CMD_PASTE_SPECIAL));
                manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.EDIT_DELETE));
                // Edit items
                manager.add(new Separator());
                manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_EDIT));
                manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_EDIT_INLINE));
                if (!valueController.isReadOnly() && !DBUtils.isNullValue(value)) /* && !attr.isRequired()*/
                {
                    manager.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_CELL_SET_NULL));
                }
            }
            manager.add(new GroupMarker(MENU_GROUP_EDIT));
        }
        if (valueController != null) {
            // Menus from value handler
            try {
                manager.add(new Separator());
                valueController.getValueManager().contributeActions(manager, valueController, null);
            } catch (Exception e) {
                log.error(e);
            }
            if (row.getState() == ResultSetRow.STATE_REMOVED || (row.changes != null && row.changes.containsKey(attr))) {
                manager.insertAfter(IResultSetController.MENU_GROUP_EDIT, ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_CELL_RESET));
            }
        }
    }
    if (dataSource != null && attr != null && model.getVisibleAttributeCount() > 0 && !model.isUpdateInProgress()) {
        // Filters and View
        manager.add(new Separator());
        {
            String filtersShortcut = ActionUtils.findCommandDescription(ResultSetCommandHandler.CMD_FILTER_MENU, getSite(), true);
            String menuName = CoreMessages.controls_resultset_viewer_action_order_filter;
            if (!CommonUtils.isEmpty(filtersShortcut)) {
                menuName += " (" + filtersShortcut + ")";
            }
            MenuManager filtersMenu = new MenuManager(menuName, DBeaverIcons.getImageDescriptor(UIIcon.FILTER), //$NON-NLS-1$
            "filters");
            filtersMenu.setRemoveAllWhenShown(true);
            filtersMenu.addMenuListener(new IMenuListener() {

                @Override
                public void menuAboutToShow(IMenuManager manager) {
                    fillFiltersMenu(attr, manager);
                }
            });
            manager.add(filtersMenu);
        }
        {
            MenuManager viewMenu = new MenuManager("View/Format", null, //$NON-NLS-1$
            "view");
            List<? extends DBDAttributeTransformerDescriptor> transformers = dataSource.getContainer().getPlatform().getValueHandlerRegistry().findTransformers(dataSource, attr, null);
            if (!CommonUtils.isEmpty(transformers)) {
                MenuManager transformersMenu = new MenuManager("View as");
                transformersMenu.setRemoveAllWhenShown(true);
                transformersMenu.addMenuListener(new IMenuListener() {

                    @Override
                    public void menuAboutToShow(IMenuManager manager) {
                        fillAttributeTransformersMenu(manager, attr);
                    }
                });
                viewMenu.add(transformersMenu);
            } else {
                final Action customizeAction = new Action("View as") {
                };
                customizeAction.setEnabled(false);
                viewMenu.add(customizeAction);
            }
            if (getModel().isSingleSource()) {
                if (valueController != null) {
                    viewMenu.add(new SetRowColorAction(attr, valueController.getValue()));
                    if (getModel().hasColorMapping(attr)) {
                        viewMenu.add(new ResetRowColorAction(attr, valueController.getValue()));
                    }
                }
                viewMenu.add(new CustomizeColorsAction(attr, row));
                viewMenu.add(new Separator());
            }
            viewMenu.add(new Action("Data formats ...") {

                @Override
                public void run() {
                    UIUtils.showPreferencesFor(getControl().getShell(), null, PrefPageDataFormat.PAGE_ID);
                }
            });
            manager.add(viewMenu);
        }
        {
            // Navigate
            MenuManager navigateMenu = new MenuManager("Navigate", null, //$NON-NLS-1$
            "navigate");
            if (ActionUtils.isCommandEnabled(ResultSetCommandHandler.CMD_NAVIGATE_LINK, site)) {
                navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_NAVIGATE_LINK));
                navigateMenu.add(new Separator());
            }
            navigateMenu.add(new Separator());
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ITextEditorActionDefinitionIds.LINE_GOTO));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_FIRST));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_NEXT));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_PREVIOUS));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_LAST));
            navigateMenu.add(new Separator());
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_PAGE));
            navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_ALL));
            if (isHasMoreData() && getDataContainer() != null && (getDataContainer().getSupportedFeatures() & DBSDataContainer.DATA_COUNT) != 0) {
                navigateMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_COUNT));
            }
            manager.add(navigateMenu);
        }
        {
            // Layout
            MenuManager layoutMenu = new MenuManager("Layout", null, //$NON-NLS-1$
            "layout");
            layoutMenu.add(new ToggleModeAction());
            layoutMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_TOGGLE_PANELS));
            layoutMenu.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_SWITCH_PRESENTATION));
            {
                layoutMenu.add(new Separator());
                for (IContributionItem item : fillPanelsMenu()) {
                    layoutMenu.add(item);
                }
            }
            manager.add(layoutMenu);
        }
        manager.add(new Separator());
    }
    // Fill general menu
    final DBSDataContainer dataContainer = getDataContainer();
    if (dataContainer != null && model.hasData()) {
        manager.add(new Action(CoreMessages.controls_resultset_viewer_action_export, DBeaverIcons.getImageDescriptor(UIIcon.EXPORT)) {

            @Override
            public void run() {
                ActiveWizardDialog dialog = new ActiveWizardDialog(site.getWorkbenchWindow(), new DataTransferWizard(new IDataTransferProducer[] { new DatabaseTransferProducer(dataContainer, model.getDataFilter()) }, null), getSelection());
                dialog.open();
            }
        });
    }
    manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
    if (dataContainer != null && model.hasData()) {
        manager.add(new Separator());
        manager.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.FILE_REFRESH));
    }
    manager.add(new Separator());
    manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
Also used : DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) List(java.util.List)

Example 3 with ActiveWizardDialog

use of org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog in project dbeaver by serge-rider.

the class NavigatorHandlerConnectionMigrate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    ActiveWizardDialog dialog = new ActiveWizardDialog(window, new MigrateConnectionWizard(DBeaverCore.getInstance().getProjectRegistry().getActiveDataSourceRegistry(), currentSelection instanceof IStructuredSelection ? (IStructuredSelection) currentSelection : null));
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) MigrateConnectionWizard(org.jkiss.dbeaver.ui.dialogs.connection.MigrateConnectionWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with ActiveWizardDialog

use of org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog in project dbeaver by serge-rider.

the class CreateDiagramHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ActiveWizardDialog dialog = new ActiveWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event), new DiagramCreateWizard());
    dialog.open();
    return null;
}
Also used : ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog)

Aggregations

ActiveWizardDialog (org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog)4 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DataTransferWizard (org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DBException (org.jkiss.dbeaver.DBException)1 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)1 IDataTransferConsumer (org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer)1 IDataTransferNode (org.jkiss.dbeaver.tools.transfer.IDataTransferNode)1 IDataTransferProducer (org.jkiss.dbeaver.tools.transfer.IDataTransferProducer)1 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)1 MigrateConnectionWizard (org.jkiss.dbeaver.ui.dialogs.connection.MigrateConnectionWizard)1