Search in sources :

Example 86 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project dbeaver by serge-rider.

the class AggregateColumnsPanel method createContents.

@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
    this.presentation = presentation;
    this.panelSettings = ResultSetUtils.getViewerSettings(SETTINGS_SECTION_AGGREGATE);
    loadSettings();
    this.aggregateTable = new Tree(parent, SWT.SINGLE | SWT.FULL_SELECTION);
    this.aggregateTable.setHeaderVisible(true);
    this.aggregateTable.setLinesVisible(true);
    new TreeColumn(this.aggregateTable, SWT.LEFT).setText("Function");
    new TreeColumn(this.aggregateTable, SWT.RIGHT).setText("Value");
    if (this.presentation instanceof ISelectionProvider) {
        ((ISelectionProvider) this.presentation).addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (presentation.getController().getVisiblePanel() == AggregateColumnsPanel.this) {
                    refresh(false);
                }
            }
        });
    }
    MenuManager menuMgr = new MenuManager();
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            manager.add(new CopyAction());
            manager.add(new CopyAllAction());
            manager.add(new Separator());
            fillToolBar(manager);
        }
    });
    menuMgr.setRemoveAllWhenShown(true);
    this.aggregateTable.setMenu(menuMgr.createContextMenu(this.aggregateTable));
    aggregateTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            presentation.getController().updatePanelActions();
        }
    });
    return this.aggregateTable;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 87 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project dbeaver by serge-rider.

the class CompileHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    List<OracleSourceObject> objects = new ArrayList<>();
    IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
    if (partSite != null) {
        final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
        if (selectionProvider != null) {
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                    final Object item = iter.next();
                    final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
                    if (sourceObject != null) {
                        objects.add(sourceObject);
                    }
                }
            }
        }
        if (objects.isEmpty()) {
            final IWorkbenchPart activePart = partSite.getPart();
            final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
            if (sourceObject != null) {
                objects.add(sourceObject);
            }
        }
    }
    if (!objects.isEmpty()) {
        if (objects.size() > 1) {
            element.setText("Compile " + objects.size() + " objects");
        } else {
            final OracleSourceObject sourceObject = objects.get(0);
            String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
            element.setText("Compile " + objectType);
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

Example 88 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    if (!updateUI) {
        return;
    }
    final ISelectionProvider selectionProvider = UIUtils.getSelectionProvider(element.getServiceLocator());
    if (selectionProvider != null) {
        ISelection selection = selectionProvider.getSelection();
        DBNNode node = NavigatorUtils.getSelectedNode(selection);
        if (node != null) {
            String actionName = CoreMessages.actions_navigator_open;
            if (node instanceof DBNDataSource) {
                actionName = CoreMessages.actions_navigator_edit;
            } else if (node instanceof DBNDatabaseNode) {
                DBSObject object = ((DBNDatabaseNode) node).getObject();
                if (object != null) {
                    DBEObjectEditor objectManager = EntityEditorsRegistry.getInstance().getObjectManager(object.getClass(), DBEObjectEditor.class);
                    actionName = objectManager == null || !objectManager.canEditObject(object) ? CoreMessages.actions_navigator_view : CoreMessages.actions_navigator_edit;
                }
            }
            String label;
            if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() > 1) {
                label = actionName + CoreMessages.actions_navigator__objects;
            } else {
                //$NON-NLS-1$
                label = actionName + " " + node.getNodeType();
            }
            element.setText(label);
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBEObjectEditor(org.jkiss.dbeaver.model.edit.DBEObjectEditor) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 89 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project dbeaver by serge-rider.

the class DataSourceToolsContributor method fillContributionItems.

@Override
protected void fillContributionItems(List<IContributionItem> menuItems) {
    IWorkbenchPart activePart = DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart();
    if (activePart == null) {
        return;
    }
    final ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return;
    }
    ISelection selection = selectionProvider.getSelection();
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    DBSObject selectedObject = NavigatorUtils.getSelectedObject((IStructuredSelection) selection);
    if (selectedObject != null) {
        List<ToolDescriptor> tools = ToolsRegistry.getInstance().getTools((IStructuredSelection) selection);
        fillToolsMenu(menuItems, tools, selection);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ToolDescriptor(org.jkiss.dbeaver.registry.tools.ToolDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 90 with ISelectionProvider

use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.

the class LogoutDatabaseAction method run.

public void run() {
    Object[] objArr = this.getSelectedObj();
    if (objArr == null || objArr.length <= 0) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    StringBuffer dbNames = new StringBuffer();
    for (int i = 0; objArr != null && i < objArr.length; i++) {
        if (!isSupported(objArr[i])) {
            setEnabled(false);
            return;
        }
        ICubridNode node = (ICubridNode) objArr[i];
        dbNames.append(node.getLabel());
        if (i != objArr.length - 1) {
            dbNames.append(",");
        }
    }
    boolean isLogout = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmLogoutDatabase, dbNames.toString()));
    if (!isLogout) {
        return;
    }
    TreeViewer viewer = (TreeViewer) provider;
    for (int i = 0; i < objArr.length; i++) {
        CubridDatabase database = (CubridDatabase) objArr[i];
        boolean isContinue = DatabaseUtils.processDatabaseLogout(database);
        if (isContinue) {
            viewer.refresh(database, true);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
        }
    }
    ActionManager.getInstance().fireSelectionChanged(getSelection());
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)169 ISelection (org.eclipse.jface.viewers.ISelection)61 TreeViewer (org.eclipse.jface.viewers.TreeViewer)40 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)25 ITextSelection (org.eclipse.jface.text.ITextSelection)25 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)24 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)21 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)14 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)13 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)13 IPostSelectionProvider (org.eclipse.jface.viewers.IPostSelectionProvider)13 IEditorPart (org.eclipse.ui.IEditorPart)13 Shell (org.eclipse.swt.widgets.Shell)11 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)10 IDocument (org.eclipse.jface.text.IDocument)9