Search in sources :

Example 1 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter in project webtools.sourceediting by eclipse.

the class XSDElementDragAndDropCommand method setup.

protected void setup() {
    canExecute = false;
    // Drop target is model group
    if (target instanceof ModelGroupEditPart) {
        parentEditPart = (ModelGroupEditPart) target;
        if (((GenericGroupFigure) parentEditPart.getFigure()).getIconFigure().getBounds().contains(location)) {
            xsdComponentToDrag = (XSDConcreteComponent) ((XSDElementDeclarationAdapter) itemToDrag.getModel()).getTarget();
            action = new MoveXSDElementAction(((ModelGroupEditPart) target).getXSDModelGroup(), xsdComponentToDrag, null, null);
            canExecute = action.canMove();
        }
    } else if (target instanceof BaseFieldEditPart) {
        targetSpacesList = new ArrayList();
        // Calculate the list of all sibling field edit parts;
        List targetEditPartSiblings = calculateFieldEditParts();
        calculateModelGroupList();
        doDrop(targetEditPartSiblings, itemToDrag);
    }
}
Also used : ModelGroupEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.ModelGroupEditPart) GenericGroupFigure(org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure) MoveXSDElementAction(org.eclipse.wst.xsd.ui.internal.actions.MoveXSDElementAction) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) BaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart)

Example 2 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter in project webtools.sourceediting by eclipse.

the class XSDBaseFieldEditPart method directEditNameField.

protected void directEditNameField() {
    Object model = getModel();
    IFieldFigure fieldFigure = getFieldFigure();
    if (model instanceof IField) {
        IField field = (IField) model;
        if (field.isReference()) {
            ReferenceDirectEditManager manager = null;
            if (field instanceof XSDElementDeclarationAdapter) {
                manager = new ElementReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
            } else if (field instanceof XSDAttributeDeclarationAdapter) {
                manager = new AttributeReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
            }
            if (manager != null) {
                ReferenceUpdateCommand elementUpdateCommand = new ReferenceUpdateCommand();
                elementUpdateCommand.setDelegate(manager);
                adtDirectEditPolicy.setUpdateCommand(elementUpdateCommand);
                manager.show();
            }
        } else {
            LabelEditManager manager = new LabelEditManager(this, new LabelCellEditorLocator(this, null));
            NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
            adtDirectEditPolicy.setUpdateCommand(wrapper);
            manager.show();
        }
    }
}
Also used : ElementReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager) LabelEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelEditManager) XSDAttributeDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter) LabelCellEditorLocator(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelCellEditorLocator) IFieldFigure(org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure) IField(org.eclipse.wst.xsd.ui.internal.adt.facade.IField) AttributeReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) AttributeReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager) ReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ReferenceDirectEditManager) ElementReferenceDirectEditManager(org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager)

Example 3 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter 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;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) XSDElementDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) XSDBaseAttributeAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAttributeAdapter) BaseDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) XSDAttributeDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)

Example 4 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter 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) {
        }
    }
}
Also used : KeyBoardAccessibilityEditPolicy(org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) XSDAttributeDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter) XSDBaseFieldEditPart(org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) XSDWildcard(org.eclipse.xsd.XSDWildcard) IEditorPart(org.eclipse.ui.IEditorPart) XSDAttributeDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDElementDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) BaseDragAndDropCommand(org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand)

Example 5 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter in project webtools.sourceediting by eclipse.

the class XSDElementDragAndDropCommand method getElement.

/*
   * (non-Javadoc)
   * @see org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand#getElement()
   */
protected Element getElement() {
    XSDElementDeclarationAdapter adapter = (XSDElementDeclarationAdapter) itemToDrag.getModel();
    XSDElementDeclaration target = (XSDElementDeclaration) adapter.getTarget();
    XSDConcreteComponent parent = (XSDConcreteComponent) target.eContainer();
    return parent.getElement();
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)

Aggregations

XSDElementDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)6 XSDBaseFieldEditPart (org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart)3 List (java.util.List)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 XSDAttributeDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter)2 BaseDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand)2 XSDAttributeDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand)2 XSDElementDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 ArrayList (java.util.ArrayList)1 Point (org.eclipse.draw2d.geometry.Point)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EditPart (org.eclipse.gef.EditPart)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorPart (org.eclipse.ui.IEditorPart)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1