use of org.eclipse.ui.IViewReference in project org.csstudio.display.builder by kasemir.
the class RuntimeViewPart method open.
/**
* Open a runtime display
*
* <p>Either opens a new display, or if there is already an existing view
* for that input, "activate" it, which pops a potentially hidden view to the top.
*
* @param page Page to use. <code>null</code> for 'active' page
* @param close_handler Code to call when part is closed
* @param info DisplayInfo (to compare with currently open displays)
* @return {@link RuntimeViewPart}
* @throws Exception on error
*/
public static RuntimeViewPart open(IWorkbenchPage page, final Consumer<DisplayModel> close_handler, final DisplayInfo info) throws Exception {
if (page == null)
page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (info != null)
for (IViewReference view_ref : page.getViewReferences()) if (view_ref.getId().startsWith(ID)) {
final IViewPart view = view_ref.getView(true);
if (view instanceof RuntimeViewPart) {
final RuntimeViewPart runtime_view = (RuntimeViewPart) view;
if (// Allow for runtime_view.getDisplayInfo() == null
info.equals(runtime_view.getDisplayInfo())) {
page.showView(view_ref.getId(), view_ref.getSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE);
return runtime_view;
}
}
}
final RuntimeViewPart part = (RuntimeViewPart) page.showView(ID, UUID.randomUUID().toString(), IWorkbenchPage.VIEW_ACTIVATE);
part.close_handler = close_handler;
return part;
}
use of org.eclipse.ui.IViewReference in project jbosstools-openshift by jbosstools.
the class UIUtils method getVisibleViewParts.
/**
* Returns the visible workbench parts which match the given ids. If no ids
* are given all visible parts are returned.
*
* @param partIds
* @return
*
* @see IWorkbenchPart
*/
public static List<IViewPart> getVisibleViewParts(String... partIds) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final List<String> partIdsList = new ArrayList<>();
List<IViewPart> parts = null;
if (partIds != null) {
parts = new ArrayList<>(partIds.length);
}
for (IViewReference viewReference : page.getViewReferences()) {
String partId = viewReference.getId();
if (partIdsList == null || partIdsList.isEmpty() || partIdsList.contains(partId)) {
IViewPart part = viewReference.getView(false);
if (part != null && page.isPartVisible(part)) {
parts.add(part);
}
}
}
parts.stream().sorted((part1, part2) -> {
int indexPart1 = partIdsList.indexOf(part1.getSite().getId());
int indexPart2 = partIdsList.indexOf(part1.getSite().getId());
if (indexPart1 > indexPart2) {
return 1;
} else {
return -1;
}
});
return parts;
}
use of org.eclipse.ui.IViewReference in project hale by halestudio.
the class InstanceValidationReportDetailsPage method showSelectionInDataView.
/**
* Shows the current selection (if valid) in the transformed data view.
*/
private void showSelectionInDataView() {
InstanceSelection selection = getValidSelection();
if (selection != null) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// pin the property sheet if possible
IViewReference ref = page.findViewReference(IPageLayout.ID_PROP_SHEET);
if (ref != null) {
IViewPart part = ref.getView(true);
if (part instanceof PropertySheet)
((PropertySheet) part).setPinned(true);
}
// show transformed data view with selection if possible
try {
TransformedDataView transformedDataView = (TransformedDataView) page.showView(TransformedDataView.ID);
transformedDataView.showSelection(selection, reportImage);
} catch (PartInitException e) {
// if it's not there, we cannot do anything
}
}
}
use of org.eclipse.ui.IViewReference in project hale by halestudio.
the class OpenPropertiesHandler method unpinAndOpenPropertiesView.
/**
* Unpin and open the porperties view.
*
* @param activeWindow the active workbench window
*/
public static void unpinAndOpenPropertiesView(IWorkbenchWindow activeWindow) {
try {
// unpin the property sheet if possible
IViewReference ref = activeWindow.getActivePage().findViewReference(IPageLayout.ID_PROP_SHEET);
if (ref != null) {
IViewPart part = ref.getView(false);
if (part instanceof PropertySheet) {
PropertySheet sheet = (PropertySheet) part;
if (sheet.isPinned()) {
sheet.setPinned(false);
IWorkbenchPart activePart = activeWindow.getActivePage().getActivePart();
/*
* Feign the part has been activated (cause else the
* PropertySheet will only take a selection from the
* last part it was displaying properties about)
*/
sheet.partActivated(activePart);
// get the current selection
ISelection sel = activePart.getSite().getSelectionProvider().getSelection();
// Update the properties view with the current selection
sheet.selectionChanged(activePart, sel);
}
}
}
// show the view
activeWindow.getActivePage().showView(IPageLayout.ID_PROP_SHEET);
} catch (PartInitException e) {
log.error("Error opening properties view", e);
}
}
use of org.eclipse.ui.IViewReference in project gfm_viewer by satyagraha.
the class ViewManager method findViewImplementing.
/**
* Find a view implementing a specified interface.
*
* @param type
* the interface
* @return the view (or null)
*/
@SuppressWarnings("unchecked")
public static <T> T findViewImplementing(Class<T> type) {
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewReference[] viewReferences = workbenchPage.getViewReferences();
IWorkbenchPart part = with(viewReferences).extract(on(IViewReference.class).getPart(false)).first(Matchers.instanceOf(type));
return (T) part;
}
Aggregations