Home » Eclipse Projects » Nebula » Checkbox GridColumn Event Handling(How to check which column is clicked on Grid?)
Checkbox GridColumn Event Handling [message #921454] |
Mon, 24 September 2012 06:07 |
Ashish Rawat Messages: 14 Registered: June 2012 |
Junior Member |
|
|
Hi,
I am trying to develop a GUI which has a Grid with 10 to 15 columns.
First column is a label, then a column group of 4-5 columns and then another column group of 4 columns and last column is with Text Editor.
The two column groups contains the columns of check boxes with some text associated with checkbox.
Now I am trying to check which checkbox is clicked in the Grid, based on that i have to do some handling.
To implement this kind of GUI, I am implementing the selection listener on Grid. I can find out whether the check box is clicked or not through following code:
public void widgetSelected(SelectionEvent e) {
if(e.detail == SWT.CHECK)
{
System.out.println("~~~~~~~~~~ CheckBox CLICKED ~~~~~~~~~~~");
}
}
After getting this message printed on my console, i am unable to find out which check box is clicked. Also I am using column spanning in column groups.
Please help me out ASAP.
Thanks in advance.
Regards,
Ashish Rawat
[Updated on: Mon, 24 September 2012 08:03] Report message to a moderator
|
|
|
Re: Checkbox GridColumn Event Handling [message #921626 is a reply to message #921454] |
Mon, 24 September 2012 09:36 |
|
Hi Ashish,
> Please help me out ASAP.
You should not add "ASAP". I am sure you do not mean to be rude but it is.
Did you examine the selection event e in the debugger to see of there are fields like widget or source that contain the checkbox or the object in the grid row? do this first.
Then, if this does not help, you can also add a listener to the checkbox directly.
Please file a bug (with a patch if you can) if all this did not help.
Regards,
Wim
|
|
| | |
Re: Checkbox GridColumn Event Handling [message #929133 is a reply to message #921769] |
Mon, 01 October 2012 08:47 |
Ashish Rawat Messages: 14 Registered: June 2012 |
Junior Member |
|
|
Hi Thomas,
Following is the source code for your inspection. Please guide me through the way where I can find the solution to my problem.
Please not that there are 2 column groups, and one group may contain any number of check-box columns. If in first group, in 1st row there are 5 check box columns then it may happen in 2nd row of same group there may be 2 check boxes only.
public PinTableGridView(Composite parent, int style,
DataBindingContext dbc, IComponent objComponent,
ArrayList<ModelItem> objChildrenList) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
this.dbContext = dbc;
this.pinSettingsComponent = objComponent;
this.list = objChildrenList;
updateMaxInputPinsCount();
updateMaxOutputPinsCount();
model = new PinSettingModel[list.size()];
for (int index = 0; index < list.size(); index++) {
ModelItem modelItem = list.get(index);
model[index] = new PinSettingModel(pinSettingsComponent,
modelItem.getSymbol(), RAppIDWizardUtility.getInputList(
pinSettingsComponent, modelItem.getSymbol()),
RAppIDWizardUtility.getOutputList(pinSettingsComponent,
modelItem.getSymbol()), modelItem.getExtraText());
}
gridTable = new Grid(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
gridTable.setHeaderVisible(true);
gridTable.setLinesVisible(true);
editor = new GridEditor(gridTable);
gridTable.addSelectionListener(this);
// Functions Column
colFunctions = new GridColumn(gridTable, SWT.NONE);
colFunctions.setText("Functions");
colFunctions.setWidth(200);
// Input Column
colGrpInput = new GridColumnGroup(gridTable, SWT.NONE);
colGrpInput.setText("Input");
if(maxInputPinsCount == 0)
{
colInputPins = new GridColumn[1];
colInputPins[0] = new GridColumn(colGrpInput, SWT.NONE);
colInputPins[0].setWidth(125);
}
else
{
colInputPins = new GridColumn[maxInputPinsCount];
for (int i = 0; i < maxInputPinsCount; i++) {
colInputPins[i] = new GridColumn(colGrpInput, SWT.CHECK | SWT.LEFT);
colInputPins[i].setWidth(50);
if(maxInputPinsCount == 1)
{
colInputPins[i].setWidth(125);
}
colInputPins[i].addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
System.out.println("~~~~ Selected Column: " + e.getSource().toString());
}
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
}
}
// Output Column
colGrpOutput = new GridColumnGroup(gridTable, SWT.NONE);
colGrpOutput.setText("Output");
if(maxOutputPinsCount == 0)
{
colOutputPins = new GridColumn[1];
colOutputPins[0] = new GridColumn(colGrpOutput, SWT.NONE);
colOutputPins[0].setWidth(125);
}
else
{
colOutputPins = new GridColumn[maxOutputPinsCount];
for (int i = 0; i < maxOutputPinsCount; i++) {
colOutputPins[i] = new GridColumn(colGrpOutput, SWT.CHECK
| SWT.LEFT);
colOutputPins[i].setWidth(50);
}
}
// User Assigned Signal Name Column
colUserSignalName = new GridColumn(gridTable, SWT.NONE);
colUserSignalName.setText("User Signal Name");
colUserSignalName.setWidth(150);
editableColumn = colInputPins.length+colOutputPins.length+1;
}
private void updateMaxOutputPinsCount() {
int maxOutputPins = 0;
for (int i = 0; i < list.size(); i++) {
ModelItem modelItem = list.get(i);
maxOutputPins = RAppIDWizardUtility.getOutputList(
pinSettingsComponent, modelItem.getSymbol()).size();
if (maxOutputPinsCount < maxOutputPins) {
maxOutputPinsCount = maxOutputPins;
}
}
}
private void updateMaxInputPinsCount() {
int maxInputPins = 0;
for (int i = 0; i < list.size(); i++) {
ModelItem modelItem = list.get(i);
maxInputPins = RAppIDWizardUtility.getInputList(
pinSettingsComponent, modelItem.getSymbol()).size();
if (maxInputPinsCount < maxInputPins) {
maxInputPinsCount = maxInputPins;
}
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
private PinSettingModel[] model;
public void setComponent(IComponent objComponent,
ArrayList<ModelItem> objChildrenList) {
this.pinSettingsComponent = objComponent;
this.list = objChildrenList;
// model = new PinSettingModel[list.size()];
for (int index = 0; index < this.list.size(); index++) {
ModelItem modelItem = this.list.get(index);
GridItem gridItem = new GridItem(gridTable, SWT.NONE);
gridItem.setHeight(18);
gridItem.setText(0, model[index].getSignalName());
ArrayList<String> lstInputPins = model[index].getInputPins();
int lastCheckBoxIndex = 0;
for (int i = 0; i < colGrpInput.getColumns().length; i++) {
if (lstInputPins.size() > 0 && i < lstInputPins.size()) {
ModelItem modelItemPin = pinSettingsComponent
.findBySymbol(lstInputPins.get(i));
PinDetails objPinDetails = model[index].getInputPinName(modelItemPin.getSymbol());
gridItem.setText(i + 1, objPinDetails.getPinName());
if(objPinDetails.isDefault())
{
gridItem.setFont(i + 1, JFaceResources.getFontRegistry().getBold(
gridItem.getFont().toString()));
}
lastCheckBoxIndex = i + 1;
if (modelItemPin.getItemName().contains(modelItem.getText())) {
gridItem.setChecked(i + 1, true);
} else {
gridItem.setChecked(i + 1, false);
}
} else {
if(lastCheckBoxIndex == 0)
{
lastCheckBoxIndex += 1;
}
gridItem.setColumnSpan(lastCheckBoxIndex, colInputPins.length - lastCheckBoxIndex);
}
}
ArrayList<String> lstOutputPins = model[index].getOutputPins();
lastCheckBoxIndex = colInputPins.length;
for (int i = 0; i < colGrpOutput.getColumns().length; i++) {
if (lstOutputPins.size() > 0 && i < lstOutputPins.size()) {
ModelItem modelItemPin = pinSettingsComponent
.findBySymbol(lstOutputPins.get(i));
PinDetails objPinDetails = model[index]
.getOutputPinName(modelItemPin.getSymbol());
gridItem.setText(i + maxInputPinsCount + 1,
objPinDetails.getPinName());
if (objPinDetails.isDefault()) {
gridItem.setFont(
i + maxInputPinsCount + 1,
JFaceResources.getFontRegistry().getBold(
gridItem.getFont().toString()));
}
lastCheckBoxIndex = i + maxInputPinsCount + 1;
if (modelItemPin.getItemName().contains(modelItem.getText())) {
gridItem.setChecked(i + maxInputPinsCount + 1, true);
} else {
gridItem.setChecked(i + maxInputPinsCount + 1, false);
}
} else {
if(lastCheckBoxIndex == colInputPins.length)
lastCheckBoxIndex += 1;
gridItem.setColumnSpan(lastCheckBoxIndex,
colInputPins.length + colOutputPins.length
- lastCheckBoxIndex);
}
}
String extraText = modelItem.getExtraText();
gridItem.setText(gridTable.getColumnCount() - 1,
extraText);
}
}
public void dispose() {
if (!gridTable.isDisposed()) {
gridTable.removeSelectionListener(this);
gridTable.dispose();
gridTable = null;
}
}
protected void refreshUI() {
}
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
System.out.println("~~~~~~~~~~ CheckBox CLICKED ~~~~~~~~~~~");
GridItem item = (GridItem) e.item;
System.out.println("Widget:::::::: " + e.widget);
System.out.println("Source::::::::: " + e.getSource());
System.out.println("Event::::::::: "
+ this.gridTable.getFocusItem());
} else {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
// Identify the selected row
GridItem item = (GridItem) e.item;
if (item == null)
return;
// The control that will be the editor must be a child of the
// Table
Text newEditor = new Text(gridTable, SWT.NONE);
final int selectedIndex = gridTable.getSelectionIndex();
final ModelItem modelItem = list.get(selectedIndex);
String extraText = modelItem.getExtraText();
// TODO: Write the logic to check for extra text for Automatic
// selection. Avoid hard coding.
if (extraText.equalsIgnoreCase("No pin routed")) {
extraText = "";
if (modelItem.getText().equalsIgnoreCase("<Automatic>")) {
newEditor.setEditable(false);
newEditor.setEnabled(false);
}
} else {
newEditor.setEditable(true);
newEditor.setEnabled(true);
}
newEditor.setText(extraText);
item.setText(editableColumn, extraText);
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent me) {
Text text = (Text) editor.getEditor();
modelItem.setExtraText(text.getText());
editor.getItem().setText(editableColumn, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, editableColumn);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
}
Regards,
Ashish Rawat
|
|
| | |
Goto Forum:
Current Time: Tue Sep 24 03:40:06 GMT 2024
Powered by FUDForum. Page generated in 0.03919 seconds
|