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;
}
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);
}
}
}
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);
}
}
}
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);
}
}
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());
}
Aggregations