本文整理匯總了Java中org.eclipse.ui.IWorkbenchPartSite類的典型用法代碼示例。如果您正苦於以下問題:Java IWorkbenchPartSite類的具體用法?Java IWorkbenchPartSite怎麽用?Java IWorkbenchPartSite使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IWorkbenchPartSite類屬於org.eclipse.ui包,在下文中一共展示了IWorkbenchPartSite類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reorganizeImport
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
/**
* @param project
*/
public static void reorganizeImport(final ICompilationUnit cu) {
Display.getDefault().syncExec(() -> {
try {
IWorkbenchWindow iww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (iww == null)
return;
IPartService partService = iww.getPartService();
if (partService == null)
return;
IWorkbenchPart wp = partService.getActivePart();
if (wp == null)
return;
IWorkbenchPartSite targetSite = wp.getSite();
if (targetSite == null)
return;
organizeImports(cu, targetSite);
} catch (Exception e) {
ResourceManager.logException(e);
}
});
}
示例2: getService
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
/**
* 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);
}
示例3: getDisplay
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
private Display getDisplay() {
XtextEditor editor = this.editor;
if (editor == null) {
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;
}
示例4: AbstractPDFViewerRunnable
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
public AbstractPDFViewerRunnable(ProducePDFHandler handler, IWorkbenchPartSite site, IResource aSpecFile) {
Assert.isNotNull(handler);
Assert.isNotNull(site);
Assert.isNotNull(aSpecFile);
this.handler = handler;
this.specFile = aSpecFile;
final boolean autoRegenerate = TLA2TeXActivator.getDefault().getPreferenceStore()
.getBoolean(ITLA2TeXPreferenceConstants.AUTO_REGENERATE);
if (autoRegenerate) {
// Subscribe to the event bus with which the TLA Editor save events are
// distributed. In other words, every time the user saves a spec, we
// receive an event and provided the spec corresponds to this PDF, we
// regenerate it.
// Don't subscribe in EmbeddedPDFViewerRunnable#though, because it is run
// repeatedly and thus would cause us to subscribe multiple times.
final IEventBroker eventService = site.getService(IEventBroker.class);
Assert.isTrue(eventService.subscribe(TLAEditor.SAVE_EVENT, this));
// Register for part close events to deregister the event handler
// subscribed to the event bus. There is no point in regenerating
// the PDF if no PDFEditor is open anymore.
final IPartService partService = site.getService(IPartService.class);
partService.addPartListener(this);
}
}
示例5: getDisplay
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
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;
}
示例6: isEnabled
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
@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();
}
示例7: getStatusLineManager
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
private IStatusLineManager getStatusLineManager() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IWorkbenchPart part = page.getActivePart();
if (part == null)
return null;
IWorkbenchPartSite site = part.getSite();
IActionBars actionBars = null;
if (site instanceof IEditorSite)
actionBars = ((IEditorSite) site).getActionBars();
else if (site instanceof IViewSite)
actionBars = ((IViewSite) site).getActionBars();
if (actionBars == null)
return null;
return actionBars.getStatusLineManager();
}
示例8: disposePart
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
/**
* Disposes the given part and its site.
*
* @param part
* The part to dispose; must not be <code>null</code>.
*/
private void disposePart(final IWorkbenchPart part) {
SafeRunner.run(new ISafeRunnable() {
public void run() {
IWorkbenchPartSite partSite = part.getSite();
part.dispose();
if (partSite instanceof MultiPageToolbarEditorSite) {
((MultiPageToolbarEditorSite) partSite).dispose();
}
}
public void handleException(Throwable e) {
// Exception has already being logged by Core. Do nothing.
}
});
}
示例9: getStatusLineManager
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
private IStatusLineManager getStatusLineManager() {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
if (page == null)
return null;
IWorkbenchPart part = page.getActivePart();
if (part == null)
return null;
IWorkbenchPartSite site = part.getSite();
IActionBars actionBars = null;
if (site instanceof IEditorSite)
actionBars = ((IEditorSite) site).getActionBars();
else if (site instanceof IViewSite)
actionBars = ((IViewSite) site).getActionBars();
if (actionBars == null)
return null;
return actionBars.getStatusLineManager();
}
示例10: initSelectionProvider
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
protected void initSelectionProvider() {
// Overrides the editors selection provider to provide the text
// selection if opened within an editor context
try {
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor().getSite();
XtextStyledTextSelectionProvider xtextStyledTextSelectionProvider = new XtextStyledTextSelectionProvider();
ChangeSelectionProviderOnFocusGain listener = new ChangeSelectionProviderOnFocusGain(site,
xtextStyledTextSelectionProvider);
styledText.addFocusListener(listener);
styledText.addDisposeListener(listener);
} catch (NullPointerException ex) {
//Do nothing, not opened within editor context
}
}
示例11: search
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
public void search() {
final IWorkbenchPart part = WorkbenchHelper.getActivePart();
if (part instanceof IEditorPart) {
final IEditorPart editor = (IEditorPart) part;
final IWorkbenchPartSite site = editor.getSite();
if (site != null) {
final ISelectionProvider provider = site.getSelectionProvider();
if (provider != null) {
final ISelection viewSiteSelection = provider.getSelection();
if (viewSiteSelection instanceof TextSelection) {
final TextSelection textSelection = (TextSelection) viewSiteSelection;
text.setText(textSelection.getText());
}
}
}
}
activate(null);
text.setFocus();
}
示例12: getStatusLineManager
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
static IStatusLineManager getStatusLineManager()
{
try
{
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActivePart().getSite();
return ((IViewSite) site).getActionBars().getStatusLineManager();
}
catch (Exception e)
{
// try to get the IStatusLineManager through an active editor
try
{
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
.getEditorSite().getActionBars().getStatusLineManager();
}
catch (Exception e1)
{
}
}
return null;
}
示例13: clearSelection
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
/**
* Clear all selection providers in all workench pages.
*/
public static void clearSelection() {
final IWorkbenchWindow wbWin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (wbWin != null) {
final IWorkbenchPage[] wbPages = wbWin.getPages();
for (final IWorkbenchPage wbPage : wbPages) {
final IWorkbenchPart wbWinPagePart = wbPage.getActivePart();
if (wbWinPagePart != null) {
final IWorkbenchPartSite site = wbWinPagePart.getSite();
if (site != null) {
final ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider instanceof PostSelectionProvider) {
((PostSelectionProvider) selectionProvider).clearSelection();
}
}
}
}
}
}
示例14: init
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
/**
* Sets the site and input for this editor then creates and initializes the actions.
* Subclasses may extend this method, but should always call <code>super.init(site, input)
* </code>.
* @see org.eclipse.ui.IEditorPart#init(IEditorSite, IEditorInput)
*/
public void init(IWorkbenchPartSite site, PlanEditorModel planEditorModel) {
super.init(site, planEditorModel.getEPlan());
this.planEditorModel = planEditorModel;
EPlan ePlan = planEditorModel.getEPlan();
this.domain = TransactionUtils.getDomain(ePlan);
this.moveThread = new MoveThread(ePlan, this);
IPreferenceStore store = TimelinePlugin.getDefault().getPreferenceStore();
if (store.getBoolean(TimelinePreferencePage.P_SNAP_TO_ACTIVE)) {
setSnapTolerance(SnapToTimelineHandler.DEFAULT_TOLERANCE);
}
//FIXME: Make stores consistent. See also SnapToAssessment.isEnabled().
setSnapToOrbitEnabled(TimelineConstants.TIMELINE_PREFERENCES.getBoolean(TimelinePreferencePage.P_SNAP_TO_ORBIT_ACTIVE));
timelineServices = ClassRegistry.createInstances(PlanTimelineService.class);
for (PlanTimelineService s : timelineServices) {
s.setTimeline(this);
}
}
示例15: init
import org.eclipse.ui.IWorkbenchPartSite; //導入依賴的package包/類
public void init(IWorkbenchPartSite site, T model) {
this.site = site;
this.model = model;
this.timelineModel.eAdapters().add(timelineModelAdapter);
if (site != null) {
ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider != null) {
selectionProvider.addSelectionChangedListener(selectionListener);
}
}
timelineServices = ClassRegistry.createInstances(TimelineService.class);
for (TimelineService s : timelineServices) {
s.setTimeline(this);
}
}