Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Ashish Rawat is currently offline Ashish RawatFriend
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 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 493
Registered: July 2009
Senior Member

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 #921651 is a reply to message #921626] Mon, 24 September 2012 09:57 Go to previous messageGo to next message
Ashish Rawat is currently offline Ashish RawatFriend
Messages: 14
Registered: June 2012
Junior Member
Hi Wim,

First of all, I am extremely sorry, as I didn't meant to be rude, but it is the issue which is holding me back from last 2 weeks. Because of that I wrote "ASAP".

Yes I had examined the selection event e, there are fields with following data:
e.widget --> Grid{}
e.getSource() --> Grid{}

Also I tried to add a listener to the checkBox Column, but it didn't worked.
Because of these issues I am unable to track the exact source (checkbox) where the selection even has been triggered.

Regards,
Ashish Rawat
Re: Checkbox GridColumn Event Handling [message #921769 is a reply to message #921651] Mon, 24 September 2012 12:05 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I'll have to inspect the source code before I can give you an answer.

Tom

Am 24.09.12 11:57, schrieb Ashish Rawat:
> Hi Wim,
>
> First of all, I am extremely sorry, as I didn't meant to be rude, but it
> is the issue which is holding me back from last 2 weeks. Because of that
> I wrote "ASAP".
>
> Yes I had examined the selection event e, there are fields with
> following data:
> e.widget --> Grid{}
> e.getSource() --> Grid{}
>
> Also I tried to add a listener to the checkBox Column, but it didn't
> worked.
> Because of these issues I am unable to track the exact source (checkbox)
> where the selection even has been triggered.
>
> Regards,
> Ashish Rawat
>
Re: Checkbox GridColumn Event Handling [message #929133 is a reply to message #921769] Mon, 01 October 2012 08:47 Go to previous messageGo to next message
Ashish Rawat is currently offline Ashish RawatFriend
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
Re: Checkbox GridColumn Event Handling [message #943804 is a reply to message #929133] Sun, 14 October 2012 19:42 Go to previous messageGo to next message
Ashish Rawat is currently offline Ashish RawatFriend
Messages: 14
Registered: June 2012
Junior Member
Hi Tom,

I found the solution for the problem which I have asked. The solution is donot add the SelectionListener to Grid, rather add Listener (generic listener), and look for Event.index value. This will return the index of the column where the click event has been triggered.

The reason that I understood is, implementing SelectionListener results in SelectionEvent, and in this SelectionEvent there are some information which gets hide in comparison to Event.

Please confirm if my understanding is wrong.


Thanks & Regards,
Ashish Rawat.
Re: Checkbox GridColumn Event Handling [message #982997 is a reply to message #943804] Tue, 13 November 2012 15:41 Go to previous message
Scott Seidl is currently offline Scott SeidlFriend
Messages: 7
Registered: November 2012
Junior Member
Would it be possible for you to post the snippet of code relating to the checkbox event handling? I have been trying to get this to work out on my own project and can't get it working.

Is there any website that clearly explains/shows how to do this with the Nebula components?
Previous Topic:GridVisibleRange and GridVisibleRangeSuppor
Next Topic:Representation of details to the seconds level
Goto Forum:
  


Current Time: Fri Apr 19 19:04:33 GMT 2024

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

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

Back to the top