org.eclipse.ui.part.MultiPageEditorPart Java Examples

The following examples show how to use org.eclipse.ui.part.MultiPageEditorPart. 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: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void partClosed(IWorkbenchPartReference partRef)
{
	if (partRef instanceof IEditorReference)
	{
		IEditorPart part = (IEditorPart) partRef.getPart(false);
		if (part instanceof MultiPageEditorPart)
		{
			MultiPageEditorPart multi = (MultiPageEditorPart) part;
			if (pageListener != null)
			{
				multi.getSite().getSelectionProvider().removeSelectionChangedListener(pageListener);
			}
		}
	}
	// If it's a search view, remove any query listeners for it!
	else if (partRef instanceof IViewReference)
	{
		IViewPart view = (IViewPart) partRef.getPart(false);
		if (queryListeners.containsKey(view))
		{
			NewSearchUI.removeQueryListener(queryListeners.remove(view));
		}
	}
}
 
Example #2
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void partOpened(IWorkbenchPartReference partRef)
{
	if (partRef instanceof IEditorReference)
	{
		IEditorPart editorPart = (IEditorPart) partRef.getPart(false);
		hijackEditor(editorPart, false);
		if (editorPart instanceof MultiPageEditorPart)
		{
			MultiPageEditorPart multi = (MultiPageEditorPart) editorPart;
			if (pageListener == null)
			{
				pageListener = new ISelectionChangedListener()
				{

					public void selectionChanged(SelectionChangedEvent event)
					{
						hijackOutline();
					}
				};
			}
			multi.getSite().getSelectionProvider().addSelectionChangedListener(pageListener);
		}
		return;
	}

	if (partRef instanceof IViewReference)
	{
		IViewPart view = (IViewPart) partRef.getPart(false);
		hijackView(view, false);
	}
}
 
Example #3
Source File: MarkRing.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Verify that the editor in the location is still in use
 * 
 * @param location
 * @return true if editor is valid
 */
private boolean checkEditor(IBufferLocation location) {
	boolean result = false;
	if (location != null) {
		ITextEditor editor = location.getEditor(); 
		if (editor != null) {
			IEditorInput input = editor.getEditorInput();
			// check all the editor references that match the input for a match
			IEditorReference[] refs = EmacsPlusUtils.getWorkbenchPage().findEditors(input,null, IWorkbenchPage.MATCH_INPUT); 
			for (int i=0; i< refs.length; i++) {
				IEditorPart ed = refs[i].getEditor(false);
				// multi page annoyance
				if (ed instanceof MultiPageEditorPart) {
					IEditorPart[] eds = ((MultiPageEditorPart)ed).findEditors(input);
					for (int j=0; j < eds.length; j++) {
						if (eds[i] == editor) {
							result = true;
							break;
						}
					}
					if (result) {
						break;
					}
				} else {
					if (ed == editor) {
						result = true;
						break;
					}
				}
			}
		}
	}
	return result;
}
 
Example #4
Source File: ISourceViewerFinder.java    From eclipse-multicursor with Eclipse Public License 1.0 5 votes vote down vote up
public static ISourceViewer fromEditorPart(IEditorPart editorPart) {
	Object activeEditor = editorPart;
	if (editorPart instanceof MultiPageEditorPart) {
		MultiPageEditorPart multiPageEditorPart = (MultiPageEditorPart) editorPart;
		activeEditor = multiPageEditorPart.getSelectedPage();
	}
	if (activeEditor instanceof AbstractTextEditor) {
		return fromAbstractTextEditor((AbstractTextEditor) activeEditor);
	} else {
		logger.info("Unable to get ISourceViewer from " + editorPart
				+ " of type " + editorPart.getClass().getCanonicalName());
		return null;
	}
}
 
Example #5
Source File: MultiPageEditorContributor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void setActiveEditor(IEditorPart part) {
  if (activeEditorPart == part)
    return;

  if (null == part)
    return;
  activeEditorPart = part;

  IActionBars actionBars = getActionBars();
  if (actionBars != null) {

    MultiPageEditorPart editor = (MultiPageEditorPart) part;

    actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor,
            ITextEditorActionConstants.DELETE));
    actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(editor,
            ITextEditorActionConstants.UNDO));
    actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(editor,
            ITextEditorActionConstants.REDO));
    actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(editor,
            ITextEditorActionConstants.CUT));
    actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(editor,
            ITextEditorActionConstants.COPY));
    actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(editor,
            ITextEditorActionConstants.PASTE));
    actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(editor,
            ITextEditorActionConstants.SELECT_ALL));
    actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction(editor,
            ITextEditorActionConstants.FIND));
    actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(editor,
            IDEActionFactory.BOOKMARK.getId()));
    actionBars.updateActionBars();
  }
}
 
Example #6
Source File: MarkGlobalHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get the next position off the global mark ring and move to that file and location
 *
 * @param editor
 * @param document
 * @param currentSelection
 * @param norotate - if true, pop else rotate and pop
 * @return NO_OFFSET
 * @throws BadLocationException
 */
protected int doTransform(ITextEditor editor, IDocument document, ITextSelection currentSelection, boolean norotate, boolean isTags)
throws BadLocationException {
	// get editor and offset
	IBufferLocation location = (isTags ? MarkUtils.popTagMark() : MarkUtils.popGlobalMark(norotate));
	if (location != null) {
		if (currentSelection != null &&
				location.getEditor() == editor && location.getOffset() == currentSelection.getOffset()) {
			// if we're already at the global mark location, move to next location
			// recurse with no selection to avoid infinite loop if only one global location
			return doTransform(editor,document,null,norotate, isTags);
		}
		ITextEditor jumpTo = location.getEditor();
		int offset = location.getOffset();
		IWorkbenchPage page = getWorkbenchPage();
		IEditorPart part = jumpTo;
		if (part != null) {
			// move to the correct page
			IEditorPart apart = part;
			IEditorSite esite = part.getEditorSite();
			if (esite instanceof MultiPageEditorSite) {
				apart = ((MultiPageEditorSite)esite).getMultiPageEditor();
				// handle multi page by activating the correct part within the parent
				if (apart instanceof MultiPageEditorPart) {
					((MultiPageEditorPart)apart).setActiveEditor(part);
				}
			}
			// check to make sure the editor is still valid
			if (page.findEditor(apart.getEditorInput()) != null)  {
				// then activate
				page.activate(apart);
				page.bringToTop(apart);
				if (part instanceof ITextEditor) {
					selectAndReveal((ITextEditor) part,offset,offset);
					EmacsPlusUtils.clearMessage(part);
				}
			} else {
				EmacsPlusUtils.showMessage(editor, String.format(BAD_MARK, apart.getTitle()), true);
			}
		}
	} else {
		beep();
	}
	return NO_OFFSET;
}
 
Example #7
Source File: RegisterJumpToHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
 */
public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {

	if (minibufferResult != null) {
		String key = (String)minibufferResult;
		IRegisterLocation location = TecoRegister.getInstance().getLocation(key);
		if (location != null) {
			IWorkbenchPage page = getWorkbenchPage();
			IEditorPart part = location.getEditor(); 
			int offset = location.getOffset();
			if (part != null) {
				// move to the correct page
				IEditorPart apart = part;
				IEditorSite esite = part.getEditorSite();
				if (esite instanceof MultiPageEditorSite) {
					apart = ((MultiPageEditorSite)esite).getMultiPageEditor();
					// handle multi page by activating the correct part within the parent
					if (apart instanceof MultiPageEditorPart) {
						((MultiPageEditorPart)apart).setActiveEditor(part);
					}
				}
				// now activate
				page.activate(apart);
				page.bringToTop(apart);
			} else {
				// restore the resource from the file system
				if (location.getPath() != null) {
					try {
						// loads and activates
						part = IDE.openEditor(page, location.getPath(), true);
						if (part instanceof IEditorPart) {
							if (part instanceof MultiPageEditorPart) {
								IEditorPart[] parts = ((MultiPageEditorPart)part).findEditors(part.getEditorInput());
								//  TODO this will only work on the first load of a multi page
								// There is no supported way to determine the correct sub part in this case
								// Investigate org.eclipse.ui.PageSwitcher (used in org.eclipse.ui.part.MultiPageEditorPart)
								// as a means for locating the correct sub page at this level
								for (int i = 0; i < parts.length; i++) {
									if (parts[i] instanceof ITextEditor) {
										((MultiPageEditorPart)part).setActiveEditor(parts[i]);
										part = parts[i];
										break;
									}
								}
							}
							location.setEditor((ITextEditor)part);
						}
					} catch (PartInitException e) {
						showResultMessage(editor, String.format(BAD_LOCATION,key + ' ' + e.getLocalizedMessage()), true);				
					}
				} else {
					showResultMessage(editor, String.format(NO_LOCATION,key), true);				
				}
			}
			if (part instanceof ITextEditor) {
				((ITextEditor) part).selectAndReveal(offset, 0);
				showResultMessage(editor, String.format(LOCATED, key), false);
			} else {
			
			}
		} else {
			showResultMessage(editor, NO_REGISTER, true);
		}
	}
	return true;
}
 
Example #8
Source File: MultiPageEditorContributor.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the action registed with the given text editor.
 *
 * @param editor the editor
 * @param actionID the action ID
 * @return IAction or null if editor is null.
 */
protected IAction getAction(MultiPageEditorPart editor, String actionID) {
  ITextEditor txtEditor = ((MultiPageEditor) editor).getSourcePageEditor();
  return (txtEditor == null ? null : txtEditor.getAction(actionID));
}