Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » DirectEdit checkbox
DirectEdit checkbox [message #900743] Wed, 08 August 2012 11:26 Go to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Is that possible to have an editor like CheckBox??

Thanks in advance
Rui
Re: DirectEdit checkbox [message #900762 is a reply to message #900743] Wed, 08 August 2012 12:24 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
A checkbox in the direct editing feature is currently not supported. It is also not planned in the future.

BR,
Matthias
Re: DirectEdit checkbox [message #900769 is a reply to message #900762] Wed, 08 August 2012 12:31 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Perhaps, you can draw your own checkbox with different graphics algorithms. E.g. a text with a leading ellipse.

On a single-click on that ellipse you can change it's graphical representation: You can add a polygon on the ellipse (a cross or a hook) to indicate that it is checked.
Re: DirectEdit checkbox [message #900790 is a reply to message #900769] Wed, 08 August 2012 13:37 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Thanks. And to detect the click, should I use canDirectEdit, or there is another way?
I see there is a method getDoubleClick in Itoolbehaviourprovider, but for single click I don't see anything else.

Thanks
Re: DirectEdit checkbox [message #900843 is a reply to message #900790] Wed, 08 August 2012 17:12 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Hi again.

I tried this way.

In canDirectEdit, I return always false, but before returning I tried to set my object model attribute, and call UpdateFeature . Nonetheless I get "Cannot modify resource set without a write transaction" using or not using a Trasaction, which means that I can't at all to make the editor react to the click in order to change layout of my checkbox.

Any sugestions?
I would really appreciate. I'm struggling with this.

Thanks
Re: DirectEdit checkbox [message #900903 is a reply to message #900843] Wed, 08 August 2012 23:00 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
i managed to achieve the expected behaviour, but I couldn't also use pe properties. I had to create an auxiliar structure, where update feature gets the information about if the value is dirty, which is set by DirectEdit Feature in method candirectedit.

I frankly believe this is not THE way, but it's working. If anyone has some better idea, please let me know.

Thanks
Re: DirectEdit checkbox [message #900925 is a reply to message #900903] Thu, 09 August 2012 06:22 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Hi all,

wouldn't the
DirectEditingFeature with Custom Type

be a candidate?

Andreas
Re: DirectEdit checkbox [message #900928 is a reply to message #900843] Thu, 09 August 2012 06:48 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
"Cannot modify resource set without a write transaction"

You will need to wrap any model modification code into a command running on
the command stack of the editor's TransactionalEditingDomain, because
Graphiti uses EMF Transactions under the hoods.

BR,
Matthias
Re: DirectEdit checkbox [message #900929 is a reply to message #900925] Thu, 09 August 2012 07:00 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Hi Andreas,

what do you mean with custom type? Should the editor developer provide his own org.eclipse.jface.viewers.CellEditor for direct editing?

BR,
Matthias
Re: DirectEdit checkbox [message #900972 is a reply to message #900928] Thu, 09 August 2012 09:25 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Hi.

I checked that option, but I wasn't successful to make DirectEditFeature to extend org.eclipse.graphiti.ui.platform.ICellEditorProvider, doing getEditingType()=TYPE_CUSTOM.

I tried with org.eclipse.jface.viewers.CheckboxCellEditor, but I got a NullPointerException.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.gef.tools.DirectEditManager.hookListeners(DirectEditManager.java:287)
	at org.eclipse.gef.tools.DirectEditManager.setCellEditor(DirectEditManager.java:353)
	at org.eclipse.gef.tools.DirectEditManager.show(DirectEditManager.java:397)


Ok. Mathias. I was not using Editor's Transactional editing domain. My bad. I was using another one. Now it works and I just change visibility of images' shape (image_checked and image_not_checked).

If some has some sppinet to use Celleditor, it would be great

Thanks a lot.

[Updated on: Thu, 09 August 2012 09:26]

Report message to a moderator

Re: DirectEdit checkbox [message #900982 is a reply to message #900972] Thu, 09 August 2012 09:53 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Which Graphiti version do you use?

Does your direct editing feature implement ICellEditorProvider?
Re: DirectEdit checkbox [message #900983 is a reply to message #900982] Thu, 09 August 2012 09:58 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Hi . Version 0.9.0.v20120613-0805 in Eclipse Juno.

Yes it implements.
Thanks.
public class DirectEditBooleanFieldRegardCheckStateFeature extends AbstractDirectEditingFeature implements ICellEditorProvider {

	public DirectEditBooleanFieldRegardCheckStateFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canDirectEdit(IDirectEditingContext context) {
	...
         }


	public int getEditingType() {
		return TYPE_NONE;
	}
	
          ...


	@Override
	public CellEditor createCellEditor(Composite parent) {
		CheckboxCellEditor ckCellEditor = new CheckboxCellEditor(parent);
		return ckCellEditor;
	}

	@Override
	public void relocate(CellEditor cellEditor, IFigure figure) {
		//nothing
		
	}



Re: DirectEdit checkbox [message #901156 is a reply to message #900983] Fri, 10 August 2012 07:14 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Your direct editing type is TYPE_NONE and not TYPE_CUSTOM ...
Re: DirectEdit checkbox [message #901163 is a reply to message #901156] Fri, 10 August 2012 07:51 Go to previous messageGo to next message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Actually I use type_custom, sorry it was my mistake when I copied.

Still, it gives a NUllPointer with type custom, and with that method createcelleditor.
Re: DirectEdit checkbox [message #901203 is a reply to message #901163] Fri, 10 August 2012 10:14 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Here is an example with the org.eclipse.jface.viewers.ColorCellEditor which works for a direct editing feature.

But I have extended this editor, so that I can fulfill the interface ICellEditorProvider.

That's the implementation of MyColorCellEditor. Internal the cell editor works with an RGB value. But the interface between direct editing feature and cell editor is a String. In this specific case the string format is "RGB {r, g, b}".

import java.util.StringTokenizer;

import org.eclipse.jface.viewers.ColorCellEditor;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class MyColorCellEditor extends ColorCellEditor {

	public MyColorCellEditor(Composite parent) {
		super(parent);
	}

	@Override
	protected void doSetValue(Object value) {
		if (value instanceof String) {
			value = stringToRGB((String) value);
		}
		super.doSetValue(value);
	}

	@Override
	protected Object doGetValue() {
		Object value = super.doGetValue();
		if (value instanceof RGB) {
			value = ((RGB) value).toString();
		}
		return value;
	}

	protected Object openDialogBox(Control cellEditorWindow) {
		ColorDialog dialog = new ColorDialog(cellEditorWindow.getShell());
		Object value = super.doGetValue();
		if (value != null) {
			dialog.setRGB((RGB) value);
		}
		value = dialog.open();
		return dialog.getRGB();
	}

	private RGB stringToRGB(String value) {

		StringTokenizer st = new StringTokenizer(value, "RGB {,}");
		int red = Integer.parseInt(st.nextToken());
		int green = Integer.parseInt(st.nextToken());
		int blue = Integer.parseInt(st.nextToken());

		RGB rgb = new RGB(red, green, blue);
		return rgb;
	}

}



My direct editing feature simply contains these lines:

	public int getEditingType() {
		return TYPE_CUSTOM;
	}

	public CellEditor createCellEditor(Composite parent) {
		ColorCellEditor ce = new MyColorCellEditor(parent);
		return ce;
	}

	public void relocate(CellEditor cellEditor, IFigure figure) {
		cellEditor.getControl().setBounds(40, 40, 200, 50);
	}


Re: DirectEdit checkbox [message #901207 is a reply to message #901203] Fri, 10 August 2012 10:32 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
You are right. The CheckboxCellEditor does not work, also if you do it with the correct implementation shown above.

The reason is, that the CheckboxCellEditor from jface does not have any controls...

BR,
Matthias
Re: DirectEdit checkbox [message #901212 is a reply to message #901207] Fri, 10 August 2012 11:08 Go to previous message
Rui Domingues is currently offline Rui DominguesFriend
Messages: 194
Registered: October 2010
Senior Member
Thanks. Ok. So I will keep my solution of exchanging images each time candirectedit is invoked.
I really appreciate that you have posted an example.

Thanks again
Previous Topic:Would it be possible to load a diagram from an URI?
Next Topic:User defined attributes for the graphical elements on the canvas
Goto Forum:
  


Current Time: Mon Dec 22 00:06:43 GMT 2014

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

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