aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Weigelt2012-03-28 05:12:42 (EDT)
committerMichael Jastram2012-04-05 06:38:10 (EDT)
commit37a2afb3494f10c86375340f89b38de86741b36d (patch)
tree00c336a5d48efb617e6e595fdda3bf7cac56ad2f
parent15cdf1be7a5b136da32ff94ea7bafbf547dd0748 (diff)
downloadorg.eclipse.rmf-37a2afb3494f10c86375340f89b38de86741b36d.zip
org.eclipse.rmf-37a2afb3494f10c86375340f89b38de86741b36d.tar.gz
org.eclipse.rmf-37a2afb3494f10c86375340f89b38de86741b36d.tar.bz2
Code cleanup
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/AbstractProrCellRenderer.java20
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGrid.java13
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java34
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrLinkCellRenderer.java9
4 files changed, 45 insertions, 31 deletions
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/AbstractProrCellRenderer.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/AbstractProrCellRenderer.java
index aec14dc..1973a21 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/AbstractProrCellRenderer.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/AbstractProrCellRenderer.java
@@ -33,7 +33,7 @@ import org.eclipse.swt.graphics.Rectangle;
/**
* @author Lukas Ladenberger
- *
+ * @author Ingo Weigelt
*/
public class AbstractProrCellRenderer extends TextCellRenderer {
@@ -46,6 +46,10 @@ public class AbstractProrCellRenderer extends TextCellRenderer {
super(agileGrid);
this.adapterFactory = adapterFactory;
}
+
+ public AbstractProrCellRenderer(AgileGrid agileGrid) {
+ this(agileGrid, null);
+ }
protected int doDrawCellContentDefault(GC gc, Rectangle rect, Object value) {
String stringValue;
@@ -105,8 +109,11 @@ public class AbstractProrCellRenderer extends TextCellRenderer {
Color vBorderColor = COLOR_LINE_LIGHTGRAY;
Color hBorderColor = COLOR_LINE_LIGHTGRAY;
- if (agileGrid instanceof ProrAgileGrid){
- if (((ProrAgileGrid)agileGrid).dndHoverCell != null && row == ((ProrAgileGrid)agileGrid).dndHoverCell.row && ((ProrAgileGrid)agileGrid).dndHoverCellMode == 0){
+ if (agileGrid instanceof ProrAgileGrid) {
+ ProrAgileGrid grid = (ProrAgileGrid) agileGrid;
+ if (grid.dndHoverCell != null
+ && row == grid.dndHoverCell.row
+ && grid.dndHoverDropMode == ProrAgileGrid.DND_DROP_AS_SIBLING) {
hBorderColor = COLOR_LINE_DARKGRAY;
}
}
@@ -124,14 +131,15 @@ public class AbstractProrCellRenderer extends TextCellRenderer {
drawDefaultCellLine(gc, rect, vBorderColor, hBorderColor);
}
+ @Override
protected void drawCellContent(GC gc, Rectangle rect, int row, int col) {
this.foreground = this.getDefaultForeground();
this.background = this.getDefaultBackground();
if (agileGrid instanceof ProrAgileGrid) {
- if (((ProrAgileGrid) agileGrid).dndHoverCell != null
- && row == ((ProrAgileGrid) agileGrid).dndHoverCell.row
- && ((ProrAgileGrid) agileGrid).dndHoverCellMode == 1) {
+ ProrAgileGrid grid = (ProrAgileGrid) agileGrid;
+ if (grid.dndHoverCell != null && row == grid.dndHoverCell.row
+ && grid.dndHoverDropMode == ProrAgileGrid.DND_DROP_AS_CHILD) {
this.background = COLOR_BGROWSELECTION;
}
}
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGrid.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGrid.java
index f2212b7..5bb862c 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGrid.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGrid.java
@@ -24,9 +24,12 @@ import org.eclipse.swt.widgets.Composite;
*/
public class ProrAgileGrid extends AgileGrid {
+ public static final int DND_DROP_AS_SIBLING = 0;
+ public static final int DND_DROP_AS_CHILD = 1;
+
protected Cell dndHoverCell;
- //TODO use constants for Hover Mode
- protected int dndHoverCellMode;
+ protected int dndHoverDropMode;
+
public ProrAgileGrid(Composite parent, int style) {
super(parent, style);
@@ -47,6 +50,12 @@ public class ProrAgileGrid extends AgileGrid {
// });
}
+ /**
+ * Returns the upper y-coordinate of a row.
+ * Returns a negative value id the row does not exist or is invisible
+ * @param row
+ * @return
+ */
public int getYForRow(int row) {
if (row < 0 || row > topRow + getRowsVisible() - 1) {
return Integer.MIN_VALUE;
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
index 61cc73e..f7ba5f2 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrAgileGridViewer.java
@@ -74,7 +74,6 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
@@ -582,17 +581,16 @@ public class ProrAgileGridViewer extends Viewer {
float location = getLocation(e);
if (location == 0.5){
agileGrid.dndHoverCell = cell;
- agileGrid.dndHoverCellMode = 1;
+ agileGrid.dndHoverDropMode = ProrAgileGrid.DND_DROP_AS_CHILD;
}
if (location == 0.0){
- //Cell prevCell = agileGrid.getCell(pos.x, pos.y-1);
Cell prevCell = agileGrid.getNeighbor(cell, AgileGrid.ABOVE, true);
agileGrid.dndHoverCell = prevCell;
- agileGrid.dndHoverCellMode = 0;
+ agileGrid.dndHoverDropMode = ProrAgileGrid.DND_DROP_AS_SIBLING;
}
if (location == 1.0){
agileGrid.dndHoverCell = cell;
- agileGrid.dndHoverCellMode = 0;
+ agileGrid.dndHoverDropMode = ProrAgileGrid.DND_DROP_AS_SIBLING;
}
agileGrid.redraw();
}
@@ -602,20 +600,26 @@ public class ProrAgileGridViewer extends Viewer {
protected float getLocation(DropTargetEvent event) {
Point pos = agileGrid.toControl(event.x, event.y);
Cell cell = agileGrid.getCell(pos.x, pos.y);
- int rowHeight = ((ProrLayoutAdvisor) agileGrid.getLayoutAdvisor()).getRowHeight(cell.row);
- int y = agileGrid.getYForRow(cell.row);
- int mouseY = pos.y - y;
- float location = (float)mouseY / (float)rowHeight;
+ if (agileGrid.getLayoutAdvisor() instanceof ProrLayoutAdvisor) {
+ ProrLayoutAdvisor layoutAdvisor = (ProrLayoutAdvisor) agileGrid.getLayoutAdvisor();
- if (location < 0.3){
- return 0.0F;
- }else if(location <= 0.7){
- return 0.5F;
- }else{
- return 1.0F;
+ int rowHeight = layoutAdvisor.getRowHeight(cell.row);
+ int y = agileGrid.getYForRow(cell.row);
+ int mouseY = pos.y - y;
+
+ float location = (float)mouseY / (float)rowHeight;
+
+ if (location < 0.3){
+ return 0.0F;
+ }else if(location <= 0.7){
+ return 0.5F;
+ }else{
+ return 1.0F;
+ }
}
+ return 1.0F;
}
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrLinkCellRenderer.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrLinkCellRenderer.java
index 25d89ba..9aa19c3 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrLinkCellRenderer.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/agilegrid/ProrLinkCellRenderer.java
@@ -29,7 +29,7 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-public class ProrLinkCellRenderer extends TextCellRenderer {
+public class ProrLinkCellRenderer extends AbstractProrCellRenderer {
private Set<SpecRelation> incoming;
private Set<SpecRelation> outgoing;
@@ -100,12 +100,5 @@ public class ProrLinkCellRenderer extends TextCellRenderer {
}
}
- // Workaround: Upon closing a UIEditor and reopening a new one, the color got
- // disposed. No idea why. This is a workaround.
- protected void initialColor(int row, int col) {
- if (agileGrid.isCellSelected(row, col)) {
- background = SWTResourceManager.getColor(223, 227, 237);
- }
- }
}