Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Horisontal scrolling during column draging
Horisontal scrolling during column draging [message #44814] Fri, 14 December 2007 10:04 Go to next message
Eclipse UserFriend
Originally posted by: akn.ciklum.net

This is a multi-part message in MIME format.
--------------050403080303090909090309
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi!

I've met some unexpected issue with column dragging. If a column is
dragged on right (or left) invisible area, a grid will not be scrolled
to reach invisible columns. Nevertheless, grid is scrolled during multi
selection dragging. Please use an attached snippet and try to select
invisible cells, than drag column into invisible target column.

Could you advice some solution for scrolling grid during column
dragging? Thank you in advance.

Andrey

--------------050403080303090909090309
Content-Type: text/plain;
name="MxSnippet026TreeViewerTabEditingForGrid.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MxSnippet026TreeViewerTabEditingForGrid.java"

package com.maconomy.widgets.snippets;

import java.util.ArrayList;

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.ColumnViewerEditorActivationStrate gy;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* A simple TreeViewer to demonstrate usage. Anyone could extend the snippet for test purposer or bug reporting.
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class MxSnippet026TreeViewerTabEditingForGrid {
/**
*
* @param shell
*/
public MxSnippet026TreeViewerTabEditingForGrid(final Shell shell) {
final Button b = new Button(shell,SWT.PUSH);
b.setText("Remove column");
// Grid used instead jFace viewer
final GridTableViewer v = new GridTableViewer(shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
v.getGrid().setLinesVisible(true);
v.getGrid().setHeaderVisible(true);
b.addSelectionListener(new SelectionListener() {

public void widgetDefaultSelected(SelectionEvent e) {

}

public void widgetSelected(SelectionEvent e) {
v.getGrid().getColumn(1).dispose();
}

});

// does not available for Grid
//TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));
final ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
System.out.println("event "+event.eventType);
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
//mouse click activation!!!
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};


GridViewerEditor.create(v, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
v.getGrid().setCellSelectionEnabled(true);

final TextCellEditor textCellEditor = new TextCellEditor(v.getGrid());

GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(270);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
column.setLabelProvider(new ColumnLabelProvider() {

@Override
public String getText(Object element) {
return "Column 1 => " + element.toString();
}

});
column.setEditingSupport(new EditingSupport(v) {
@Override
protected boolean canEdit(Object element) {
return false;
}

@Override
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}

@Override
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}

@Override
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});

column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(270);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
column.setLabelProvider(new ColumnLabelProvider() {

@Override
public String getText(Object element) {
return "Column 2 => " + element.toString();
}

});
column.setEditingSupport(new EditingSupport(v) {
@Override
protected boolean canEdit(Object element) {
return true;
}

@Override
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}

@Override
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}

@Override
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});

column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
column.setLabelProvider(new ColumnLabelProvider() {

@Override
public String getText(Object element) {
return "Column 3 => " + element.toString();
}

});
column.setEditingSupport(new EditingSupport(v) {
@Override
protected boolean canEdit(Object element) {
return true;
}

@Override
protected CellEditor getCellEditor(Object element) {
return textCellEditor;
}

@Override
protected Object getValue(Object element) {
return ((MyModel) element).counter + "";
}

@Override
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
v.update(element, null);
}
});

column = new GridViewerColumn(v, SWT.CHECK | SWT.CENTER);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 4");
column.setLabelProvider(new ColumnLabelProvider() {

@Override
public String getText(Object element) {
return null;
}

});

v.setContentProvider(new MyContentProvider());

v.setInput(createModel());
}

private MyModel createModel() {

final MyModel root = new MyModel(0, null);
root.counter = 0;

MyModel tmp;
MyModel subItem;
for (int i = 1; i < 10; i++) {
tmp = new MyModel(i, root);
root.child.add(tmp);
for (int j = 1; j < i; j++) {
subItem = new MyModel(j, tmp);
subItem.child.add(new MyModel(j * 100, subItem));
tmp.child.add(subItem);
}
}

return root;
}

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new MxSnippet026TreeViewerTabEditingForGrid(shell);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}

private class MyContentProvider implements ITreeContentProvider {

public Object[] getElements(Object inputElement) {
return ((MyModel) inputElement).child.toArray();
}

public void dispose() {
}

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}

public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}

public Object getParent(Object element) {
if (element == null) {
return null;
}
return ((MyModel) element).parent;
}

public boolean hasChildren(Object element) {
return ((MyModel) element).child.size() > 0;
}

}

public class MyModel {
public MyModel parent;

public ArrayList child = new ArrayList();

public int counter;

public MyModel(int counter, MyModel parent) {
this.parent = parent;
this.counter = counter;
}

@Override
public String toString() {
String rv = "Item ";
if (parent != null) {
rv = parent.toString() + ".";
}

rv += counter;

return rv;
}
}

}



--------------050403080303090909090309--
Re: Horisontal scrolling during column draging [message #45251 is a reply to message #44814] Fri, 04 January 2008 21:00 Go to previous message
Chris Gross is currently offline Chris GrossFriend
Messages: 253
Registered: July 2009
Senior Member
Hi Andrey,

Unfortunately the Grid simply does not have that feature right now. Its
a prime area for an outside developer to write and contribute the code.

Regards,
-Chris

Andrey wrote:
> Hi!
>
> I've met some unexpected issue with column dragging. If a column is
> dragged on right (or left) invisible area, a grid will not be scrolled
> to reach invisible columns. Nevertheless, grid is scrolled during multi
> selection dragging. Please use an attached snippet and try to select
> invisible cells, than drag column into invisible target column.
>
> Could you advice some solution for scrolling grid during column
> dragging? Thank you in advance.
>
> Andrey
>
Re: Horisontal scrolling during column draging [message #587120 is a reply to message #44814] Fri, 04 January 2008 21:00 Go to previous message
Chris Gross is currently offline Chris GrossFriend
Messages: 471
Registered: July 2009
Senior Member
Hi Andrey,

Unfortunately the Grid simply does not have that feature right now. Its
a prime area for an outside developer to write and contribute the code.

Regards,
-Chris

Andrey wrote:
> Hi!
>
> I've met some unexpected issue with column dragging. If a column is
> dragged on right (or left) invisible area, a grid will not be scrolled
> to reach invisible columns. Nevertheless, grid is scrolled during multi
> selection dragging. Please use an attached snippet and try to select
> invisible cells, than drag column into invisible target column.
>
> Could you advice some solution for scrolling grid during column
> dragging? Thank you in advance.
>
> Andrey
>
Previous Topic:GridViewer and multicolumn text
Next Topic:Pressing "Arrow Down" key right after focusing and selection of some cell in Grid programm
Goto Forum:
  


Current Time: Wed Apr 24 19:00:55 GMT 2024

Powered by FUDForum. Page generated in 0.03687 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top