Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cdb5757dd1c74eb78ebd2624b41c17e0e5a92ffa (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf.
 * 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:
 *     Michael Jastram - initial API and implementation
 ******************************************************************************/
package org.eclipse.rmf.pror.reqif10.editor.agilegrid;

import java.util.HashMap;

import org.agilemore.agilegrid.AgileGrid;
import org.agilemore.agilegrid.DefaultLayoutAdvisor;
import org.agilemore.agilegrid.ICellRenderer;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.Specification;

public class ProrLayoutAdvisor extends DefaultLayoutAdvisor {

	private final HashMap<Integer, String> topHeaderLabel = new HashMap<Integer, String>();
	private int columnCount;
	private int rowCount;

	private final HashMap<Integer, HashMap<Integer, Integer>> cachedCellHeights = new HashMap<Integer, HashMap<Integer, Integer>>();

	public ProrLayoutAdvisor(AgileGrid agileGrid) {
		super(agileGrid);

	}

	@Override
	public String getTopHeaderLabel(int col) {
		String label;
		if (col == columnCount - 1) {
			label = "Link";
		} else {
			label = topHeaderLabel.get(col);
		}
		return label != null ? label : ("Column " + (col + 1));
	}

	@Override
	protected void doSetTopHeaderLabel(int col, String label) {
		topHeaderLabel.put(col, label);
	}

	@Override
	protected void doSetColumnCount(int columnCount) {
		this.columnCount = columnCount;
	}

	@Override
	public int getColumnCount() {
		return columnCount;
	}

	@Override
	protected void doSetRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	@Override
	public int getRowCount() {
		return rowCount;
	}

	/**
	 * Used by some {@link ICellRenderer}s to store the cell's height. The
	 * method checks whether the row height has changed and notifies the
	 * associated {@link ProrAgileGrid}.
	 */
	void setCellHeight(int row, int col, int height) {
		int oldRowHeight = getRowHeight(row);
		HashMap<Integer, Integer> cols = cachedCellHeights.get(row);
		if (cols == null) {
			cols = new HashMap<Integer, Integer>();
			cachedCellHeights.put(row, cols);
		}
		cols.put(col, height);

		int newRowHeight = getRowHeight(row);
		if (oldRowHeight != newRowHeight) {
			super.setRowHeight(row, newRowHeight);
			agileGrid.redraw();
		}
	}

	@Override
	public int getRowHeight(int row) {
		int height = 18;
		if (cachedCellHeights.get(row) == null) {
			return height;
		}
		HashMap<Integer, Integer> cols = cachedCellHeights.get(row);
		if (cols == null) {
			return height;
		}
		for (Integer h : cols.values()) {
			if (h > height) {
				height = h;
			}
		}
		return height;
	}

	@Override
	public String getLeftHeaderLabel(int row) {
		StringBuffer sb = new StringBuffer();
		SpecHierarchy specHierarchy = ((ProrAgileGridContentProvider) agileGrid
				.getContentProvider()).getProrRow(row).getSpecHierarchy();

		if (specHierarchy == null) {
			return "";
		}

		while (specHierarchy.eContainer() instanceof SpecHierarchy) {
			SpecHierarchy parent = (SpecHierarchy) specHierarchy.eContainer();
			int level = parent.getChildren().indexOf(specHierarchy) + 1;
			sb.insert(0, level);
			sb.insert(0, ".");
			specHierarchy = parent;
		}
		if (specHierarchy.eContainer() instanceof Specification) {
			Specification parent = (Specification) specHierarchy
					.eContainer();
			int level = parent.getChildren().indexOf(specHierarchy) + 1;
			sb.insert(0, level);
		}
		return sb.toString();
	}

}

Back to the top