|
|
|
Re: Share EditingDomain between multiple diagram editors [message #643575 is a reply to message #643242] |
Tue, 07 December 2010 14:00 |
Ken Wenzel Messages: 51 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 #650322 is a reply to message #650173] |
Mon, 24 January 2011 12:06 |
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);
|
|
|
Powered by
FUDForum. Page generated in 0.03317 seconds