Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Single cell sellection in SWT table from keyboard

Posted on 2004-08-06
6
Medium Priority
?
3,022 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 600 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

598 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