Skip to content
Snippets Groups Projects
Commit 6af0ef1e authored by Johannes Eder's avatar Johannes Eder
Browse files

deletion of allocation connections

new factorised gef editor base class
refs 2446
parent 37cf9496
No related branches found
No related tags found
No related merge requests found
Showing
with 679 additions and 802 deletions
......@@ -17,46 +17,12 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_ENABLED;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_ORIGIN;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_SPACING;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_VISIBLE;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_X;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_Y;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE;
import static org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils.getFirstElement;
import java.util.ArrayList;
import java.util.List;
import org.conqat.ide.commons.ui.selection.SelectionUtils;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.SnapToGeometry;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.UpdateAction;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.IPostSelectionProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.ui.editpart.ExtendedLayerRootEditPart;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
import org.fortiss.tooling.kernel.ui.service.IActionService;
import org.fortiss.tooling.base.ui.editpart.allocation.AllocationConnectionEditPartBase;
import org.fortiss.tooling.kernel.ui.service.IAllocationEditPartFactoryService;
/**
......@@ -72,173 +38,17 @@ import org.fortiss.tooling.kernel.ui.service.IAllocationEditPartFactoryService;
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class AllocationDiagramEditorBase<T extends EObject> extends GEFEditorBase<T> implements
IPostSelectionProvider, ContextMenuContextProvider {
/** Actions which need update upon selection changes. */
private final List<String> selectionActions = new ArrayList<String>();
/** Stores the viewer. */
protected GraphicalViewer viewer = new ScrollingGraphicalViewer();
/** A container for editor actions. */
private final ActionRegistry actionRegistry = new ActionRegistry();
/** {@inheritDoc} */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
getSite().getWorkbenchWindow().getSelectionService()
.addSelectionListener(selectionListener);
// Install adapter to top-most object to watch for addition of IConnections.
// if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
// EObject model = getEditedObject();
// EObject obj = model;
// while(obj != null) {
// obj = obj.eContainer();
// }
//
// if(!model.eAdapters().contains(addConnectionAdapter)) {
// model.eAdapters().add(addConnectionAdapter);
// }
// }
viewer.setKeyHandler(new DiagramKeyHandler(viewer));
}
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
viewer.setRootEditPart(new ExtendedLayerRootEditPart());
viewer.createControl(parent);
getEditDomain().addViewer(viewer);
viewer.setEditPartFactory(IAllocationEditPartFactoryService.INSTANCE);
viewer.setContents(getViewerContentObject());
getSite().setSelectionProvider(this);
viewer.getControl().setBackground(parent.getBackground());
viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, true);
viewer.setProperty(PROPERTY_GRID_ORIGIN, new Point(DEFAULT_GRID_ORIGIN_X,
DEFAULT_GRID_ORIGIN_Y));
Dimension gridSpacing = new Dimension(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
viewer.setProperty(PROPERTY_GRID_SPACING, gridSpacing);
viewer.setProperty(PROPERTY_GRID_ENABLED, true);
viewer.setProperty(PROPERTY_GRID_VISIBLE, true);
}
/** Selection listener used to update selection actions. */
private final ISelectionListener selectionListener = new ISelectionListener() {
/** {@inheritDoc} */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
EditPart ep = SelectionUtils.checkAndPickFirstSafe(selection, EditPart.class);
if(ep != null) {
Control control = ep.getViewer().getControl();
Object model = ep.getModel();
String hint = "";
// if(numberOfConnectionsToBeCreatedUntilCreationHintIsHidden > 0) {
// if(model instanceof IConnector) {
// hint =
// "Link two connectors by pressing ALT and dragging from source to target.";
// } else
if(model instanceof IHierarchicElement) {
hint = "Create a connection by pressing ALT and dragging.";
public class AllocationDiagramEditorBase<T extends EObject> extends CommonDiagramEditorBase<T> {
/** Constructor. */
public AllocationDiagramEditorBase() {
super(new ScrollingGraphicalViewer() {
@Override
public void select(EditPart editpart) {
if(editpart instanceof AllocationConnectionEditPartBase<?>) {
super.select(editpart);
}
// }
control.setToolTipText(hint);
}
updateActions(selectionActions);
}
};
/** Updates a list of actions. */
@SuppressWarnings({"rawtypes", "unchecked"})
private void updateActions(List<String> actionIds) {
EObject element = getSelectedModelElement();
for(String id : actionIds) {
IAction action = actionRegistry.getAction(id);
if(action instanceof UpdateAction) {
((UpdateAction)action).update();
} else if(action instanceof EObjectActionBase) {
((EObjectActionBase)action).refresh(element);
}
}
IActionService.INSTANCE.refresh();
}, IAllocationEditPartFactoryService.INSTANCE);
}
/**
* Returns the root object used as content root. Sub-classes may override to
* provide a different content root object. The default implementation uses
* {@link GEFEditorBase#getEditedObject()}
*/
protected Object getViewerContentObject() {
return getEditedObject();
}
/** {@inheritDoc} */
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
// TODO Auto-generated method stub
}
/** {@inheritDoc} */
@Override
public ISelection getSelection() {
return viewer.getSelection();
}
/** {@inheritDoc} */
@Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
// TODO Auto-generated method stub
}
/** {@inheritDoc} */
@Override
public void setSelection(ISelection selection) {
// TODO Auto-generated method stub
}
/** {@inheritDoc} */
@Override
public EObject getSelectedModelElement() {
if(getSite().getSelectionProvider() != null) {
return getFirstElement(getSite().getSelectionProvider().getSelection());
}
return null;
}
/** {@inheritDoc} */
@Override
public List<EObject> getSelectedModelElementList() {
// TODO Auto-generated method stub
return null;
}
/** {@inheritDoc} */
@Override
public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
// TODO Auto-generated method stub
}
/** {@inheritDoc} */
@Override
public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
// TODO Auto-generated method stub
}
}
......@@ -91,7 +91,7 @@ public abstract class AllocationDiagramEditPartBase<T extends EObject> extends
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
// nothing to do
// do nothing
}
/** {@inheritDoc} */
......
......@@ -224,7 +224,9 @@ public abstract class AllocationElementEditPartBase<T extends ILayoutedModelElem
req.getExtendedData().put(parent, elements);
parent.performRequest(req);
}
if(req.getType() == RequestConstants.REQ_SELECTION) {
System.out.println("Selected: " + getModel().getName());
}
}
/** Returns the sub elements of T if existing. */
......
......@@ -55,4 +55,9 @@ public abstract class AllocationFreeConnectorEditPartBase<T extends ILayoutedMod
baseBounds.y, textBounds.width, baseBounds.height);
}
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
// do nothing since ports must not be removed in the allocation editor
}
}
......@@ -54,4 +54,9 @@ public abstract class AllocationStickyConnectorEditPartBase<T extends ILayoutedM
baseBounds.y, textBounds.width, baseBounds.height);
}
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
// do nothing since ports must not be removed in the allocation editor
}
}
......@@ -233,7 +233,7 @@ public abstract class AllocationSubDiagramEditPartBase<T extends INamedCommented
/** {@inheritDoc} */
@Override
protected void createEditPolicies() {
// nothing to do
// installEditPolicy(COMPONENT_ROLE, new RemoveEditPolicy());
}
/** Returns the foreground color used. */
......
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