use of org.eclipse.gef.internal.ui.rulers.RulerEditPart 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)));
}
Aggregations