Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Share EditingDomain between multiple diagram editors
Share EditingDomain between multiple diagram editors [message #565521] Tue, 24 August 2010 08:50 Go to next message
Ken Wenzel is currently offline Ken Wenzel
Messages: 39
Registered: July 2009
Member
Hello,

I want to share the same EditingDomain instance between multiple diagram editors to implement a drill down feature while storing all diagrams in one file.

The following code in DiagramEditorBehavior.dispose() makes this impossible since it removes all resources from the ResourceSet:


// Clear the editing domain of all resources with potentially unsaved changes
try {
editingDomain.runExclusive(new Runnable() {
@Override
public void run() {
editingDomain.getResourceSet().getResources().retainAll(Coll ections.EMPTY_LIST);
}
});
} catch (final InterruptedException e) {
T.racer().error(e.getMessage(), e);
}


Is it be possible to only clear the ResourceSet if DiagramEditorInput.disposeEditingDomain?

Thank you.

Best regards,
Ken
Re: Share EditingDomain between multiple diagram editors [message #565574 is a reply to message #565521] Wed, 25 August 2010 07:14 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1577
Registered: July 2009
Location: Walldorf, Germany
Senior Member
You're right, this coding currently prevents sharing one editing domain
accross editors. I moved this passage to the disposal of the editing domain
and checked-in that fix to CVS. This should solve that issue.

-Michael


"Ken Wenzel" <kenwenzel@gmx.net> wrote in message
news:i50f79$itp$1@build.eclipse.org...
> Hello,
>
> I want to share the same EditingDomain instance between multiple diagram
> editors to implement a drill down feature while storing all diagrams in
> one file.
>
> The following code in DiagramEditorBehavior.dispose() makes this
> impossible since it removes all resources from the ResourceSet:
>
>
> // Clear the editing domain of all resources with potentially unsaved
> changes try {
> editingDomain.runExclusive(new Runnable() {
> @Override
> public void run() {
> editingDomain.getResourceSet().getResources().retainAll(Coll ections.EMPTY_LIST);
> }
> });
> } catch (final InterruptedException e) {
> T.racer().error(e.getMessage(), e);
> }
>
>
> Is it be possible to only clear the ResourceSet if
> DiagramEditorInput.disposeEditingDomain?
>
> Thank you.
>
> Best regards,
> Ken
Re: Share EditingDomain between multiple diagram editors [message #643242 is a reply to message #565521] Mon, 06 December 2010 03:59 Go to previous messageGo to next message
Murthy Bhat is currently offline Murthy Bhat
Messages: 159
Registered: July 2009
Senior Member
Hello Ken,

If i understand correctly, you were talking about implementing a drill down feature in GAPHITI. Actually, Even I am trying to implement such a feature, but currently I am unable to get it implemented.

It would be of great help if you could share your ideas about implementing the drilling down feature.

Thanks in advance for help.


Regards,
Murthy
Re: Share EditingDomain between multiple diagram editors [message #643575 is a reply to message #643242] Tue, 07 December 2010 09:00 Go to previous messageGo to next message
Ken Wenzel is currently offline Ken Wenzel
Messages: 39
Registered: July 2009
Member
Hello Murthy,

you are right, I've spoken about a drill down feature for Graphiti.

We've created our own drill down feature by using the code of
org.eclipse.graphiti.ui.features.AbstractDrillDownFeature as an example.

You first need a function that retrieves or creates (if not existent) a diagram object within the current resource set for the selected pictogram element (the one that should be drilled down).

	IFeatureProvider featureProvider;
	IPeService peService;

	public Collection<Diagram> getLinkedDiagrams(PictogramElement pe,
			boolean createOnDemand) {
		final Diagram currentDiagram = featureProvider.getDiagramTypeProvider()
				.getDiagram();
		final Collection<Diagram> diagrams = new HashSet<Diagram>();

		final Object[] businessObjectsForPictogramElement = featureProvider
				.getAllBusinessObjectsForPictogramElement(pe);
		String firstID = null;
		for (Object bo : businessObjectsForPictogramElement) {
			firstID = getIDOfBusinessObject(bo);
			if (firstID != null) break;
		}
		if (firstID != null) {
			String diagramId = "diagram_" + firstID;

			EObject linkedDiagram = null;
			for (TreeIterator<EObject> i = EcoreUtil.getAllProperContents(
					currentDiagram.eResource().getContents(), false); i
					.hasNext();) {
				EObject eObject = i.next();
				if (eObject instanceof Diagram) {
					if (diagramId.equals(((Diagram) eObject).getName())) {
						linkedDiagram = eObject;
						break;
					}
				}
			}

			if (!(linkedDiagram instanceof Diagram)) {
				if (createOnDemand) {
					Diagram newDiagram = peService.createDiagram(
							currentDiagram.getDiagramTypeId(), diagramId,
							currentDiagram.isSnapToGrid());
					currentDiagram.eResource().getContents().add(newDiagram);

					linkedDiagram = newDiagram;
				} else {
					return diagrams;
				}
			}

			if (!EcoreUtil.equals(currentDiagram, linkedDiagram)) {
				diagrams.add((Diagram) linkedDiagram);
			}
		}

		return diagrams;
	}


Then you can simply use this function within your custom feature.

	public void execute(ICustomContext context) {
		final PictogramElement pe = context.getPictogramElements()[0];
		final Collection<Diagram> possibleDiagramsList = getLinkedDiagrams(pe, true);

		if (!possibleDiagramsList.isEmpty()) {
			final Diagram[] possibleDiagrams = possibleDiagramsList
					.toArray(new Diagram[0]);
			if (possibleDiagramsList.size() == 1) {
				final Diagram diagram = possibleDiagrams[0];
				openDiagram(context, diagram);
			} else {
				ListDialog dialog = new ListDialog(PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getShell());
				dialog.setContentProvider(new IStructuredContentProvider() {

					@Override
					public void dispose() {
					}

					@Override
					public Object[] getElements(Object inputElement) {
						return possibleDiagramsList.toArray();
					}

					@Override
					public void inputChanged(Viewer viewer, Object oldInput,
							Object newInput) {
					}
				});
				dialog.setTitle("Choose Diagram");
				dialog.setMessage("Choose Diagram to open");
				dialog.setInitialSelections(new Diagram[] { possibleDiagrams[0] });
				dialog.setLabelProvider(new DiagramLabelProvider());
				dialog.setAddCancelButton(true);
				dialog.setHelpAvailable(false);
				dialog.setInput(new Object());
				dialog.open();
				Object[] result = dialog.getResult();
				if (result != null) {
					for (int i = 0; i < result.length; i++) {
						Diagram diagram = (Diagram) result[i];
						openDiagram(context, diagram);
					}
				}
			}
		}
	}

	protected void openDiagram(ICustomContext context, Diagram diagram) {
		openDiagramEditor(diagram,
				getDiagramEditor().getEditingDomain(),
				getFeatureProvider().getDiagramTypeProvider().getProviderId(),
				false);
	}


I hope this helps...

Good luck and best regards,

Ken
Re: Share EditingDomain between multiple diagram editors [message #643780 is a reply to message #643575] Wed, 08 December 2010 04:25 Go to previous messageGo to next message
Murthy Bhat is currently offline Murthy Bhat
Messages: 159
Registered: July 2009
Senior Member
Hey Ken,

Thanks a lot. It helped Smile

Regards,
Murthy
Re: Share EditingDomain between multiple diagram editors [message #650173 is a reply to message #565521] Sat, 22 January 2011 06:21 Go to previous messageGo to next message
Yann Armelin is currently offline Yann Armelin
Messages: 4
Registered: January 2011
Location: France
Junior Member
Hello,

Your drill down feature helped me too, thanks.

But I still have a problem with this line :
currentDiagram.eResource().getContents().add(newDiagram);
It breaks the behavior of the DiagramEditorMatchingStrategy.

Indeed, when you add newDiagram in eResource, the URI of currentDiagram changes from "[...].diagram#/" to "[...].diagram#/0".
After that, when a user double-clicks multiple times on the diagram file in the explorer, a new editor is open each time.

Do you have an idea to fix this problem ?


Thank you
Regard.
Re: Share EditingDomain between multiple diagram editors [message #650322 is a reply to message #650173] Mon, 24 January 2011 07:06 Go to previous message
Yann Armelin is currently offline Yann Armelin
Messages: 4
Registered: January 2011
Location: France
Junior Member
Yann Armelin wrote on Sat, 22 January 2011 12:21
Hello,

Your drill down feature helped me too, thanks.

But I still have a problem with this line :
currentDiagram.eResource().getContents().add(newDiagram);
It breaks the behavior of the DiagramEditorMatchingStrategy.

Indeed, when you add newDiagram in eResource, the URI of currentDiagram changes from "[...].diagram#/" to "[...].diagram#/0".
After that, when a user double-clicks multiple times on the diagram file in the explorer, a new editor is open each time.

Do you have an idea to fix this problem ?


Thank you
Regard.



Besides, there is the same problem in the TutorialAddEClassFeature class of the tutorial, with this line :
getDiagram().eResource().getContents().add(addedClass);
Previous Topic:DirectEditingFeature with white text
Next Topic:de-select a shape on double click
Goto Forum:
  


Current Time: Thu Aug 21 04:26:33 EDT 2014

Powered by FUDForum. Page generated in 0.01803 seconds