use of org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart in project webtools.sourceediting by eclipse.
the class DragAndDropEditPolicy method getCommand.
public org.eclipse.gef.commands.Command getCommand(Request request) {
BaseDragAndDropCommand command = null;
if (request instanceof ChangeBoundsRequest) {
ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
Point location = changeBoundsRequest.getLocation();
GraphicalEditPart target = (GraphicalEditPart) viewer.findObjectAt(location);
location = getPointerLocation(changeBoundsRequest.getLocation());
((GraphicalEditPart) viewer.getRootEditPart()).getFigure().translateToRelative(location);
List list = changeBoundsRequest.getEditParts();
// allow drag and drop of only one selected object
if (list.size() == 1) {
Object itemToDrag = list.get(0);
if (itemToDrag instanceof XSDBaseFieldEditPart) {
XSDBaseFieldEditPart selected = (XSDBaseFieldEditPart) itemToDrag;
if (selected.getModel() instanceof XSDElementDeclarationAdapter) {
command = new XSDElementDragAndDropCommand(viewer, (ChangeBoundsRequest) request, target, selected, location);
selectionHandlesEditPolicy.setDragAndDropCommand(command);
} else if (selected.getModel() instanceof XSDBaseAttributeAdapter) {
command = new XSDAttributeDragAndDropCommand(viewer, (ChangeBoundsRequest) request, target, selected, location);
selectionHandlesEditPolicy.setDragAndDropCommand(command);
}
}
}
}
return command;
}
use of org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart in project webtools.sourceediting by eclipse.
the class KeyboardDragImpl method performKeyboardDrag.
public void performKeyboardDrag(GraphicalEditPart movingElement, int direction) {
KeyBoardAccessibilityEditPolicy policy = (KeyBoardAccessibilityEditPolicy) movingElement.getEditPolicy(KeyBoardAccessibilityEditPolicy.KEY);
EditPart rightElement = policy.getRelativeEditPart(movingElement, direction);
policy = (KeyBoardAccessibilityEditPolicy) rightElement.getEditPolicy(KeyBoardAccessibilityEditPolicy.KEY);
EditPart leftElement = (policy != null) ? policy.getRelativeEditPart(rightElement, direction) : null;
// TODO: add support for extenders
if (!(movingElement instanceof XSDBaseFieldEditPart))
return;
XSDBaseFieldEditPart movingField = (XSDBaseFieldEditPart) movingElement;
XSDBaseFieldEditPart leftField = (XSDBaseFieldEditPart) leftElement;
XSDBaseFieldEditPart rightField = (XSDBaseFieldEditPart) rightElement;
Object movingObject = movingField.getModel();
BaseDragAndDropCommand command = null;
if (movingObject instanceof XSDElementDeclarationAdapter || movingObject instanceof XSDWildcard) {
command = new XSDElementDragAndDropCommand(movingField, leftField, rightField, direction);
} else if (movingObject instanceof XSDAttributeDeclarationAdapter) {
command = new XSDAttributeDragAndDropCommand(movingField, leftField, rightField, direction);
}
if (command != null && command.canExecute()) {
command.execute();
// This is to reselect the moved item
try {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor != null && editor.getAdapter(ISelectionProvider.class) != null) {
ISelectionProvider provider = (ISelectionProvider) editor.getAdapter(ISelectionProvider.class);
if (provider != null) {
provider.setSelection(new StructuredSelection(movingElement.getModel()));
}
}
} catch (Exception e) {
}
}
}
use of org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart in project webtools.sourceediting by eclipse.
the class BaseDragAndDropCommand method calculateLeftAndRightXSDComponents.
protected void calculateLeftAndRightXSDComponents() {
if (leftSiblingEditPart instanceof XSDBaseFieldEditPart) {
Object leftModel = ((XSDBaseFieldEditPart) leftSiblingEditPart).getModel();
previousRefComponent = null;
if (leftModel instanceof XSDBaseAdapter) {
XSDBaseAdapter leftAdapter = (XSDBaseAdapter) leftModel;
previousRefComponent = (XSDConcreteComponent) leftAdapter.getTarget();
}
}
if (rightSiblingEditPart instanceof XSDBaseFieldEditPart) {
Object rightModel = ((XSDBaseFieldEditPart) rightSiblingEditPart).getModel();
nextRefComponent = null;
if (rightModel instanceof XSDBaseAdapter) {
XSDBaseAdapter rightAdapter = (XSDBaseAdapter) rightModel;
nextRefComponent = (XSDConcreteComponent) rightAdapter.getTarget();
}
}
}
Aggregations