下面列出了org.eclipse.jface.viewers.ILabelProviderListener#org.eclipse.ui.IEditorPart 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int lastRow = handler.countEditableTransUnit() - 1;
if (lastSelectedRow == lastRow) {
lastSelectedRow = lastRow - 1;
}
xliffEditor.jumpToRow(lastSelectedRow + 1);
return null;
}
public void earlyStartup() {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
addListener(part);
}
}
window.getPartService().addPartListener(new PartListener());
}
workbench.addWindowListener(new WindowListener());
}
});
}
/**
* @return
*/
public static DebugJsEditor getActiveJsEditor( )
{
IWorkbenchWindow window = PlatformUI.getWorkbench( )
.getActiveWorkbenchWindow( );
if ( window != null )
{
IWorkbenchPage pg = window.getActivePage( );
if ( pg != null )
{
IEditorPart editor = pg.getActiveEditor( );
if ( editor != null )
{
if ( editor instanceof DebugJsEditor )
{
return (DebugJsEditor) editor;
}
}
}
}
return null;
}
public void modifyContext(CommandElement command, CommandContext context)
{
IEditorPart editor = this.getActiveEditor();
if (editor != null && command != null)
{
Ruby runtime = command.getRuntime();
if (runtime != null)
{
IRubyObject rubyInstance = ScriptUtils.instantiateClass(runtime, ScriptUtils.RUBLE_MODULE,
EDITOR_RUBY_CLASS, JavaEmbedUtils.javaToRuby(runtime, editor));
context.put(EDITOR_PROPERTY_NAME, rubyInstance);
}
else
{
context.put(EDITOR_PROPERTY_NAME, null);
}
}
}
public void onDone()
{
super.onDone();
getTraceExpressionsInformation();
processTraceForTraceExplorer();
final IEditorPart activeEditor = UIHelper.getActiveEditor();
if (activeEditor != null) {
if (activeEditor instanceof ModelEditor) {
final ModelEditor activeModelEditor = (ModelEditor) activeEditor;
if (activeModelEditor.getModel() != null) {
UIHelper.runUIAsync(() -> {
TLCErrorView.updateErrorView(activeModelEditor);
});
}
}
}
}
/**
* Sets the active editor.
*
* @param part the new active editor
*/
@Override
public void setActiveEditor(IEditorPart part) {
super.setActiveEditor(part);
if (mActiveEditorPart != part && part instanceof AnnotationEditor) {
mActiveEditorPart = (AnnotationEditor) part;
mActiveEditorPart.setStatusField(mStatusLineModeItem, ID);
Type annotationType = mActiveEditorPart.getAnnotationMode();
if (annotationType != null) {
mStatusLineModeItem.setText(annotationType.getShortName());
}
}
}
public void setSelection( ISelection selection )
{
IEditorPart activeEditor = ( (FormEditor) getMultiPageEditor( ) ).getActivePageInstance( );
if ( activeEditor != null )
{
ISelectionProvider selectionProvider = activeEditor.getSite( )
.getSelectionProvider( );
if ( selectionProvider != null )
selectionProvider.setSelection( selection );
}
else
{
this.globalSelection = selection;
fireSelectionChanged( new SelectionChangedEvent( this,
globalSelection ) );
}
}
@Override
public void launch(IEditorPart editor, String mode) {
IEditorInput input = editor.getEditorInput();
IFile dockerfile = (IFile) input.getAdapter(IFile.class);
IPath dockerfilePath = null;
if (dockerfile != null) {
dockerfilePath = dockerfile.getLocation().removeLastSegments(1);
}
if (dockerfilePath == null) {
ILocationProvider locationProvider = (ILocationProvider) input.getAdapter(ILocationProvider.class);
if (locationProvider != null) {
dockerfilePath = locationProvider.getPath(input);
}
}
if (dockerfilePath != null) {
launch(dockerfile, dockerfilePath);
}
}
/**
* Returns the nested editor instance open on moduleName (without the .tla extension).
* Returns null if no such editor is open in this model editor.
*
* @param moduleName
* @return
*/
public ITextEditor getSavedModuleEditor(String moduleName)
{
for (int i = 0; i < getPageCount(); i++)
{
IEditorPart nestedEditor = getEditor(i);
if (nestedEditor != null
&& nestedEditor instanceof ITextEditor
&& ((FileEditorInput) nestedEditor.getEditorInput()).getName().equals(
ResourceHelper.getModuleFileName(moduleName)))
{
return (ITextEditor) nestedEditor;
}
}
return null;
}
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
if (storages != null && storages.hasNext()) {
try {
IStorage storage = storages.next().getFirst();
IEditorInput editorInput = EditorUtils.createEditorInput(storage);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
selectAndReveal(editor, uri, crossReference, indexInList, select);
return EditorUtils.getXtextEditor(editor);
} catch (WrappedException e) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
} catch (PartInitException partInitException) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
}
}
return null;
}
public static IDominoDesignerProject getDominoDesignerProject (IEditorPart editorPart) {
if ( editorPart != null ) {
if ( editorPart.getEditorInput() instanceof IFileEditorInput ) {
IFileEditorInput file = (IFileEditorInput)editorPart.getEditorInput();
IProject prj = file.getFile().getProject();
try {
IDominoDesignerProject desPrj = DominoResourcesPlugin.getDominoDesignerProject(prj);
return desPrj;
} catch (NsfException e) {
if (BluemixLogger.BLUEMIX_LOGGER.isErrorEnabled()) {
BluemixLogger.BLUEMIX_LOGGER.errorp(BluemixUtil.class, "getDominoDesignerProject", e, "Failed to get Domino Designer Project"); // $NON-NLS-1$ $NLE-BluemixUtil.FailedtogetDominoDesignerProject-2$
}
}
}
if (editorPart instanceof ManifestMultiPageEditor) {
return ((ManifestMultiPageEditor)editorPart).getDesignerProject();
}
}
return null;
}
/**
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof IXliffEditor)) {
return null;
}
PrefrenceParameters ps = PrefrenceParameters.getInstance();
if (!ps.isGoogleState()) {
MessageDialog.openError(window.getShell(),
Messages.getString("handler.ExecuteGoogleTransHandler.msgTitle"),
Messages.getString("handler.ExecuteGoogleTransHandler.msg"));
return null;
}
final IXliffEditor xliffEditor = (IXliffEditor) editor;
final int[] selectedRowIndexs = xliffEditor.getSelectedRows();
if (selectedRowIndexs.length == 0) {
return null;
}
ISimpleMatcher matcher = new SimpleMatcherGoogleImpl();
IViewPart viewPart = window.getActivePage().findView(MatchViewPart.ID);
if (viewPart != null && viewPart instanceof MatchViewPart) {
MatchViewPart matchView = (MatchViewPart) viewPart;
matchView.manualExecSimpleTranslation(selectedRowIndexs[0], xliffEditor, matcher);
}
return null;
}
private IProject getProject() {
IEditorPart editorPart = HybridUI.getDefault().getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart.getEditorInput() instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) editorPart
.getEditorInput();
IProject activeProject = input.getFile().getProject();
return activeProject;
} else {
return null;
}
}
public static IOpenable getJavaInput(IEditorPart part) {
IEditorInput editorInput= part.getEditorInput();
if (editorInput != null) {
IJavaElement input= (IJavaElement)editorInput.getAdapter(IJavaElement.class);
if (input instanceof IOpenable) {
return (IOpenable) input;
}
}
return null;
}
private void removeAndUpdateUndoActions(Node n, IAction undo, IAction redo, CommandStack stack, IActionBars bars) {
RemoveNodeCommand cmd = new RemoveNodeCommand(n);
XPagesEditorUtils.executeCommand(cmd, (IEditorPart)null);
if(stack != null){
if(undo != null){
undo.setEnabled(stack.canUndo());
}
if(redo != null){
redo.setEnabled(stack.canRedo());
}
if(bars != null){
bars.updateActionBars();
}
}
}
/**
* @return Returns the {@link IEditorPart} for the given editor id without
* opening the editor or null if no editor with the given id exists.
* Contrary to the Eclipse facilities to find and editor, this method
* does not initialize/render/configure the editor instance. It is left
* to the callee to properly initialize the editor instance by e.g.
* adding it to a MultipageEditor.
* @throws CoreException
*/
public static IEditorPart findEditor(final String editorId) throws CoreException {
final IExtensionRegistry registry = Platform.getExtensionRegistry();
final IConfigurationElement[] elements = registry.getConfigurationElementsFor(PlatformUI.PLUGIN_ID, "editors");
for (IConfigurationElement ice : elements) {
if (editorId.equals(ice.getAttribute("id"))) {
return (IEditorPart) ice.createExecutableExtension("class");
}
}
return null;
}
private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {
if (file == null)
throwPartInitException(JavaEditorMessages.EditorUtility_file_must_not_be_null);
IWorkbenchPage p= JavaPlugin.getActivePage();
if (p == null)
throwPartInitException(JavaEditorMessages.EditorUtility_no_active_WorkbenchPage);
IEditorPart editorPart= IDE.openEditor(p, file, activate);
initializeHighlightRange(editorPart);
return editorPart;
}
/**
* Close any duplicate editors that match this one
*
* @param editor
* @return true if any were closed
*/
boolean closeOthers(IEditorPart editor) {
IWorkbenchPage page = EmacsPlusUtils.getWorkbenchPage();
int pre = EmacsPlusUtils.getSortedEditors(page).length;
if (isSplitSelf()) {
try {
EmacsPlusUtils.executeCommand(IEmacsPlusCommandDefinitionIds.CLOSE_OTHER_INSTANCES, null, editor);
} catch (Exception e) {}
}
return (pre != EmacsPlusUtils.getSortedEditors(page).length);
}
private static Object[] openSaveDialog(Shell shell, Collection<IEditorPart> editors) {
ListSelectionDialog lsd = new ListSelectionDialog(shell, editors, new ArrayContentProvider(),
getLabelProvider(), "Select resources to save:");
lsd.setInitialSelections(editors.toArray());
lsd.setTitle("Save and Launch");
lsd.open();
return lsd.getResult();
}
@Override
public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart editorpart) {
IResource launchableResource = getLaunchableResource(editorpart);
if (launchableResource != null) {
return getLaunchConfigurations(launchableResource.getLocation().toFile());
}
return getLaunchConfigurations(SelectionUtils.getFile(editorpart.getEditorInput(), this::canLaunch));
}
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
xliffEditor.jumpToRow(0);
return null;
}
/**
* Sets the current selection for the given range.
*
* @param editor the editor to be operated on
* @param offset the offset of the range, must not be negative
* @param length the length of the range, must not be negative
*/
public static void setSelection(IEditorPart editor, int offset, int length)
{
ISelectionProvider provider = editor.getEditorSite().getSelectionProvider();
if (provider != null) {
IWorkbenchPart activePart = WorkbenchUtils.getActivePart();
if (activePart instanceof IEditorPart) {
IWorkbenchPage page = WorkbenchUtils.getActivePage();
page.getNavigationHistory().markLocation((IEditorPart) activePart);
}
provider.setSelection(new TextSelection(offset, length));
}
}
/** (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
String selectPureText ="";
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
selectPureText= xliffEditor.getSelectPureText();
}
try {
IViewPart showView = getActivePage().showView(BrowserViewPart.ID);
if(showView instanceof BrowserViewPart){
BrowserViewPart browserViewPart = (BrowserViewPart) showView;
browserViewPart.setKeyWord(selectPureText,true);
}
} catch (PartInitException e) {
e.printStackTrace();
logger.error("", e);
}
// 暂时去掉VIEW弹出显示
// IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// if (activePage instanceof WorkbenchPage) {
// WorkbenchPage workbenchPage = (WorkbenchPage) activePage;
// IViewReference findViewReference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
// .findViewReference(BrowserViewPart.ID);
// workbenchPage.detachView(findViewReference);
// }
return null;
}
private IEditorPart getActiveEditor() {
IWorkbenchPage activePage= JavaPlugin.getActivePage();
if (activePage != null) {
return activePage.getActiveEditor();
}
return null;
}
private ITextEditor getActiveEditor() {
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page= window.getActivePage();
if (page != null) {
IEditorPart editor= page.getActiveEditor();
if (editor instanceof ITextEditor)
return (JavaEditor) editor;
}
}
return null;
}
public static Optional<IEditorPart> findOpenedEditor(Function<IEditorPart, Boolean> editorInstanceValidator) {
if (PlatformUI.isWorkbenchRunning()
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
return Arrays.asList(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences())
.stream()
.map(ref -> ref.getEditor(false))
.filter(editorInstanceValidator::apply)
.findFirst();
}
return Optional.empty();
}
public boolean hasVariable(IEditorPart editor, String variable) {
boolean result = false;
if (editor != null && variable != null) {
Map<String, Object> table = bufferlocal.get(editor);
if (table != null) {
result = table.containsKey(variable);
}
}
return result;
}
private PropertiesAssistContext createAssistContext(IQuickAssistInvocationContext invocationContext) {
IEditorPart editorPart= fAssistant.getEditor();
IFile file= (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
ISourceViewer sourceViewer= invocationContext.getSourceViewer();
IType accessorType= ((PropertiesFileEditor) editorPart).getAccessorType();
return new PropertiesAssistContext(sourceViewer, invocationContext.getOffset(), invocationContext.getLength(), file, sourceViewer.getDocument(), accessorType);
}
private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
try {
IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
HashMap<String, Integer> attributes= new HashMap<String, Integer>(4);
attributes.put(IMarker.CHAR_START, new Integer(offset));
attributes.put(IMarker.CHAR_END, new Integer(offset + length));
marker.setAttributes(attributes);
IDE.gotoMarker(editor, marker);
marker.delete();
} catch (CoreException e) {
throw new PartInitException(SearchMessages.JavaSearchResultPage_error_marker, e);
}
}
/**
* This method closes the currently open editor.
*
* @param editor
*/
public static void closeEditor(final IEditorPart editor) {
final IWorkbenchPage workbenchPage = UIUtils.getCurrentlyOpenPage();
if (workbenchPage != null) {
workbenchPage.closeEditor(editor, true);
}
}