Search in sources :

Example 1 with SelectionManager

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);
}
Also used : SelectionManager(org.eclipse.gef.SelectionManager) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) TreeViewer(org.eclipse.gef.ui.parts.TreeViewer) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) IGotoMarker(org.eclipse.ui.ide.IGotoMarker) IOException(java.io.IOException) IContentOutlinePage(org.eclipse.ui.views.contentoutline.IContentOutlinePage) ContentOutlinePage(org.eclipse.gef.ui.parts.ContentOutlinePage) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IContextProvider(org.eclipse.help.IContextProvider) CoreException(org.eclipse.core.runtime.CoreException) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) EventObject(java.util.EventObject) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

IOException (java.io.IOException)1 EventObject (java.util.EventObject)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 IMarker (org.eclipse.core.resources.IMarker)1 CoreException (org.eclipse.core.runtime.CoreException)1 EditPart (org.eclipse.gef.EditPart)1 RootEditPart (org.eclipse.gef.RootEditPart)1 SelectionManager (org.eclipse.gef.SelectionManager)1 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 ContentOutlinePage (org.eclipse.gef.ui.parts.ContentOutlinePage)1 TreeViewer (org.eclipse.gef.ui.parts.TreeViewer)1 IContextProvider (org.eclipse.help.IContextProvider)1 IGotoMarker (org.eclipse.ui.ide.IGotoMarker)1 IContentOutlinePage (org.eclipse.ui.views.contentoutline.IContentOutlinePage)1