Solved

Single cell sellection in SWT table from keyboard

Posted on 2004-08-06
6
2,887 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now