Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Editing columns in "Tree with Columns" view
Editing columns in "Tree with Columns" view [message #912369] Thu, 13 September 2012 12:51 Go to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hello,

I am trying to use the "Tree with Columns" view for editing my data.
My first implementation looks like the following:

final Tree tree = treeViewerWithColumns.getTree();
final TreeEditor editor = new TreeEditor(tree);

tree.setLayoutData(new FillLayout());
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tree.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseDoubleClick(MouseEvent e) {
		// Clean up any previous editor control
		Control oldEditor = editor.getEditor();
		if (oldEditor != null)
			oldEditor.dispose();

		if (tree.getSelectionCount() != 1) {
			return;
		}

		// Identify the selected row
		TreeItem[] selection = tree.getSelection();
		TreeItem item = selection[0];
		if (item == null)
			return;

		final SequenceContentImpl s = (SequenceContentImpl) item.getData();
		
		// The control that will be the editor must be a
		// child of the Table
		Text newEditor = new Text(tree, SWT.BORDER);
		newEditor.setText(s.getComment());
		newEditor.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent me) {
				Text text = (Text) editor.getEditor();
				s.setComment(text.getText());
			}
		});
		newEditor.selectAll();
		newEditor.setFocus();
		editor.setEditor(newEditor, item, COLUMN_INDEX_COMMENT);
	}
});

TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
objectColumn.setText(getString("_UI_ObjectColumn_label"));
objectColumn.setResizable(true);
objectColumn.setWidth(250);

TreeColumn commentColumn = new TreeColumn(tree, SWT.NONE);
commentColumn.setText("Comment");
commentColumn.setResizable(true);
commentColumn.setWidth(200);

treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
treeViewerWithColumns.setLabelProvider(new SequenceTreeColumnLabelProvider(adapterFactory));
treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
treeViewerWithColumns.setInput(s);


It works so far, but the file is never marked as dirty. I have tried it with
firePropertyChange(PROP_DIRTY);
, but no result.
How can I mark the file as dirty?

Furthermore the input field is never shown directly, so it is impossible to see that the editor is active.

I think there could be a easier way, but I don't know which. Thanks for any advices.
Re: Editing columns in "Tree with Columns" view [message #912380 is a reply to message #912369] Thu, 13 September 2012 13:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
You must use commands to make changes to the model, so you shouldn't
just do s.setComment you should use SetCommand.create to create the
command and then execute it on the command stack. Have a look at
org.eclipse.emf.edit.provider.ItemPropertyDescriptor.setPropertyValue(Object,
Object)

On 13/09/2012 2:51 PM, Missing name Mising name wrote:
> Hello,
>
> I am trying to use the "Tree with Columns" view for editing my data.
> My first implementation looks like the following:
>
> final Tree tree = treeViewerWithColumns.getTree();
> final TreeEditor editor = new TreeEditor(tree);
>
> tree.setLayoutData(new FillLayout());
> tree.setHeaderVisible(true);
> tree.setLinesVisible(true);
> tree.addMouseListener(new MouseAdapter() {
> @Override
> public void mouseDoubleClick(MouseEvent e) {
> // Clean up any previous editor control
> Control oldEditor = editor.getEditor();
> if (oldEditor != null)
> oldEditor.dispose();
>
> if (tree.getSelectionCount() != 1) {
> return;
> }
>
> // Identify the selected row
> TreeItem[] selection = tree.getSelection();
> TreeItem item = selection[0];
> if (item == null)
> return;
>
> final SequenceContentImpl s = (SequenceContentImpl)
> item.getData();
>
> // The control that will be the editor must be a
> // child of the Table
> Text newEditor = new Text(tree, SWT.BORDER);
> newEditor.setText(s.getComment());
> newEditor.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent me) {
> Text text = (Text) editor.getEditor();
> s.setComment(text.getText());
> }
> });
> newEditor.selectAll();
> newEditor.setFocus();
> editor.setEditor(newEditor, item, COLUMN_INDEX_COMMENT);
> }
> });
>
> TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
> objectColumn.setText(getString("_UI_ObjectColumn_label"));
> objectColumn.setResizable(true);
> objectColumn.setWidth(250);
>
> TreeColumn commentColumn = new TreeColumn(tree, SWT.NONE);
> commentColumn.setText("Comment");
> commentColumn.setResizable(true);
> commentColumn.setWidth(200);
>
> treeViewerWithColumns.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory));
> treeViewerWithColumns.setLabelProvider(new
> SequenceTreeColumnLabelProvider(adapterFactory));
> treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
> treeViewerWithColumns.setInput(s);
>
> It works so far, but the file is never marked as dirty. I have tried
> it with firePropertyChange(PROP_DIRTY);, but no result.
> How can I mark the file as dirty?
>
> Furthermore the input field is never shown directly, so it is
> impossible to see that the editor is active.
>
> I think there could be a easier way, but I don't know which. Thanks
> for any advices.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in "Tree with Columns" view [message #912386 is a reply to message #912380] Thu, 13 September 2012 13:20 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Thanks for your advice.
Is there no possibility to activate the editor function in the generated editor?
Re: Editing columns in "Tree with Columns" view [message #912477 is a reply to message #912386] Thu, 13 September 2012 16:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I'm not sure what you're asking now. You asked about why the editor (I
assume the generated editor) doesn't get dirty, and I explained that
it's because you're not using a command. The editor determines
dirtiness from the state of the command stack. Is this question
different but related somehow?

On 13/09/2012 3:20 PM, Missing name Mising name wrote:
> Thanks for your advice.
> Is there no possibility to activate the editor function in the
> generated editor?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in "Tree with Columns" view [message #912491 is a reply to message #912386] Thu, 13 September 2012 16:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
If you look at what that does:

public static void delete(EObject eObject)
{
EObject rootEObject = getRootContainer(eObject);
Resource resource = rootEObject.eResource();

Collection<EStructuralFeature.Setting> usages;
if (resource == null)
{
usages = UsageCrossReferencer.find(eObject, rootEObject);
}
else
{
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet == null)
{
usages = UsageCrossReferencer.find(eObject, resource);
}
else
{
usages = UsageCrossReferencer.find(eObject, resourceSet);
}
}

for (EStructuralFeature.Setting setting : usages)
{
if (setting.getEStructuralFeature().isChangeable())
{
remove(setting, eObject);
}
}

remove(eObject);
}

You can imagine that doing a UsageCrossReferencer.findAll would visit
the whole model just once, looking for all the objects, rather than
visiting the whole model once per object. That ought to be a lot faster.


On 13/09/2012 3:20 PM, Missing name Mising name wrote:
> Thanks for your advice.
> Is there no possibility to activate the editor function in the
> generated editor?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in &amp;quot;Tree with Columns&amp;quot; view [message #912495 is a reply to message #912491] Thu, 13 September 2012 16:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sorry, that was for the UML2 newsgroup.

On 13/09/2012 6:52 PM, Ed Merks wrote:
> If you look at what that does:
>
> public static void delete(EObject eObject)
> {
> EObject rootEObject = getRootContainer(eObject);
> Resource resource = rootEObject.eResource();
>
> Collection<EStructuralFeature.Setting> usages;
> if (resource == null)
> {
> usages = UsageCrossReferencer.find(eObject, rootEObject);
> }
> else
> {
> ResourceSet resourceSet = resource.getResourceSet();
> if (resourceSet == null)
> {
> usages = UsageCrossReferencer.find(eObject, resource);
> }
> else
> {
> usages = UsageCrossReferencer.find(eObject, resourceSet);
> }
> }
>
> for (EStructuralFeature.Setting setting : usages)
> {
> if (setting.getEStructuralFeature().isChangeable())
> {
> remove(setting, eObject);
> }
> }
>
> remove(eObject);
> }
>
> You can imagine that doing a UsageCrossReferencer.findAll would visit
> the whole model just once, looking for all the objects, rather than
> visiting the whole model once per object. That ought to be a lot faster.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in &amp;quot;Tree with Columns&amp;quot; view [message #912835 is a reply to message #912477] Fri, 14 September 2012 09:14 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
>> Thanks for your advice.
>> Is there no possibility to activate the editor function in the
>> generated editor?
> I'm not sure what you're asking now. You asked about why the editor (I
> assume the generated editor) doesn't get dirty, and I explained that
> it's because you're not using a command. The editor determines
> dirtiness from the state of the command stack. Is this question
> different but related somehow?

The first thing I got working.
I was searching for a simple possibility to activate the editor functionality in that view.

My solution for the moment:
TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(treeViewerWithColumns,
		new FocusCellOwnerDrawHighlighter(treeViewerWithColumns));
ColumnViewerEditorActivationStrategy actStrategy = new ColumnViewerEditorActivationStrategy(
		treeViewerWithColumns) {
	@Override
	protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
		return super.isEditorActivationEvent(event)
				|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
	}
};

TreeViewerEditor.create(treeViewerWithColumns, focusCellManager, actStrategy,
		ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL
				| ColumnViewerEditor.KEYBOARD_ACTIVATION);

TreeViewerColumn viewerColumn = new TreeViewerColumn(treeViewerWithColumns, commentColumn);
viewerColumn.setLabelProvider(new DelegatingSequenceColumnLabelProvider(slp, COLUMN_INDEX_COMMENT));
viewerColumn.setEditingSupport(new EditingSupport(treeViewerWithColumns) {
	@Override
	protected void setValue(Object element, Object value) {
		if (element instanceof CommandImpl && !value.equals(((CommandImpl) element).getComment())) {
			Command save = SetCommand.create(getEditingDomain(), element,
					SequencePackage.Literals.SEQUENCE_CONTENT__COMMENT, value);
			getEditingDomain().getCommandStack().execute(save);
		}
	}

	@Override
	protected Object getValue(Object element) {
		return ((SequenceContentImpl) element).getComment();
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return new TextCellEditor((Composite) treeViewerWithColumns.getControl());
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}
});


Perhaps there is a more recommend way.
Re: Editing columns in &amp;amp;quot;Tree with Columns&amp;amp;quot; view [message #912871 is a reply to message #912835] Fri, 14 September 2012 10:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
The rest is more of a JFace question. I don't have so much experience
with that. It looks quite complicated. I have a feeling it does
something very similar to the utilities described here:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=220843#c3

These are part of JFace now. They help delegate editing to EMF's
property descriptors so you don't have to write much of anything...

I see again you're casting to CommandImpl? Why? Why not use the
Command interface.


On 14/09/2012 11:14 AM, Missing name Mising name wrote:
>>> Thanks for your advice.
>>> Is there no possibility to activate the editor function in the
>>> generated editor?
>> I'm not sure what you're asking now. You asked about why the editor
>> (I assume the generated editor) doesn't get dirty, and I explained
>> that it's because you're not using a command. The editor determines
>> dirtiness from the state of the command stack. Is this question
>> different but related somehow?
>
> The first thing I got working.
> I was searching for a simple possibility to activate the editor
> functionality in that view.
>
> My solution for the moment:
> TreeViewerFocusCellManager focusCellManager = new
> TreeViewerFocusCellManager(treeViewerWithColumns,
> new FocusCellOwnerDrawHighlighter(treeViewerWithColumns));
> ColumnViewerEditorActivationStrategy actStrategy = new
> ColumnViewerEditorActivationStrategy(
> treeViewerWithColumns) {
> @Override
> protected boolean
> isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
> return super.isEditorActivationEvent(event)
> || (event.eventType ==
> ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode ==
> SWT.CR);
> }
> };
>
> TreeViewerEditor.create(treeViewerWithColumns, focusCellManager,
> actStrategy,
> ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
> ColumnViewerEditor.TABBING_VERTICAL
> | ColumnViewerEditor.KEYBOARD_ACTIVATION);
>
> TreeViewerColumn viewerColumn = new
> TreeViewerColumn(treeViewerWithColumns, commentColumn);
> viewerColumn.setLabelProvider(new
> DelegatingSequenceColumnLabelProvider(slp, COLUMN_INDEX_COMMENT));
> viewerColumn.setEditingSupport(new
> EditingSupport(treeViewerWithColumns) {
> @Override
> protected void setValue(Object element, Object value) {
> if (element instanceof CommandImpl &&
> !value.equals(((CommandImpl) element).getComment())) {
> Command save = SetCommand.create(getEditingDomain(), element,
> SequencePackage.Literals.SEQUENCE_CONTENT__COMMENT, value);
> getEditingDomain().getCommandStack().execute(save);
> }
> }
>
> @Override
> protected Object getValue(Object element) {
> return ((SequenceContentImpl) element).getComment();
> }
>
> @Override
> protected CellEditor getCellEditor(Object element) {
> return new TextCellEditor((Composite)
> treeViewerWithColumns.getControl());
> }
>
> @Override
> protected boolean canEdit(Object element) {
> return true;
> }
> });
>
> Perhaps there is a more recommend way.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in &amp;amp;quot;Tree with Columns&amp;amp;quot; view [message #912907 is a reply to message #912871] Fri, 14 September 2012 11:36 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Thanks for the link, I will try it, but I don't know what content adapterFactoryContentProvider shall contain.
Yeah it is "complicated", that was the reason why I am asking for a way.

I don't know why I always use the Impl. I have changed it to the interface.
Re: Editing columns in &amp;amp;amp;quot;Tree with Columns&amp;amp;amp;quot; view [message #912932 is a reply to message #912907] Fri, 14 September 2012 12:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
In the generated editor you'll see this several times:<br>
<blockquote>new AdapterFactoryContentProvider(adapterFactory)<br>
</blockquote>
This approach should work well if your columns correspond to
properties you could normally edit in the properties view...<br>
<br>
<br>
<div class="moz-cite-prefix">On 14/09/2012 1:36 PM, Missing name
Mising name wrote:<br>
</div>
<blockquote cite="mid:k2v4rh$5c3$1@xxxxxxxxe.org" type="cite">Thanks
for the link, I will try it, but I don't know what content
adapterFactoryContentProvider shall contain.
<br>
Yeah it is "complicated", that was the reason why I am asking for
a way.
<br>
<br>
I don't know why I always use the Impl. I have changed it to the
interface.
<br>
</blockquote>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Editing columns in &amp;amp;amp;quot;Tree with Columns&amp;amp;amp;quot; view [message #912939 is a reply to message #912932] Fri, 14 September 2012 12:46 Go to previous message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Ah okay ... I have missed it. Thanks.
Now it is working and I need less code. Smile
Previous Topic:DND create EObject while dragging
Next Topic:[CDO]Permission management available?
Goto Forum:
  


Current Time: Thu Apr 25 11:00:30 GMT 2024

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

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

Back to the top