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)));
}
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);
}
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;
}
Aggregations