org.eclipse.ui.IWorkbenchPartSite Java Examples

The following examples show how to use org.eclipse.ui.IWorkbenchPartSite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomPopupMenuExtender.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Notifies the listener that the menu is about to be hidden.
 */
@Override
public final void menuAboutToHide(final IMenuManager mgr) {
    gatherContributions(mgr);
    cleanupNeeded = true;
    // Remove this menu as a visible menu.
    final IWorkbenchPartSite site = part.getSite();
    if (site != null) {
        final IWorkbench workbench = site.getWorkbenchWindow().getWorkbench();
        if (workbench instanceof Workbench) {
            // try delaying this until after the selection event
            // has been fired.
            // This is less threatening if the popup: menu
            // contributions aren't tied to the evaluation service
            workbench.getDisplay().asyncExec(() -> {
                final Workbench realWorkbench = (Workbench) workbench;
                runCleanUp(realWorkbench);
            });
        }
    }
}
 
Example #2
Source File: JavaReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void uninstall() {

	IWorkbenchPartSite site= fTextEditor.getSite();
	IWorkbenchWindow window= site.getWorkbenchWindow();
	window.getPartService().removePartListener(fPartListener);
	fPartListener= null;

	Shell shell= window.getShell();
	if (shell != null && !shell.isDisposed())
		shell.removeShellListener(fActivationListener);
	fActivationListener= null;

	JavaCore.removeElementChangedListener(fJavaElementChangedListener);
	fJavaElementChangedListener= null;

	IWorkspace workspace= JavaPlugin.getWorkspace();
	workspace.removeResourceChangeListener(fResourceChangeListener);
	fResourceChangeListener= null;

	JavaPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
	fPropertyChangeListener= null;

	super.uninstall();
}
 
Example #3
Source File: SemanticHighlightingReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Update the presentation.
 *
 * @param textPresentation the text presentation
 * @param addedPositions the added positions
 * @param removedPositions the removed positions
 */
private void updatePresentation(TextPresentation textPresentation, List<Position> addedPositions, List<Position> removedPositions) {
	Runnable runnable= fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions);
	if (runnable == null)
		return;

	JavaEditor editor= fEditor;
	if (editor == null)
		return;

	IWorkbenchPartSite site= editor.getSite();
	if (site == null)
		return;

	Shell shell= site.getShell();
	if (shell == null || shell.isDisposed())
		return;

	Display display= shell.getDisplay();
	if (display == null || display.isDisposed())
		return;

	display.asyncExec(runnable);
}
 
Example #4
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Makes sure that the editor's folding state is correct the next time
 * it becomes visible. If it already is visible, it toggles the folding
 * state. If not, it either registers a part listener to toggle folding
 * when the editor becomes visible, or cancels an already registered
 * runner.
 */
public void runWhenNextVisible() {
	// if there is one already: toggling twice is the identity
	if (fFoldingRunner != null) {
		fFoldingRunner.cancel();
		return;
	}
	IWorkbenchPartSite site= getSite();
	if (site != null) {
		IWorkbenchPage page= site.getPage();
		if (!page.isPartVisible(JavaEditor.this)) {
			// if we're not visible - defer until visible
			fPage= page;
			fFoldingRunner= this;
			page.addPartListener(this);
			return;
		}
	}
	// we're visible - run now
	toggleFolding();
}
 
Example #5
Source File: ServiceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
Example #6
Source File: NewTextSearchActionGroup.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public NewTextSearchActionGroup(IViewPart part) {
    Assert.isNotNull(part);
    IWorkbenchPartSite site = part.getSite();
    fSelectionProvider = site.getSelectionProvider();
    fPage = site.getPage();
    fOpenPropertiesDialog = new PropertyDialogAction(site, fSelectionProvider);
    fOpenAction = new OpenFileAction(fPage);
    ISelection selection = fSelectionProvider.getSelection();

    if (selection instanceof IStructuredSelection) {
        fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection);
    } else {
        fOpenPropertiesDialog.selectionChanged(selection);
    }

}
 
Example #7
Source File: HighlightingReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private Display getDisplay() {
	XtextEditor editor = this.editor;
	if (editor == null){
		if(sourceViewer != null)
			return sourceViewer.getControl().getDisplay();
		return null;
	}
	IWorkbenchPartSite site = editor.getSite();
	if (site == null)
		return null;

	Shell shell = site.getShell();
	if (shell == null || shell.isDisposed())
		return null;

	Display display = shell.getDisplay();
	if (display == null || display.isDisposed())
		return null;
	return display;
}
 
Example #8
Source File: MedicationComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create the composite.
 * 
 * @param parent
 * @param style
 * @param partSite
 */
public MedicationComposite(Composite parent, int style, IWorkbenchPartSite partSite){
	super(parent, style);
	setLayout(new GridLayout(1, false));
	
	searchFilterComposite();
	medicationTableComposite(partSite);
	stateComposite();
	medicationDetailComposite();
	
	showSearchFilterComposite(false);
	showMedicationDetailComposite(null);
	
	dropTarget =
		new GenericObjectDropTarget("Medication", this,
		new DropMedicationReceiver(getShell()));
}
 
Example #9
Source File: NewTextSearchActionGroup.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public NewTextSearchActionGroup(IViewPart part) {
    Assert.isNotNull(part);
    IWorkbenchPartSite site = part.getSite();
    fSelectionProvider = site.getSelectionProvider();
    fPage = site.getPage();
    fOpenPropertiesDialog = new PropertyDialogAction(site, fSelectionProvider);
    fOpenAction = new OpenFileAction(fPage);
    ISelection selection = fSelectionProvider.getSelection();

    if (selection instanceof IStructuredSelection) {
        fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection);
    } else {
        fOpenPropertiesDialog.selectionChanged(selection);
    }

}
 
Example #10
Source File: UnansweredDocumentsView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public UnansweredDocumentsView(Composite parent, IWorkbenchPartSite site,
        Supplier<Questionnaire> questionnaireSupplier, Supplier<IProject> projectSupplier) {
    this.questionnaireSupplier = questionnaireSupplier;
    this.projectSupplier = projectSupplier;

    incompleteDocumentsLabel = new Label(parent, 0);
    incompleteDocumentsLabel.setText(TEMPLATE_ANSWERS_COMPLETE);
    incompleteDocumentsLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));

    incompleteDocumentsList = new ListViewer(parent, SWT.V_SCROLL);
    GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1);
    gd.heightHint = (int) (((org.eclipse.swt.widgets.List) incompleteDocumentsList.getControl()).getItemHeight()
            * 4);
    gd.widthHint = 300;
    incompleteDocumentsList.getControl().setLayoutData(gd);
    incompleteDocumentsList.getControl().setVisible(false);
    incompleteDocumentsList.setSorter(new ViewerSorter());
    incompleteDocumentsList.setContentProvider(ArrayContentProvider.getInstance());
    incompleteDocumentsList.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Document) element).getKey();
        }
    });
    site.setSelectionProvider(incompleteDocumentsList);
}
 
Example #11
Source File: EditorUtils.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static IWorkbenchPartSite getSite() {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }
    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (activePage == null) {
        return null;
    }
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor == null) {
        return null;
    }
    return activeEditor.getSite();
}
 
Example #12
Source File: BaseYankHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * In the console context, use paste as
 * in some consoles (e.g. org.eclipse.debug.internal.ui.views.console.ProcessConsole), updateText
 * will not simulate keyboard input
 *  
 * @param event the ExecutionEvent
 * @param widget The consoles StyledText widget
 */
protected void paste(ExecutionEvent event, StyledText widget) {
		IWorkbenchPart apart = HandlerUtil.getActivePart(event);
		if (apart != null) {
			try {
				IWorkbenchPartSite site = apart.getSite();
				if (site != null) {
					IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
					if (service != null) {
						service.executeCommand(IEmacsPlusCommandDefinitionIds.EMP_PASTE, null);
						KillRing.getInstance().setYanked(true);
					}
				}
			} catch (CommandException e) {
			}
		}
}
 
Example #13
Source File: OpenEditorAction.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (inputFile == null) {
		return;
	}
	IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
	IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
	try {
		IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile),
				COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
		if (selectedRegion != null) {
			((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
		}
	} catch (PartInitException partInitException) {
		throw new WrappedRuntimeException(partInitException);
	}

}
 
Example #14
Source File: FixedHighlightingReconciler.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
private Display getDisplay() {
  XtextEditor editor = this.editor;
  if (editor == null) {
    if (sourceViewer != null) {
      return sourceViewer.getControl().getDisplay();
    }
    return null;
  }
  IWorkbenchPartSite site = editor.getSite();
  if (site == null) {
    return null;
  }

  Shell shell = site.getShell();
  if (shell == null || shell.isDisposed()) {
    return null;
  }

  Display display = shell.getDisplay();
  if (display == null || display.isDisposed()) {
    return null;
  }
  return display;
}
 
Example #15
Source File: NatTableWrapper.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public void addContextMenu(String string, IWorkbenchPartSite iWorkbenchPartSite){
	
	MenuManager mgr = new MenuManager();
	Menu popupmenu = new PopupMenuBuilder(natTable, mgr).build();
	iWorkbenchPartSite.registerContextMenu(string, mgr, null);
	
	natTable.addConfiguration(new AbstractUiBindingConfiguration() {
		
		@Override
		public void configureUiBindings(UiBindingRegistry uiBindingRegistry){
			uiBindingRegistry.registerMouseDownBinding(
				new MouseEventMatcher(SWT.NONE, null, MouseEventMatcher.RIGHT_BUTTON),
				new PopupMenuAction(popupmenu));
		}
	});
}
 
Example #16
Source File: RenameElementHandler.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isEnabled() {
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window == null) {
		return false;
	}
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	if (site == null) {
		return false;
	}
	ISelectionProvider selectionProvider = site.getSelectionProvider();
	if (selectionProvider == null) {
		return false;
	}
	ISelection currentSelection = selectionProvider.getSelection();
	setContext(refactoring, currentSelection);
	return refactoring.isExecutable();
}
 
Example #17
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static CallHierarchyViewPart findAndShowCallersView(IWorkbenchPartSite site) {
    IWorkbenchPage workbenchPage = site.getPage();
    CallHierarchyViewPart callersView = null;

    try {
        callersView = (CallHierarchyViewPart) workbenchPage.showView(CallHierarchyViewPart.ID_CALL_HIERARCHY);
    } catch (PartInitException e) {
        JavaPlugin.log(e);
    }

    return callersView;
}
 
Example #18
Source File: CommonSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private List<TextHoverDescriptor> getEnabledTextHoverDescriptors(ITextViewer textViewer, int offset)
{
	List<TextHoverDescriptor> result = new ArrayList<TextHoverDescriptor>();
	if (fTextEditor == null)
	{
		return result;
	}
	try
	{
		QualifiedContentType contentType = CommonEditorPlugin.getDefault().getDocumentScopeManager()
				.getContentType(textViewer.getDocument(), offset);
		IEvaluationContext context = new EvaluationContext(null, textViewer);
		IWorkbenchPartSite site = fTextEditor.getSite();
		if (site != null)
		{
			context.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, site.getId());
		}
		for (TextHoverDescriptor descriptor : TextHoverDescriptor.getContributedHovers())
		{
			if (descriptor.isEnabledFor(contentType, context))
			{
				result.add(descriptor);
			}
		}
	}
	catch (BadLocationException e)
	{
	}
	return result;
}
 
Example #19
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Shell getShell() {
	ITextEditor editor= getTextEditor();
	if (editor != null) {
		IWorkbenchPartSite site= editor.getSite();
		Shell shell= site.getShell();
		if (shell != null && !shell.isDisposed()) {
			return shell;
		}
	}
	return null;
}
 
Example #20
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IProgressService getProgressService() {
	IEditorPart editor= getTextEditor();
	if (editor != null) {
		IWorkbenchPartSite site= editor.getSite();
		if (site != null)
			return (IWorkbenchSiteProgressService) editor.getSite().getAdapter(IWorkbenchSiteProgressService.class);
	}
	return PlatformUI.getWorkbench().getProgressService();
}
 
Example #21
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object computeInput(Object input) {
	if (getControl() == null || ! (input instanceof IJavaElement))
		return null;

	IWorkbenchPart part= null;
	IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page= window.getActivePage();
		if (page != null) {
			part= page.getActivePart();
		}
	}

	ISelection selection= null;
	if (part != null) {
		IWorkbenchPartSite site= part.getSite();
		if (site != null) {
			ISelectionProvider provider= site.getSelectionProvider();
			if (provider != null) {
				selection= provider.getSelection();
			}
		}
	}

	return computeInput(part, selection, (IJavaElement) input, new NullProgressMonitor());
}
 
Example #22
Source File: AnyPyStackFrameSelected.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public AnyPyStackFrameSelected() {
    IWorkbenchPart activePart = UIUtils.getActivePart();
    if (activePart != null) {
        IWorkbenchPartSite site = activePart.getSite();
        DebugUITools.addPartDebugContextListener(site, this);
    }
}
 
Example #23
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void setSelectionFromEditor(IWorkbenchPart part) {
	if (!fProcessSelectionEvents || !linkBrowsingViewSelectionToEditor() || !(part instanceof IEditorPart))
		return;

	IWorkbenchPartSite site= part.getSite();
	if (site == null)
		return;
	ISelectionProvider provider= site.getSelectionProvider();
	if (provider != null)
		setSelectionFromEditor(part, provider.getSelection());
}
 
Example #24
Source File: BaseDebugView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
    IViewSite viewSite = getViewSite();
    if (viewSite != null) {
        configureToolBar(viewSite);
    }

    parent.setLayout(new GridLayout(1, true));

    viewer = new TreeViewer(parent);
    provider = createContentProvider();
    viewer.setContentProvider(provider);
    viewer.setLabelProvider(new PyDebugModelPresentation(false));

    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getTree());

    MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(viewer.getTree());
    viewer.getTree().setMenu(menu);
    IWorkbenchPartSite site = getSite();
    site.registerContextMenu(menuManager, viewer);
    site.setSelectionProvider(viewer);

    this.parent = parent;

    listener = createListener();
    if (listener != null) {
        DebugPlugin plugin = DebugPlugin.getDefault();

        ILaunchManager launchManager = plugin.getLaunchManager();
        launchManager.addLaunchListener(listener);

        plugin.addDebugEventListener(listener);
    }
}
 
Example #25
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private boolean viewIsDetached() {
	// Uses the trick from
	// http://eclipsesource.com/blogs/2010/06/23/tip-how-to-detect-that-a-view-was-detached/
	final boolean[] result = new boolean[] { false };
	WorkbenchHelper.run(() -> {
		final IWorkbenchPartSite site = view.getSite();
		if (site == null) { return; }
		final Shell shell = site.getShell();
		if (shell == null) { return; }
		final String text = shell.getText();
		result[0] = text == null || text.isEmpty();
	});
	return result[0];

}
 
Example #26
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initContextMenu(Control control) {
	MenuManager menuManager = new FilteringMenuManager();
	Menu contextMenu = menuManager.createContextMenu(control);
	control.setMenu(contextMenu);
	IWorkbenchPartSite site = editorPart.getSite();
	if (site != null)
		site.registerContextMenu("org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapterContextMenu",
				menuManager, site.getSelectionProvider());
}
 
Example #27
Source File: AbstractEditorPropertySection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initContextMenu(Control control) {
	MenuManager menuManager = new FilteringMenuManager();
	Menu contextMenu = menuManager.createContextMenu(control);
	control.setMenu(contextMenu);
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider());
}
 
Example #28
Source File: StyledTextSelectionListener.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public StyledTextSelectionListener(IWorkbenchPartSite site, StyledText widget,
		ISelectionProvider selectionProviderOnFocusGain) {
	super(site, selectionProviderOnFocusGain, widget);
	site.setSelectionProvider(selectionProviderOnFocusGain);
	widget.addFocusListener(this);
	widget.addDisposeListener(this);
}
 
Example #29
Source File: XtextStyledTextCellEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void initContextMenu(Control control) {
	MenuManager menuManager = createMenuManager();
	Menu contextMenu = menuManager.createContextMenu(control);
	control.setMenu(contextMenu);
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
	site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider());
}
 
Example #30
Source File: FindBarActions.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void setFindBarContextActive(boolean activate)
{
	fActivated = activate;
	IWorkbenchPartSite site = textEditor.getSite();
	IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class);
	IBindingService service = (IBindingService) site.getService(IBindingService.class);

	if (activate)
	{

		// These will be the only active commands (note that they may have multiple keybindings
		// defined in plugin.xml)
		for (Map.Entry<String, AbstractHandler> entry : fCommandToHandler.entrySet())
		{
			AbstractHandler handler = entry.getValue();
			if (handler != null)
			{
				fHandlerActivations.add(handlerService.activateHandler(entry.getKey(), handler));
			}
		}

		// Yes, no longer execute anything from the binding service (we'll do our own handling so that the commands
		// we need still get executed).
		service.setKeyFilterEnabled(false);

		service.addBindingManagerListener(fClearCommandToBindingOnChangesListener);
	}
	else
	{
		fCommandToBinding = null;
		service.setKeyFilterEnabled(true);

		service.removeBindingManagerListener(fClearCommandToBindingOnChangesListener);
		handlerService.deactivateHandlers(fHandlerActivations);
		fHandlerActivations.clear();
	}
}