blob: 6afee026a9372add64fa5c7d2c4ece3699c77a13 (
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*****************************************************************************
* Copyright (c) 2009 CEA LIST.
*
*
* 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:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.diagram.clazz.custom.policies;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.swt.graphics.Color;
/**
* This policy is used to change background of container when we move or connect an elent to them
*/
public class ContainerHighlightEditPolicy extends org.eclipse.gef.editpolicies.GraphicalEditPolicy {
/**
* the color when the element is selected
*/
private Color revertColor;
/**
*
* {@inheritedDoc}
*/
public void eraseTargetFeedback(Request request) {
if(revertColor != null) {
setContainerBackground(revertColor);
revertColor = null;
}
}
/**
*
* @return the background color of the figure
*/
private Color getContainerBackground() {
return getContainerFigure().getBackgroundColor();
}
/**
*
* get the figure attach to the editpart
*
* @return
*/
private IFigure getContainerFigure() {
return ((GraphicalEditPart)getHost()).getFigure();
}
/**
*
* {@inheritedDoc}
*/
public EditPart getTargetEditPart(Request request) {
return request.getType().equals(RequestConstants.REQ_SELECTION_HOVER) ? getHost() : null;
}
/**
* set the color to the figure attached to the editpart
*
* @param c
* the background color
*/
private void setContainerBackground(Color c) {
getContainerFigure().setBackgroundColor(c);
}
/**
* change the color of the figure
*/
protected void showHighlight() {
if(revertColor == null) {
revertColor = getContainerBackground();
setContainerBackground(ColorConstants.lightBlue);
}
}
/**
*
* {@inheritedDoc}
*/
public void showTargetFeedback(Request request) {
if(request.getType().equals(RequestConstants.REQ_MOVE) || request.getType().equals(RequestConstants.REQ_ADD) || request.getType().equals(RequestConstants.REQ_CLONE) || request.getType().equals(RequestConstants.REQ_CONNECTION_START) || request.getType().equals(RequestConstants.REQ_CONNECTION_END) || request.getType().equals(RequestConstants.REQ_CREATE)) {
showHighlight();
}
}
}
|