Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 105448 Details for
Bug 237846
Add possibility to add a control to the head of a column
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Work ontop of the original one
patch.txt (text/plain), 42.23 KB, created by
Thomas Schindl
on 2008-06-19 16:39:01 EDT
(
hide
)
Description:
Work ontop of the original one
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2008-06-19 16:39:01 EDT
Size:
42.23 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.swt.nebula.snippets >Index: src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java,v >retrieving revision 1.4 >diff -u -r1.4 GridSnippet2.java >--- src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java 27 Mar 2007 20:04:08 -0000 1.4 >+++ src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java 19 Jun 2008 20:36:02 -0000 >@@ -15,9 +15,11 @@ > import org.eclipse.nebula.widgets.grid.GridColumn; > import org.eclipse.nebula.widgets.grid.GridItem; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CCombo; > import org.eclipse.swt.layout.FillLayout; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; > > /* > * Create a grid with an item that spans columns. >@@ -34,12 +36,20 @@ > > Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); > grid.setHeaderVisible(true); >+ > GridColumn column = new GridColumn(grid,SWT.NONE); > column.setText("Column 1"); > column.setWidth(100); >+ column.setHeaderControl(new CCombo(grid,SWT.READ_ONLY|SWT.BORDER)); >+ column.setMoveable(true); >+ > GridColumn column2 = new GridColumn(grid,SWT.NONE); > column2.setText("Column 2"); > column2.setWidth(100); >+ column2.setMoveable(true); >+ column2.setHeaderControl(new Text(grid,SWT.NONE)); >+ >+ > GridItem item1 = new GridItem(grid,SWT.NONE); > item1.setText("First Item"); > item1.setText(1,"xxxxxxx"); >Index: src/org/eclipse/swt/nebula/snippets/cdatetime/CDTSnippet01.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/src/org/eclipse/swt/nebula/snippets/cdatetime/CDTSnippet01.java,v >retrieving revision 1.5 >diff -u -r1.5 CDTSnippet01.java >--- src/org/eclipse/swt/nebula/snippets/cdatetime/CDTSnippet01.java 12 Mar 2007 08:24:46 -0000 1.5 >+++ src/org/eclipse/swt/nebula/snippets/cdatetime/CDTSnippet01.java 19 Jun 2008 20:36:02 -0000 >@@ -3,10 +3,13 @@ > import org.eclipse.nebula.widgets.cdatetime.CDT; > import org.eclipse.nebula.widgets.cdatetime.CDateTime; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > >@@ -25,9 +28,20 @@ > GridLayout layout = new GridLayout(); > shell.setLayout(layout); > >- final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN); >+ final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN | CDT.DATE_LONG | CDT.TIME_SHORT ); > cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); > >+ >+ Button b = new Button(shell,SWT.PUSH); >+ b.addSelectionListener(new SelectionAdapter() { >+ >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ System.err.println(cdt.getSelection()); >+ } >+ >+ }); >+ > shell.pack(); > Point size = shell.getSize(); > Rectangle screen = display.getMonitors()[0].getBounds(); >@@ -37,6 +51,8 @@ > size.x, > size.y > ); >+ >+ > shell.open(); > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/META-INF/MANIFEST.MF,v >retrieving revision 1.11 >diff -u -r1.11 MANIFEST.MF >--- META-INF/MANIFEST.MF 25 Jan 2008 21:24:54 -0000 1.11 >+++ META-INF/MANIFEST.MF 19 Jun 2008 20:36:02 -0000 >@@ -9,14 +9,11 @@ > org.eclipse.core.runtime, > org.eclipse.nebula.jface.gridviewer, > org.eclipse.nebula.widgets.cdatetime, >- org.eclipse.nebula.widgets.ctree, >- org.eclipse.nebula.widgets.datechooser, >- org.eclipse.nebula.widgets.formattedtext, >- org.eclipse.nebula.widgets.gallery, > org.eclipse.nebula.widgets.grid, >- org.eclipse.nebula.widgets.pgroup, > org.eclipse.nebula.widgets.pshelf, >- org.eclipse.nebula.widgets.compositetable >+ org.eclipse.nebula.widgets.calendarcombo;bundle-version="1.0.0", >+ org.eclipse.nebula.widgets.datechooser;bundle-version="1.0.0", >+ org.eclipse.nebula.widgets.formattedtext;bundle-version="1.0.0" > Export-Package: org.eclipse.swt.nebula.snippets.ctree, > org.eclipse.swt.nebula.snippets.grid > Bundle-ClassPath: . >Index: .classpath >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.swt.nebula.snippets/.classpath,v >retrieving revision 1.1 >diff -u -r1.1 .classpath >--- .classpath 7 Jun 2006 17:18:11 -0000 1.1 >+++ .classpath 19 Jun 2008 20:36:02 -0000 >@@ -1,7 +1,7 @@ > <?xml version="1.0" encoding="UTF-8"?> > <classpath> >- <classpathentry kind="src" path="src"/> > <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> > <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> >+ <classpathentry kind="src" path="src"/> > <classpathentry kind="output" path="bin"/> > </classpath> >Index: src/org/eclipse/nebula/snippets/gridviewer/Test.java >=================================================================== >RCS file: src/org/eclipse/nebula/snippets/gridviewer/Test.java >diff -N src/org/eclipse/nebula/snippets/gridviewer/Test.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/snippets/gridviewer/Test.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,223 @@ >+package org.eclipse.nebula.snippets.gridviewer; >+ >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; >+ >+import org.eclipse.jface.viewers.ArrayContentProvider; >+import org.eclipse.jface.viewers.CellEditor; >+import org.eclipse.jface.viewers.ColumnLabelProvider; >+import org.eclipse.jface.viewers.ColumnViewerEditor; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener; >+import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; >+import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent; >+import org.eclipse.jface.viewers.ICellModifier; >+import org.eclipse.jface.viewers.TextCellEditor; >+import org.eclipse.nebula.jface.gridviewer.GridTableViewer; >+import org.eclipse.nebula.jface.gridviewer.GridViewerColumn; >+import org.eclipse.nebula.jface.gridviewer.GridViewerEditor; >+import org.eclipse.nebula.widgets.grid.Grid; >+import org.eclipse.nebula.widgets.grid.GridItem; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+ >+public class Test >+{ >+ private Pattern m_IsValidPattern = null; >+ >+ public class MyModel >+ { >+ private String sCounter = ""; >+ >+ public MyModel(){ >+ } >+ >+ public void setCounter(String sCounter) >+ { >+ this.sCounter = sCounter; >+ } >+ >+ public String toString() >+ { >+ return sCounter; >+ } >+ } >+ >+ public class MyTextCellEditor extends TextCellEditor >+ { >+ /** >+ * search pattern is Numeric character >+ */ >+ private Pattern m_IsValidPattern = null; >+ >+ public MyTextCellEditor(Grid parent) { >+ super(parent); >+ m_IsValidPattern = Pattern.compile("[\\w+-\\.]"); >+ } >+ >+ @Override >+ public void activate(ColumnViewerEditorActivationEvent activationEvent) { >+ >+ // set the activation character >+ String s1 = String.valueOf( activationEvent.character ); >+ Matcher matcher = m_IsValidPattern.matcher( s1 ); >+ if (matcher.matches()) { >+ doSetValue(s1); >+ } >+ super.activate(activationEvent); >+ } >+ } >+ >+ >+ public Test(Shell shell) >+ { >+ /* allow numbers and characters */ >+ m_IsValidPattern = Pattern.compile("[\\w+-\\.]"); >+ >+ final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER >+ | SWT.H_SCROLL | SWT.V_SCROLL); >+ >+ >+ v.setCellEditors(new CellEditor[] { >+ new MyTextCellEditor(v.getGrid()), >+ new MyTextCellEditor(v.getGrid()) >+ }); >+ >+ v.setCellModifier(new ICellModifier() { >+ >+ public boolean canModify(Object element, String property) { >+ return true; >+ } >+ >+ public Object getValue(Object element, String property) { >+ return element.toString(); >+ } >+ >+ public void modify(Object element, String property, Object value) { >+ if (element instanceof GridItem) { >+ GridItem item = (GridItem)element; >+ MyModel model = (MyModel)(item.getData()); >+ model.setCounter(value.toString()); >+ v.update(model, null); >+ } >+ } >+ }); >+ >+ >+ ColumnViewerEditorActivationListener listener = new ColumnViewerEditorActivationListener() { >+ >+ public void afterEditorActivated( >+ ColumnViewerEditorActivationEvent event) >+ { >+ } >+ >+ public void afterEditorDeactivated( >+ ColumnViewerEditorDeactivationEvent event) >+ { >+ } >+ >+ public void beforeEditorActivated( >+ ColumnViewerEditorActivationEvent event) >+ { >+ } >+ >+ public void beforeEditorDeactivated( >+ ColumnViewerEditorDeactivationEvent event) >+ { >+ } >+ }; >+ >+ v.setContentProvider(new ArrayContentProvider()); >+ v.setColumnProperties(new String[] { "1", "2" }); >+ v.getGrid().setCellSelectionEnabled(true); >+ v.getGrid().setLinesVisible(true); >+ v.getGrid().setHeaderVisible(true); >+ >+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy( >+ v) { >+ protected boolean isEditorActivationEvent( >+ ColumnViewerEditorActivationEvent event) >+ { >+ boolean result; >+ >+ String s1 = String.valueOf( event.character ); >+ Matcher matcher = m_IsValidPattern.matcher( s1 ); >+ boolean bIsCharKey = matcher.matches(); >+ >+ boolean bEnableKey = >+ (event.keyCode == SWT.CR) || >+ (event.keyCode == SWT.KEYPAD_CR) || >+ (event.keyCode == SWT.F2) || >+ bIsCharKey; >+ >+ result = event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL >+ || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION >+ || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && bEnableKey) >+ || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; >+ >+ return result; >+ } >+ }; >+ >+ GridViewerEditor.create(v, actSupport, >+ ColumnViewerEditor.TABBING_HORIZONTAL >+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR >+ | ColumnViewerEditor.TABBING_VERTICAL >+ | ColumnViewerEditor.KEYBOARD_ACTIVATION); >+ >+ v.getColumnViewerEditor().addEditorActivationListener(listener); >+ >+ GridViewerColumn column = new GridViewerColumn(v, SWT.NONE); >+ column.getColumn().setWidth(200); >+ column.getColumn().setMoveable(true); >+ column.getColumn().setText("Column 1"); >+ column.setLabelProvider(new ColumnLabelProvider()); >+ >+ column = new GridViewerColumn(v, SWT.NONE); >+ column.getColumn().setWidth(200); >+ column.getColumn().setMoveable(true); >+ column.getColumn().setText("Column 2"); >+ column.setLabelProvider(new ColumnLabelProvider()); >+ >+ MyModel[] model = createModel(); >+ >+ v.setInput(model); >+ } >+ >+ private MyModel[] createModel() { >+ >+ MyModel[] elements = new MyModel[10]; >+ >+ for (int i = 0; i < 10; i++) >+ { >+ elements[i] = new MyModel(); >+ if (i<3){ >+ Double h = Double.valueOf(i); >+ elements[i].setCounter( h.toString() ); >+ } >+ } >+ return elements; >+ } >+ >+ public static void main(String[] args) >+ { >+ Display display = new Display(); >+ >+ Shell shell = new Shell(display); >+ shell.setLayout(new FillLayout()); >+ new Test(shell); >+ shell.open(); >+ >+ while (!shell.isDisposed()) >+ { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ >+ display.dispose(); >+ >+ } >+} >#P org.eclipse.nebula.widgets.grid >Index: src/org/eclipse/nebula/widgets/grid/GridColumn.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridColumn.java,v >retrieving revision 1.5 >diff -u -r1.5 GridColumn.java >--- src/org/eclipse/nebula/widgets/grid/GridColumn.java 7 May 2007 15:03:33 -0000 1.5 >+++ src/org/eclipse/nebula/widgets/grid/GridColumn.java 19 Jun 2008 20:36:04 -0000 >@@ -18,6 +18,7 @@ > import org.eclipse.swt.graphics.GC; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Item; > import org.eclipse.swt.widgets.TypedListener; >@@ -40,6 +41,7 @@ > */ > public class GridColumn extends Item > { >+ private GridHeaderEditor controlEditor; > > /** > * Default width of the column. >@@ -1086,4 +1088,28 @@ > cellRenderer.setWordWrap(wordWrap); > parent.redraw(); > } >+ >+ /** >+ * Set a new editor at the top of the control. If there's an editor already >+ * set it is disposed. >+ * >+ * @param control >+ * the control to be displayed in the header >+ */ >+ public void setHeaderControl(Control control) { >+ if (this.controlEditor == null) { >+ this.controlEditor = new GridHeaderEditor(this); >+ } >+ this.controlEditor.setEditor(control); >+ } >+ >+ /** >+ * @return the current header control >+ */ >+ public Control getHeaderControl() { >+ if( this.controlEditor != null ) { >+ return this.controlEditor.getEditor(); >+ } >+ return null; >+ } > } >Index: src/org/eclipse/nebula/widgets/grid/GridHeaderRenderer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridHeaderRenderer.java,v >retrieving revision 1.3 >diff -u -r1.3 GridHeaderRenderer.java >--- src/org/eclipse/nebula/widgets/grid/GridHeaderRenderer.java 27 Mar 2007 23:09:55 -0000 1.3 >+++ src/org/eclipse/nebula/widgets/grid/GridHeaderRenderer.java 19 Jun 2008 20:36:04 -0000 >@@ -4,40 +4,52 @@ > > /** > * <p> >- * NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A PRE-RELEASE ALPHA >- * VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE VERSIONS. >- * </p> >- * The super class for all grid header renderers. Contains the properties specific >- * to a grid header. >- * >+ * NOTE: THIS WIDGET AND ITS API ARE STILL UNDER DEVELOPMENT. THIS IS A >+ * PRE-RELEASE ALPHA VERSION. USERS SHOULD EXPECT API CHANGES IN FUTURE >+ * VERSIONS. >+ * </p> >+ * The super class for all grid header renderers. Contains the properties >+ * specific to a grid header. >+ * > * @author chris.gross@us.ibm.com > */ >-public abstract class GridHeaderRenderer extends AbstractInternalWidget >-{ >- /** >- * Returns the bounds of the text in the cell. This is used when displaying in-place tooltips. >- * If <code>null</code> is returned here, in-place tooltips will not be displayed. If the >- * <code>preferred</code> argument is <code>true</code> then the returned bounds should be large >- * enough to show the entire text. If <code>preferred</code> is <code>false</code> then the >- * returned bounds should be be relative to the current bounds. >- * >- * @param value the object being rendered. >- * @param preferred true if the preferred width of the text should be returned. >- * @return bounds of the text. >- */ >- public Rectangle getTextBounds(Object value, boolean preferred) >- { >- return null; >- } >- >- /** >- * Returns the bounds of the toggle within the header (typically only group headers have toggles) >- * or null. >- * >- * @return toggle bounds or null if no toggle exists. >- */ >- public Rectangle getToggleBounds() >- { >- return null; >- } >+public abstract class GridHeaderRenderer extends AbstractInternalWidget { >+ >+ /** >+ * Returns the bounds of the text in the cell. This is used when displaying >+ * in-place tooltips. If <code>null</code> is returned here, in-place >+ * tooltips will not be displayed. If the <code>preferred</code> argument is >+ * <code>true</code> then the returned bounds should be large enough to show >+ * the entire text. If <code>preferred</code> is <code>false</code> then the >+ * returned bounds should be be relative to the current bounds. >+ * >+ * @param value >+ * the object being rendered. >+ * @param preferred >+ * true if the preferred width of the text should be returned. >+ * @return bounds of the text. >+ */ >+ public Rectangle getTextBounds(Object value, boolean preferred) { >+ return null; >+ } >+ >+ /** >+ * Returns the bounds of the toggle within the header (typically only group >+ * headers have toggles) or null. >+ * >+ * @return toggle bounds or null if no toggle exists. >+ */ >+ public Rectangle getToggleBounds() { >+ return null; >+ } >+ >+ /** >+ * Returns the bounds of the control to display >+ * >+ * @return the bounds for the control or <code>null</code> if no control is >+ * rendered >+ */ >+ protected Rectangle getControlBounds(Object value, boolean preferred) { >+ return null; >+ } > } >Index: src/org/eclipse/nebula/widgets/grid/internal/DefaultColumnHeaderRenderer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/internal/DefaultColumnHeaderRenderer.java,v >retrieving revision 1.4 >diff -u -r1.4 DefaultColumnHeaderRenderer.java >--- src/org/eclipse/nebula/widgets/grid/internal/DefaultColumnHeaderRenderer.java 2 Jan 2008 18:48:03 -0000 1.4 >+++ src/org/eclipse/nebula/widgets/grid/internal/DefaultColumnHeaderRenderer.java 19 Jun 2008 20:36:04 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * chris.gross@us.ibm.com - initial API and implementation >- *******************************************************************************/ >+ *******************************************************************************/ > package org.eclipse.nebula.widgets.grid.internal; > > import org.eclipse.nebula.widgets.grid.GridColumn; >@@ -20,289 +20,286 @@ > > /** > * The column header renderer. >- * >+ * > * @author chris.gross@us.ibm.com > * @since 2.0.0 > */ >-public class DefaultColumnHeaderRenderer extends GridHeaderRenderer >-{ >+public class DefaultColumnHeaderRenderer extends GridHeaderRenderer { > >- int leftMargin = 6; >+ int leftMargin = 6; > >- int rightMargin = 6; >+ int rightMargin = 6; > >- int topMargin = 3; >+ int topMargin = 3; > >- int bottomMargin = 3; >- >- int arrowMargin = 6; >- >- int imageSpacing = 3; >- >- private SortArrowRenderer arrowRenderer = new SortArrowRenderer(); >- >- /** >- * {@inheritDoc} >- */ >- public Point computeSize(GC gc, int wHint, int hHint, Object value) >- { >- GridColumn column = (GridColumn)value; >- >- int x = 0; >- >- x += leftMargin; >- >- x += gc.stringExtent(column.getText()).x + rightMargin; >- >- int y = 0; >- >- y += topMargin; >- >- y += gc.getFontMetrics().getHeight(); >- >- y += bottomMargin; >- >- if (column.getImage() != null) >- { >- x += column.getImage().getBounds().width + imageSpacing; >- >- y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin); >- } >- >- return new Point(x, y); >- } >- >- /** >- * {@inheritDoc} >- */ >- public void paint(GC gc, Object value) >- { >- GridColumn column = (GridColumn)value; >- >- boolean flat = (column.getParent().getCellSelectionEnabled() && !column.getMoveable()); >- >- boolean drawSelected = ((isMouseDown() && isHover())); >- >- gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); >- >- if (flat && isSelected()) >- { >- gc.setBackground(column.getParent().getCellHeaderSelectionBackground()); >- } >- >- gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, >- getBounds().height); >- >- int pushedDrawingOffset = 0; >- if (drawSelected) >- { >- pushedDrawingOffset = 1; >- } >- >- int x = leftMargin; >- >- if (column.getImage() != null) >- { >- gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset, >- getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height); >- x += column.getImage().getBounds().width + imageSpacing; >- } >- >- int width = getBounds().width - x; >- >- if (column.getSort() == SWT.NONE) >- { >- width -= rightMargin; >- } >- else >- { >- width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin; >- } >- >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); >- >- int y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight(); >- >- String text = TextUtils.getShortString(gc, column.getText(), width); >- >- if (column.getAlignment() == SWT.RIGHT) >- { >- int len = gc.stringExtent(text).x; >- if (len < width) >- { >- x += width - len; >- } >- } >- else if (column.getAlignment() == SWT.CENTER) >- { >- int len = gc.stringExtent(text).x; >- if (len < width) >- { >- x += (width - len) / 2; >- } >- } >- >- >- gc.drawString(text, getBounds().x + x + pushedDrawingOffset, >- y + pushedDrawingOffset,true); >- >- if (column.getSort() != SWT.NONE) >- { >- arrowRenderer.setSelected(column.getSort() == SWT.UP); >- if (drawSelected) >- { >- arrowRenderer >- .setLocation( >- getBounds().x + getBounds().width - arrowMargin >- - arrowRenderer.getBounds().width + 1, >- getBounds().y >- + ((getBounds().height - arrowRenderer.getBounds().height) / 2) >- + 1); >- } >- else >- { >- arrowRenderer >- .setLocation( >- getBounds().x + getBounds().width - arrowMargin >- - arrowRenderer.getBounds().width, >- getBounds().y >- + ((getBounds().height - arrowRenderer.getBounds().height) / 2)); >- } >- arrowRenderer.paint(gc, null); >- } >- >- if (!flat) >- { >- >- if (drawSelected) >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); >- } >- else >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); >- } >- >- gc.drawLine(getBounds().x, getBounds().y, getBounds().x + getBounds().width - 1, >- getBounds().y); >- gc.drawLine(getBounds().x, getBounds().y, getBounds().x, getBounds().y + getBounds().height >- - 1); >- >- if (!drawSelected) >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); >- gc.drawLine(getBounds().x + 1, getBounds().y + 1, >- getBounds().x + getBounds().width - 2, getBounds().y + 1); >- gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x + 1, >- getBounds().y + getBounds().height - 2); >- } >- >- if (drawSelected) >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); >- } >- else >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >- } >- gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x >- + getBounds().width - 1, >- getBounds().y + getBounds().height - 1); >- gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x >- + getBounds().width - 1, >- getBounds().y + getBounds().height - 1); >- >- if (!drawSelected) >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); >- gc.drawLine(getBounds().x + getBounds().width - 2, getBounds().y + 1, >- getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height >- - 2); >- gc.drawLine(getBounds().x + 1, getBounds().y + getBounds().height - 2, >- getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height >- - 2); >- } >- >- } >- else >- { >- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); >- >- gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x >- + getBounds().width - 1, >- getBounds().y + getBounds().height - 1); >- gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x >- + getBounds().width - 1, >- getBounds().y + getBounds().height - 1); >- } >- >- >- } >- >- /** >- * {@inheritDoc} >- */ >- public void setDisplay(Display display) >- { >- super.setDisplay(display); >- arrowRenderer.setDisplay(display); >- } >- >- /** >- * {@inheritDoc} >- */ >- public boolean notify(int event, Point point, Object value) >- { >- return false; >- } >- >- /** >- * {@inheritDoc} >- */ >- public Rectangle getTextBounds(Object value, boolean preferred) >- { >- GridColumn column = (GridColumn)value; >- >- int x = leftMargin; >- >- if (column.getImage() != null) >- { >- x += column.getImage().getBounds().width + imageSpacing; >- } >- >- >- >- GC gc = new GC(column.getParent()); >- gc.setFont(column.getParent().getFont()); >- int y = getBounds().height - bottomMargin - gc.getFontMetrics().getHeight(); >- >- Rectangle bounds = new Rectangle(x,y,0,0); >- >- Point p = gc.stringExtent(column.getText()); >- >- bounds.height = p.y; >- >- if (preferred) >- { >- bounds.width = p.x; >- } >- else >- { >- int width = getBounds().width - x; >- if (column.getSort() == SWT.NONE) >- { >- width -= rightMargin; >- } >- else >- { >- width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin; >- } >- bounds.width = width; >- } >- >- >- gc.dispose(); >- >- return bounds; >- } >+ int bottomMargin = 3; >+ >+ int arrowMargin = 6; >+ >+ int imageSpacing = 3; >+ >+ private SortArrowRenderer arrowRenderer = new SortArrowRenderer(); >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Point computeSize(GC gc, int wHint, int hHint, Object value) { >+ GridColumn column = (GridColumn) value; >+ >+ int x = 0; >+ >+ x += leftMargin; >+ >+ x += gc.stringExtent(column.getText()).x + rightMargin; >+ >+ int y = 0; >+ >+ y += topMargin; >+ >+ y += gc.getFontMetrics().getHeight(); >+ >+ y += bottomMargin; >+ >+ if (column.getImage() != null) { >+ x += column.getImage().getBounds().width + imageSpacing; >+ >+ y = Math.max(y, topMargin + column.getImage().getBounds().height >+ + bottomMargin); >+ } >+ >+ y += computeControlSize(column).y; >+ >+ return new Point(x, y); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void paint(GC gc, Object value) { >+ GridColumn column = (GridColumn) value; >+ >+ boolean flat = (column.getParent().getCellSelectionEnabled() && !column >+ .getMoveable()); >+ >+ boolean drawSelected = ((isMouseDown() && isHover())); >+ >+ gc.setBackground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_BACKGROUND)); >+ >+ if (flat && isSelected()) { >+ gc.setBackground(column.getParent() >+ .getCellHeaderSelectionBackground()); >+ } >+ >+ gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, >+ getBounds().height); >+ >+ int pushedDrawingOffset = 0; >+ if (drawSelected) { >+ pushedDrawingOffset = 1; >+ } >+ >+ int x = leftMargin; >+ >+ if (column.getImage() != null) { >+ gc.drawImage(column.getImage(), getBounds().x + x >+ + pushedDrawingOffset, getBounds().y + pushedDrawingOffset >+ + getBounds().height - bottomMargin >+ - column.getImage().getBounds().height); >+ x += column.getImage().getBounds().width + imageSpacing; >+ } >+ >+ int width = getBounds().width - x; >+ >+ if (column.getSort() == SWT.NONE) { >+ width -= rightMargin; >+ } else { >+ width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin; >+ } >+ >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_FOREGROUND)); >+ >+ int y = bottomMargin; >+ >+ if( column.getHeaderControl() == null ) { >+ y = getBounds().y + getBounds().height - bottomMargin >+ - gc.getFontMetrics().getHeight(); >+ } >+ >+ String text = TextUtils.getShortString(gc, column.getText(), width); >+ >+ if (column.getAlignment() == SWT.RIGHT) { >+ int len = gc.stringExtent(text).x; >+ if (len < width) { >+ x += width - len; >+ } >+ } else if (column.getAlignment() == SWT.CENTER) { >+ int len = gc.stringExtent(text).x; >+ if (len < width) { >+ x += (width - len) / 2; >+ } >+ } >+ >+ gc.drawString(text, getBounds().x + x + pushedDrawingOffset, y >+ + pushedDrawingOffset, true); >+ >+ if (column.getSort() != SWT.NONE) { >+ arrowRenderer.setSelected(column.getSort() == SWT.UP); >+ if (drawSelected) { >+ arrowRenderer.setLocation(getBounds().x + getBounds().width >+ - arrowMargin - arrowRenderer.getBounds().width + 1, >+ getBounds().y >+ + ((getBounds().height - arrowRenderer >+ .getBounds().height) / 2) + 1); >+ } else { >+ arrowRenderer.setLocation(getBounds().x + getBounds().width >+ - arrowMargin - arrowRenderer.getBounds().width, >+ getBounds().y >+ + ((getBounds().height - arrowRenderer >+ .getBounds().height) / 2)); >+ } >+ arrowRenderer.paint(gc, null); >+ } >+ >+ if (!flat) { >+ >+ if (drawSelected) { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_NORMAL_SHADOW)); >+ } else { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); >+ } >+ >+ gc.drawLine(getBounds().x, getBounds().y, getBounds().x >+ + getBounds().width - 1, getBounds().y); >+ gc.drawLine(getBounds().x, getBounds().y, getBounds().x, >+ getBounds().y + getBounds().height - 1); >+ >+ if (!drawSelected) { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_LIGHT_SHADOW)); >+ gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x >+ + getBounds().width - 2, getBounds().y + 1); >+ gc.drawLine(getBounds().x + 1, getBounds().y + 1, >+ getBounds().x + 1, getBounds().y + getBounds().height >+ - 2); >+ } >+ >+ if (drawSelected) { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_NORMAL_SHADOW)); >+ } else { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_DARK_SHADOW)); >+ } >+ gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, >+ getBounds().x + getBounds().width - 1, getBounds().y >+ + getBounds().height - 1); >+ gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, >+ getBounds().x + getBounds().width - 1, getBounds().y >+ + getBounds().height - 1); >+ >+ if (!drawSelected) { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_NORMAL_SHADOW)); >+ gc.drawLine(getBounds().x + getBounds().width - 2, >+ getBounds().y + 1, getBounds().x + getBounds().width >+ - 2, getBounds().y + getBounds().height - 2); >+ gc.drawLine(getBounds().x + 1, getBounds().y >+ + getBounds().height - 2, getBounds().x >+ + getBounds().width - 2, getBounds().y >+ + getBounds().height - 2); >+ } >+ >+ } else { >+ gc.setForeground(getDisplay().getSystemColor( >+ SWT.COLOR_WIDGET_DARK_SHADOW)); >+ >+ gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, >+ getBounds().x + getBounds().width - 1, getBounds().y >+ + getBounds().height - 1); >+ gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, >+ getBounds().x + getBounds().width - 1, getBounds().y >+ + getBounds().height - 1); >+ } >+ >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void setDisplay(Display display) { >+ super.setDisplay(display); >+ arrowRenderer.setDisplay(display); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public boolean notify(int event, Point point, Object value) { >+ return false; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Rectangle getTextBounds(Object value, boolean preferred) { >+ GridColumn column = (GridColumn) value; >+ >+ int x = leftMargin; >+ >+ if (column.getImage() != null) { >+ x += column.getImage().getBounds().width + imageSpacing; >+ } >+ >+ GC gc = new GC(column.getParent()); >+ gc.setFont(column.getParent().getFont()); >+ int y = bottomMargin; >+ >+ if( column.getHeaderControl() != null ) { >+ y = getBounds().height - bottomMargin >+ - gc.getFontMetrics().getHeight(); >+ } >+ >+ Rectangle bounds = new Rectangle(x, y, 0, 0); >+ >+ Point p = gc.stringExtent(column.getText()); >+ >+ bounds.height = p.y; >+ >+ if (preferred) { >+ bounds.width = p.x; >+ } else { >+ int width = getBounds().width - x; >+ if (column.getSort() == SWT.NONE) { >+ width -= rightMargin; >+ } else { >+ width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin; >+ } >+ bounds.width = width; >+ } >+ >+ gc.dispose(); >+ >+ return bounds; >+ } >+ >+ /** >+ * @return the bounds reserved for the control >+ */ >+ protected Rectangle getControlBounds(Object value, boolean preferred) { >+ Rectangle bounds = getBounds(); >+ GridColumn column = (GridColumn) value; >+ Point controlSize = computeControlSize(column); >+ return new Rectangle(bounds.x+3,bounds.height-bottomMargin-controlSize.y,bounds.width-6,controlSize.y); >+ } >+ >+ private Point computeControlSize(GridColumn column) { >+ if( column.getHeaderControl() != null ) { >+ return column.getHeaderControl().computeSize(SWT.DEFAULT, SWT.DEFAULT); >+ } >+ return new Point(0,0); >+ } > } >Index: src/org/eclipse/nebula/widgets/grid/GridHeaderEditor.java >=================================================================== >RCS file: src/org/eclipse/nebula/widgets/grid/GridHeaderEditor.java >diff -N src/org/eclipse/nebula/widgets/grid/GridHeaderEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/nebula/widgets/grid/GridHeaderEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,227 @@ >+package org.eclipse.nebula.widgets.grid; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.ControlEditor; >+import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.ControlListener; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * Manager for a Control that appears below the grid column header. >+ * Based on {@link GridEditor}. >+ */ >+class GridHeaderEditor extends ControlEditor { >+ >+ private Grid table; >+ >+ private GridColumn column; >+ >+ ControlListener columnListener; >+ >+ Listener resizeListener; >+ >+ private final Listener columnVisibleListener; >+ >+ private final Listener columnGroupListener; >+ >+ private final SelectionListener scrollListener; >+ >+ /** >+ * Creates a TableEditor for the specified Table. >+ * >+ * @param column the Table Control above which this editor will be displayed >+ */ >+ GridHeaderEditor(final GridColumn column) >+ { >+ super(column.getParent()); >+ >+ this.table = column.getParent(); >+ this.column = column; >+ >+ >+ columnListener = new ControlListener() >+ { >+ public void controlMoved(ControlEvent e) >+ { >+ table.getDisplay().asyncExec(new Runnable() { >+ >+ public void run() { >+ layout(); >+ } >+ >+ }); >+ } >+ >+ public void controlResized(ControlEvent e) >+ { >+ layout(); >+ } >+ }; >+ >+ columnVisibleListener = new Listener() >+ { >+ public void handleEvent(Event event) >+ { >+ getEditor().setVisible(((GridColumn)event.widget).isVisible()); >+ if (getEditor().isVisible()) layout(); >+ } >+ }; >+ >+ resizeListener = new Listener() >+ { >+ public void handleEvent(Event event) >+ { >+ layout(); >+ } >+ }; >+ >+ scrollListener = new SelectionListener() >+ { >+ public void widgetSelected(SelectionEvent e) >+ { >+ layout(); >+ } >+ public void widgetDefaultSelected(SelectionEvent e) >+ { >+ } >+ }; >+ >+ columnGroupListener = new Listener() >+ { >+ public void handleEvent(Event event) >+ { >+ if (getEditor() == null || getEditor().isDisposed()) return; >+ getEditor().setVisible(column.isVisible()); >+ if (getEditor().isVisible()) layout(); >+ } >+ }; >+ >+ // The following three listeners are workarounds for >+ // Eclipse bug 105764 >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105764 >+ table.addListener(SWT.Resize, resizeListener); >+ >+ if (table.getVerticalScrollBarProxy() != null) >+ { >+ table.getVerticalScrollBarProxy().addSelectionListener(scrollListener); >+ } >+ if (table.getHorizontalScrollBarProxy() != null) >+ { >+ table.getHorizontalScrollBarProxy().addSelectionListener(scrollListener); >+ } >+ >+ // To be consistent with older versions of SWT, grabVertical defaults to >+ // true >+ grabVertical = true; >+ >+ initColumn(); >+ } >+ >+ /** >+ * Returns the bounds of the editor. >+ * @return bounds of the editor. >+ */ >+ protected Rectangle internalComputeBounds() >+ { >+ return column.getHeaderRenderer().getControlBounds(column,true); >+ } >+ >+ /** >+ * Removes all associations between the TableEditor and the cell in the >+ * table. The Table and the editor Control are <b>not</b> disposed. >+ */ >+ public void dispose() >+ { >+ if (!table.isDisposed() && !column.isDisposed() ) >+ { >+ column.removeControlListener(columnListener); >+ if (column.getColumnGroup() != null){ >+ column.getColumnGroup().removeListener(SWT.Expand, columnGroupListener); >+ column.getColumnGroup().removeListener(SWT.Collapse, columnGroupListener); >+ } >+ } >+ >+ if (!table.isDisposed()) >+ { >+ table.removeListener(SWT.Resize, resizeListener); >+ >+ if (table.getVerticalScrollBarProxy() != null) >+ table.getVerticalScrollBarProxy().removeSelectionListener(scrollListener); >+ >+ if (table.getHorizontalScrollBarProxy() != null) >+ table.getHorizontalScrollBarProxy().removeSelectionListener(scrollListener); >+ } >+ >+ columnListener = null; >+ resizeListener = null; >+ table = null; >+ super.dispose(); >+ } >+ >+ /** >+ * Sets the zero based index of the column of the cell being tracked by this >+ * editor. >+ * >+ * @param column the zero based index of the column of the cell being >+ * tracked by this editor >+ */ >+ void initColumn() >+ { >+ >+ column.addControlListener(columnListener); >+ column.addListener(SWT.Show, columnVisibleListener); >+ column.addListener(SWT.Hide, columnVisibleListener); >+ >+ if (column.getColumnGroup() != null){ >+ column.getColumnGroup().addListener(SWT.Expand, columnGroupListener); >+ column.getColumnGroup().addListener(SWT.Collapse, columnGroupListener); >+ } >+ layout(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void layout() >+ { >+ if (table.isDisposed()) >+ return; >+ >+ >+ table.getDisplay().asyncExec(new Runnable() { >+ >+ public void run() { >+ boolean hadFocus = false; >+ >+ if (getEditor() == null || getEditor().isDisposed()) { >+ return; >+ } >+ >+ if (getEditor().getVisible()) >+ { >+ hadFocus = getEditor().isFocusControl(); >+ } >+ Rectangle rect = internalComputeBounds(); >+ if( rect == null ) { >+ getEditor().setVisible(false); >+ return; >+ } >+ getEditor().setBounds(rect); >+ >+ if (hadFocus) >+ { >+ if (getEditor() == null || getEditor().isDisposed()) >+ return; >+ getEditor().setFocus(); >+ } >+ } >+ >+ }); >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 237846
:
105448
|
105452
|
105637
|
105902