Skip to content
Snippets Groups Projects
Commit a47e1a9d authored by Daniel Ratiu's avatar Daniel Ratiu
Browse files

resolving this issue

refs 332
parent 159cc390
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,14 @@ package org.fortiss.tooling.base.ui.editor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.conqat.ide.commons.gef.editpart.EditPartUtils;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
......@@ -37,6 +42,7 @@ import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.SnapToGeometry;
import org.eclipse.gef.SnapToGrid;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.editparts.ZoomManager;
......@@ -59,6 +65,7 @@ import org.eclipse.jface.viewers.IPostSelectionProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
......@@ -70,6 +77,7 @@ import org.eclipse.ui.PartInitException;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import org.fortiss.tooling.base.ui.ToolingBaseUIActivator;
import org.fortiss.tooling.base.ui.dnd.ElementCompositionDropTargetListener;
import org.fortiss.tooling.base.ui.editpart.ConnectorEditPartBase;
import org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart;
import org.fortiss.tooling.base.ui.editpart.figure.EVisualStyle;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
......@@ -86,7 +94,7 @@ import org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 63FF468A2D042586A22495828A0798EF
* @ConQAT.Rating YELLOW Hash: 68835BEA73B1CA070BA7EAD5C14D8C00
*/
public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T>
implements IPostSelectionProvider, ContextMenuContextProvider {
......@@ -435,4 +443,77 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T>
public void setSelection(ISelection selection) {
viewer.setSelection(selection);
}
/** {@inheritDoc} */
@Override
public void setHighlight(EObject element, boolean highlighted) {
EditPart ep = findEditPart(viewer.getRootEditPart(), element);
if (ep instanceof AbstractGraphicalEditPart) {
IFigure fig = ((AbstractGraphicalEditPart) ep).getFigure();
setHighlight(fig, highlighted);
}
}
/**
* Highlights a figure by setting its color to be RED. This implementation
* can be changed by more specific editors.
*/
protected void setHighlight(IFigure fig, boolean highlighted) {
if (highlighted) {
highlightedFigures2NormalColor.put(fig, fig.getForegroundColor());
fig.setForegroundColor(ColorConstants.red);
} else {
Color normalColor = highlightedFigures2NormalColor.get(fig);
fig.setForegroundColor(normalColor);
highlightedFigures2NormalColor.remove(fig);
}
}
/**
* A map from figures that are currently highlighted to their normal
* foreground color.
*/
private HashMap<IFigure, Color> highlightedFigures2NormalColor = new HashMap<IFigure, Color>();
/**
* Returns the edit part corresponding to the EObject or null if it cannot
* be found.
*/
@SuppressWarnings("unchecked")
private EditPart findEditPart(EditPart container, EObject element) {
if (container.getModel().equals(element)) {
return container;
}
List<EditPart> subEditParts = new ArrayList<EditPart>();
if (container.getChildren() != null) {
subEditParts.addAll(container.getChildren());
}
if (container instanceof ConnectorEditPartBase) {
ConnectorEditPartBase<?> connector = (ConnectorEditPartBase<?>) container;
if (connector.getSourceConnections() != null) {
subEditParts.addAll(connector.getSourceConnections());
}
}
for (EditPart child : subEditParts) {
EditPart foundEditPart = findEditPart(child, element);
if (foundEditPart != null) {
return foundEditPart;
}
}
return null;
}
/** {@inheritDoc} */
@Override
public void clearAllHighlights() {
Set<IFigure> figs = new HashSet<IFigure>(
highlightedFigures2NormalColor.keySet());
for (IFigure figure : figs) {
setHighlight(figure, false);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment