Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 54ed350ac379f54befebf8db2a71e4a4d72ae50e (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
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.tableedit;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.handles.HandleBounds;
import org.eclipse.gef.handles.MoveHandleLocator;
import org.eclipse.jst.pagedesigner.editpolicies.ITableEditAdapter;

/**
 * @author mengbo
 * @version 1.5
 */
public class TableRowHandleLocator extends MoveHandleLocator {

	GraphicalEditPart _tablePart;

	/**
	 * @param tablePart
	 */
	public TableRowHandleLocator(GraphicalEditPart tablePart) {
		super(tablePart.getFigure());
		_tablePart = tablePart;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.gef.handles.MoveHandleLocator#relocate(org.eclipse.draw2d.IFigure)
	 */
	public void relocate(IFigure target) {
		Rectangle bounds;
		if (getReference() instanceof HandleBounds) {
			bounds = ((HandleBounds) getReference()).getHandleBounds();
		} else {
			bounds = getReference().getBounds();
		}
		// bounds = new PrecisionRectangle(bounds.getResized(-1, -1));
		Insets referenceInsets = getReference().getInsets();

		Rectangle r = new Rectangle(bounds.x + bounds.width, bounds.y
				+ referenceInsets.top, TableEditConst.WIDTH, bounds.height
				- referenceInsets.getHeight());
		bounds = new PrecisionRectangle(r);

		getReference().translateToAbsolute(bounds);
		target.translateToRelative(bounds);

		target.setBounds(bounds);
		relocateChildren(target, getReference());
	}

	/**
	 * @param target
	 * @param reference
	 */
	private void relocateChildren(IFigure target, IFigure reference) {
		// As user may removed columns/rows, so need to recalculate columns.
		TableRowHandle tableRowHandle = (TableRowHandle) target;
		tableRowHandle.removeAll();
		tableRowHandle.setupRows();
		List children = target.getChildren();

		ITableEditAdapter tableAdapter = TableEditHelper
				.getTableEditAdapter(this._tablePart);
		if (tableAdapter == null) {
			return;
		}
		for (int i = 0, size = children.size(); i < size; i++) {
			Rectangle rect = null;
			IFigure child = (IFigure) children.get(i);
			if (child instanceof RowHandle) {
				RowHandle rowHandle = (RowHandle) child;
				int rowIndex = rowHandle.getIndex();
				rect = new Rectangle(0, tableAdapter.getRowStart(rowIndex),
						TableEditConst.WIDTH, tableAdapter
								.getRowHeight(rowIndex));
			} else if (child instanceof RowResizeHandle) {
				RowResizeHandle resizeHandle = (RowResizeHandle) child;
				int rowIndex = resizeHandle.getRowIndex();
				rect = new Rectangle(0, tableAdapter
						.getRowResizeStart(rowIndex), TableEditConst.WIDTH,
						tableAdapter.getRowResizeWidth());
			} else {
				// should not happen.
			}
			if (rect != null) {
				child.setBounds(rect);
			}
		}
	}

}

Back to the top