Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #248 from eclipse/erwin/ft/160/editor-outline-sele…
Browse files Browse the repository at this point in the history
…ction-synch

#160 : guideline 6.21 outline/editor selection linking
  • Loading branch information
erwindl0 authored Jun 16, 2017
2 parents 2e2d314 + 92b277c commit e5f3d8a
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.ui.util.EditUIUtil;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.ui.parts.SelectionSynchronizer;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
Expand All @@ -28,6 +29,7 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.triquetrum.workflow.editor.outline.DiagramEditorOutlinePage;
import org.eclipse.triquetrum.workflow.editor.views.TriqSelectionSynchronizer;
import org.eclipse.triquetrum.workflow.model.NamedObj;
import org.eclipse.triquetrum.workflow.model.util.PtObjectBuilderVisitor;
import org.eclipse.triquetrum.workflow.model.util.PtObjectLinkerVisitor;
Expand All @@ -41,6 +43,7 @@
public class TriqDiagramEditor extends DiagramEditor {
public final static String EDITOR_ID = "org.eclipse.triquetrum.workflow.editor.TriqDiagramEditor";
public final static String DIAGRAM_FILE_EXTENSION = "tdml";
private SelectionSynchronizer synchronizer;

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
Expand Down Expand Up @@ -178,4 +181,13 @@ public void setFocus() {
public CommandStack getCommandStack() {
return super.getCommandStack();
}

@Override
protected SelectionSynchronizer getSelectionSynchronizer() {
if (synchronizer == null) {
synchronizer = new TriqSelectionSynchronizer();
}
return synchronizer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.styles.LineStyle;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.tb.ContextButtonEntry;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
import org.eclipse.graphiti.tb.IContextButtonPadData;
import org.eclipse.graphiti.tb.IShapeSelectionInfo;
import org.eclipse.graphiti.tb.ShapeSelectionInfoImpl;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.triquetrum.workflow.editor.features.ModelElementConfigureFeature;
import org.eclipse.triquetrum.workflow.editor.features.PauseFeature;
import org.eclipse.triquetrum.workflow.editor.features.ResumeFeature;
Expand Down Expand Up @@ -169,6 +174,14 @@ public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
}
return super.getSelectionBorder(pe);
}

public IShapeSelectionInfo getSelectionInfoForShape(Shape shape) {
IShapeSelectionInfo si = new ShapeSelectionInfoImpl();
si.setColor(IColorConstant.BLUE);
si.setLineStyle(LineStyle.DASH);
return si;
}


@Override
public boolean isShowFlyoutPalette() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.triquetrum.workflow.editor.ImageConstants;
import org.eclipse.triquetrum.workflow.editor.TriqDiagramTypeProvider;
import org.eclipse.triquetrum.workflow.editor.outline.tree.OutlinePartFactory;
import org.eclipse.triquetrum.workflow.editor.outline.tree.TriqOutlineTreeViewer;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.actions.ActionFactory;
Expand Down Expand Up @@ -98,7 +99,7 @@ public class DiagramEditorOutlinePage extends ContentOutlinePage implements IPro
* @since 0.9
*/
public DiagramEditorOutlinePage(IDiagramContainerUI diagramEditor) {
super(new TreeViewer());
super(new TriqOutlineTreeViewer(diagramEditor));
_graphicalViewer = diagramEditor.getGraphicalViewer();
_actionRegistry = diagramEditor.getAdapter(ActionRegistry.class);
_editDomain = diagramEditor.getEditDomain();
Expand Down
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.LinkedList;
import java.util.List;

import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.PlatformGraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.styles.Color;
Expand Down Expand Up @@ -41,6 +40,7 @@
import org.eclipse.triquetrum.workflow.model.Relation;
import org.eclipse.triquetrum.workflow.model.TriqFactory;
import org.eclipse.triquetrum.workflow.model.util.PtObjectBuilderAndApplierVisitor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;

Expand Down Expand Up @@ -100,7 +100,7 @@ public static int[] setExpanded(PictogramElement pe) {
Graphiti.getPeService().setPropertyValue(pe, "isCollapsed", "false");
return new int[] { originalWidth, originalHeight };
} else {
return new int[] {pe.getGraphicsAlgorithm().getWidth(), pe.getGraphicsAlgorithm().getHeight()};
return new int[] { pe.getGraphicsAlgorithm().getWidth(), pe.getGraphicsAlgorithm().getHeight() };
}
}

Expand Down Expand Up @@ -218,10 +218,15 @@ public static TriqDiagramEditor getSelectedDiagramEditor() {
TriqDiagramEditor result = null;
IWorkbenchPage page = EclipseUtils.getPage();
if (page != null) {
for (IEditorReference editorRef : page.getEditorReferences()) {
if (editorRef.getId().contains("triquetrum")) {
result = ((TriqDiagramEditor) editorRef.getEditor(true));
break;
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor instanceof TriqDiagramEditor) {
result = (TriqDiagramEditor) activeEditor;
} else {
for (IEditorReference editorRef : page.getEditorReferences()) {
if (editorRef.getId().contains("triquetrum")) {
result = ((TriqDiagramEditor) editorRef.getEditor(true));
break;
}
}
}
}
Expand Down Expand Up @@ -278,14 +283,19 @@ public static CompositeActor getSelectedModel() {
*/
public static NamedObj getModelObjectForSelection(Object editPart) {
NamedObj result = null;
PictogramElement pe = (editPart instanceof PictogramElement) ? (PictogramElement) editPart : null;
if (editPart instanceof GraphitiShapeEditPart) {
GraphitiShapeEditPart shapeEditPart = (GraphitiShapeEditPart) editPart;
IFeatureProvider fp = shapeEditPart.getFeatureProvider();
Object bo = fp.getBusinessObjectForPictogramElement(shapeEditPart.getPictogramElement());
pe = shapeEditPart.getPictogramElement();
}

if (pe != null) {
Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
if (bo instanceof NamedObj) {
result = (NamedObj) bo;
}
}

return result;
}

Expand Down Expand Up @@ -459,9 +469,8 @@ public static boolean containsExternallyDefinedFigure(PictogramElement pe) {
}

/**
* Returns a freshly created list of the port anchors for the given actor shape (or composite actor shape)
* that are in the given category. The list can be manipulated/changed without risk of impacting
* the original actorShape definition (at least when the contained anchors properties are not touched!).
* Returns a freshly created list of the port anchors for the given actor shape (or composite actor shape) that are in the given category. The list can be
* manipulated/changed without risk of impacting the original actorShape definition (at least when the contained anchors properties are not touched!).
*
* @param actorShape
* @param portIoType
Expand All @@ -479,7 +488,7 @@ public static List<Anchor> getContainedPorts(ContainerShape actorShape, PortCate
}
return portShapes;
}

/**
*
* @param source
Expand All @@ -504,14 +513,15 @@ public static Relation createRelation(NamedObj source, NamedObj target, IORelati
relation = TriqFactory.eINSTANCE.createRelation();
CompositeActor relationContainer = null;
NamedObj potentialRelationContainer = source.getLowestCommonContainer(target);
if(potentialRelationContainer instanceof CompositeActor) {
if (potentialRelationContainer instanceof CompositeActor) {
relationContainer = (CompositeActor) potentialRelationContainer;
} else {
// this should only happen when connecting an output port and an input port of the same atomic actor
if (potentialRelationContainer.getContainer() instanceof CompositeActor) {
relationContainer = (CompositeActor) potentialRelationContainer.getContainer();
} else {
throw new IllegalActionException(source.getWrappedObject(), target.getWrappedObject(), "Unsupported source and target hierarchy for creating a relation");
throw new IllegalActionException(source.getWrappedObject(), target.getWrappedObject(),
"Unsupported source and target hierarchy for creating a relation");
}
}

Expand Down
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);
}
}

0 comments on commit e5f3d8a

Please sign in to comment.