Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 237846 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/nebula/widgets/grid/internal/DefaultColumnHeaderRenderer.java (-15 / +56 lines)
Lines 68-76 Link Here
68
68
69
            y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin);
69
            y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin);
70
        }
70
        }
71
71
		
72
        return new Point(x, y);
72
		y += computeControlSize(column).y;
73
    }
73
		
74
		return new Point(x, y);
75
	}
74
76
75
    /** 
77
    /** 
76
     * {@inheritDoc}
78
     * {@inheritDoc}
Lines 78-84 Link Here
78
    public void paint(GC gc, Object value)
80
    public void paint(GC gc, Object value)
79
    {
81
    {
80
        GridColumn column = (GridColumn)value;
82
        GridColumn column = (GridColumn)value;
81
82
        boolean flat = (column.getParent().getCellSelectionEnabled() && !column.getMoveable());
83
        boolean flat = (column.getParent().getCellSelectionEnabled() && !column.getMoveable());
83
        
84
        
84
        boolean drawSelected = ((isMouseDown() && isHover()));
85
        boolean drawSelected = ((isMouseDown() && isHover()));
Lines 103-110 Link Here
103
104
104
        if (column.getImage() != null)
105
        if (column.getImage() != null)
105
        {
106
        {
106
                gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset,
107
        	int y = bottomMargin;
107
                        getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height);        		
108
        	
109
        	if( column.getHeaderControl() == null ) {
110
        		y = getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height;
111
        	}
112
        	
113
            gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset, y);        		
108
            x += column.getImage().getBounds().width + imageSpacing;
114
            x += column.getImage().getBounds().width + imageSpacing;
109
        }
115
        }
110
116
Lines 121-128 Link Here
121
127
122
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
128
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
123
129
124
        int y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight();
130
        int y = bottomMargin;
125
131
        		
132
        if( column.getHeaderControl() == null ) {
133
        	y = getBounds().y + getBounds().height - bottomMargin
134
        		- gc.getFontMetrics().getHeight();			
135
        }
136
        
126
        String text = TextUtils.getShortString(gc, column.getText(), width);
137
        String text = TextUtils.getShortString(gc, column.getText(), width);
127
        
138
        
128
        if (column.getAlignment() == SWT.RIGHT)
139
        if (column.getAlignment() == SWT.RIGHT)
Lines 148-172 Link Here
148
159
149
        if (column.getSort() != SWT.NONE)
160
        if (column.getSort() != SWT.NONE)
150
        {
161
        {
162
        	if( column.getHeaderControl() == null ) {
163
        		y = getBounds().y
164
                + ((getBounds().height - arrowRenderer.getBounds().height) / 2)
165
                + 1;
166
        	} else {
167
        		y = getBounds().y
168
                + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2)
169
                + 1;
170
        	}
171
        	
151
            arrowRenderer.setSelected(column.getSort() == SWT.UP);
172
            arrowRenderer.setSelected(column.getSort() == SWT.UP);
152
            if (drawSelected)
173
            if (drawSelected)
153
            {
174
            {
154
                arrowRenderer
175
                arrowRenderer
155
                    .setLocation(
176
                    .setLocation(
156
                                 getBounds().x + getBounds().width - arrowMargin
177
                                 getBounds().x + getBounds().width - arrowMargin
157
                                     - arrowRenderer.getBounds().width + 1,
178
                                     - arrowRenderer.getBounds().width + 1,y
158
                                 getBounds().y
179
                                 );
159
                                     + ((getBounds().height - arrowRenderer.getBounds().height) / 2)
160
                                     + 1);
161
            }
180
            }
162
            else
181
            else
163
            {
182
            {
183
            	if( column.getHeaderControl() == null ) {
184
            		y = getBounds().y
185
                    + ((getBounds().height - arrowRenderer.getBounds().height) / 2);
186
            	} else {
187
            		y = getBounds().y 
188
                    + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2);
189
            	}
164
                arrowRenderer
190
                arrowRenderer
165
                    .setLocation(
191
                    .setLocation(
166
                                 getBounds().x + getBounds().width - arrowMargin
192
                                 getBounds().x + getBounds().width - arrowMargin
167
                                     - arrowRenderer.getBounds().width,
193
                                     - arrowRenderer.getBounds().width,y);
168
                                 getBounds().y
169
                                     + ((getBounds().height - arrowRenderer.getBounds().height) / 2));
170
            }
194
            }
171
            arrowRenderer.paint(gc, null);
195
            arrowRenderer.paint(gc, null);
172
        }
196
        }
Lines 305-308 Link Here
305
        
329
        
306
        return bounds;        
330
        return bounds;        
307
    }    
331
    }    
332
333
	/**
334
	 * @return the bounds reserved for the control
335
	 */
336
	protected Rectangle getControlBounds(Object value, boolean preferred) {
337
		Rectangle bounds = getBounds();
338
		GridColumn column = (GridColumn) value;
339
		Point controlSize = computeControlSize(column);
340
		return new Rectangle(bounds.x+3,bounds.height-bottomMargin-controlSize.y,bounds.width-6,controlSize.y);
341
	}
342
343
	private Point computeControlSize(GridColumn column) {
344
		if( column.getHeaderControl() != null ) {
345
			return column.getHeaderControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
346
		}
347
		return new Point(0,0);
348
	}
308
}
349
}
(-)src/org/eclipse/nebula/widgets/grid/GridColumn.java (+27 lines)
Lines 18-23 Link Here
18
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.graphics.GC;
19
import org.eclipse.swt.graphics.Point;
19
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Item;
23
import org.eclipse.swt.widgets.Item;
23
import org.eclipse.swt.widgets.TypedListener;
24
import org.eclipse.swt.widgets.TypedListener;
Lines 40-45 Link Here
40
 */
41
 */
41
public class GridColumn extends Item
42
public class GridColumn extends Item
42
{
43
{
44
	private GridHeaderEditor controlEditor;
43
45
44
    /**
46
    /**
45
     * Default width of the column.
47
     * Default width of the column.
Lines 1086-1089 Link Here
1086
        cellRenderer.setWordWrap(wordWrap);
1088
        cellRenderer.setWordWrap(wordWrap);
1087
        parent.redraw();
1089
        parent.redraw();
1088
    }
1090
    }
1091
    
1092
    /**
1093
	 * Set a new editor at the top of the control. If there's an editor already
1094
	 * set it is disposed.
1095
	 * 
1096
	 * @param control
1097
	 *            the control to be displayed in the header
1098
	 */
1099
	public void setHeaderControl(Control control) {
1100
		if (this.controlEditor == null) {
1101
			this.controlEditor = new GridHeaderEditor(this);
1102
		}
1103
		this.controlEditor.setEditor(control);
1104
		getParent().recalculateHeader();
1105
	}
1106
	
1107
	/**
1108
	 * @return the current header control
1109
	 */
1110
	public Control getHeaderControl() {
1111
		if( this.controlEditor != null ) {
1112
			return this.controlEditor.getEditor();
1113
		}
1114
		return null;
1115
	}
1089
}
1116
}
(-)src/org/eclipse/nebula/widgets/grid/GridHeaderRenderer.java (+10 lines)
Lines 40-43 Link Here
40
    {
40
    {
41
        return null;
41
        return null;
42
    }
42
    }
43
44
	/**
45
	 * Returns the bounds of the control to display
46
	 * 
47
	 * @return the bounds for the control or <code>null</code> if no control is
48
	 *         rendered
49
	 */
50
	protected Rectangle getControlBounds(Object value, boolean preferred) {
51
		return null;
52
	}
43
}
53
}
(-)src/org/eclipse/nebula/widgets/grid/Grid.java (+6 lines)
Lines 7660-7665 Link Here
7660
        return columns.size() - 1;
7660
        return columns.size() - 1;
7661
    }
7661
    }
7662
7662
7663
    void recalculateHeader() {
7664
        computeHeaderHeight(sizingGC);
7665
        scrollValuesObsolete = true;
7666
        redraw();    	
7667
    }
7668
    
7663
    /**
7669
    /**
7664
     * Removes the given column from the table.
7670
     * Removes the given column from the table.
7665
     * 
7671
     * 
(-)src/org/eclipse/nebula/widgets/grid/GridHeaderEditor.java (+225 lines)
Added Link Here
1
package org.eclipse.nebula.widgets.grid;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.custom.ControlEditor;
5
import org.eclipse.swt.events.ControlEvent;
6
import org.eclipse.swt.events.ControlListener;
7
import org.eclipse.swt.events.SelectionEvent;
8
import org.eclipse.swt.events.SelectionListener;
9
import org.eclipse.swt.graphics.Rectangle;
10
import org.eclipse.swt.widgets.Event;
11
import org.eclipse.swt.widgets.Listener;
12
13
/**
14
 * Manager for a Control that appears below the grid column header.
15
 * Based on {@link GridEditor}. 
16
 */
17
class GridHeaderEditor extends ControlEditor {
18
19
  private Grid table;
20
21
  private GridColumn column;
22
  
23
  ControlListener columnListener;
24
  
25
  Listener resizeListener;
26
27
  private final Listener columnVisibleListener;
28
29
  private final Listener columnGroupListener;
30
31
  private final SelectionListener scrollListener;
32
  
33
  /**
34
   * Creates a TableEditor for the specified Table.
35
   * 
36
   * @param column the Table Control above which this editor will be displayed
37
   */
38
  GridHeaderEditor(final GridColumn column)
39
  {
40
      super(column.getParent());
41
      
42
      this.table = column.getParent();
43
      this.column = column;
44
      
45
      
46
      columnListener = new ControlListener()
47
      {
48
          public void controlMoved(ControlEvent e)
49
          {
50
              table.getDisplay().asyncExec(new Runnable() {
51
52
				public void run() {
53
					layout();
54
				}
55
            	  
56
              });
57
          }
58
59
          public void controlResized(ControlEvent e)
60
          {
61
              layout();
62
          }
63
      };
64
      
65
      columnVisibleListener = new Listener()
66
      {
67
        public void handleEvent(Event event)
68
          {
69
            getEditor().setVisible(((GridColumn)event.widget).isVisible());
70
            if (getEditor().isVisible()) layout();
71
          }  
72
      };
73
      
74
      resizeListener = new Listener()
75
      {
76
       public void handleEvent(Event event)
77
          {
78
              layout();
79
          }   
80
      };
81
      
82
      scrollListener = new SelectionListener()
83
      {
84
          public void widgetSelected(SelectionEvent e)
85
          {
86
              layout();
87
          }
88
          public void widgetDefaultSelected(SelectionEvent e)
89
          {
90
          }        
91
      };
92
      
93
      columnGroupListener = new Listener()
94
      {
95
          public void handleEvent(Event event)
96
          {
97
              if (getEditor() == null || getEditor().isDisposed()) return;
98
              getEditor().setVisible(column.isVisible());
99
              if (getEditor().isVisible()) layout();
100
          }
101
      };
102
103
      // The following three listeners are workarounds for
104
      // Eclipse bug 105764
105
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105764
106
      table.addListener(SWT.Resize, resizeListener);
107
      
108
      if (table.getVerticalScrollBarProxy() != null)
109
      {
110
          table.getVerticalScrollBarProxy().addSelectionListener(scrollListener);
111
      }
112
      if (table.getHorizontalScrollBarProxy() != null)
113
      {
114
          table.getHorizontalScrollBarProxy().addSelectionListener(scrollListener);
115
      }
116
117
      // To be consistent with older versions of SWT, grabVertical defaults to
118
      // true
119
      grabVertical = true;
120
      
121
      initColumn();
122
  }
123
124
  /**
125
   * Returns the bounds of the editor.
126
   * @return bounds of the editor.
127
   */
128
  protected Rectangle internalComputeBounds()
129
  {
130
	return column.getHeaderRenderer().getControlBounds(column,true);
131
  }
132
133
  /**
134
   * Removes all associations between the TableEditor and the cell in the
135
   * table. The Table and the editor Control are <b>not</b> disposed.
136
   */
137
  public void dispose()
138
  {
139
      if (!table.isDisposed() && !column.isDisposed() )
140
      {
141
    	  column.removeControlListener(columnListener);
142
          if (column.getColumnGroup() != null){
143
        	  column.getColumnGroup().removeListener(SWT.Expand, columnGroupListener);
144
        	  column.getColumnGroup().removeListener(SWT.Collapse, columnGroupListener);
145
          }
146
      }
147
      
148
      if (!table.isDisposed())
149
      {
150
          table.removeListener(SWT.Resize, resizeListener);
151
          
152
          if (table.getVerticalScrollBarProxy() != null)
153
              table.getVerticalScrollBarProxy().removeSelectionListener(scrollListener);
154
          
155
          if (table.getHorizontalScrollBarProxy() != null)
156
              table.getHorizontalScrollBarProxy().removeSelectionListener(scrollListener);
157
      }
158
      
159
      columnListener = null;
160
      resizeListener = null;
161
      table = null;
162
      super.dispose();
163
  }
164
165
  /**
166
   * Sets the zero based index of the column of the cell being tracked by this
167
   * editor.
168
   * 
169
   * @param column the zero based index of the column of the cell being
170
   * tracked by this editor
171
   */
172
  void initColumn()
173
  {
174
175
	  column.addControlListener(columnListener);
176
	  column.addListener(SWT.Show, columnVisibleListener);
177
	  column.addListener(SWT.Hide, columnVisibleListener);
178
	  
179
      if (column.getColumnGroup() != null){
180
    	  column.getColumnGroup().addListener(SWT.Expand, columnGroupListener);
181
    	  column.getColumnGroup().addListener(SWT.Collapse, columnGroupListener);
182
      }
183
      layout();
184
  }
185
  
186
  /** 
187
   * {@inheritDoc}
188
   */
189
  public void layout()
190
  {
191
      if (table.isDisposed())
192
          return;
193
      table.getDisplay().asyncExec(new Runnable() {
194
195
		public void run() {
196
		      boolean hadFocus = false;
197
198
		      if (getEditor() == null || getEditor().isDisposed()) {
199
		          return;
200
		      }
201
		      
202
		      if (getEditor().getVisible())
203
		      {
204
		          hadFocus = getEditor().isFocusControl();
205
		      }
206
			Rectangle rect = internalComputeBounds();
207
		      if( rect == null ) {
208
		    	  getEditor().setVisible(false);
209
		    	  return;
210
		      }
211
		      getEditor().setBounds(rect);
212
		      
213
		      if (hadFocus)
214
		      {
215
		          if (getEditor() == null || getEditor().isDisposed())
216
		              return;
217
		          getEditor().setFocus();
218
		      }
219
		}
220
    	  
221
      });
222
223
  }
224
225
}
(-)src/org/eclipse/swt/nebula/snippets/grid/GridSnippet2.java (-33 / +58 lines)
Lines 9-23 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.swt.nebula.snippets.grid;
11
package org.eclipse.swt.nebula.snippets.grid;
12
 
13
12
14
import org.eclipse.nebula.widgets.grid.Grid;
13
import org.eclipse.nebula.widgets.grid.Grid;
15
import org.eclipse.nebula.widgets.grid.GridColumn;
14
import org.eclipse.nebula.widgets.grid.GridColumn;
16
import org.eclipse.nebula.widgets.grid.GridItem;
15
import org.eclipse.nebula.widgets.grid.GridItem;
17
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.custom.CCombo;
18
import org.eclipse.swt.events.MouseAdapter;
19
import org.eclipse.swt.events.MouseEvent;
20
import org.eclipse.swt.events.MouseListener;
18
import org.eclipse.swt.layout.FillLayout;
21
import org.eclipse.swt.layout.FillLayout;
19
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Display;
20
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Text;
21
25
22
/*
26
/*
23
 * Create a grid with an item that spans columns.
27
 * Create a grid with an item that spans columns.
Lines 27-61 Link Here
27
 */
31
 */
28
public class GridSnippet2 {
32
public class GridSnippet2 {
29
33
30
public static void main (String [] args) {
34
	public static void main(String[] args) {
31
    Display display = new Display ();
35
		Display display = new Display();
32
    Shell shell = new Shell (display);
36
		Shell shell = new Shell(display);
33
    shell.setLayout(new FillLayout());
37
		shell.setLayout(new FillLayout());
34
38
35
    Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
39
		final Grid grid = new Grid(shell, SWT.BORDER | SWT.V_SCROLL
36
    grid.setHeaderVisible(true);
40
				| SWT.H_SCROLL);
37
    GridColumn column = new GridColumn(grid,SWT.NONE);
41
		grid.setHeaderVisible(true);
38
    column.setText("Column 1");
42
39
    column.setWidth(100);
43
		GridColumn column = new GridColumn(grid, SWT.NONE);
40
    GridColumn column2 = new GridColumn(grid,SWT.NONE);
44
		column.setText("Column 1");
41
    column2.setText("Column 2");
45
		column.setWidth(100);
42
    column2.setWidth(100);
46
		column.setHeaderControl(new CCombo(grid, SWT.READ_ONLY | SWT.BORDER));
43
    GridItem item1 = new GridItem(grid,SWT.NONE);
47
		column.setMoveable(true);
44
    item1.setText("First Item");
48
45
    item1.setText(1,"xxxxxxx");
49
		GridColumn column2 = new GridColumn(grid, SWT.NONE);
46
    GridItem item2 = new GridItem(grid,SWT.NONE);
50
		column2.setText("Column 2");
47
    item2.setText("This cell spans both columns");
51
		column2.setWidth(100);
48
    item1.setText(1,"xxxxxxx");
52
		column2.setMoveable(true);
49
    item2.setColumnSpan(0,1);
53
		column2.setHeaderControl(new Text(grid, SWT.BORDER));
50
    GridItem item3 = new GridItem(grid,SWT.NONE);
54
51
    item3.setText("Third Item");
55
		for (int i = 0; i < 100; i++) {
52
    item1.setText(1,"xxxxxxx");
56
			GridItem item1 = new GridItem(grid, SWT.NONE);
53
    
57
			item1.setText("First Item");
54
    shell.setSize(200,200);
58
			item1.setText(1, "xxxxxxx");
55
    shell.open ();
59
			GridItem item2 = new GridItem(grid, SWT.NONE);
56
    while (!shell.isDisposed()) {
60
			item2.setText("This cell spans both columns");
57
        if (!display.readAndDispatch ()) display.sleep ();
61
			item1.setText(1, "xxxxxxx");
58
    }
62
			item2.setColumnSpan(0, 1);
59
    display.dispose ();
63
			GridItem item3 = new GridItem(grid, SWT.NONE);
60
}
64
			item3.setText("Third Item");
61
} 
65
			item1.setText(1, "xxxxxxx");
66
		}
67
68
		grid.addMouseListener(new MouseAdapter() {
69
70
			public void mouseDown(MouseEvent e) {
71
				if (e.y < grid.getHeaderHeight()) {
72
					System.out.println("header click");
73
				}
74
			}
75
76
		});
77
78
		shell.setSize(200, 200);
79
		shell.open();
80
		while (!shell.isDisposed()) {
81
			if (!display.readAndDispatch())
82
				display.sleep();
83
		}
84
		display.dispose();
85
	}
86
}
(-)src/org/eclipse/swt/nebula/snippets/cdatetime/CDTSnippet01.java (-1 / +17 lines)
Lines 3-12 Link Here
3
import org.eclipse.nebula.widgets.cdatetime.CDT;
3
import org.eclipse.nebula.widgets.cdatetime.CDT;
4
import org.eclipse.nebula.widgets.cdatetime.CDateTime;
4
import org.eclipse.nebula.widgets.cdatetime.CDateTime;
5
import org.eclipse.swt.SWT;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.events.SelectionAdapter;
7
import org.eclipse.swt.events.SelectionEvent;
6
import org.eclipse.swt.graphics.Point;
8
import org.eclipse.swt.graphics.Point;
7
import org.eclipse.swt.graphics.Rectangle;
9
import org.eclipse.swt.graphics.Rectangle;
8
import org.eclipse.swt.layout.GridData;
10
import org.eclipse.swt.layout.GridData;
9
import org.eclipse.swt.layout.GridLayout;
11
import org.eclipse.swt.layout.GridLayout;
12
import org.eclipse.swt.widgets.Button;
10
import org.eclipse.swt.widgets.Display;
13
import org.eclipse.swt.widgets.Display;
11
import org.eclipse.swt.widgets.Shell;
14
import org.eclipse.swt.widgets.Shell;
12
15
Lines 25-33 Link Here
25
		GridLayout layout = new GridLayout();
28
		GridLayout layout = new GridLayout();
26
		shell.setLayout(layout);
29
		shell.setLayout(layout);
27
30
28
		final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
31
		final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN | CDT.DATE_LONG | CDT.TIME_SHORT );
29
		cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
32
		cdt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
30
33
34
		
35
		Button b = new Button(shell,SWT.PUSH);
36
		b.addSelectionListener(new SelectionAdapter() {
37
38
			@Override
39
			public void widgetSelected(SelectionEvent e) {
40
				System.err.println(cdt.getSelection());
41
			}
42
			
43
		});
44
		
31
		shell.pack();
45
		shell.pack();
32
		Point size = shell.getSize();
46
		Point size = shell.getSize();
33
		Rectangle screen = display.getMonitors()[0].getBounds();
47
		Rectangle screen = display.getMonitors()[0].getBounds();
Lines 37-42 Link Here
37
				size.x,
51
				size.x,
38
				size.y
52
				size.y
39
		);
53
		);
54
		
55
		
40
		shell.open();
56
		shell.open();
41
		while (!shell.isDisposed()) {
57
		while (!shell.isDisposed()) {
42
			if (!display.readAndDispatch())
58
			if (!display.readAndDispatch())
(-)META-INF/MANIFEST.MF (-6 / +3 lines)
Lines 9-22 Link Here
9
 org.eclipse.core.runtime,
9
 org.eclipse.core.runtime,
10
 org.eclipse.nebula.jface.gridviewer,
10
 org.eclipse.nebula.jface.gridviewer,
11
 org.eclipse.nebula.widgets.cdatetime,
11
 org.eclipse.nebula.widgets.cdatetime,
12
 org.eclipse.nebula.widgets.ctree,
13
 org.eclipse.nebula.widgets.datechooser,
14
 org.eclipse.nebula.widgets.formattedtext,
15
 org.eclipse.nebula.widgets.gallery,
16
 org.eclipse.nebula.widgets.grid,
12
 org.eclipse.nebula.widgets.grid,
17
 org.eclipse.nebula.widgets.pgroup,
18
 org.eclipse.nebula.widgets.pshelf,
13
 org.eclipse.nebula.widgets.pshelf,
19
 org.eclipse.nebula.widgets.compositetable
14
 org.eclipse.nebula.widgets.calendarcombo;bundle-version="1.0.0",
15
 org.eclipse.nebula.widgets.datechooser;bundle-version="1.0.0",
16
 org.eclipse.nebula.widgets.formattedtext;bundle-version="1.0.0"
20
Export-Package: org.eclipse.swt.nebula.snippets.ctree,
17
Export-Package: org.eclipse.swt.nebula.snippets.ctree,
21
 org.eclipse.swt.nebula.snippets.grid
18
 org.eclipse.swt.nebula.snippets.grid
22
Bundle-ClassPath: .
19
Bundle-ClassPath: .
(-).classpath (-1 / +1 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
7
</classpath>
(-)src/org/eclipse/nebula/snippets/gridviewer/Test.java (+223 lines)
Added Link Here
1
package org.eclipse.nebula.snippets.gridviewer;
2
3
import java.util.regex.Matcher;
4
import java.util.regex.Pattern;
5
6
import org.eclipse.jface.viewers.ArrayContentProvider;
7
import org.eclipse.jface.viewers.CellEditor;
8
import org.eclipse.jface.viewers.ColumnLabelProvider;
9
import org.eclipse.jface.viewers.ColumnViewerEditor;
10
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
11
import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
12
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
13
import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
14
import org.eclipse.jface.viewers.ICellModifier;
15
import org.eclipse.jface.viewers.TextCellEditor;
16
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
17
import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
18
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
19
import org.eclipse.nebula.widgets.grid.Grid;
20
import org.eclipse.nebula.widgets.grid.GridItem;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.FillLayout;
23
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.Shell;
25
26
27
public class Test
28
{
29
    private Pattern m_IsValidPattern = null;
30
31
    public class MyModel
32
    {
33
        private String sCounter = "";
34
35
        public MyModel(){
36
        }
37
38
        public void setCounter(String sCounter)
39
        {
40
            this.sCounter = sCounter;
41
        }
42
43
        public String toString()
44
        {
45
            return sCounter;
46
        }
47
    }
48
49
    public class MyTextCellEditor extends TextCellEditor
50
    {
51
        /**
52
         * search pattern is Numeric character
53
         */
54
        private Pattern m_IsValidPattern = null;
55
56
        public MyTextCellEditor(Grid parent) {
57
            super(parent);
58
            m_IsValidPattern = Pattern.compile("[\\w+-\\.]");
59
        }
60
61
        @Override
62
        public void activate(ColumnViewerEditorActivationEvent activationEvent) {
63
64
            // set the activation character
65
            String s1 = String.valueOf( activationEvent.character );
66
            Matcher matcher = m_IsValidPattern.matcher( s1 );
67
            if (matcher.matches()) {
68
                doSetValue(s1);
69
            }
70
            super.activate(activationEvent);
71
        }
72
    }
73
74
75
    public Test(Shell shell)
76
    {
77
        /* allow numbers and characters */
78
        m_IsValidPattern = Pattern.compile("[\\w+-\\.]");
79
80
        final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER
81
                | SWT.H_SCROLL | SWT.V_SCROLL);
82
83
84
        v.setCellEditors(new CellEditor[] {
85
                new MyTextCellEditor(v.getGrid()),
86
                new MyTextCellEditor(v.getGrid())
87
        });
88
89
        v.setCellModifier(new ICellModifier() {
90
91
            public boolean canModify(Object element, String property) {
92
                return true;
93
            }
94
95
            public Object getValue(Object element, String property) {
96
                return element.toString();
97
            }
98
99
            public void modify(Object element, String property, Object value) {
100
                if (element instanceof GridItem) {
101
                    GridItem item = (GridItem)element;
102
                    MyModel model = (MyModel)(item.getData());
103
                    model.setCounter(value.toString());
104
                    v.update(model, null);
105
                }
106
            }
107
        });
108
109
110
        ColumnViewerEditorActivationListener listener = new ColumnViewerEditorActivationListener() {
111
112
            public void afterEditorActivated(
113
                    ColumnViewerEditorActivationEvent event)
114
            {
115
            }
116
117
            public void afterEditorDeactivated(
118
                    ColumnViewerEditorDeactivationEvent event)
119
            {
120
            }
121
122
            public void beforeEditorActivated(
123
                    ColumnViewerEditorActivationEvent event)
124
            {
125
            }
126
127
            public void beforeEditorDeactivated(
128
                    ColumnViewerEditorDeactivationEvent event)
129
            {
130
            }
131
        };
132
133
        v.setContentProvider(new ArrayContentProvider());
134
        v.setColumnProperties(new String[] { "1", "2" });
135
        v.getGrid().setCellSelectionEnabled(true);
136
        v.getGrid().setLinesVisible(true);
137
        v.getGrid().setHeaderVisible(true);
138
139
        ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
140
                v) {
141
            protected boolean isEditorActivationEvent(
142
                    ColumnViewerEditorActivationEvent event)
143
            {
144
                boolean result;
145
146
                String s1          = String.valueOf( event.character );
147
                Matcher matcher    = m_IsValidPattern.matcher( s1 );
148
                boolean bIsCharKey = matcher.matches();
149
150
                boolean bEnableKey =
151
                    (event.keyCode == SWT.CR) ||
152
                    (event.keyCode == SWT.KEYPAD_CR) ||
153
                    (event.keyCode == SWT.F2) ||
154
                    bIsCharKey;
155
156
                result = event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
157
                        || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
158
                        || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && bEnableKey)
159
                        || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
160
161
                return result;
162
            }
163
        };
164
165
        GridViewerEditor.create(v, actSupport,
166
                ColumnViewerEditor.TABBING_HORIZONTAL
167
                        | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
168
                        | ColumnViewerEditor.TABBING_VERTICAL
169
                        | ColumnViewerEditor.KEYBOARD_ACTIVATION);
170
171
        v.getColumnViewerEditor().addEditorActivationListener(listener);
172
173
        GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
174
        column.getColumn().setWidth(200);
175
        column.getColumn().setMoveable(true);
176
        column.getColumn().setText("Column 1");
177
        column.setLabelProvider(new ColumnLabelProvider());
178
179
        column = new GridViewerColumn(v, SWT.NONE);
180
        column.getColumn().setWidth(200);
181
        column.getColumn().setMoveable(true);
182
        column.getColumn().setText("Column 2");
183
        column.setLabelProvider(new ColumnLabelProvider());
184
185
        MyModel[] model = createModel();
186
187
        v.setInput(model);
188
    }
189
190
    private MyModel[] createModel() {
191
192
        MyModel[] elements = new MyModel[10];
193
194
        for (int i = 0; i < 10; i++)
195
        {
196
            elements[i] = new MyModel();
197
            if (i<3){
198
                Double h = Double.valueOf(i);
199
                elements[i].setCounter( h.toString() );
200
            }
201
        }
202
        return elements;
203
    }
204
205
    public static void main(String[] args)
206
    {
207
        Display display = new Display();
208
209
        Shell shell = new Shell(display);
210
        shell.setLayout(new FillLayout());
211
        new Test(shell);
212
        shell.open();
213
214
        while (!shell.isDisposed())
215
        {
216
            if (!display.readAndDispatch())
217
                display.sleep();
218
        }
219
220
        display.dispose();
221
222
    }
223
} 

Return to bug 237846