Solved

Single cell sellection in SWT table from keyboard

Posted on 2004-08-06
6
2,968 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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