本文整理汇总了Java中org.eclipse.ui.IWorkbenchPartSite.getService方法的典型用法代码示例。如果您正苦于以下问题:Java IWorkbenchPartSite.getService方法的具体用法?Java IWorkbenchPartSite.getService怎么用?Java IWorkbenchPartSite.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.IWorkbenchPartSite
的用法示例。
在下文中一共展示了IWorkbenchPartSite.getService方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: paste
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
/**
* 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) {
}
}
}
示例4: createViewInstance
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
final VisualInterfaceViewInstance instance = new VisualInterfaceViewInstance ( viewManager, viewManagerContext, viewHolder, descriptor, site.getService ( IEvaluationService.class ) );
instance.init ();
return instance;
}
示例5: createViewInstance
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
@Override
public ViewInstance createViewInstance ( final ViewManager viewManager, final ViewManagerContext viewManagerContext, final ViewInstanceDescriptor descriptor, final Composite viewHolder, final ResourceManager manager, final IWorkbenchPartSite site )
{
final ChartView view = new ChartView ( viewManagerContext, manager, descriptor, viewHolder, (IEvaluationService)site.getService ( IEvaluationService.class ), true );
view.init ();
return view;
}
示例6: setFindBarContextActive
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
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();
}
}
示例7: setSite
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
@Override
protected void setSite(IWorkbenchPartSite newSite) {
newSite.setSelectionProvider(new EnsembleSelectionProvider(this.toString()));
super.setSite(newSite);
IContextService contextService = (IContextService)newSite.getService(IContextService.class);
contextService.activateContext("timeline");
}
示例8: consoleDispatch
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
/**
* @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
*/
@Override
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
Object result = null;
IDocument doc = viewer.getDocument();
try {
IWorkbenchPartSite site = activePart.getSite();
if (site != null) {
IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
if (doc != null && service != null) {
doc.addDocumentListener(KillRing.getInstance());
String cmdId = getId(event, viewer);
if (cmdId != null) {
result = service.executeCommand(cmdId, null);
}
}
}
} catch (CommandException e) {
// Shouldn't happen as the Command id will be null or valid
e.printStackTrace();
} finally {
if (doc != null) {
doc.removeDocumentListener(KillRing.getInstance());
}
// clear kill command flag
KillRing.getInstance().setKill(null, false);
}
MarkUtils.clearConsoleMark(viewer);
return result;
}
示例9: getCommandToBindings
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
/**
* @return a map with the commands -> bindings available.
*/
public HashMap<String, List<TriggerSequence>> getCommandToBindings()
{
HashMap<String, List<TriggerSequence>> commandToBinding = new HashMap<String, List<TriggerSequence>>();
IWorkbenchPartSite site = textEditor.getSite();
IBindingService service = (IBindingService) site.getService(IBindingService.class);
Binding[] bindings = service.getBindings();
for (int i = 0; i < bindings.length; i++)
{
Binding binding = bindings[i];
ParameterizedCommand command = binding.getParameterizedCommand();
if (command != null)
{
String id = command.getId();
// Filter only the actions we decided would be active.
//
// Note: we don't just make all actions active because they conflict with the find bar
// expected accelerators, so, things as Alt+W don't work -- even a second Ctrl+F isn't properly
// treated as specified in the options.
// A different option could be filtering those out and let everything else enabled,
// but this would need to be throughly tested to know if corner-cases work.
if (fCommandToHandler.containsKey(id))
{
List<TriggerSequence> list = commandToBinding.get(id);
if (list == null)
{
list = new ArrayList<TriggerSequence>();
commandToBinding.put(id, list);
}
list.add(binding.getTriggerSequence());
}
// Uncomment to know which actions will be disabled
// else
// {
// try
// {
// System.out.println("Command disabled: " + id + ": " + command.getName());
// }
// catch (NotDefinedException e)
// {
//
// }
// }
}
}
return commandToBinding;
}
示例10: setSite
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
@Override
protected void setSite(IWorkbenchPartSite newSite) {
super.setSite(newSite);
IContextService contextService = (IContextService) newSite.getService(IContextService.class);
contextService.activateContext("timeline");
}
示例11: execute
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
srcLang,tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(
ICommandService.class);
Command command = commandService
.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(
IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {}
}
}
}
return null;
}
示例12: execute
import org.eclipse.ui.IWorkbenchPartSite; //导入方法依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
String tshelp = System.getProperties().getProperty("TSHelp");
String tsstate = System.getProperties().getProperty("TSState");
if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
LoggerFactory.getLogger(ConcordanceSearchHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
System.exit(0);
}
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
Messages.getString("handler.ConcordanceSearchHandler.msgTitle"),
Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file,
xliffEditor.getSrcColumnName(), xliffEditor.getTgtColumnName(), selectText.trim());
dialog.open();
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(
ICommandService.class);
Command command = commandService
.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(
IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {}
}
}
}
return null;
}