Search in sources :

Example 6 with RulerProvider

use of org.eclipse.gef.rulers.RulerProvider in project archi by archimatetool.

the class CreateGuideAction method run.

/**
 * @see org.eclipse.jface.action.IAction#run()
 */
@Override
public void run() {
    RulerProvider provider = ((RulerEditPart) viewer.getRootEditPart().getChildren().get(0)).getRulerProvider();
    // Determine where the guide should be created
    int[] positions = provider.getGuidePositions();
    Arrays.sort(positions);
    int index = 0;
    int newPosition = GuideEditPart.MIN_DISTANCE_BW_GUIDES + 1;
    int desiredDifference = (GuideEditPart.MIN_DISTANCE_BW_GUIDES * 2) + 1;
    boolean found = positions.length > 0 && positions[0] > desiredDifference;
    while (index < positions.length - 1 && !found) {
        if (positions[index + 1] - positions[index] > desiredDifference) {
            newPosition += positions[index];
            found = true;
        }
        index++;
    }
    if (!found && positions.length > 0)
        newPosition += positions[positions.length - 1];
    // Create the guide and reveal it
    viewer.getEditDomain().getCommandStack().execute(provider.getCreateGuideCommand(newPosition));
    viewer.reveal((EditPart) viewer.getEditPartRegistry().get(provider.getGuideAt(newPosition)));
}
Also used : RulerProvider(org.eclipse.gef.rulers.RulerProvider) RulerEditPart(org.eclipse.gef.internal.ui.rulers.RulerEditPart)

Example 7 with RulerProvider

use of org.eclipse.gef.rulers.RulerProvider in project archi by archimatetool.

the class RulerComposite method setGraphicalViewer.

/**
 * Creates rulers for the given graphical viewer.
 * <p>
 * The primaryViewer or its Control cannot be <code>null</code>. The
 * primaryViewer's Control should be a FigureCanvas and a child of this
 * Composite. This method should only be invoked once.
 * <p>
 * To create ruler(s), simply add the RulerProvider(s) (with the right key:
 * RulerProvider.PROPERTY_HORIZONTAL_RULER or
 * RulerProvider.PROPERTY_VERTICAL_RULER) as a property on the given viewer.
 * It can be done after this method is invoked.
 * RulerProvider.PROPERTY_RULER_VISIBILITY can be used to show/hide the
 * rulers.
 *
 * @param primaryViewer
 *            The graphical viewer for which the rulers have to be created
 */
public void setGraphicalViewer(ScrollingGraphicalViewer primaryViewer) {
    // pre-conditions
    Assert.isNotNull(primaryViewer);
    Assert.isNotNull(primaryViewer.getControl());
    Assert.isTrue(diagramViewer == null);
    diagramViewer = primaryViewer;
    editor = (FigureCanvas) diagramViewer.getControl();
    // layout whenever the scrollbars are shown or hidden, and whenever the
    // RulerComposite
    // is resized
    layoutListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            // @TODO:Pratik If you use Display.asyncExec(runnable) here,
            // some flashing
            // occurs. You can see it when the palette is in the editor, and
            // you hit
            // the button to show/hide it.
            layout(true);
        }
    };
    addListener(SWT.Resize, layoutListener);
    editor.getHorizontalBar().addListener(SWT.Show, layoutListener);
    editor.getHorizontalBar().addListener(SWT.Hide, layoutListener);
    editor.getVerticalBar().addListener(SWT.Show, layoutListener);
    editor.getVerticalBar().addListener(SWT.Hide, layoutListener);
    propertyListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String property = evt.getPropertyName();
            if (RulerProvider.PROPERTY_HORIZONTAL_RULER.equals(property)) {
                setRuler((RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), PositionConstants.NORTH);
            } else if (RulerProvider.PROPERTY_VERTICAL_RULER.equals(property)) {
                setRuler((RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), PositionConstants.WEST);
            } else if (RulerProvider.PROPERTY_RULER_VISIBILITY.equals(property))
                setRulerVisibility(((Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY)).booleanValue());
        }
    };
    diagramViewer.addPropertyChangeListener(propertyListener);
    Boolean rulerVisibility = (Boolean) diagramViewer.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
    if (rulerVisibility != null)
        setRulerVisibility(rulerVisibility.booleanValue());
    setRuler((RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER), PositionConstants.NORTH);
    setRuler((RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER), PositionConstants.WEST);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) RulerProvider(org.eclipse.gef.rulers.RulerProvider) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 8 with RulerProvider

use of org.eclipse.gef.rulers.RulerProvider in project archi by archimatetool.

the class RulerEditPartFactory method getVerticalRuler.

protected Object getVerticalRuler() {
    Object ruler = null;
    RulerProvider provider = (RulerProvider) diagramViewer.getProperty(RulerProvider.PROPERTY_VERTICAL_RULER);
    if (provider != null) {
        ruler = provider.getRuler();
    }
    return ruler;
}
Also used : RulerProvider(org.eclipse.gef.rulers.RulerProvider)

Aggregations

RulerProvider (org.eclipse.gef.rulers.RulerProvider)8 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 DiagramRuler (org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRuler)2 DiagramRulerProvider (org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRulerProvider)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1 RulerModel (org.csstudio.opibuilder.model.RulerModel)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 RulerEditPart (org.eclipse.gef.internal.ui.rulers.RulerEditPart)1 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)1 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)1 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)1 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)1 IAction (org.eclipse.jface.action.IAction)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 Event (org.eclipse.swt.widgets.Event)1