Solved

Single cell sellection in SWT table from keyboard

Posted on 2004-08-06
6
2,958 Views
Last Modified: 2007-12-19
I have following problem.
In SWT table I should edit cells from the keyboard.
After end of editing of first column cursor on pressing Enter should pass to the following column (second) etc.
When I use of style:      int style =      SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
full line is selected, but I need only one cell.
Now I can specify a cell for editing only through the mouse, but I need edit table from keyboard.

Thank you
0
Comment
Question by:oraelbis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:JohnnyAffa
ID: 11741655
can you post you code here becuse im not really sure what you are talking about
0
 
LVL 3

Author Comment

by:oraelbis
ID: 11742065
Now I have full row selection see:
http://berdachuk.at.tut.by/temp/table1.gif
But I need something leke
http://berdachuk.at.tut.by/temp/table2.gif


There is some code (itemList - data model)

private void createTable(Composite parent) {
            int style =
                  SWT.SINGLE
                        | SWT.BORDER
                        | SWT.H_SCROLL
                        | SWT.V_SCROLL
                        | SWT.FULL_SELECTION;
            

            table = new Table(parent, style);

            GridData gridData = new GridData(GridData.FILL_BOTH);
            gridData.grabExcessVerticalSpace = true;
            gridData.horizontalSpan = 3;

            table.setLayoutData(gridData);

            table.setLinesVisible(true);
            table.setHeaderVisible(true);
            

            TableColumn column0 = new TableColumn(table, SWT.NONE, 0);
            column0.setText(itemList.getColumnHeading(0));
            column0.setAlignment(SWT.LEFT);
            column0.setWidth(150);

            TableColumn column1 = new TableColumn(table, SWT.NONE, 1);
            column1.setText(itemList.getColumnHeading(1));
            column1.setAlignment(SWT.LEFT);
            column1.setWidth(150);

            TableColumn column2 = new TableColumn(table, SWT.NONE, 2);
            column2.setText(itemList.getColumnHeading(2));
            column2.setAlignment(SWT.LEFT);
            column2.setWidth(200);

            TableColumn column3 = new TableColumn(table, SWT.NONE, 3);
            column3.setText(itemList.getColumnHeading(3));
            column3.setAlignment(SWT.LEFT);
            column3.setWidth(150);
      }

      private void createTableViewer() {

            tableViewer = new TableViewer(table);
            tableViewer.setUseHashlookup(true);

            tableViewer.setColumnProperties(itemList.columnNames);

            //Initialise cell editors
            CellEditor editors[] = new CellEditor[itemList.columnNames.length];

            editors[0] = new TextCellEditor(table);

            editors[1] = new TextCellEditor(table);

            editors[2] = new TextCellEditor(table);

            //      Column 3  (Combo Box)
            editors[3] =
                  new ComboBoxCellEditor(
                        table,
                        itemList.getConfirmModes(),
                        SWT.READ_ONLY);

            tableViewer.setColumnProperties(itemList.columnNames);
            //Assign the cell editors to the viewer
            tableViewer.setCellEditors(editors);
            // Set the cell modifier for the viewer
            tableViewer.setCellModifier(new ItemListCellModifier(itemList));
      }


/////////////////////////////////////////////////////////////////////////////////////////
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.swt.widgets.TableItem;

/**
 * @author sberdachuk
 * */
public class ItemListCellModifier implements ICellModifier {
      private ItemList itemList = null;
      /**
       *
       */
      public ItemListCellModifier(ItemList itemList) {
            super();
            this.itemList = itemList;
      }

      public void modify(Object element, String property, Object value) {
            int columnIndex = itemList.getColumnNames().indexOf(property);
            TableItem item = (TableItem) element;
            Item r = (Item) item.getData();
            String valueString;
            switch (columnIndex) {
                  case 0 :
                        itemList.setData(r.getRowIndex(), columnIndex, (String) value);
                        break;
                  case 1 :
                        itemList.setData(r.getRowIndex(), columnIndex, (String) value);
                        break;
                  case 2 :
                        itemList.setData(r.getRowIndex(), columnIndex, (String) value);
                        break;
                  case 3 :
                        valueString =
                              itemList
                                    .getConfirmModes()[((Integer) value)
                                    .intValue()]
                                    .trim();
                        String s = r.getString(3);
                        if (!s.equals(valueString)) {
                              r.setData(columnIndex, valueString);
                        }
                        break;
                  default :
                        }

      }

      public boolean canModify(Object element, String property) {
            return true;
      }

      public Object getValue(Object element, String property) {
            Item r = (Item) element;
            int columnIndex = itemList.getColumnNames().indexOf(property);
            String stringValue = r.getString(columnIndex);
            if (columnIndex == 3) {
                  String[] choices = itemList.getConfirmModes(property);
                  int i = choices.length - 1;
                  while (!stringValue.equals(choices[i]) && i > 0)
                        --i;
                  return new Integer(i);

            } else {
                  return stringValue;
            }
      }
}
0
 
LVL 3

Expert Comment

by:JohnnyAffa
ID: 11752775
when you mean keyboard, do you mean command line?  
where is your InputStream object?
mouse? so its a gui interface and yet you can enter value from the command line?

is this your code or someone elses?

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Author Comment

by:oraelbis
ID: 11762876
This is GUI application with org.eclipse.swt library.
I need have access for table like spreadshet in MS Excell.
After editing first cell I need select next cell and etc.  
At current time I can select any cell for editing only with mice clicking.
I'd like do it from keyboard
0
 
LVL 3

Accepted Solution

by:
JohnnyAffa earned 300 total points
ID: 11773667
first of all, im not familiar with the org.eclipse.library class.  however, if its similar to javax.swing.Jtable class then all you need to do is add a key listener/cell listener to your table  eg (in swing)

JTable table = new JTable([object]);

table.addKeyListener(this);

public void keyPressed(KeyEvent event)
{
             if ( event.getKeyCode() == KeyEvent.VK_RIGHT ) // right arrow
             {
                      Object object = event.getSource(); // here you get a reference to the cell
                 // move to next cell
              }

}

i hope that helps a little, but like i said, i dont know anything about eclipse.libaray class
0
 
LVL 3

Author Comment

by:oraelbis
ID: 11928910
Thank you for advice. But this problem still exist. May be I rewrite code for using my own combined swt widgets.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
throw exception 21 78
difference between sorce folder and folder in eclipise 3 64
SequenceInputStream example 3 38
Firefox and firebub 5 26
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question