Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Plz somebody help me with SWT Table
Plz somebody help me with SWT Table [message #447856] Mon, 20 December 2004 06:47 Go to next message
Eclipse UserFriend
Originally posted by: swtnewbie.hotmail.com

hai all,
i do not understand what is wrong with my code.
I just want to select a particular row from my Swt Table as per my code
below. i created my own InputDialog Box in order to input n Search the
elements in my Table.
heres the Dialog area of my Input Dialog:
------------------------------------------------------

package kr.re.etri.esto.monitor.dialogs;
//import org.eclipse.core.runtime.IPath;


import org.eclipse.jface.dialogs.*;
import org.eclipse.swt.SWT;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

//import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
//import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;




public class InputDialog_GoToEvent extends Dialog
{
private String title;
private String message;
private String value = "";
private IInputValidator validator;

private Button findButton;
private Button CPU_ID;
private Button EVENT_TYPE;
private Button PID;
private Button ENTRY_LENGTH;
private Button EVENT_DESCRIPTION;

private Text txt_CPU_ID;
private Combo txt_EventType;
private Text txt_PID;
private Text txt_EntryLength;
private Text txt_EventDescription;
private Text text;
private Text errorMessageText;


private int rowCount;
private int division = 0;
private String SelectItem = new String();
public String r="";
static int item_index =0;
static int entry_pos=0;

private String str_CPU_ID;
private String str_EventType;
private String str_PID;
private String str_EntryLength;
private String str_EventDescription;

public InputDialog_GoToEvent(Shell parentShell, String dialogTitle,
String dialogMessage, IInputValidator validator) {
super(parentShell);
this.title = dialogTitle;
message = dialogMessage;
}

public void setTableIndex ()
{
entry_pos = 0;
}


protected void buttonPressed(int buttonId) {
if (buttonId == IDialog4GoToEvent.OK_ID) {
value = txt_CPU_ID.getText(); }

else {
value = null;
}
super.buttonPressed(buttonId);
}


protected void configureShell(Shell shell) {
super.configureShell(shell);
if (title != null)
shell.setText(title);
}

protected void createButtonsForButtonBar(Composite parent) {
findButton = createButton(parent, IDialog4GoToEvent.OK_ID,
IDialog4GoToEvent.OK_LABEL, true);
createButton(parent, IDialog4GoToEvent.CLOSE_ID,
IDialog4GoToEvent.CLOSE_LABEL, false);
//do this here because setting the text will set enablement on the ok
// button
//text1.setFocus();
if (value != null) {
txt_CPU_ID.setText(value);
txt_CPU_ID.selectAll();
}
}

protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new RowLayout());

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 6;


CPU_ID = new Button (composite, SWT.RADIO);
CPU_ID.setText ("CPU ID: ");
txt_CPU_ID=new Text(composite,SWT.SINGLE | SWT.BORDER);
//dialog.setLayout (new RowLayout ());
CPU_ID.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txt_CPU_ID.setFocus();
division = 0;
System.out.println("cpu ese");
}
});
txt_CPU_ID.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
if(!(r.equals(str_CPU_ID))) setTableIndex();
r = str_CPU_ID;
System.out.println("txt_CPU_ID exe");
}
});


EVENT_TYPE = new Button (composite, SWT.RADIO);
EVENT_TYPE .setText ("Event Type: ");
txt_EventType = new Combo (composite, SWT.READ_ONLY);
txt_EventType.setItems (new String [] {"Trace start","System call
entry","System call exit","Trap entry","Trap exit","IRQ entry",
"IRQ exit","Schedule change","Kernel timer","Soft IRQ","Process
management","File system management",
"Timer management","Memory management","Socket
communication","Inter-process communication",
"Network communication","Creation of custom event","Custom event
occurrence"});
final String Item2[] = {"Trace start","Syscall entry","Syscall
exit","Trap entry","Trap exit","IRQ entry",
"IRQ exit","Sched change","Kernel timer","Soft IRQ","Process","File
system",
"Timer","Memory","Socket","IPC",
"Network","Event creation","Custom event"};
EVENT_TYPE.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txt_EventType.setFocus();
division = 1;
System.out.println("event exe");
}
});
txt_EventType.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
if(item_index != txt_EventType.getSelectionIndex())
setTableIndex();
item_index = txt_EventType.getSelectionIndex();
r = Item2[item_index];
System.out.println("txt_EventType exe");
}
});


PID = new Button (composite, SWT.RADIO);
PID .setText ("PID: ");
txt_PID=new Text(composite,SWT.SINGLE | SWT.BORDER);
PID.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txt_PID.setFocus();
division = 2;
System.out.println("pid exe");
}
});
txt_PID.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
if(!(r.equals(str_PID))) setTableIndex();
r = str_PID;
System.out.println("txt_PID exe");
}
});



ENTRY_LENGTH = new Button (composite, SWT.RADIO);
ENTRY_LENGTH.setText ("Entry Length: ");
txt_EntryLength=new Text(composite,SWT.SINGLE | SWT.BORDER);
ENTRY_LENGTH.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txt_EntryLength.setFocus();
division = 3;
System.out.println("entry length exe");
}
});
txt_EntryLength.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
if(!(r.equals(str_EntryLength))) setTableIndex();
r = str_EntryLength;
System.out.println(" txt_EntryLength exe");
}
});


EVENT_DESCRIPTION = new Button (composite, SWT.RADIO);
EVENT_DESCRIPTION.setText ("Event Description: ");
txt_EventDescription=new Text(composite,SWT.SINGLE | SWT.BORDER);
EVENT_DESCRIPTION.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txt_EventDescription.setFocus();
division = 4;
System.out.println("event description exe");
}
});
txt_EventDescription.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
if(!(r.equals(str_EventDescription))) setTableIndex();
r = str_EventDescription;
System.out.println(" txt_EventDescription exe");
}
});


applyDialogFont(composite);
return composite;
}

protected Label getErrorMessageLabel() {
return null;
}

public Button getCPU_ID(){
return CPU_ID;
}

public Button getEVENT_TYPE(){
return EVENT_TYPE;
}

public Button getPID() {
return PID;
}

public Button getENTRY_LENGTH(){
return ENTRY_LENGTH;
}

public Button getEVENT_DESCRIPTION(){
return EVENT_DESCRIPTION;
}



public String getstringCPU_IDpath() {
return str_CPU_ID;
}

public String getstringEventTypepath() {
return str_EventType;
}

public String getstringPIDpath() {
return str_PID;
}

public String getstringEntryLengthpath() {
return str_EntryLength;
}

public String getstringEventDescriptionpath() {
return str_EventDescription;
}


//////////////////TEXT BEGIN////////////////////////////
public Text gettxtCPU_ID()
{
return txt_CPU_ID;
}

public Combo gettxtEVENT_TYPE(){
return txt_EventType;
}

public Text gettxtPID() {
return txt_PID;
}

public Text gettxtENTRY_LENGTH(){
return txt_EntryLength ;
}

public Text gettxtEVENT_DESCRIPTION(){
return txt_EventDescription;
}



protected IInputValidator getValidator() {
return validator;
}

public String getValue() {
return value;
}

protected void validateInput() {
String errorMessage = null;
if (validator != null) {
errorMessage = validator.isValid(txt_CPU_ID.getText());
}
// Bug 16256: important not to treat "" (blank error) the same as null
// (no error)
setErrorMessage(errorMessage);
}

public void setErrorMessage(String errorMessage) {
errorMessageText.setText(errorMessage == null ? "" : errorMessage);
//$NON-NLS-1$
findButton.setEnabled(errorMessage == null);
errorMessageText.getParent().update();
}

protected void okPressed() {
str_CPU_ID = txt_CPU_ID.getText();
str_EventType = txt_EventType.getText();
str_PID = txt_PID.getText();
str_EntryLength = txt_EntryLength.getText();
str_EventDescription = txt_EventDescription.getText();


setReturnCode(OK);
close();
}

}


------------------------------------------------------------ -------

heres my parent class:
----------------------

package kr.re.etri.esto.monitor.views;

import java.awt.BorderLayout;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

import kr.re.etri.esto.monitor.dialogs.*;

import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.*;

import org.eclipse.jface.viewers.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.window.*;






public class EstoMonitor extends ViewPart {

public class ActionLtt extends Action {

private EstoMonitor m_monior;
public ActionLtt(EstoMonitor mon){
m_monior = mon;
}
public EstoMonitor getMonitor()
{
return m_monior;
}
}



private ActionLtt Tool_Go_To_Event;
private Composite parent_comp; //open trace
private Display display;
public Table rawTable;
private TableItem tableitem;
private String message;
private Shell shell;
private TabFolder tabFolder;
private TabItem tabitem1;
private Window window;
public int rowCount;
private int division = 0;
public StringTokenizer tok;
public Image icon;



public InputDialog_GoToEvent inputGoToEvent ;

private String SelectItem = new String();
static int entry_pos=0;
private String r="";
static int item_index =0;
public String[] strItems;

public EstoMonitor() {


}


public void createPartControl(Composite parent) {
parent_comp = parent;

contributeToActionBars();
makeActions();
tabFolder = new TabFolder(parent,SWT.BAR);

tabitem1=new TabItem(tabFolder,SWT.BORDER | SWT.V_SCROLL |
SWT.FULL_SELECTION);
{
tabitem1.setText("Raw Trace(&R) ");
rawTable = new Table(tabFolder,SWT.SINGLE|SWT.FULL_SELECTION);
TableColumn col1 = new TableColumn(rawTable,SWT.RIGHT);
col1.setText("CPU-ID");
col1.setWidth(50);
TableColumn col2 = new TableColumn(rawTable,SWT.NULL);
col2.setText(" Event ");
col2.setWidth(100);
TableColumn col3 = new TableColumn(rawTable,SWT.NULL);
col3.setText( " Time ");
col3.setWidth(200);
TableColumn col4 = new TableColumn(rawTable,SWT.NULL);
col4.setText(" PID ");
col4.setWidth(50);
TableColumn col5 = new TableColumn(rawTable,SWT.NULL);
col5.setText(" Entry Length ");
col5.setWidth(200);
TableColumn col6 = new TableColumn(rawTable,SWT.NULL);
col6.setText(" Event Description ");
col6.setWidth(200);
//
rawTable.setHeaderVisible(true);
rawTable.setLinesVisible(true);
tabitem1.setControl( rawTable);
}
}


private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
EstoMonitor.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
}

private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();
fillLocalPullDown(bars.getMenuManager());
}

////////////////////////////////////// START TABLE
//////////////////////////////////////////////////////////// //////

public void setTableData(String cmd, int row)
{
pdata = new String();
try
{
tok = new StringTokenizer(cmd, "^");
strItems = new String[6];

tableitem = new TableItem(rawTable, SWT.NULL);
for(int i=0; tok.hasMoreTokens();i++)
{
if( i == 6 ) break;//break given so that the next column does not
display any data ie. the column after the last specified column.
pdata = tok.nextToken();
strItems[i] = pdata;
}
tableitem.setText(strItems);
rawTable.pack();

}
catch(Exception e)
{
System.out.println(pdata);
e.printStackTrace();
}
}//end


public int selectTable(String SelData, int rCount,final int division)
{
for(;entry_pos < rCount;entry_pos++)
{
Point pt = new Point (entry_pos,division);
if(SelData.equals(rawTable.getItem(pt).toString().trim()))
{System.out.println("Text field");
//int index =rawTable.getTopIndex ();
rawTable.setSelection(entry_pos,entry_pos);
Rectangle clientArea = rawTable.getClientArea ();
rawTable.setBounds(clientArea);
rawTable.setFocus();
System.out.println("hhg");

rawTable.redraw();
return entry_pos++;
}
}
entry_pos = 0;
return entry_pos;
}



private void fillLocalPullDown(IMenuManager manager) {

Tool_Go_To_Event= new ActionLtt(this) {
public void run() {
System.out.println("Tool executed");
if(rowCount!=0)
{
inputGoToEvent = new InputDialog_GoToEvent(shell,"Go To
Event","",null);
inputGoToEvent.open();
if( inputGoToEvent.getReturnCode() == 0 )
{ selectTable(r,rowCount,division);
}
inputGoToEvent.getValue();
}
}
};
Tool_Go_To_Event.setText("&Go_To_Event");
tool_menu.add(Tool_Go_To_Event);

manager.add(tool_menu);
}

}


//////////////////////////////////////////////////////////// ////////

private void fillContextMenu(IMenuManager manager) {
}

private void makeActions() {
}

private void showMessage(String message) {
MessageDialog.openInformation(
viewer.getControl().getShell(),
"Esto Monitor",
message);
}

public void setFocus() {
}


}
Re: Plz somebody help me with SWT Table [message #447857 is a reply to message #447856] Mon, 20 December 2004 06:53 Go to previous message
Eclipse UserFriend
Originally posted by: stnewbie.hotmail.com

sorry i didnt mention what my problem was in my previous post.

the columns in my Table are my Buttons in the Dialog Box. And there is a
corresponding text beside each of these buttons.
All i want to do is to Select the row of the Table; that which contains
the value that i enter in my Dialog. I just enter one value at a time for
selection.
Somebody plz help me.
Or atleast provide me with links that would help me finish this.
thanx in advance
Previous Topic:Any for SWT UI design?
Next Topic:Why the drop method never been called?
Goto Forum:
  


Current Time: Fri Oct 23 09:32:36 GMT 2020

Powered by FUDForum. Page generated in 0.01619 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top