Skip to main content
summaryrefslogtreecommitdiffstats
blob: a84adf13ff936d47d2b45c3541e1947435af60c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.asd.design;

import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.wst.wsdl.ui.internal.asd.actions.BaseSelectionAction;
import org.eclipse.wst.wsdl.ui.internal.asd.facade.IMessageReference;
import org.eclipse.wst.wsdl.ui.internal.asd.facade.IOperation;
import org.eclipse.wst.wsdl.ui.internal.asd.facade.IParameter;
import org.eclipse.wst.xsd.ui.internal.adt.design.IKeyboardDrag;
import org.eclipse.wst.xsd.ui.internal.adt.design.editpolicies.KeyBoardAccessibilityEditPolicy;

public class KeyboardDragImpl extends BaseSelectionAction implements IKeyboardDrag {

	public KeyboardDragImpl() {
		super(null);
	}
	
	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;
		  
		Object leftSibElement = (leftElement != null)? leftElement.getModel() : null;
		Object rightSibElement = (rightElement != null)? rightElement.getModel() : null;
		if (direction == PositionConstants.SOUTH) {
			leftSibElement = rightSibElement;
			rightSibElement = leftSibElement;
		} else if (direction != PositionConstants.NORTH) return;
		
		Object source = movingElement.getModel();

		if (source instanceof IMessageReference) {
  			
			if(!(leftSibElement instanceof IMessageReference)) leftSibElement = null;
			if(!(rightSibElement instanceof IMessageReference)) rightSibElement = null;
			
			Object messageRefOwner = ((IMessageReference) source).getOwnerOperation();
  			if (messageRefOwner instanceof IOperation) {
  				IMessageReference leftSib = (IMessageReference) leftSibElement;
  				IMessageReference rightSib = (IMessageReference) rightSibElement;
  				IMessageReference movingSib = (IMessageReference) source;
  				Command command = ((IOperation) messageRefOwner).getReorderMessageReferencesCommand(leftSib, rightSib, movingSib);
  				command.execute();
  				performSelection(source);
  			}
  		}
  		else if (source instanceof IParameter) {
  			
  			if(!(leftSibElement instanceof IParameter)) leftSibElement = null;
			if(!(rightSibElement instanceof IParameter)) rightSibElement = null;
			
  			Object paramOwner = ((IParameter) source).getOwner();
  			if (paramOwner instanceof IMessageReference) {
  				IParameter leftSib = (IParameter) leftSibElement;
  				IParameter rightSib = (IParameter) rightSibElement;
  				IParameter movingSib = (IParameter) source;
  				Command command = ((IMessageReference) paramOwner).getReorderParametersCommand(leftSib, rightSib, movingSib);
  				command.execute();
  				performSelection(source);
  			}
  		}
	}
}

Back to the top