/** * The creation tool only works by clicking mouse button 1 (the left mouse button in a * right-handed world). If any other button is pressed, the tool goes into an invalid * state. Otherwise, it goes into the drag state, updates the request's location and * calls {@link TargetingTool#lockTargetEditPart(EditPart)} with the edit part that was * just clicked on. * * @see org.eclipse.gef.tools.AbstractTool#handleButtonDown(int) */ protectedboolean handleButtonDown(int button) { if (button !=1) { setState(STATE_INVALID); handleInvalidInput(); returntrue; } if (stateTransition(STATE_INITIAL, STATE_DRAG))
{ getCreateRequest().setLocation(getLocation()); lockTargetEditPart(getTargetEditPart()); // Snap only when size on drop is employed helper = (SnapToHelper)getTargetEditPart().getAdapter(SnapToHelper.class); } returntrue; }
c銆?/SPAN>CreationTool榪樹細鏍規嵁Request鐨勭被鍨嬪強浣嶇疆灝嗗叾鍒嗘淳緇欑浉搴旂殑EditPart銆?/SPAN>[Targeting tools work with a target request. This request is used along with the mouse location to obtain an active target from the current EditPartViewer. This target is then asked for the Command that performs the given request. The target is also asked to show target feedback. (鎽樿嚜org.eclipse.gef.tools.TargetingTool)]
/** * Upon activation, attach to the model element as a notification change * listener. */ publicvoid activate() { if (!isActive()) { super.activate(); ((ModelElement) getModel()).eAdapters().add(this); } }
/** * Upon deactivation, detach from the model element as a notification change * listener. */ publicvoid deactivate() { if (isActive()) { super.deactivate(); ((ModelElement) getModel()).eAdapters().remove(this); } }