org.eclipse.ui.part.ShowInContext Java Examples

The following examples show how to use org.eclipse.ui.part.ShowInContext. 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: N4JSEditor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Provides input so that the Project Explorer can locate the editor's input in its tree.
 */
@Override
public ShowInContext getShowInContext() {
	IEditorInput editorInput = getEditorInput();
	if (editorInput instanceof FileEditorInput) {
		FileEditorInput fei = (FileEditorInput) getEditorInput();
		return new ShowInContext(fei.getFile(), null);
	} else if (editorInput instanceof XtextReadonlyEditorInput) {
		XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
		IStorage storage;
		try {
			storage = readOnlyEditorInput.getStorage();
			return new ShowInContext(storage.getFullPath(), null);
		} catch (CoreException e) {
			// Do nothing
		}
	}
	return new ShowInContext(null, null);
}
 
Example #2
Source File: LangOutlinePage.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected IShowInTarget getShowInTarget() {
	return new IShowInTarget() {
		@Override
		public boolean show(ShowInContext context) {
			StructureElement structureElement = getStructureElementFor(context.getSelection());
			
			if(structureElement != null) {
				setSelection(new StructuredSelection(structureElement));
				return true;
			}
			
			return false;
		}

	};
}
 
Example #3
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the <code>IShowInTarget</code> for this view.
 *
 * @return the {@link IShowInTarget}
 */
protected IShowInTarget getShowInTarget() {
	return new IShowInTarget() {
		public boolean show(ShowInContext context) {
			ISelection sel= context.getSelection();
			if (sel instanceof ITextSelection) {
				ITextSelection tsel= (ITextSelection) sel;
				int offset= tsel.getOffset();
				IJavaElement element= fEditor.getElementAt(offset);
				if (element != null) {
					setSelection(new StructuredSelection(element));
					return true;
				}
			} else if (sel instanceof IStructuredSelection) {
				setSelection(sel);
				return true;
			}
			return false;
		}
	};
}
 
Example #4
Source File: PydevPackageExplorer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Implements the 'show in...' action
 */
@Override
public boolean show(ShowInContext context) {
    Object elementOfInput = null;
    ISelection selection = context.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
        if (structuredSelection.size() == 1) {
            elementOfInput = structuredSelection.getFirstElement();
        }
    }

    Object input = context.getInput();
    if (input instanceof IEditorInput) {
        elementOfInput = getElementOfInput((IEditorInput) context.getInput());
    }

    return elementOfInput != null && tryToReveal(elementOfInput);
}
 
Example #5
Source File: QuickOutline.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleSelection() {
    ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();

    if (selection != null) {
        Object element = selection.getFirstElement();

        if (element instanceof AbstractNode) {
            Model model = ((AbstractNode) element).getModel();

            if (model.getPath() != null) {
                DocumentUtils.openAndReveal(model.getPath(), selection);
            } else {
                editor.show(new ShowInContext(null, selection));
            }
        }
    }
}
 
Example #6
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean show(ShowInContext context) {
    ISelection selection = context.getSelection();

    if (selection instanceof IStructuredSelection) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();

        if (selected instanceof AbstractNode) {
            Position position = ((AbstractNode) selected).getPosition(getSourceViewer().getDocument());
            selectAndReveal(position.getOffset(), position.getLength());
            return true;
        }
    }

    return false;
}
 
Example #7
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean show(ShowInContext context) {
	ISelection selection= context.getSelection();
	if (selection instanceof IStructuredSelection) {
		// fix for 64634 Navigate/Show in/Package Explorer doesn't work
		IStructuredSelection structuredSelection= ((IStructuredSelection) selection);
		if (structuredSelection.size() == 1) {
			int res= tryToReveal(structuredSelection.getFirstElement());
			if (res == IStatus.OK)
				return true;
			if (res == IStatus.CANCEL)
				return false;
		} else if (structuredSelection.size() > 1) {
			selectReveal(structuredSelection);
			return true;
		}
	}

	Object input= context.getInput();
	if (input instanceof IEditorInput) {
		Object elementOfInput= getInputFromEditor((IEditorInput) input);
		return elementOfInput != null && (tryToReveal(elementOfInput) == IStatus.OK);
	}

	return false;
}
 
Example #8
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the <code>IShowInSource</code> for this view.
 * @return returns the <code>IShowInSource</code>
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
			getSite().getSelectionProvider().getSelection());
		}
	};
}
 
Example #9
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return Returns the <code>IShowInSource</code> for this view.
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
			getSite().getSelectionProvider().getSelection());
		}
	};
}
 
Example #10
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the <code>IShowInSource</code> for this view.
 *
 * @return the {@link IShowInSource}
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				null,
				getSite().getSelectionProvider().getSelection());
		}
	};
}
 
Example #11
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the <code>IShowInSource</code> for this view.
 */
private IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(null, fSelectionProviderMediator.getSelection());
		}
	};
}
 
Example #12
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the <code>IShowInSource</code> for this view.
 * @return the <code>IShowInSource</code>
 */
protected IShowInSource getShowInSource() {
	return new IShowInSource() {
		public ShowInContext getShowInContext() {
			return new ShowInContext(
				getTreeViewer().getInput(),
				getTreeViewer().getSelection());
		}
	};
}
 
Example #13
Source File: AbstractSearchIndexResultPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public Object getAdapter(Class<?> adapter) {
    if (IShowInTargetList.class.equals(adapter)) {
        return SHOW_IN_TARGET_LIST;
    }

    if (adapter == IShowInSource.class) {
        ISelectionProvider selectionProvider = getSite().getSelectionProvider();
        if (selectionProvider == null) {
            return null;
        }

        ISelection selection = selectionProvider.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = ((StructuredSelection) selection);
            final Set<Object> newSelection = new HashSet<>(structuredSelection.size());
            Iterator<?> iter = structuredSelection.iterator();
            while (iter.hasNext()) {
                Object element = iter.next();
                if (element instanceof ICustomLineElement) {
                    element = ((ICustomLineElement) element).getParent();
                }
                newSelection.add(element);
            }

            return new IShowInSource() {
                @Override
                public ShowInContext getShowInContext() {
                    return new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection)));
                }
            };
        }
        return null;
    }

    return null;
}
 
Example #14
Source File: DocumentUtils.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens the editor for the file located at the given path and reveal the selection.
 * 
 * @param path
 * @param selection
 */
public static void openAndReveal(IPath path, ISelection selection) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IFile file = root.getFile(path);
    final IEditorPart editor = openEditor(file);

    if (editor instanceof IShowInTarget) {
        IShowInTarget showIn = (IShowInTarget) editor;
        showIn.show(new ShowInContext(null, selection));
    }
}
 
Example #15
Source File: TypeScriptSearchResultPage.java    From typescript.java with MIT License 5 votes vote down vote up
public Object getAdapter(Class adapter) {
	if (IShowInTargetList.class.equals(adapter)) {
		return SHOW_IN_TARGET_LIST;
	}

	if (adapter == IShowInSource.class) {
		ISelectionProvider selectionProvider= getSite().getSelectionProvider();
		if (selectionProvider == null)
			return null;

		ISelection selection= selectionProvider.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= ((StructuredSelection)selection);
			final Set newSelection= new HashSet(structuredSelection.size());
			Iterator iter= structuredSelection.iterator();
			while (iter.hasNext()) {
				Object element= iter.next();
				if (element instanceof LineElement)
					element= ((LineElement)element).getParent();
				newSelection.add(element);
			}

			return new IShowInSource() {
				public ShowInContext getShowInContext() {
					return new ShowInContext(null, new StructuredSelection(new ArrayList(newSelection)));
				}
			};
		}
		return null;
	}

	return null;
}
 
Example #16
Source File: BaseOutlinePage.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean show(ShowInContext context) {
    linkWithEditor.doLinkOutlinePosition(this.editorView, this,
            EditorUtils.createTextSelectionUtils(this.editorView));
    return true;
}
 
Example #17
Source File: ProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
* @generated
*/
public ShowInContext getShowInContext() {
	return new ShowInContext(getEditorInput(), getNavigatorSelection());
}
 
Example #18
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object getAdapter(Class required) {

	if (IContentOutlinePage.class.equals(required)) {
		if (fOutlinePage == null && getSourceViewer() != null && isCalledByOutline())
			fOutlinePage= createOutlinePage();
		return fOutlinePage;
	}

	if (IEncodingSupport.class.equals(required))
		return fEncodingSupport;

	if (required == IShowInTargetList.class) {
		return new IShowInTargetList() {
			public String[] getShowInTargetIds() {
				return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_OUTLINE, JavaPlugin.ID_RES_NAV };
			}

		};
	}

	if (required == IShowInSource.class) {
		IJavaElement inputJE= getInputJavaElement();
		if (inputJE instanceof ICompilationUnit && !JavaModelUtil.isPrimary((ICompilationUnit) inputJE))
			return null;

		return new IShowInSource() {
			public ShowInContext getShowInContext() {
				return new ShowInContext(null, null) {
					/*
					 * @see org.eclipse.ui.part.ShowInContext#getInput()
					 * @since 3.4
					 */
					@Override
					public Object getInput() {
						if (isBreadcrumbActive())
							return null;

						return getEditorInput();
					}

					/*
					 * @see org.eclipse.ui.part.ShowInContext#getSelection()
					 * @since 3.3
					 */
					@Override
					public ISelection getSelection() {
						if (isBreadcrumbActive())
							return getBreadcrumb().getSelectionProvider().getSelection();

						try {
							IJavaElement je= SelectionConverter.getElementAtOffset(JavaEditor.this);
							if (je != null)
								return new StructuredSelection(je);
							return null;
						} catch (JavaModelException ex) {
							return null;
						}
					}
				};
			}
		};
	}

	if (required == IJavaFoldingStructureProvider.class)
		return fProjectionModelUpdater;

	if (fProjectionSupport != null) {
		Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required);
		if (adapter != null)
			return adapter;
	}

	if (required == IContextProvider.class) {
		if (isBreadcrumbActive()) {
			return JavaUIHelp.getHelpContextProvider(this, IJavaHelpContextIds.JAVA_EDITOR_BREADCRUMB);
		} else {
			return JavaUIHelp.getHelpContextProvider(this, IJavaHelpContextIds.JAVA_EDITOR);
		}
	}

	return super.getAdapter(required);
}
 
Example #19
Source File: JsonEditor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ShowInContext getShowInContext() {
    return new ShowInContext(getEditorInput(), new StructuredSelection());
}
 
Example #20
Source File: JsonContentOutlinePage.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void selectionChanged(SelectionChangedEvent event) {
    super.selectionChanged(event);

    showInTarget.show(new ShowInContext(null, event.getSelection()));
}
 
Example #21
Source File: DerivedSourceView.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean show(ShowInContext context) {
	selectionChanged(getSite().getPage().getActiveEditor(), context.getSelection());
	return true;
}
 
Example #22
Source File: CrossflowDiagramEditor.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
/**
* @generated
*/
public ShowInContext getShowInContext() {
	return new ShowInContext(getEditorInput(), getNavigatorSelection());
}