Search in sources :

Example 6 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.

the class NavigatorHandlerObjectDelete method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    this.structSelection = null;
    this.deleteAll = null;
    this.tasksToExecute.clear();
    final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            if (element instanceof DBNDatabaseNode) {
                deleteObject(activeWorkbenchWindow, (DBNDatabaseNode) element);
            } else if (element instanceof DBNResource) {
                deleteResource(activeWorkbenchWindow, (DBNResource) element);
            } else if (element instanceof DBNLocalFolder) {
                deleteLocalFolder(activeWorkbenchWindow, (DBNLocalFolder) element);
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$
                log.warn("Don't know how to delete element '" + element + "'");
            }
            if (deleteAll != null && !deleteAll) {
                break;
            }
        }
    }
    if (!tasksToExecute.isEmpty()) {
        TasksJob.runTasks(tasksToExecute.size() > 1 ? "Delete " + tasksToExecute.size() + " objects" : "Delete object", tasksToExecute);
        tasksToExecute.clear();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.

the class NavigatorHandlerCopyAbstract method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    DBeaverUI.syncExec(new Runnable() {

        @Override
        public void run() {
            copySelection(workbenchWindow, activePart, selection);
        }
    });
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection)

Example 8 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.

the class DataSourceAutoCommitHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        return;
    }
    IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    boolean autoCommit = true;
    DBPTransactionIsolation isolation = null;
    DBCExecutionContext context = getExecutionContext(activeEditor);
    if (context != null && context.isConnected()) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                // Change auto-commit mode
                autoCommit = txnManager.isAutoCommit();
                isolation = txnManager.getTransactionIsolation();
            } catch (DBCException e) {
                log.warn(e);
            }
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        if (container != null) {
            autoCommit = container.isDefaultAutoCommit();
            isolation = container.getActiveTransactionsIsolation();
        }
    }
    element.setChecked(autoCommit);
    // Update command image
    element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
    String isolationName = isolation == null ? "?" : isolation.getTitle();
    element.setText(autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit");
    element.setTooltip(autoCommit ? "Manual commit (" + isolationName + ")" : "Auto-commit");
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPTransactionIsolation(org.jkiss.dbeaver.model.DBPTransactionIsolation) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 9 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project dbeaver by serge-rider.

the class DataSourceToolsContributor method fillToolsMenu.

private static void fillToolsMenu(List<IContributionItem> menuItems, List<ToolDescriptor> tools, ISelection selection) {
    boolean hasTools = false;
    if (!CommonUtils.isEmpty(tools)) {
        IWorkbenchWindow workbenchWindow = DBeaverUI.getActiveWorkbenchWindow();
        if (workbenchWindow.getActivePage() != null) {
            IWorkbenchPart activePart = workbenchWindow.getActivePage().getActivePart();
            if (activePart != null) {
                Map<ToolGroupDescriptor, IMenuManager> groupsMap = new HashMap<>();
                for (ToolDescriptor tool : tools) {
                    hasTools = true;
                    IMenuManager parentMenu = null;
                    if (tool.getGroup() != null) {
                        parentMenu = getGroupMenu(menuItems, groupsMap, tool.getGroup());
                    }
                    IAction action = ActionUtils.makeAction(new NavigatorActionExecuteTool(workbenchWindow, tool), activePart.getSite(), selection, tool.getLabel(), tool.getIcon() == null ? null : DBeaverIcons.getImageDescriptor(tool.getIcon()), tool.getDescription());
                    if (parentMenu == null) {
                        menuItems.add(new ActionContributionItem(action));
                    } else {
                        parentMenu.add(new ActionContributionItem(action));
                    }
                }
            }
        }
    }
    if (!hasTools) {
        menuItems.add(new ActionContributionItem(new EmptyListAction()));
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) HashMap(java.util.HashMap) ToolDescriptor(org.jkiss.dbeaver.registry.tools.ToolDescriptor) ToolGroupDescriptor(org.jkiss.dbeaver.registry.tools.ToolGroupDescriptor) EmptyListAction(org.jkiss.dbeaver.ui.actions.common.EmptyListAction) NavigatorActionExecuteTool(org.jkiss.dbeaver.ui.actions.navigator.NavigatorActionExecuteTool)

Example 10 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow 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)

Aggregations

IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)284 IEditorPart (org.eclipse.ui.IEditorPart)114 PartInitException (org.eclipse.ui.PartInitException)70 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)68 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)39 IViewPart (org.eclipse.ui.IViewPart)38 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)35 ArrayList (java.util.ArrayList)34 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)32 IEditorReference (org.eclipse.ui.IEditorReference)30 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)27 ISelection (org.eclipse.jface.viewers.ISelection)25 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)24 IFile (org.eclipse.core.resources.IFile)23 IWorkbench (org.eclipse.ui.IWorkbench)21 CoreException (org.eclipse.core.runtime.CoreException)20 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)19 IProject (org.eclipse.core.resources.IProject)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)17