Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Open dynamically a part
Open dynamically a part [message #1074342] Fri, 26 July 2013 14:42 Go to next message
anthony palmieri is currently offline anthony palmieri
Messages: 20
Registered: July 2013
Junior Member
Hello ,
I have a browser and i want open a new part when i double click on a node. I follow some instruction in previous post but i have an incomprehensible error . Therefore when i click on a node nothing happend handlers execute methode not called
Thanks you for your answers
My error stack:
!ENTRY org.eclipse.equinox.event 4 0 2013-07-26 16:06:48.300
!MESSAGE Exception while dispatching event org.osgi.service.event.Event [topic=org/eclipse/e4/ui/model/application/Contribution/object/SET] to handler org.eclipse.e4.ui.services.internal.events.UIEventHandler@3f651673
!STACK 0
java.lang.ClassCastException: org.eclipse.e4.ui.model.application.commands.impl.HandlerImpl cannot be cast to org.eclipse.e4.ui.model.application.ui.MUIElement
	at org.eclipse.ui.internal.WorkbenchPage$5.handleEvent(WorkbenchPage.java:4957)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.impl.ContributionImpl.setObject(ContributionImpl.java:131)
	at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.processActiveHandler(HandlerProcessingAddon.java:158)
	at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.access$0(HandlerProcessingAddon.java:151)
	at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon$2.handleEvent(HandlerProcessingAddon.java:120)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl.setContext(PartImpl.java:399)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:614)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:735)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:706)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:700)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:685)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1096)
	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:66)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$9.widgetSelected(StackRenderer.java:885)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:778)
	at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3061)
	at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1753)
	at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:278)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at test.rcp.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:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
	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:606)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)


My handlers
public class OpenNodeDatastoreBrowserHandler {

	public OpenNodeDatastoreBrowserHandler() {
	System.out.println("objet appelé");
	}

	@Execute
	public void openNode(
			@Named(IServiceConstants.ACTIVE_SELECTION) Item selectedItem,EPartService partService,EModelService modelService, MApplication app) {
		System.out
				.println("OpenTreeNodeHandler - Handler invoked with selected item "
						+ selectedItem);
		String partId="test.rcp.inputpart.dataseteditor";
		//String partId = createEditorPartIdFor(selectedItem);
		MPart editorPart = partService.findPart(partId);
		if (editorPart == null) {
			System.out.println("OpenTreeNodeHandler - No editor found with id="
					+ partId);
			editorPart = createEditorFor(selectedItem);

			MPartStack editorsStack = (MPartStack) modelService.find(
					"sample.part.stack.editors", app);
			editorsStack.getChildren().add(editorPart);
			System.out.println("OpenTreeNodeHandler - Editor with id=" + partId
					+ " created and added to stack");
		} else {
			System.out.println("OpenTreeNodeHandler - Editor with id=" + partId
					+ " already exists");
		}

		partService.activate(editorPart);
		System.out.println("OpenTreeNodeHandler - Editor with id=" + partId
				+ " activated");
	}

	private String createEditorPartIdFor(Item selectedItem) {
		return "sample.editor." + selectedItem.toString();
	}

	private MPart createEditorFor(Item selectedItem) {
		MPart editorPart = MBasicFactory.INSTANCE.createPart();
		editorPart.setElementId(createEditorPartIdFor(selectedItem));
		String shortName = selectedItem.toString();
		editorPart.setLabel(shortName);
		editorPart.setTooltip(shortName);
		editorPart.setCloseable(true);
		editorPart
				.setContributionURI("bundleclass://test.rcp/com.itf.tvt.tool.datastore.gui.DatasetEditorPart");
		return editorPart;
	}


my listener for the tree
treeViewer.addDoubleClickListener(new IDoubleClickListener() {

			@SuppressWarnings("restriction")
			@Override
			public void doubleClick(DoubleClickEvent event) {
				IStructuredSelection selection = ((IStructuredSelection) event
						.getSelection());
				System.out.println(selection);
				if (!selection.isEmpty()) {
					System.out.println(selectionService);
					selectionService.setSelection(selection.getFirstElement());
					// ParameterizedCommand command = commandService
					// .createCommand(
					// "test.rcp.command.datastore.browser.opennode",
					// null);

					Command command = commandService
							.getCommand("test.rcp.command.datastore.browser.opennode");

					// Check if the command is defined
					System.out.println("command defini:" + command.isDefined());

					// Activate Handler, assume AboutHandler() class exists
					// already
					handlerService.activateHandler(
							"test.rcp.command.datastore.browser.opennode",
							new OpenNodeDatastoreBrowserHandler());

					ParameterizedCommand cmd = commandService
							.createCommand(
									"test.rcp.command.datastore.browser.opennode",
									null);

					// Check if the command can get executed
					System.out.println(handlerService.canExecute(cmd));

					// Execute the command
					handlerService.executeHandler(cmd);

					// System.out.println(command.getCommand().isHandled());
					// IHandlerService hs = (IHandlerService)
					// locationService.getService(IHandlerService.class)
					// handlerService.executeHandler(command);

				}

			}

		});

[Updated on: Fri, 26 July 2013 14:42]

Report message to a moderator

Re: Open dynamically a part [message #1074366 is a reply to message #1074342] Fri, 26 July 2013 15:28 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

What does your application model look like?

JD
Re: Open dynamically a part [message #1075277 is a reply to message #1074366] Mon, 29 July 2013 07:03 Go to previous messageGo to next message
anthony palmieri is currently offline anthony palmieri
Messages: 20
Registered: July 2013
Junior Member
Hi ,
My application is into the file , sorry because i have error if it's in text

Cordially
thanks for help
Re: Open dynamically a part [message #1075430 is a reply to message #1075277] Mon, 29 July 2013 12:18 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

Is this a pure e4 app? I smell a compat layer issue.
Re: Open dynamically a part [message #1075470 is a reply to message #1075277] Mon, 29 July 2013 13:35 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

I am going to assume that the node (or button or whatever) is a child of the Datastore Browser part. With that, your application model looks fine. My only comment is be careful with the o.e.u.internal.*Handler's eg:
<handlers xmi:id="_BpYwkOk5EeKK7dLmcrkNfg" elementId="test.rcp.handler.4" contributionURI="bundleclass://org.eclipse.ui/org.eclipse.ui.internal.CloseAllHandler"/>


I have not worked with these much, so someone else might be able to speak to this better than I am. Depending upon your application (3.x, migration, pure E4), you might be better off using something like o.e.e4.ui.internal.workbench.handlers.SaveAllHandler.

But to echo what Sopot said, Quote:
Is this a pure e4 app?


In addition, what version of Eclipse are you targeting? (4.2.2, 4.3.0, ... ?)

JD
Re: Open dynamically a part [message #1075862 is a reply to message #1075470] Tue, 30 July 2013 08:06 Go to previous messageGo to next message
anthony palmieri is currently offline anthony palmieri
Messages: 20
Registered: July 2013
Junior Member
Sorry, I use compatibility with eclipse Kepler 4.3 but i want migr to pure rcp 4.

Quote:
I have not worked with these much, so someone else might be able to speak to this better than I am. Depending upon your application (3.x, migration, pure E4), you might be better off using something like o.e.e4.ui.internal.workbench.handlers.SaveAllHandler.


Yes it's to the beginning i have use some command from 3.x version .And i read that commands import not exist in pure eclipse 4 , yet?

Thanks for your helps
Re: Open dynamically a part [message #1075888 is a reply to message #1075470] Tue, 30 July 2013 09:25 Go to previous message
anthony palmieri is currently offline anthony palmieri
Messages: 20
Registered: July 2013
Junior Member
I have find a solution but i think that not the best way :/
So what's the best practise ?

I add a IDoubleClickListener to my TreeView :

@Override
	public void doubleClick(DoubleClickEvent event) {
		boolean partExist = false;
		for(MPart part: partService.getParts() ){
			if(part.getLabel().equals(event.getSelection().toString())){
				partService.showPart(part, PartState.ACTIVATE);
				partExist=true;
			}
			if(partExist)break;
		}
		if(!partExist){
		MPart part = partService
		        .createPart("com.itf.tvt.tool.datastore.gui.partdescriptor.dataseteditor"); 
		part.setLabel(event.getSelection().toString());
//		    
//		    // If multiple parts of this type is allowed 
//		    // in the application model, 
//		    // then the provided part will be shown 
//		    // and returned
		    partService.showPart(part, PartState.ACTIVATE);}
		  

[Updated on: Wed, 31 July 2013 08:29]

Report message to a moderator

Previous Topic:Setting elements as transient
Next Topic:Unregister from EventBroker
Goto Forum:
  


Current Time: Thu Oct 23 09:31:12 GMT 2014

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

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