use of org.eclipse.gef.SelectionManager in project yamcs-studio by yamcs.
the class OPIEditor method getAdapter.
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
if (type == IPropertySheetPage.class)
return getPropertySheetPage();
else if (type == ZoomManager.class)
return ((ScalableFreeformRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager();
else // return getOverviewOutlinePage();
if (type == IContentOutlinePage.class) {
outlinePage = new OutlinePage(new TreeViewer());
return outlinePage;
} else if (type.equals(IContextProvider.class)) {
if (helpContextProvider == null)
helpContextProvider = new OPIHelpContextProvider(getGraphicalViewer());
return helpContextProvider;
} else if (type.equals(IGotoMarker.class)) {
return new IGotoMarker() {
@Override
public void gotoMarker(IMarker marker) {
try {
String wuid = (String) marker.getAttribute(AbstractWidgetModel.PROP_WIDGET_UID);
if (wuid == null) {
// if wuid is not stored in the marker try to find it based on character
Integer charStart = (Integer) marker.getAttribute(IMarker.CHAR_START);
if (charStart == null) {
return;
}
// Get the closest widget to charStart position
wuid = XMLUtil.findClosestWidgetUid(getInputStream(), charStart);
if (wuid == null) {
return;
}
}
AbstractWidgetModel widget = getDisplayModel().getWidgetFromWUID(wuid);
if (widget == null) {
return;
}
// Get the widget editPart
Object obj = getGraphicalViewer().getEditPartRegistry().get(widget);
if (obj != null && obj instanceof AbstractBaseEditPart) {
EditPart widgetEditPart = (AbstractBaseEditPart) obj;
// Reveal the widget
getGraphicalViewer().reveal(widgetEditPart);
// Find the closest selectable part
while (widgetEditPart != null && !widgetEditPart.isSelectable()) {
widgetEditPart = widgetEditPart.getParent();
}
if (widgetEditPart != null) {
// Select the widget in OPI
SelectionManager selectionManager = getGraphicalViewer().getSelectionManager();
selectionManager.deselectAll();
selectionManager.appendSelection(widgetEditPart);
}
}
} catch (IOException e) {
MessageDialog.openError(getSite().getShell(), "IO Error", e.getMessage());
OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
e);
} catch (CoreException e) {
MessageDialog.openError(getSite().getShell(), "Core Error", e.getMessage());
OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
e);
}
}
};
}
return super.getAdapter(type);
}
Aggregations