001: package newprocess.diagram.edit.policies;
002:
003: import java.util.Collections;
004: import java.util.List;
005:
006: import org.eclipse.draw2d.ColorConstants;
007: import org.eclipse.draw2d.Figure;
008: import org.eclipse.draw2d.Graphics;
009: import org.eclipse.draw2d.IFigure;
010: import org.eclipse.draw2d.Label;
011: import org.eclipse.draw2d.RectangleFigure;
012: import org.eclipse.draw2d.geometry.Rectangle;
013: import org.eclipse.gef.GraphicalEditPart;
014: import org.eclipse.gef.handles.MoveHandle;
015: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
016: import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
017: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
018:
019: /**
020: * @generated
021: */
022: public class New_processTextNonResizableEditPolicy extends
023: NonResizableEditPolicyEx {
024:
025: /**
026: * @generated
027: */
028: private IFigure selectionFeedbackFigure;
029:
030: /**
031: * @generated
032: */
033: private IFigure focusFeedbackFigure;
034:
035: /**
036: * @generated
037: */
038: protected void showPrimarySelection() {
039: if (getHostFigure() instanceof WrapLabel) {
040: ((WrapLabel) getHostFigure()).setSelected(true);
041: ((WrapLabel) getHostFigure()).setFocus(true);
042: } else {
043: showSelection();
044: showFocus();
045: }
046: }
047:
048: /**
049: * @generated
050: */
051: protected void showSelection() {
052: if (getHostFigure() instanceof WrapLabel) {
053: ((WrapLabel) getHostFigure()).setSelected(true);
054: ((WrapLabel) getHostFigure()).setFocus(false);
055: } else {
056: hideSelection();
057: addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
058: refreshSelectionFeedback();
059: hideFocus();
060: }
061: }
062:
063: /**
064: * @generated
065: */
066: protected void hideSelection() {
067: if (getHostFigure() instanceof WrapLabel) {
068: ((WrapLabel) getHostFigure()).setSelected(false);
069: ((WrapLabel) getHostFigure()).setFocus(false);
070: } else {
071: if (selectionFeedbackFigure != null) {
072: removeFeedback(selectionFeedbackFigure);
073: selectionFeedbackFigure = null;
074: }
075: hideFocus();
076: }
077: }
078:
079: /**
080: * @generated
081: */
082: protected void showFocus() {
083: if (getHostFigure() instanceof WrapLabel) {
084: ((WrapLabel) getHostFigure()).setFocus(true);
085: } else {
086: hideFocus();
087: addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
088: refreshFocusFeedback();
089: }
090: }
091:
092: /**
093: * @generated
094: */
095: protected void hideFocus() {
096: if (getHostFigure() instanceof WrapLabel) {
097: ((WrapLabel) getHostFigure()).setFocus(false);
098: } else {
099: if (focusFeedbackFigure != null) {
100: removeFeedback(focusFeedbackFigure);
101: focusFeedbackFigure = null;
102: }
103: }
104: }
105:
106: /**
107: * @generated
108: */
109: protected Rectangle getFeedbackBounds() {
110: Rectangle bounds;
111: if (getHostFigure() instanceof Label) {
112: bounds = ((Label) getHostFigure()).getTextBounds();
113: bounds.intersect(getHostFigure().getBounds());
114: } else {
115: bounds = getHostFigure().getBounds().getCopy();
116: }
117: getHostFigure().getParent().translateToAbsolute(bounds);
118: getFeedbackLayer().translateToRelative(bounds);
119: return bounds;
120: }
121:
122: /**
123: * @generated
124: */
125: protected IFigure createSelectionFeedbackFigure() {
126: if (getHostFigure() instanceof Label) {
127: Label feedbackFigure = new Label();
128: feedbackFigure.setOpaque(true);
129: feedbackFigure
130: .setBackgroundColor(ColorConstants.menuBackgroundSelected);
131: feedbackFigure
132: .setForegroundColor(ColorConstants.menuForegroundSelected);
133: return feedbackFigure;
134: } else {
135: RectangleFigure feedbackFigure = new RectangleFigure();
136: feedbackFigure.setFill(false);
137: return feedbackFigure;
138: }
139: }
140:
141: /**
142: * @generated
143: */
144: protected IFigure createFocusFeedbackFigure() {
145: return new Figure() {
146:
147: protected void paintFigure(Graphics graphics) {
148: graphics.drawFocus(getBounds().getResized(-1, -1));
149: }
150: };
151: }
152:
153: /**
154: * @generated
155: */
156: protected void updateLabel(Label target) {
157: Label source = (Label) getHostFigure();
158: target.setText(source.getText());
159: target.setTextAlignment(source.getTextAlignment());
160: target.setFont(source.getFont());
161: }
162:
163: /**
164: * @generated
165: */
166: protected void refreshSelectionFeedback() {
167: if (selectionFeedbackFigure != null) {
168: if (selectionFeedbackFigure instanceof Label) {
169: updateLabel((Label) selectionFeedbackFigure);
170: selectionFeedbackFigure.setBounds(getFeedbackBounds());
171: } else {
172: selectionFeedbackFigure.setBounds(getFeedbackBounds()
173: .expand(5, 5));
174: }
175: }
176: }
177:
178: /**
179: * @generated
180: */
181: protected void refreshFocusFeedback() {
182: if (focusFeedbackFigure != null) {
183: focusFeedbackFigure.setBounds(getFeedbackBounds());
184: }
185: }
186:
187: /**
188: * @generated
189: */
190: public void refreshFeedback() {
191: refreshSelectionFeedback();
192: refreshFocusFeedback();
193: }
194:
195: /**
196: * @generated
197: */
198: protected List createSelectionHandles() {
199: MoveHandle moveHandle = new MoveHandle(
200: (GraphicalEditPart) getHost());
201: moveHandle.setBorder(null);
202: moveHandle
203: .setDragTracker(new DragEditPartsTrackerEx(getHost()));
204: return Collections.singletonList(moveHandle);
205: }
206: }
|