Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Renaming an item in a TreeView(Unable to rename a file on disk using a rename button)
Renaming an item in a TreeView [message #986315] Mon, 19 November 2012 21:52 Go to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Hello Guys,

I'm a student and very new in RCP development. I have actually a file explorer to develop and i'm a bit stuck in renaming a file.

I have a TreeView which shows me all the files and directories on my hard drive and i want to be able to rename a file or a directory. For this, i have set up a contextual menu and in it, i have a button named "Renommer". On click, i want to be able to edit the file or the directory directly on this TreeView.

I have followed lots of tutorials on the net but still i'm not able to achieve this.

Can someone please help me?

Below is a piece of code i have developped :

}else if (actionEnCours.compareTo("ActRen") == 0){
//on click on the menu Renommer
			System.out.println("Rename");
		

			viewer.getTree().setHeaderVisible(true);
			//new RenameFile(viewer);
			
			TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(viewer,new FocusCellOwnerDrawHighlighter(viewer));
			
			ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
				protected boolean isEditorActivationEvent(
						ColumnViewerEditorActivationEvent event) {
					return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
							|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
							|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
							|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
				}
			};
			
			TreeViewerEditor.create(viewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
					| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
					| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
			
			final TextCellEditor textCellEditor = new TextCellEditor(viewer.getTree());
			
			TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);

			column.getColumn().setWidth(200);
			column.getColumn().setMoveable(true);
			column.getColumn().setText("Column 1");
			column.setLabelProvider(new ColumnLabelProvider() {

				public String getText(Object element) {
					return "Column 1 => " + element.toString();
				}

			});
			//adding the EditingSupport
			column.setEditingSupport(new EditingSupport(viewer) {
				
				@Override
				protected void setValue(Object element, Object value) {
					// TODO Auto-generated method stub
					//not yet implemented
				}
				
				@Override
				protected Object getValue(Object element) {
					// TODO Auto-generated method stub
					return ((TreeObject)element).getName();
				}
				
				@Override
				protected CellEditor getCellEditor(Object element) {
					// TODO Auto-generated method stub
					return textCellEditor;
				}
				
				@Override
				protected boolean canEdit(Object element) {
					// TODO Auto-generated method stub
					return true;
				}
			});
		}
	}


The problem with this piece of code is that, it is creating a column next to my original one.
Re: Renaming an item in a TreeView [message #986373 is a reply to message #986315] Tue, 20 November 2012 09:28 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
No one can help me please??

It's quite urgent.

Thanks you guys.
Re: Renaming an item in a TreeView [message #986392 is a reply to message #986373] Tue, 20 November 2012 10:21 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Ronnie,

the code you posted should be called only once, when you create the tree. Then you should be able to edit nodes by doubleclicking on them.
Re: Renaming an item in a TreeViewer [message #986402 is a reply to message #986392] Tue, 20 November 2012 10:36 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
The thing is that i don't want to use the double click option. As i said before, i have a context menu in which i have a menu called "Renommer". On click of this menu item, i shall be able to edit the file or directory directly without any dialog box. The code i posted is in fact called only once as when the user click on this menu item "Renommer".

Any suggestion?

Thanks
Re: Renaming an item in a TreeViewer [message #986408 is a reply to message #986402] Tue, 20 November 2012 10:45 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Don't call it in that action. Call it when you create the treeViewer.
If you want to edit nodes only using the context menu, do it this way:

@Override
public void run() {
    // this is the context menu action
    viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), 0);
}


and change activation strategy like this:
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
	protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
		return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
	}
};


Note that the action always edits the selected item in the first column, so if you have more columns,
you need to find a way to get actually selected column.
Re: Renaming an item in a TreeViewer [message #986410 is a reply to message #986408] Tue, 20 November 2012 10:57 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
@Override
public void run() {
    v.editElement(((IStructuredSelection) v.getSelection()).getFirstElement(), focusCellManager.getFocusCell().getColumnIndex());
}

This could work, but I don't know whether it has any other pitfalls.
Re: Renaming an item in a TreeView [message #986418 is a reply to message #986315] Tue, 20 November 2012 11:17 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
Just a note:
A TreeViewer by default has only one column. Note that your code above creates a new column in the viewer:

TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);

column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
column.setLabelProvider(new ColumnLabelProvider() {



This is not what you want. Besides whenever you start renaming, you create yet another column.

Ever thought about the alternative to pop up a dialog for the new name? That's much easier. Eclipse does it the same way when renaming a file. Or is "editing in a viewer" the task to accomplish?

Regards,
Thorsten

[Updated on: Tue, 20 November 2012 11:19]

Report message to a moderator

Re: Renaming an item in a TreeView [message #986486 is a reply to message #986418] Tue, 20 November 2012 15:52 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Well the real task to accomplish is in fact "editing the file/directory name in the viewer itself".

An example :

Directory1
---DirectoryInsideDirecory1
------FileToRename
Directory2
---FileInsideDirectory

On a user right click --> option "Renommer", the file "FileToRename" name must be editable and afterwards the file name updated on the hard drive.

I have already thought about the popup idea but i was thinking that editing the element itself directly in the viewer could be much more fluid for the user.. Smile

Thanks for your help Smile

Re: Renaming an item in a TreeView [message #986521 is a reply to message #986486] Tue, 20 November 2012 17:50 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Any idea of how to achieve this please?
Re: Renaming an item in a TreeView [message #986534 is a reply to message #986521] Tue, 20 November 2012 19:07 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I already wrote it to you. Call all the code you posted here in the time of creation of your viewer.

In the "Renommer" action call this
viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), focusCellManager.getFocusCell().getColumnIndex());
it should activate editing of the element you select in the viewer.

What the editing does itself is accomplished here:
//adding the EditingSupport
column.setEditingSupport(new EditingSupport(viewer) {
				
	@Override
	protected void setValue(Object element, Object value) {
	    // set the file name here
	}
				
	...
});
Re: Renaming an item in a TreeView [message #986550 is a reply to message #986534] Tue, 20 November 2012 22:01 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
I did what you told me but unfortunately it didn't work. In fact when i click on the "Renommer" button inside my context menu, all i get is an empty treeviewer. I mean that my tree(where all my files and directories are displayed) completely disappears. Below is a piece of my code. This code executes itself when the user clicks on the "Renommer" option inside my context menu. Note that the setValue method is not yet implemented.


else if (actionEnCours.compareTo("ActRen") == 0){
			System.out.println("Rename");

			viewer.getTree().setHeaderVisible(true);
			//new RenameFile(viewer);
			
			TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(viewer,new FocusCellOwnerDrawHighlighter(viewer));
			
			ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
				protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
					return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
				}
			};
			
			TreeViewerEditor.create(viewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
					| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
					| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
			
			final TextCellEditor textCellEditor = new TextCellEditor(viewer.getTree());
			
			TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
			//added the line which you told me
			viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), focusCellManager.getFocusCell().getColumnIndex());
			
                        //adding the editong support without the setValue method implemented
			column.setEditingSupport(new EditingSupport(viewer) {
				
				@Override
				protected void setValue(Object element, Object value) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				protected Object getValue(Object element) {
					// TODO Auto-generated method stub
					return ((TreeObject)element).getName();
				}
				
				@Override
				protected CellEditor getCellEditor(Object element) {
					// TODO Auto-generated method stub
					return textCellEditor;
				}
				
				@Override
				protected boolean canEdit(Object element) {
					// TODO Auto-generated method stub
					return true;
				}
			});



What am i doing wrong? Can someone tell me please?

Thanking you in advance for your precious help. Smile
Re: Renaming an item in a TreeView [message #986552 is a reply to message #986550] Tue, 20 November 2012 22:04 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Got an error message too from Eclipse :

!ENTRY org.eclipse.ui 4 0 2012-11-20 22:55:59.177
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
at test.ManipFichiers.run(ManipFichiers.java:86)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3554)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3179)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at test.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

Thanks guys
Re: Renaming an item in a TreeView [message #986601 is a reply to message #986552] Wed, 21 November 2012 07:19 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
You better read the stacktrace. Its your fault:

java.lang.NullPointerException
at test.ManipFichiers.run(ManipFichiers.java:86)


Look in the code or use the debugger to check the NullPointer issue.

Regards,
Thorsten
Re: Renaming an item in a TreeView [message #986635 is a reply to message #986601] Wed, 21 November 2012 09:25 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I really don't understand why are you still creating the TreeViewer within the "Renommer" action.

This should be the only piece of code in the action
viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), focusCellManager.getFocusCell().getColumnIndex());


All other code has to be called when you create the tree.
Re: Renaming an item in a TreeView [message #986639 is a reply to message #986635] Wed, 21 November 2012 09:39 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
I have two seperate classes. One which is for manipulating files and folders in the treeviewer(ManipFichiers class) and the other is the NavigationView. In the NavigationView class, i create the treeviewer. If i create the focuscellmanager for example in the Navigation class, how can i get it from the ManipFichiers class?
Re: Renaming an item in a TreeView [message #986640 is a reply to message #986639] Wed, 21 November 2012 09:39 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), focusCellManager.getFocusCell().getColumnIndex());


The debugger isn't ok with this piece of code.
Re: Renaming an item in a TreeView [message #986653 is a reply to message #986640] Wed, 21 November 2012 10:03 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), viewer.getColumnViewerEditor().getFocusCell().getColumnIndex());
Re: Renaming an item in a TreeView [message #986662 is a reply to message #986653] Wed, 21 November 2012 10:25 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Still isn't working, i really don't know what am i doing wrong... Sad

I'm uploading the two source files of the two classes involved too. The NavigationView class where the TreeViewer is created and the ManipFichiers class where all operations on files and folders can be done.

I really hope that you will be able to help me with this issue.

Thanks for all.
Re: Renaming an item in a TreeView [message #986667 is a reply to message #986662] Wed, 21 November 2012 10:35 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
You are ignoring what I'm telling to you.

This should be the only piece of code in the action
else if (actionEnCours.compareTo("ActRen") == 0){
    viewer.editElement(((IStructuredSelection) viewer.getSelection()).getFirstElement(), viewer.getColumnViewerEditor().getFocusCell().getColumnIndex());
}

All other code has to be called when you create the tree, so move it from the ManipFichiers class to the NavigationView class!

Re: Renaming an item in a TreeView [message #986675 is a reply to message #986667] Wed, 21 November 2012 10:48 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
I tried to do this before but still it won't work.

I did exactly what you told me but now when i execute the program, i can't see my files and folders. The workbench where all these items are supposed to be seen, is completely empty.

Uploading the two classes once again Sad
Re: Renaming an item in a TreeView [message #986678 is a reply to message #986675] Wed, 21 November 2012 10:58 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hmm, it's hard to say. Try to call viewer.setInput(root) as last statement of the createPartControl() method.
Re: Renaming an item in a TreeView [message #986681 is a reply to message #986678] Wed, 21 November 2012 11:08 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Stil not working. It is this piece of code which makes that the treeviewer is empty :

TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
Re: Renaming an item in a TreeView [message #986683 is a reply to message #986681] Wed, 21 November 2012 11:13 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I see, you forgot to set column width.

column.getColumn().setWidth(200);
Re: Renaming an item in a TreeView [message #986684 is a reply to message #986681] Wed, 21 November 2012 11:14 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I see, you've forgot to set the column width

column.getColumn().setWidth(200);
Re: Renaming an item in a TreeView [message #986688 is a reply to message #986681] Wed, 21 November 2012 11:17 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Besides, if i put the call viewer.setInput(root) at the end of the method, i got some errors which tell me that no label provider is present and if i put the line viewer.setLabelProvider(new ViewLabelProvider()); together with the viewer.setInput(root) at the end of the method, it won't work neither... Sad
Re: Renaming an item in a TreeView [message #986691 is a reply to message #986688] Wed, 21 November 2012 11:20 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
With the piece of code which you told me, i can see my tree now.

But when i try to open a node, i'm getting this error message :
!ENTRY org.eclipse.jface 4 2 2012-11-21 12:20:10.796
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface".
!STACK 0
org.eclipse.core.runtime.AssertionFailedException: assertion failed: Column 0 has no label provider.
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:149)
at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:953)
at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:113)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1033)
at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:485)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2167)
at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:848)
at org.eclipse.jface.viewers.AbstractTreeViewer.updateChildren(AbstractTreeViewer.java:2773)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefreshStruct(AbstractTreeViewer.java:1923)
at org.eclipse.jface.viewers.TreeViewer.internalRefreshStruct(TreeViewer.java:721)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefreshStruct(AbstractTreeViewer.java:1930)
at org.eclipse.jface.viewers.TreeViewer.internalRefreshStruct(TreeViewer.java:721)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefreshStruct(AbstractTreeViewer.java:1930)
at org.eclipse.jface.viewers.TreeViewer.internalRefreshStruct(TreeViewer.java:721)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1898)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1855)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1841)
at org.eclipse.jface.viewers.StructuredViewer$7.run(StructuredViewer.java:1508)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1443)
at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:403)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1404)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1506)
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1465)
at test.NavigationView$1$1.run(NavigationView.java:265)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3529)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3182)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at test.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Re: Renaming an item in a TreeView [message #986693 is a reply to message #986688] Wed, 21 November 2012 11:24 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Yes, you have to set a labelProvider to the column. You've done that in your first post, but in the file you've posted a little while ago, you've omitted that

column.getColumn().setWidth(200);
column.setLabelProvider(new ColumnLabelProvider() {

	public String getText(Object element) {
		return "Column 1 => " + element.toString();
	}

});

Anyway, you can let the viewer.setInput(root) as is, so you don't need to call it as a last statement.
Re: Renaming an item in a TreeView [message #986694 is a reply to message #986691] Wed, 21 November 2012 11:25 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
I think we are on our way towards success Smile

I can now edit an item in my treeviewer(i mean the parent).

But the problem is with the children. When i try to expand a parent node, the children won't display themselves and i get the error message as before which tells me that no label provider is set up(same error if the line viewer.setInput(root) was at the end of the method).
Re: Renaming an item in a TreeView [message #986695 is a reply to message #986694] Wed, 21 November 2012 11:27 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
No. The piece of code will just add another column next to my main column, that's why i've deleted it.

The problem now is when i try to expand an item in my treeviewer :s
Re: Renaming an item in a TreeView [message #986697 is a reply to message #986695] Wed, 21 November 2012 11:28 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
if i try to add this piece of code, when i try to click on an item in order to expand it, it won't expand and the tree expan icon disappears Sad
Re: Renaming an item in a TreeView [message #986753 is a reply to message #986697] Wed, 21 November 2012 14:36 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Can you just tell me how can i get back my files and folders name inside a parent node in my treeviewer?

Actually, what i get is something like that :

ParentFolder(on expanded)
---AFile
---AFolder
------AFileInsideAFolder

But the problem is that the name in the above example for the 'AFile' and 'AFileInsideFolder' is not shown, but i can expand these elements if ever they have something inside. It is just the display which isn't good but i can now edit directly the node name.

For this, i have added this piece of code :

column.getColumn().setWidth(200);

and added also :

column.setLabelProvider(new CellLabelProvider() {

@Override
public void update(ViewerCell cell) {
// TODO Auto-generated method stub

}
});

If not, i got the famous error of not setting a label provider.

My real problem i think is with this method inside the label provider. What shall i implement here?

Thanks Smile
Re: Renaming an item in a TreeView [message #986762 is a reply to message #986753] Wed, 21 November 2012 15:00 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
column.setLabelProvider(new ColumnLabelProvider());
Re: Renaming an item in a TreeView [message #986768 is a reply to message #986762] Wed, 21 November 2012 15:12 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
This won't work, i have already tried that. WHich is normal, inside my parent node, i don't have anymore columns, but rows. We have achieved the step in displaying the column and now we must display the rows. But how can i do that?

When i added the above code, when i click on a non-empty node, the node won't open and the expand icon can't be seen anymore. And i get an error message too on Eclipse which is a looooooonnnnnngggggg error message...
Re: Renaming an item in a TreeView [message #986770 is a reply to message #986768] Wed, 21 November 2012 15:13 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Error message starts like that :

!ENTRY org.eclipse.ui 4 0 2012-11-21 16:13:35.853
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.StackOverflowError
at org.eclipse.swt.internal.gtk.OS._gtk_tree_store_set(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_tree_store_set(OS.java:11962)
at org.eclipse.swt.widgets.TreeItem.setBackground(TreeItem.java:1197)
at org.eclipse.jface.viewers.TreeViewerRow.setBackground(TreeViewerRow.java:134)
at org.eclipse.jface.viewers.ViewerCell.setBackground(ViewerCell.java:129)
at org.eclipse.jface.viewers.ColumnLabelProvider.update(ColumnLabelProvider.java:39)
at org.eclipse.jface.viewers.SWTFocusCellManager$4.getName(SWTFocusCellManager.java:195)
at org.eclipse.swt.accessibility.AccessibleObject.atkObject_get_name(AccessibleObject.java:972)
at org.eclipse.swt.internal.gtk.OS._gtk_tree_store_set(Native Method)
at org.eclipse.swt.internal.gtk.OS.gtk_tree_store_set(OS.java:11962)
at org.eclipse.swt.widgets.TreeItem.setBackground(TreeItem.java:1197)
at org.eclipse.jface.viewers.TreeViewerRow.setBackground(TreeViewerRow.java:134)
Re: Renaming an item in a TreeView [message #986788 is a reply to message #986770] Wed, 21 November 2012 16:03 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I think it will be a problem within your model. Try to debug it. This is something I can't help you with.
Re: Renaming an item in a TreeView [message #986828 is a reply to message #986788] Wed, 21 November 2012 19:49 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
This isn't a problem with my model. I verified several times the model and did a print out of what contains the arraylist. On load the program only loads root files and directories. On expand of a directory containing other files and directories, those names are correctly added to my arraylist.

Now when working with the graphical interface, i can see these root files and folders displayed correctly and i can also edit inline those files and folders names. On expand, i can only see the expand icons for other files and directories. The names have completely disappeared and what i did to verify if ever the files and folders are present, i added the following lines :


column.setLabelProvider(new CellLabelProvider() {
			
			@Override
			public void update(ViewerCell cell) {
				System.out.println(cell.getElement().toString());
			}
		});



This piece of code helped me to find out that the correct name of the file or folder showed up on the console but not on the graphical interface.

I'm uploading a screen capture and the source code too. On the screen capture you will notice that i clicked on a folder and the correct name showed up on the console.

Can you please help me with displaying the names please?

Thanks for all Smile
Re: Renaming an item in a TreeView [message #986830 is a reply to message #986828] Wed, 21 November 2012 19:59 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Another thing is that in the NavigationView class, the model is found inside.
Re: Renaming an item in a TreeView [message #986906 is a reply to message #986830] Thu, 22 November 2012 10:42 Go to previous messageGo to next message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
No one has any idea of what is going wrong? Is there and relationship with the plugin.xml? Or setting something visible?

Thanks
Re: Renaming an item in a TreeView [message #986993 is a reply to message #986906] Thu, 22 November 2012 17:38 Go to previous message
Ronnie Pottayya is currently offline Ronnie PottayyaFriend
Messages: 24
Registered: November 2012
Junior Member
Still no idea of what's going wrong please????

[Updated on: Thu, 22 November 2012 18:20]

Report message to a moderator

Previous Topic: Quick Context View from Navigate Menu
Next Topic:Unable to check for file extension in expression?
Goto Forum:
  


Current Time: Tue Apr 16 08:30:24 GMT 2024

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

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

Back to the top