Java Code Examples for org.eclipse.ui.IEditorReference#getPart()

The following examples show how to use org.eclipse.ui.IEditorReference#getPart() . 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: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static IFile getEditorFile( IEditorReference fileRef )
{
	if ( fileRef != null )
	{
		IEditorPart part = (IEditorPart) fileRef.getPart( false );
		if ( part != null )
		{
			IEditorInput input = part.getEditorInput( );

			if ( input != null && input instanceof IFileEditorInput )
			{
				return ( (IFileEditorInput) input ).getFile( );
			}
		}
	}
	return null;
}
 
Example 2
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkAndAddToEditorLists(
		List<IEditorPart> openedEditorRefs,
		List<IEditorPart> openedDirtyEditorRefs, IEditorReference fileRef )
{
	if ( fileRef != null )
	{
		IEditorPart part = (IEditorPart) fileRef.getPart( false );
		if ( part != null )
		{
			if ( part.isDirty( ) )
			{
				openedDirtyEditorRefs.add( part );
			}
			openedEditorRefs.add( part );
		}
	}
}
 
Example 3
Source File: NextEditorHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static void switchEditor(IWorkbenchPage activePage, boolean next)
{
	IEditorPart activeEditor = activePage.getActiveEditor();
	if (activeEditor != null)
	{
		IEditorReference[] editorReferences = activePage.getEditorReferences();
		if (editorReferences != null && editorReferences.length >= 2)
		{
			List<IEditorPart> editorsList = new LinkedList<IEditorPart>();
			for (IEditorReference editorReference : editorReferences)
			{
				IWorkbenchPart editorPart = editorReference.getPart(true);
				if (editorPart instanceof IEditorPart)
				{
					editorsList.add((IEditorPart) editorPart);
				}
			}
			int activeEditorIndex = editorsList.indexOf(activeEditor);
			int toEditorIndex = ((activeEditorIndex == -1) ? 0 : (activeEditorIndex + (next ? 1 : -1)));
			if (toEditorIndex < 0)
			{
				toEditorIndex = editorsList.size() - 1;
			}
			else if (toEditorIndex >= editorsList.size())
			{
				toEditorIndex = 0;
			}
			activePage.activate(editorsList.get(toEditorIndex));
		}
	}
}
 
Example 4
Source File: TabbedPropertySynchronizerListener.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void selectionChanged(final SelectionChangedEvent event) {
    final ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        return;
    }
    final EObject element = unwrap(selection);
    final IEditorReference activeEditorReference = activeEditorReference(activePage);
    final IWorkbenchPart editorPart = activeEditorReference.getPart(false);
    if (editorPart instanceof DiagramEditor) {
        final DiagramEditor diagramEditor = (DiagramEditor) editorPart;
        try {
            final IGraphicalEditPart editPart = editPartResolver.findEditPart(diagramEditor.getDiagramEditPart(), element);
            final ITabbedPropertySelectionProvider defaultProvider = findDefaultProvider(editorPart, editPart);
            updateDiagramSelection(diagramEditor, editPart);
            final ITabbedPropertySelectionProvider selectionProvider = registry.findSelectionProvider(element, activeEditorReference, defaultProvider);
            IViewPart part = null;
            try {
                part = activePage.showView(selectionProvider.viewId());
            } catch (final PartInitException e1) {
                return;
            }
            if (part != null) {
                updateSelectedTabInPage(element, selectionProvider, part);
            }
        } catch (final EditPartNotFoundException e) {
            BonitaStudioLog.debug("No edit part found for semantic element: " + element, Activator.PLUGIN_ID);
        }
    }
}
 
Example 5
Source File: BonitaOperationHistory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void dispose(final IUndoContext context, final boolean flushUndo, final boolean flushRedo, final boolean flushContext) {
    // dispose of any limit that was set for the context if it is not to be
    // used again.
    if (context instanceof EditingDomainUndoContext) {
        final EditingDomainUndoContext editingDomainContext = (EditingDomainUndoContext) context;
        final EditingDomain editingDomain = editingDomainContext.getEditingDomain();
        if (PlatformUI.isWorkbenchRunning()
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null) {

            final IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
            for (final IEditorReference editorRef : editorReferences) {
                try {
                    final IWorkbenchPart part = editorRef.getPart(false);
                    if (part instanceof DiagramEditor) {
                        final DiagramEditor editor = (DiagramEditor) part;
                        if (editor.getEditingDomain() != null && editor.getEditingDomain().equals(editingDomain)) {
                            return;// do not dispose if the editing domain
                            // is else
                        }
                    }
                } catch (final Exception e) {
                    BonitaStudioLog.error(e);
                }
            }
        }
    }
    defaultOperationHistory.dispose(context, flushUndo, flushRedo, flushContext);
}