Java Code Examples for org.eclipse.ui.handlers.HandlerUtil#getActivePart()
The following examples show how to use
org.eclipse.ui.handlers.HandlerUtil#getActivePart() .
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: Execute.java From EasyShell with Eclipse Public License 2.0 | 6 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart != null) { String commandID = event.getCommand().getId(); ResourceType resourceType = ResourceType.getFromEnum(event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.resource")); CommandType commandType = CommandType.getFromAction(event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.type")); String commandValue = event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.value"); String commandWorkingDir = event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.workingdir"); CommandTokenizer commandTokenizer = CommandTokenizer.getFromEnum(event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.tokenizer")); ActionDelegate action = EditorPropertyTester.getActionExactResourceType(activePart, resourceType); if (action != null) { action.setResourceType(resourceType); action.setCommandType(commandType); action.setCommandValue(commandValue); action.setCommandWorkingDir(commandWorkingDir); action.setCommandTokenizer(commandTokenizer); Action act = new Action(commandID); action.run((IAction)act); } action = null; } else { Activator.logError("HandlerUtil.getActivePart() returns null: see Eclipse platform bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=242246", null); } return null; }
Example 2
Source File: YankRotateHandler.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Execute directly * * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart apart = HandlerUtil.getActivePart(event); if (apart != null) { int count = extractUniversalCount(event); if (!isUniversalPresent()) { // if default 1, then we want to rotate once 'forward' count++; } IRingBufferElement<?> element = KillRing.getInstance().rotateYankPos(count); if (element != null) { asyncShowMessage(apart, EmacsPlusUtils.normalizeString(element.toString(), MAX_SHOW), false); } } return null; }
Example 3
Source File: RevealInWorkspace.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event); if (sel.isEmpty()) { return null; } final IWorkbenchPart part = HandlerUtil.getActivePart(event); if (!(part instanceof GamaNavigator)) { return null; } final GamaNavigator nav = (GamaNavigator) part; final List<Object> selection = sel.toList(); final List<WrappedFile> newSelection = new ArrayList<>(); for (final Object o : selection) { if (o instanceof LinkedFile) { newSelection.add(((LinkedFile) o).getTarget()); } } if (newSelection.isEmpty()) { return null; } nav.selectReveal(new StructuredSelection(newSelection)); return this; }
Example 4
Source File: BaseYankHandler.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * 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 5
Source File: ExpandLevelHandler.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { // assumes to expand to level 1 if not specified int level = 1; String levelStr = event.getParameter(LEVEL); if (levelStr != null) { level = Integer.parseInt(levelStr); } IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof ContentOutline) { IPage page = ((ContentOutline) part).getCurrentPage(); if (page instanceof CommonOutlinePage) { CommonOutlinePage outlinePage = (CommonOutlinePage) page; // we want to expand to the specified level and collapse everything below outlinePage.collapseAll(); outlinePage.expandToLevel(level); } } return null; }
Example 6
Source File: ExpandAllHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof ContentOutline) { IPage page = ((ContentOutline) part).getCurrentPage(); if (page instanceof CommonOutlinePage) { ((CommonOutlinePage) page).expandAll(); } } return null; }
Example 7
Source File: PrintRecipeHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private List<IPrescription> sortPrescriptions(List<IPrescription> prescRecipes, ExecutionEvent event){ SorterAdapter sorter = new SorterAdapter(event); IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof MedicationView) { return sorter.getSorted(prescRecipes); } return prescRecipes; }
Example 8
Source File: PrintTakingsListHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private List<IPrescription> sortPrescriptions(List<IPrescription> prescRecipes, ExecutionEvent event){ SorterAdapter sorter = new SorterAdapter(event); IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof MedicationView) { return sorter.getSorted(prescRecipes); } return prescRecipes; }
Example 9
Source File: EmacsPlusCmdHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Get the current active editor * @param event * @return the current active editor, else null if some other part is active * * @throws ExecutionException */ protected IEditorPart getEditor(ExecutionEvent event) throws ExecutionException { IEditorPart epart = HandlerUtil.getActiveEditorChecked(event); if (HandlerUtil.getActivePart(event) != epart) { // When something other than the editor is active (e.g. the JavaStackTraceConsole) // Then don't return the editor return null; } return epart; }
Example 10
Source File: TmfViewBaseHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof TmfView) { execute((TmfView) part); } } return null; }
Example 11
Source File: CollapseAllHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof ContentOutline) { IPage page = ((ContentOutline) part).getCurrentPage(); if (page instanceof CommonOutlinePage) { ((CommonOutlinePage) page).collapseAll(); } } return null; }
Example 12
Source File: All.java From EasyShell with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // get resource type IWorkbenchPart activePart = HandlerUtil.getActivePart(event); ActionDelegate action = EditorPropertyTester.getActionExactResourceType(activePart, ResourceType.resourceTypeFileOrDirectory); if (action != null) { // load the preferences list = getMenuDataList(action.getCommonResourceType()); if (list.size() > 0) { IWorkbenchWindow workbenchWindow = activePart.getSite().getWorkbenchWindow(); if (list.size() == 1) { Utils.executeCommand(workbenchWindow.getWorkbench(), list.get(0), false); } else { // create and open a new dialog // close the old dialog if (dialog != null) { dialog.close(); dialog = null; } if (usePopup) { dialog = new ExecuteCommandPopup(workbenchWindow.getShell(), workbenchWindow.getWorkbench(), list, getTitle()); } else { dialog = new ExecuteCommandDialog(workbenchWindow.getShell(), workbenchWindow.getWorkbench(), list, getTitle()); } dialog.open(); } } } return null; }
Example 13
Source File: OpenWith.java From LogViewer with Eclipse Public License 2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart part = HandlerUtil.getActivePart(event); IObjectActionDelegate action = EditorPropertyTester.hasResourceSelection(part); if (action == null) { action = EditorPropertyTester.hasAbstractConsole(part); } if (action != null) action.run(null); return null; }
Example 14
Source File: TimeGraphBaseHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof AbstractTimeGraphView) { AbstractTimeGraphView view = (AbstractTimeGraphView) part; execute(view); } return null; }
Example 15
Source File: NextSplitPointHandler.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor"; IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); final Shell shell = window.getShell(); XLIFFEditorImplWithNatTable xliffEditor = null; IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart instanceof IEditorPart) { if (XLIFF_EDITOR_ID.equals(activePart.getSite().getId())) { xliffEditor = (XLIFFEditorImplWithNatTable) activePart; List<String> splitPointList = xliffEditor.getSplitXliffPoints(); if (splitPointList.size() <= 0) { MessageDialog.openInformation(shell, Messages.getString("all.dialog.info"), Messages.getString("NextSplitPointHandler.msg.nullSplitPoint")); return null; } final XLFHandler xlfHander = xliffEditor.getXLFHandler(); // 先对 splitPointList 进行排序 Collections.sort(splitPointList, new Comparator<String>() { public int compare(String rowId1, String rowId2) { int rowIndex1 = xlfHander.getRowIndex(rowId1); int rowIndex2 = xlfHander.getRowIndex(rowId2); return rowIndex1 > rowIndex2 ? 1 : -1; } }); List<String> selectionRowIdList = xliffEditor.getSelectedRowIds(); if (selectionRowIdList != null && selectionRowIdList.size() > 0) { curSelectionRowId = selectionRowIdList.get(0); } // 开始定位,定位之前让 nattable 恢复默认布局 xliffEditor.resetOrder(); if (curSelectionRowId == null) { curSelectionRowId = splitPointList.get(0); }else { int curSelectionRowIndex = xlfHander.getRowIndex(curSelectionRowId); for (String curRowId : splitPointList) { int pointRowIndex = xlfHander.getRowIndex(curRowId); if (pointRowIndex > curSelectionRowIndex) { curSelectionRowId = curRowId; xliffEditor.jumpToRow(curSelectionRowId); break; } } } } } return null; }
Example 16
Source File: CloseViewHandler.java From eclipse-extras with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute( ExecutionEvent event ) { IWorkbenchPart activePart = HandlerUtil.getActivePart( event ); closeView( activePart ); return null; }
Example 17
Source File: EmacsPlusCmdHandler.java From e4macs with Eclipse Public License 1.0 | 4 votes |
/** * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @SuppressWarnings("unchecked") public Object execute(ExecutionEvent event) throws ExecutionException { ITextEditor editor = getTextEditor(event); if (editor == null) { if (isWindowCommand()) { Object result = checkExecute(event); if (result == Check.Fail) { beep(); result = null; } return result; } else if (isConsoleCommand()) { // intercept and dispatch execution if console supported and used in a console view IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart != null && (activePart instanceof IConsoleView) && (activePart instanceof PageBookView)) { IPage textPage = ((PageBookView)activePart).getCurrentPage(); if (textPage instanceof TextConsolePage) { return ((IConsoleDispatch)this).consoleDispatch(((TextConsolePage)textPage).getViewer(),(IConsoleView)activePart,event); } } } } try { setThisEditor(editor); isEditable = getEditable(); if (editor == null || isBlocked()) { beep(); asyncShowMessage(editor, INEDITABLE_BUFFER, true); return null; } // Retrieve the universal-argument parameter value if passed if (extractUniversalCount(event) != 1) { // check if we should dispatch a related command based on the universal argument String dispatchId = checkDispatchId(event.getCommand().getId()); if (dispatchId != null) { // recurse on new id (inverse or arg value driven) return dispatchId(editor, dispatchId, getParams(event.getCommand(), event.getParameters())); } } setThisDocument(editor.getDocumentProvider().getDocument(editor.getEditorInput())); // Get the current selection ISelectionProvider selectionProvider = editor.getSelectionProvider(); ITextSelection selection = (ITextSelection) selectionProvider.getSelection(); preTransform(editor, selection); return transformWithCount(editor, getThisDocument(), selection, event); } finally { // normal commands clean up here if (isTransform()) { postExecute(); } } }
Example 18
Source File: SortMoveHandler.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException{ String direction = event.getParameter("ch.elexis.core.ui.medication.sortmove.direction"); //$NON-NLS-1$ if (direction != null) { IWorkbenchPart part = HandlerUtil.getActivePart(event); if (part instanceof MedicationView) { MedicationComposite composite = ((MedicationView) part).getMedicationComposite(); composite.setViewerSortOrder(ViewerSortOrder.MANUAL); TableViewer activeViewer = composite.getActiveTableViewer(); if (activeViewer != null) { int selectionIndex = activeViewer.getTable().getSelectionIndex(); if(moveNotPossible(selectionIndex, activeViewer, direction)) { return null; } List<TableItem> asList = Arrays.asList(activeViewer.getTable().getItems()); if (directionIsUp(direction)) { Collections.swap(asList, selectionIndex, selectionIndex - 1); } else { Collections.swap(asList, selectionIndex, selectionIndex + 1); } for (int i = 0; i < asList.size(); i++) { TableItem tableItem = asList.get(i); MedicationTableViewerItem pres = (MedicationTableViewerItem) tableItem.getData(); pres.setOrder(i); } activeViewer.refresh(); if (directionIsUp(direction)) { activeViewer.getTable().setSelection(selectionIndex - 1); } else { activeViewer.getTable().setSelection(selectionIndex + 1); } } } } return null; }
Example 19
Source File: CppStyleHandler.java From CppStyle with MIT License | 3 votes |
protected ICEditor getSaveableEditor(ExecutionEvent event) { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart instanceof ICEditor) { return (ICEditor) activePart; } return null; }