01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Common Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/cpl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.openwfe.gpe.policies;
11:
12: import org.eclipse.swt.graphics.Color;
13:
14: import org.eclipse.draw2d.IFigure;
15:
16: import org.eclipse.gef.EditPart;
17: import org.eclipse.gef.GraphicalEditPart;
18: import org.eclipse.gef.Request;
19: import org.eclipse.gef.RequestConstants;
20: import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
21:
22: /**
23: * @author Daniel Lee
24: */
25: public class ActivityContainerHighlightEditPolicy extends
26: GraphicalEditPolicy {
27:
28: private Color revertColor;
29: private static Color highLightColor = new Color(null, 200, 200, 240);
30:
31: /**
32: * @see org.eclipse.gef.EditPolicy#eraseTargetFeedback(org.eclipse.gef.Request)
33: */
34: public void eraseTargetFeedback(Request request) {
35: if (revertColor != null) {
36: setContainerBackground(revertColor);
37: revertColor = null;
38: }
39: }
40:
41: private Color getContainerBackground() {
42: return getContainerFigure().getBackgroundColor();
43: }
44:
45: private IFigure getContainerFigure() {
46: return ((GraphicalEditPart) getHost()).getFigure();
47: }
48:
49: /**
50: * @see org.eclipse.gef.EditPolicy#getTargetEditPart(org.eclipse.gef.Request)
51: */
52: public EditPart getTargetEditPart(Request request) {
53: return request.getType().equals(
54: RequestConstants.REQ_SELECTION_HOVER) ? getHost()
55: : null;
56: }
57:
58: private void setContainerBackground(Color c) {
59: getContainerFigure().setBackgroundColor(c);
60: }
61:
62: /**
63: * Changes the background color of the container to the highlight color
64: */
65: protected void showHighlight() {
66: if (revertColor == null) {
67: revertColor = getContainerBackground();
68: setContainerBackground(highLightColor);
69: }
70: }
71:
72: /**
73: * @see org.eclipse.gef.EditPolicy#showTargetFeedback(org.eclipse.gef.Request)
74: */
75: public void showTargetFeedback(Request request) {
76: if (request.getType().equals(RequestConstants.REQ_CREATE)
77: || request.getType().equals(RequestConstants.REQ_ADD))
78: showHighlight();
79: }
80:
81: }
|