use of org.eclipse.ui.IWorkbenchPartSite 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.ui.IWorkbenchPartSite in project dbeaver by serge-rider.
the class AbstractPresentation method trackPresentationControl.
protected void trackPresentationControl() {
final Control control = getControl();
final IWorkbenchPartSite site = controller.getSite();
UIUtils.addFocusTracker(site, PRESENTATION_CONTROL_ID, control);
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
UIUtils.removeFocusTracker(site, control);
}
});
}
use of org.eclipse.ui.IWorkbenchPartSite in project cubrid-manager by CUBRID.
the class CubridNavigatorView method createPartControl.
/**
* Create the part control
*
* @param parent Composite
*/
public void createPartControl(Composite parent) {
ViewForm viewForm = new ViewForm(parent, SWT.NONE);
viewForm.setLayout(new GridLayout());
tv = new TreeViewer(viewForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
tv.setFilters(NodeFilterManager.getInstance().getViewerFilter());
//create the navigator
createNavigator();
//get the isShowGroup configuration
isShowGroup = savedIsShowGroup();
//set the tree view's input.
setTreeInput();
toolTip = new ToolTip(tv.getTree().getShell(), SWT.BALLOON);
toolTip.setAutoHide(true);
//Create the context menu
MenuManager contextMenuManager = new MenuManager("#PopupMenu", "navigatorContextMenu");
contextMenuManager.setRemoveAllWhenShown(true);
contextMenuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
buildPopupMenu(manager);
}
});
Menu contextMenu = contextMenuManager.createContextMenu(tv.getControl());
tv.getControl().setMenu(contextMenu);
// register the context menu for providing extension by extension point
IWorkbenchPartSite site = getSite();
site.registerContextMenu(contextMenuManager, tv);
site.setSelectionProvider(tv);
//add the select the object text composite to top left of toolbar
ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
ToolBarManager toolBarManager = new ToolBarManager(toolBar);
SelectTreeObjContrItem textContrItem = new SelectTreeObjContrItem(tv);
toolBarManager.add(textContrItem);
toolBarManager.update(true);
viewForm.setContent(tv.getControl());
viewForm.setTopLeft(toolBar);
//add the other actions to the top right of toolbar
toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.CENTER);
toolBarManager = new ToolBarManager(toolBar);
buildToolBar(toolBarManager);
toolBarManager.update(true);
viewForm.setTopRight(toolBar);
//Add the actions to view menu bar, you can add them by extension point or code define
IActionBars actionBar = getViewSite().getActionBars();
final IMenuManager menuManager = actionBar.getMenuManager();
menuManager.addMenuListener(new IMenuListener2() {
//reserve these actions by code define,these codes rebuild every time.
//hence when hide, remove them not including these actions by extension point
private IMenuManager lastMenuManager = new MenuManager();
public void menuAboutToShow(IMenuManager manager) {
lastMenuManager.removeAll();
//build the code defined actions
buildViewMenu(lastMenuManager);
for (IContributionItem item : lastMenuManager.getItems()) {
manager.add(item);
}
}
public void menuAboutToHide(IMenuManager manager) {
for (IContributionItem item : lastMenuManager.getItems()) {
manager.remove(item);
}
}
});
menuManager.add(new Separator());
activeContext();
addListener();
setFocus();
}
Aggregations