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
Solved

Single cell sellection in SWT table from keyboard

Posted on 2004-08-06
6
2,931 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 54
Running JavaFX on JDeveloper 12C 1 54
jsp insert to database example 2 46
running on tomcat not jboss eap 7.0 3 18
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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