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 105902 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]
Fix sorter location
patch.txt (text/plain), 29.97 KB, created by
Thomas Schindl
on 2008-06-26 09:41:54 EDT
(
hide
)
Description:
Fix sorter location
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2008-06-26 09:41:54 EDT
Size:
29.97 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.nebula.widgets.grid >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 26 Jun 2008 13:40:55 -0000 >@@ -68,9 +68,11 @@ > > y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin); > } >- >- return new Point(x, y); >- } >+ >+ y += computeControlSize(column).y; >+ >+ return new Point(x, y); >+ } > > /** > * {@inheritDoc} >@@ -78,7 +80,6 @@ > public void paint(GC gc, Object value) > { > GridColumn column = (GridColumn)value; >- > boolean flat = (column.getParent().getCellSelectionEnabled() && !column.getMoveable()); > > boolean drawSelected = ((isMouseDown() && isHover())); >@@ -103,8 +104,13 @@ > > if (column.getImage() != null) > { >- gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset, >- getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height); >+ int y = bottomMargin; >+ >+ if( column.getHeaderControl() == null ) { >+ y = getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height; >+ } >+ >+ gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset, y); > x += column.getImage().getBounds().width + imageSpacing; > } > >@@ -121,8 +127,13 @@ > > gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); > >- int y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight(); >- >+ 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) >@@ -148,25 +159,38 @@ > > if (column.getSort() != SWT.NONE) > { >+ if( column.getHeaderControl() == null ) { >+ y = getBounds().y >+ + ((getBounds().height - arrowRenderer.getBounds().height) / 2) >+ + 1; >+ } else { >+ y = getBounds().y >+ + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2) >+ + 1; >+ } >+ > 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); >+ - arrowRenderer.getBounds().width + 1,y >+ ); > } > else > { >+ if( column.getHeaderControl() == null ) { >+ y = getBounds().y >+ + ((getBounds().height - arrowRenderer.getBounds().height) / 2); >+ } else { >+ y = getBounds().y >+ + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2); >+ } > arrowRenderer > .setLocation( > getBounds().x + getBounds().width - arrowMargin >- - arrowRenderer.getBounds().width, >- getBounds().y >- + ((getBounds().height - arrowRenderer.getBounds().height) / 2)); >+ - arrowRenderer.getBounds().width,y); > } > arrowRenderer.paint(gc, null); > } >@@ -305,4 +329,21 @@ > > 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/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 26 Jun 2008 13:40:55 -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,29 @@ > 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); >+ getParent().recalculateHeader(); >+ } >+ >+ /** >+ * @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 26 Jun 2008 13:40:55 -0000 >@@ -40,4 +40,14 @@ > { > 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/Grid.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/Grid.java,v >retrieving revision 1.63 >diff -u -r1.63 Grid.java >--- src/org/eclipse/nebula/widgets/grid/Grid.java 27 Feb 2008 16:42:07 -0000 1.63 >+++ src/org/eclipse/nebula/widgets/grid/Grid.java 26 Jun 2008 13:40:54 -0000 >@@ -7660,6 +7660,12 @@ > return columns.size() - 1; > } > >+ void recalculateHeader() { >+ computeHeaderHeight(sizingGC); >+ scrollValuesObsolete = true; >+ redraw(); >+ } >+ > /** > * Removes the given column from the table. > * >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,225 @@ >+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(); >+ } >+ } >+ >+ }); >+ >+ } >+ >+} >#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 26 Jun 2008 13:40:56 -0000 >@@ -9,15 +9,19 @@ > * IBM Corporation - initial API and implementation > *******************************************************************************/ > package org.eclipse.swt.nebula.snippets.grid; >- > > import org.eclipse.nebula.widgets.grid.Grid; > 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.events.MouseAdapter; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.MouseListener; > 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. >@@ -27,35 +31,56 @@ > */ > public class GridSnippet2 { > >-public static void main (String [] args) { >- Display display = new Display (); >- Shell shell = new Shell (display); >- shell.setLayout(new FillLayout()); >- >- 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); >- GridColumn column2 = new GridColumn(grid,SWT.NONE); >- column2.setText("Column 2"); >- column2.setWidth(100); >- GridItem item1 = new GridItem(grid,SWT.NONE); >- item1.setText("First Item"); >- item1.setText(1,"xxxxxxx"); >- GridItem item2 = new GridItem(grid,SWT.NONE); >- item2.setText("This cell spans both columns"); >- item1.setText(1,"xxxxxxx"); >- item2.setColumnSpan(0,1); >- GridItem item3 = new GridItem(grid,SWT.NONE); >- item3.setText("Third Item"); >- item1.setText(1,"xxxxxxx"); >- >- shell.setSize(200,200); >- shell.open (); >- while (!shell.isDisposed()) { >- if (!display.readAndDispatch ()) display.sleep (); >- } >- display.dispose (); >-} >-} >\ No newline at end of file >+ public static void main(String[] args) { >+ Display display = new Display(); >+ Shell shell = new Shell(display); >+ shell.setLayout(new FillLayout()); >+ >+ final 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.BORDER)); >+ >+ for (int i = 0; i < 100; i++) { >+ GridItem item1 = new GridItem(grid, SWT.NONE); >+ item1.setText("First Item"); >+ item1.setText(1, "xxxxxxx"); >+ GridItem item2 = new GridItem(grid, SWT.NONE); >+ item2.setText("This cell spans both columns"); >+ item1.setText(1, "xxxxxxx"); >+ item2.setColumnSpan(0, 1); >+ GridItem item3 = new GridItem(grid, SWT.NONE); >+ item3.setText("Third Item"); >+ item1.setText(1, "xxxxxxx"); >+ } >+ >+ grid.addMouseListener(new MouseAdapter() { >+ >+ public void mouseDown(MouseEvent e) { >+ if (e.y < grid.getHeaderHeight()) { >+ System.out.println("header click"); >+ } >+ } >+ >+ }); >+ >+ shell.setSize(200, 200); >+ shell.open(); >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) >+ display.sleep(); >+ } >+ display.dispose(); >+ } >+} >\ No newline at end of file >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 26 Jun 2008 13:40:56 -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 26 Jun 2008 13:40:56 -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 26 Jun 2008 13:40:56 -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(); >+ >+ } >+}
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
Flags:
wim.jongman
:
iplog+
wim.jongman
:
review-
Actions:
View
|
Diff
Attachments on
bug 237846
:
105448
|
105452
|
105637
| 105902