This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from eclipse/erwin/ft/160/editor-outline-sele…
…ction-synch #160 : guideline 6.21 outline/editor selection linking
- Loading branch information
Showing
6 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../main/java/org/eclipse/triquetrum/workflow/editor/outline/tree/TriqOutlineTreeViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 iSencia Belgium NV. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Erwin De Ley - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.triquetrum.workflow.editor.outline.tree; | ||
|
||
import org.eclipse.emf.transaction.util.Adaptable; | ||
import org.eclipse.gef.EditPart; | ||
import org.eclipse.gef.ui.parts.TreeViewer; | ||
import org.eclipse.graphiti.ui.editor.IDiagramContainerUI; | ||
import org.eclipse.triquetrum.workflow.editor.util.EditorUtils; | ||
|
||
public class TriqOutlineTreeViewer extends TreeViewer implements Adaptable { | ||
|
||
private IDiagramContainerUI diagramContainer; | ||
|
||
public TriqOutlineTreeViewer(IDiagramContainerUI diagramContainer) { | ||
this.diagramContainer = diagramContainer; | ||
} | ||
|
||
@Override | ||
public Object getAdapter(Class adapterType) { | ||
if (adapterType == IDiagramContainerUI.class) | ||
return diagramContainer; | ||
else if (diagramContainer != null) | ||
return diagramContainer.getAdapter(adapterType); | ||
return null; | ||
} | ||
|
||
public EditPart convert(EditPart part) { | ||
Object result = EditorUtils.getModelObjectForSelection(part.getModel()); | ||
if (result != null) { | ||
return (EditPart) getEditPartRegistry().get(result); | ||
} else { | ||
return part; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...src/main/java/org/eclipse/triquetrum/workflow/editor/views/TriqSelectionSynchronizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 iSencia Belgium NV. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Erwin De Ley - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package org.eclipse.triquetrum.workflow.editor.views; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.gef.EditPart; | ||
import org.eclipse.gef.EditPartViewer; | ||
import org.eclipse.gef.GraphicalViewer; | ||
import org.eclipse.gef.ui.parts.SelectionSynchronizer; | ||
import org.eclipse.graphiti.mm.pictograms.ContainerShape; | ||
import org.eclipse.graphiti.mm.pictograms.PictogramElement; | ||
import org.eclipse.graphiti.services.Graphiti; | ||
import org.eclipse.triquetrum.workflow.editor.outline.tree.OutlineEditPart; | ||
import org.eclipse.triquetrum.workflow.editor.outline.tree.TriqOutlineTreeViewer; | ||
import org.eclipse.triquetrum.workflow.editor.util.EditorUtils; | ||
import org.eclipse.triquetrum.workflow.model.NamedObj; | ||
|
||
/** | ||
* This is used as a selection broker between views combined with converting | ||
* selected elements between the different types of parts/widgets/... as used | ||
* in the involved views. | ||
* | ||
*/ | ||
public class TriqSelectionSynchronizer extends SelectionSynchronizer { | ||
|
||
@Override | ||
protected EditPart convert(EditPartViewer viewer, EditPart part) { | ||
if(viewer instanceof TriqOutlineTreeViewer) { | ||
// This is for when the user selects an element in the graphical editor, | ||
// to make sure the outline tree view reflects the same selection. | ||
return ((TriqOutlineTreeViewer)viewer).convert(part); | ||
} else if (viewer instanceof GraphicalViewer && part instanceof OutlineEditPart) { | ||
// This is for when the user selects an element in the outline tree view, | ||
// and we want to select the corresponding shape in the graphical editor. | ||
Object selectedBO = part.getModel(); | ||
NamedObj modelElement = null; | ||
if(selectedBO instanceof NamedObj) { | ||
// We want to select a top-level entity or parameter in the diagram, | ||
// even when the user clicks on an actor port or parameter in the outline tree view. | ||
// So we move up the containment tree a bit, until we reach the right level. | ||
modelElement = (NamedObj) selectedBO; | ||
while (modelElement.getContainer() != modelElement.topLevel()) { | ||
modelElement = modelElement.getContainer(); | ||
} | ||
} | ||
List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(EditorUtils.getSelectedDiagram(), modelElement); | ||
PictogramElement pe = null; | ||
for (PictogramElement pictogramElement : pes) { | ||
if(pictogramElement instanceof ContainerShape) { | ||
pe = pictogramElement; | ||
break; | ||
} | ||
} | ||
return (EditPart) viewer.getEditPartRegistry().get(pe); | ||
} | ||
return super.convert(viewer, part); | ||
} | ||
} |