Search in sources :

Example 6 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project gemoc-studio by eclipse.

the class AbstractTimelineView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final Composite container;
    if (hasDetailViewer()) {
        final SashForm mainSashForm = new SashForm(parent, SWT.HORIZONTAL);
        container = mainSashForm;
        detailViewer = createDetailViewer(container);
    } else {
        container = parent;
    }
    timelineViewer = new ScrollingGraphicalViewer();
    Composite timelineComposite = new Composite(container, SWT.NONE);
    timelineComposite.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));
    if (hasDetailViewer()) {
        ((SashForm) container).setWeights(new int[] { DETAIL_RATIO, TIMELINE_RATIO });
    }
    GridLayout layout = new GridLayout(1, false);
    timelineComposite.setLayout(layout);
    timelineViewer.createControl(timelineComposite);
    timelineSlider = new Slider(timelineComposite, SWT.HORIZONTAL);
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    timelineSlider.setLayoutData(gridData);
    gridData.grabExcessHorizontalSpace = true;
    rootEditPart = new ScalableFreeformRootEditPart();
    rootEditPart.setViewer(timelineViewer);
    timelineViewer.setRootEditPart(rootEditPart);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = SWT.FILL;
    gridData.grabExcessVerticalSpace = true;
    timelineViewer.getControl().setLayoutData(gridData);
    timelineViewer.setEditPartFactory(getTimelineEditPartFactory());
    timelineWindow = new TimelineWindow(provider);
    timelineViewer.setContents(timelineWindow);
    timelineSlider.setPageIncrement(timelineWindow.getLength());
    timelineSlider.setThumb(timelineWindow.getLength());
    timelineSlider.setSelection(timelineWindow.getStart());
    if (provider != null) {
        timelineSlider.setMaximum(timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
        timelineSlider.setVisible(timelineWindow.getLength() < timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
    } else {
        timelineSlider.setVisible(false);
    }
    timelineSlider.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }
    });
    timelineWindowListener = new TimelineWindowListener();
    timelineWindow.addTimelineWindowListener(timelineWindowListener);
    if (provider != null) {
        provider.addTimelineListener(timelineWindowListener);
    }
    timelineViewer.getControl().setBackground(ColorConstants.listBackground);
    if (hasDetailViewer()) {
        timelineViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                final ISelection selection = event.getSelection();
                if (selection instanceof IStructuredSelection) {
                    final Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                    if (firstElement instanceof PossibleStepEditPart) {
                        final PossibleStepEditPart possibleStepEditPart = (PossibleStepEditPart) firstElement;
                        detailViewer.setInput(possibleStepEditPart.getModel().getPossibleStep());
                    }
                }
            }
        });
    }
    timelineViewer.getControl().addKeyListener(new TimelineKeyListener());
    final TimelineMouseListener listener = new TimelineMouseListener();
    timelineViewer.getControl().addMouseListener(listener);
    timelineViewer.getControl().addMouseMoveListener(listener);
    timelineViewer.getControl().addMouseWheelListener(new TimelineMouseWheelListener());
    rootEditPart.getZoomManager().addZoomListener(new ZoomListener() {

        @Override
        public void zoomChanged(double zoom) {
            timelineWindow.setLength(getWindowLength());
        }
    });
    timelineViewer.getControl().addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            timelineWindow.setLength(getWindowLength());
            final Canvas canevas = (Canvas) timelineViewer.getControl();
            canevas.getHorizontalBar().setVisible(false);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // nothing to do here
        }
    });
    final ICommandService cmdService = (ICommandService) getSite().getService(ICommandService.class);
    String commandID = getFollowCommandID();
    if (commandID != null) {
        final Command followCommand = cmdService.getCommand(commandID);
        if (followCommand != null) {
            final State state = followCommand.getState(RegistryToggleState.STATE_ID);
            follow = state != null && ((Boolean) state.getValue()).booleanValue();
        }
    }
    createMenuManager();
}
Also used : Slider(org.eclipse.swt.widgets.Slider) TimelineWindow(org.eclipse.gemoc.timeline.model.TimelineWindow) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICommandService(org.eclipse.ui.commands.ICommandService) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ControlListener(org.eclipse.swt.events.ControlListener) PossibleStepEditPart(org.eclipse.gemoc.timeline.editpart.PossibleStepEditPart) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FigureCanvas(org.eclipse.draw2d.FigureCanvas) Canvas(org.eclipse.swt.widgets.Canvas) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) ZoomListener(org.eclipse.gef.editparts.ZoomListener) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent) ITimelineWindowListener(org.eclipse.gemoc.timeline.model.ITimelineWindowListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project webtools.sourceediting by eclipse.

the class XSDGraphViewerDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    viewer = new ScrollingGraphicalViewer();
    Composite c = (Composite) super.createDialogArea(parent);
    if (isHighContrast) {
        c.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    } else {
        c.setBackground(ColorConstants.white);
    }
    c.setLayout(new FillLayout());
    RootEditPart root = new RootEditPart();
    viewer.setRootEditPart(root);
    viewer.createControl(c);
    // The graphical viewer tool tip processing creates an extra shell which
    // interferes with the PopupDialog's deactivation logic.
    removeMouseListeners(viewer.getControl());
    if (isHighContrast) {
        viewer.getControl().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    } else {
        viewer.getControl().setBackground(ColorConstants.white);
    }
    EditPartFactory editPartFactory = new XSDEditPartFactory(new TypeVizFigureFactory());
    viewer.setEditPartFactory(editPartFactory);
    RootContentEditPart rootContentEditPart = new RootContentEditPart();
    rootContentEditPart.setModel(model);
    viewer.setContents(rootContentEditPart);
    getShell().addControlListener(moveListener);
    return c;
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) Composite(org.eclipse.swt.widgets.Composite) XSDEditPartFactory(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDEditPartFactory) EditPartFactory(org.eclipse.gef.EditPartFactory) FillLayout(org.eclipse.swt.layout.FillLayout) RootContentEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootContentEditPart) TypeVizFigureFactory(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.TypeVizFigureFactory) RootEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.RootEditPart) XSDEditPartFactory(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDEditPartFactory)

Example 8 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project yamcs-studio by yamcs.

the class OPIEditor method createGraphicalViewer.

@Override
protected void createGraphicalViewer(Composite parent) {
    initDisplayModel();
    rulerComposite = new RulerComposite(parent, SWT.NONE);
    GraphicalViewer viewer = new PatchedScrollingGraphicalViewer();
    viewer.createControl(rulerComposite);
    setGraphicalViewer(viewer);
    configureGraphicalViewer();
    hookGraphicalViewer();
    initializeGraphicalViewer();
    rulerComposite.setGraphicalViewer((ScrollingGraphicalViewer) getGraphicalViewer());
}
Also used : RulerComposite(org.eclipse.gef.ui.rulers.RulerComposite) GraphicalViewer(org.eclipse.gef.GraphicalViewer) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)

Example 9 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project archi by archimatetool.

the class RulerComposite method createRulerContainer.

private GraphicalViewer createRulerContainer(int orientation) {
    ScrollingGraphicalViewer viewer = new RulerViewer();
    final boolean isHorizontal = orientation == PositionConstants.NORTH || orientation == PositionConstants.SOUTH;
    // Finish initializing the viewer
    viewer.setRootEditPart(new RulerRootEditPart(isHorizontal));
    viewer.setEditPartFactory(new RulerEditPartFactory(diagramViewer));
    viewer.createControl(this);
    ((GraphicalEditPart) viewer.getRootEditPart()).getFigure().setBorder(new RulerBorder(isHorizontal));
    viewer.setProperty(GraphicalViewer.class.toString(), diagramViewer);
    // Configure the viewer's control
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    if (font == null) {
        FontData[] data = canvas.getFont().getFontData();
        for (int i = 0; i < data.length; i++) {
            data[i].setHeight(data[i].getHeight() - 1);
        }
        font = new Font(Display.getCurrent(), data);
    }
    canvas.setFont(font);
    if (isHorizontal) {
        canvas.getViewport().setHorizontalRangeModel(editor.getViewport().getHorizontalRangeModel());
    } else {
        canvas.getViewport().setVerticalRangeModel(editor.getViewport().getVerticalRangeModel());
    }
    // Add the viewer to the rulerEditDomain
    if (rulerEditDomain == null) {
        rulerEditDomain = new EditDomain();
        rulerEditDomain.setCommandStack(diagramViewer.getEditDomain().getCommandStack());
    }
    rulerEditDomain.addViewer(viewer);
    return viewer;
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) GraphicalViewer(org.eclipse.gef.GraphicalViewer) EditDomain(org.eclipse.gef.EditDomain) FontData(org.eclipse.swt.graphics.FontData) RulerRootEditPart(org.eclipse.gef.internal.ui.rulers.RulerRootEditPart) Font(org.eclipse.swt.graphics.Font) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) FigureCanvas(org.eclipse.draw2d.FigureCanvas) RulerEditPartFactory(org.eclipse.gef.internal.ui.rulers.RulerEditPartFactory)

Example 10 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project cubrid-manager by CUBRID.

the class ERSchemaEditor method createGraphicalViewer.

/**
	 * Creates a new <code>GraphicalViewer</code>, configures, registers and
	 * initializes it.
	 * 
	 * @param parent the parent composite
	 * @return a new <code>GraphicalViewer</code>
	 */
protected void createGraphicalViewer(Composite parent) {
    IEditorSite editorSite = getEditorSite();
    ScrollingGraphicalViewer viewer = createGraphicalViewer(editorSite, parent);
    ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
    zoomManager = rootEditPart.getZoomManager();
    zoomManager.setZoomLevels(ZOOM_LEVELS);
    // hook the viewer into the EditDomain
    getEditDomain().addViewer(viewer);
    // acticate the viewer as selection provider for Eclipse
    getSite().setSelectionProvider(viewer);
    viewer.setContents(erSchema);
    ContextMenuProvider provider = new SchemaContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);
    getSite().registerContextMenu(provider.getId(), provider, viewer);
    graphicalViewer = viewer;
    // key handler
    GraphicalViewerKeyHandler graphicalViewerKeyHandler = new GraphicalViewerKeyHandler(viewer);
    KeyHandler parentKeyHandler = graphicalViewerKeyHandler.setParent(getCommonKeyHandler());
    viewer.setKeyHandler(parentKeyHandler);
    registDropTarget();
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) KeyHandler(org.eclipse.gef.KeyHandler) IEditorSite(org.eclipse.ui.IEditorSite) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) SchemaContextMenuProvider(com.cubrid.common.ui.er.SchemaContextMenuProvider) SchemaContextMenuProvider(com.cubrid.common.ui.er.SchemaContextMenuProvider)

Aggregations

ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)18 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)6 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)5 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)5 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 Dimension (org.eclipse.draw2d.geometry.Dimension)3 ToggleGridAction (org.eclipse.gef.ui.actions.ToggleGridAction)3 ToggleSnapToGeometryAction (org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction)3 IAction (org.eclipse.jface.action.IAction)3 ArrayList (java.util.ArrayList)2 ConnectionLayer (org.eclipse.draw2d.ConnectionLayer)2 FigureCanvas (org.eclipse.draw2d.FigureCanvas)2 DefaultEditDomain (org.eclipse.gef.DefaultEditDomain)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)2 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)2 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2