Skip to content
Snippets Groups Projects
Commit 398e2513 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

refactoring of connection compositor service

channel creation works on the model level, but not yet on the UI level
parent 629c6d13
No related branches found
No related tags found
No related merge requests found
Showing
with 116 additions and 68 deletions
......@@ -12,6 +12,7 @@ Bundle-Vendor: fortiss
Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.action,
org.fortiss.tooling.base.ui.command,
org.fortiss.tooling.base.ui.compose,
org.fortiss.tooling.base.ui.dnd,
org.fortiss.tooling.base.ui.editor,
org.fortiss.tooling.base.ui.editor.gef,
......@@ -22,4 +23,5 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.editpart.policy,
org.fortiss.tooling.base.ui.layout,
org.fortiss.tooling.base.ui.layout.constants,
org.fortiss.tooling.base.ui.layout.util
org.fortiss.tooling.base.ui.layout.util,
org.fortiss.tooling.base.ui.preferences
......@@ -23,7 +23,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.fortiss.tooling.base.ui.dnd.DragContext;
import org.fortiss.tooling.base.ui.editpart.policy.ConnectionGraphicalNodeEditPolicy;
import org.fortiss.tooling.kernel.services.IConnectorService;
import org.fortiss.tooling.kernel.services.IConnectionCompositorService;
/**
* This command is used by {@link ConnectionGraphicalNodeEditPolicy} to
......@@ -62,7 +62,7 @@ public class ConnectionCommand extends Command {
}
if (context.getSource().getModel() instanceof EObject
&& context.getTarget().getModel() instanceof EObject) {
return IConnectorService.INSTANCE.canConnect((EObject) context
return IConnectionCompositorService.INSTANCE.canConnect((EObject) context
.getSource().getModel(), (EObject) context.getTarget()
.getModel(), connection, context);
}
......@@ -72,7 +72,7 @@ public class ConnectionCommand extends Command {
/** {@inheritDoc} */
@Override
public void execute() {
IConnectorService.INSTANCE.connect((EObject) context.getSource()
IConnectionCompositorService.INSTANCE.connect((EObject) context.getSource()
.getModel(), (EObject) context.getTarget().getModel(),
connection, context);
}
......
......@@ -25,7 +25,7 @@ import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.ui.dnd.DragContext;
import org.fortiss.tooling.base.ui.dnd.DropContext;
import org.fortiss.tooling.base.ui.editpart.RootEditPartBase;
import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
import org.fortiss.tooling.kernel.interfaces.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.services.ICompositorService;
/**
......@@ -36,13 +36,13 @@ import org.fortiss.tooling.kernel.services.ICompositorService;
* Sub-classes must implement:
* <UL>
* <LI>
* {@link #createConnection(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* {@link #createConnection(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)}
* <LI>
* {@link #createSourceConnector(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* {@link #createSourceConnector(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)}
* <LI>
* {@link #createTargetConnector(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* {@link #createTargetConnector(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)}
* <LI>
* {@link #getParent(IHierarchicElement, IHierarchicElement, IConnectionContext)}
* {@link #getParent(IHierarchicElement, IHierarchicElement, IConnectionCompositionContext)}
* </UL>
* These methods are called in order to create specific model elements.
*
......@@ -57,7 +57,7 @@ import org.fortiss.tooling.kernel.services.ICompositorService;
* @ConQAT.Rating RED Hash:
*/
public abstract class HierarchicElementConnectionCompositorBase<HE extends IHierarchicElement, S extends IHierarchicElement, T extends IHierarchicElement>
implements org.fortiss.tooling.kernel.interfaces.IConnector<S, T> {
implements org.fortiss.tooling.kernel.interfaces.IConnectionCompositor<S, T> {
/**
* Determines whether connectors of the component may be connected
......@@ -69,28 +69,28 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier
/** Creates the application specific {@link IConnection} model element. */
protected abstract IConnection createConnection(S source, T target,
IConnectionContext context);
IConnectionCompositionContext context);
/**
* Creates the application specific source {@link IConnector} model element.
*/
protected abstract IConnector createSourceConnector(S source, T target,
IConnectionContext context);
IConnectionCompositionContext context);
/**
* Creates the application specific target {@link IConnector} model element.
*/
protected abstract IConnector createTargetConnector(S source, T target,
IConnectionContext context);
IConnectionCompositionContext context);
/** Returns the parent model element used to compose the connection. */
protected abstract HE getParent(S source, T target,
IConnectionContext context);
IConnectionCompositionContext context);
/** {@inheritDoc} */
@Override
public boolean canConnect(S source, T target, EObject connection,
IConnectionContext context) {
IConnectionCompositionContext context) {
if (context instanceof DragContext) {
DragContext dc = (DragContext) context;
// Is an internal feedback connection allowed?
......@@ -106,7 +106,7 @@ public abstract class HierarchicElementConnectionCompositorBase<HE extends IHier
/** {@inheritDoc} */
@Override
public void connect(S source, T target, EObject conn,
IConnectionContext context) {
IConnectionCompositionContext context) {
// create application specific connection
IConnection connection = createConnection(source, target, context);
......
......@@ -19,7 +19,7 @@ package org.fortiss.tooling.base.ui.dnd;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
import org.fortiss.tooling.kernel.interfaces.IConnectionCompositionContext;
/**
* A {@link DragContext} stores information obtained from user's drag gesture,
......@@ -31,7 +31,7 @@ import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 61FB58030A2C456B296353EEC89181DD
*/
public class DragContext implements IConnectionContext {
public class DragContext implements IConnectionCompositionContext {
/** Source edit part. */
private final EditPart source;
......
......@@ -250,11 +250,13 @@ public class GraphicalViewerEditorBase<T extends EObject> extends EditorBase<T>
ZoomManager.FIT_HEIGHT });
/** Registers global actions (including zoom action). */
@Override
public void registerGlobalActions(IActionBars bars) {
bars.getToolBarManager().add(zoomContribution);
}
/** Unregisters global actions (including zoom action). */
@Override
public void unregisterGlobalActions(IActionBars bars) {
bars.getToolBarManager().remove(zoomContribution);
}
......
......@@ -3,10 +3,10 @@
<plugin>
<extension-point id="modelPrototypeProvider" name="Model Prototype Provider" schema="schema/modelPrototypeProvider.exsd"/>
<extension-point id="modelElementCompositor" name="Model Element Compositor" schema="schema/modelElementCompositor.exsd"/>
<extension-point id="modelElementConnector" name="Model Element Connector" schema="schema/modelElementConnector.exsd"/>
<extension-point id="modelStorageProvider" name="Model Storage Provider" schema="schema/modelStorageProvider.exsd"/>
<extension-point id="modelConstraintChecker" name="Model Constraint Checker" schema="schema/modelConstraintChecker.exsd"/>
<extension-point id="eclipseResourceStorageLocationProvider" name="Eclipse Resource Storage Location Provider" schema="schema/eclipseResourceStorageLocationProvider.exsd"/>
<extension-point id="modelElementConnectionCompositor" name="Model Element Connection Compositor" schema="schema/modelElementConnectionCompositor.exsd"/>
<extension
point="org.eclipse.emf.ecore.generated_package">
<package
......
......@@ -20,7 +20,7 @@
</annotation>
<complexType>
<sequence>
<element ref="connector" minOccurs="1" maxOccurs="unbounded"/>
<element ref="modelElementConnectionCompositor" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
......@@ -49,13 +49,13 @@
</complexType>
</element>
<element name="connector">
<element name="modelElementConnectionCompositor">
<complexType>
<sequence>
<element ref="source" minOccurs="1" maxOccurs="unbounded"/>
<element ref="target" minOccurs="1" maxOccurs="unbounded"/>
<element ref="source"/>
<element ref="target"/>
</sequence>
<attribute name="connector" type="string" use="required">
<attribute name="modelElementConnectionCompositor" type="string" use="required">
<annotation>
<documentation>
The connector class registered.
......
......@@ -28,13 +28,39 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.interfaces.IEObjectAware2;
import org.fortiss.tooling.kernel.internal.ConnectionCompositorService;
import org.fortiss.tooling.kernel.util.ExtensionPointUtils;
import org.fortiss.tooling.kernel.util.LoggingUtils;
import org.osgi.framework.Bundle;
/**
* Service base implementation, which supports handler registration with two
* related {@link EObject} classes.
* Service base implementation, which supports handler registration with a set
* of source and a set of target classes.
*
* <p>
* Sub-classes must implement:
* <UL>
* <LI>{@link #getExtensionPointName()} to provide the extension point ID,
* <LI>{@link #getConfigurationElementName()} to provide the configuration
* element ID,
* <LI>{@link #getHandlerClassAttribute()} to provide the attribute of the
* handler class.
* </UL>
*
* <p>
* Sub-classes may override:
* <UL>
* <LI>{@link #getSourceAttribute()} to provide a source attribute ID,
* <LI>{@link #getTargetAttribute()} to provide a target attribute ID,
* <LI>{@link #getModelElementClassConfigurationElement()} to provide a element
* class configuration element,
* <LI>{@link #getModelElementClassAttribute()} to provide a element class
* attribute.
* </UL>
*
* An example implementation of a service based on this class is given by
* {@link ConnectionCompositorService}. The corresponding extension point schema
* is defined in <code>schema/modelElementConnectionCompositor.exsd</code>.
*
* @author hoelzlf
* @author $Author$
......@@ -81,6 +107,15 @@ public abstract class EObjectAware2ServiceBase<T extends IEObjectAware2<? extend
return "target";
}
/**
* Returns the configuration element name for the model element class.
* Sub-classes may override, but should first consider to use the default
* value <i>modelElementClass</i> in the extension point definition.
*/
protected String getModelElementClassConfigurationElement() {
return "modelElementClass";
}
/**
* Returns the attribute name for the model element class. Sub-classes may
* override, but should first consider to use the default value
......@@ -138,25 +173,33 @@ public abstract class EObjectAware2ServiceBase<T extends IEObjectAware2<? extend
List<Class<?>> sources = new ArrayList<Class<?>>();
List<Class<?>> targets = new ArrayList<Class<?>>();
for (final IConfigurationElement child : ce.getChildren()) {
for (IConfigurationElement child : ce.getChildren()) {
if (child.getName().equals(getSourceAttribute())) {
sources.add(ExtensionPointUtils.loadClass(
child.getAttribute(getModelElementClassAttribute()),
bundle));
addRegisteredClasses(child, sources, bundle);
} else if (child.getName().equals(getTargetAttribute())) {
targets.add(ExtensionPointUtils.loadClass(
child.getAttribute(getModelElementClassAttribute()),
bundle));
addRegisteredClasses(child, targets, bundle);
}
}
for (final Class<?> source : sources) {
for (final Class<?> destination : targets) {
addHandler(source, destination, handler);
for (Class<?> source : sources) {
for (Class<?> target : targets) {
addHandler(source, target, handler);
}
}
}
/** Adds all registered classes to the given list. */
private void addRegisteredClasses(IConfigurationElement element,
List<Class<? extends Object>> list, Bundle bundle)
throws ClassNotFoundException {
for (IConfigurationElement ce : element
.getChildren(getModelElementClassConfigurationElement())) {
Class<?> modelElementClass = ExtensionPointUtils.loadClass(
ce.getAttribute(getModelElementClassAttribute()), bundle);
list.add(modelElementClass);
}
}
/** Adds the given handler to the map. */
private void addHandler(Class<?> sourceElementClass,
Class<?> targetElementClass, T handler) {
......
......@@ -19,8 +19,8 @@ $Id$
package org.fortiss.tooling.kernel.interfaces;
/**
* An {@link IConnectionContext} provides additional information like drag point
* positions to an {@link IConnector}.
* An {@link IConnectionCompositionContext} provides additional information like drag point
* positions to an {@link IConnectionCompositor}.
*
* @FloH: what is a "drag point position"?
*
......@@ -29,6 +29,6 @@ package org.fortiss.tooling.kernel.interfaces;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BE7A6E2BC307F4A6894607896C09D3E8
*/
public interface IConnectionContext {
public interface IConnectionCompositionContext {
// this is just a marker interface
}
......@@ -30,7 +30,7 @@ import org.eclipse.emf.ecore.EObject;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 3AF8EF4B6F61B768A17A63A6FF51CB2B
*/
public interface IConnector<S extends EObject, T extends EObject> extends
public interface IConnectionCompositor<S extends EObject, T extends EObject> extends
IEObjectAware2<S, T> {
/**
* Returns whether a connection between the source and the destination is
......@@ -39,12 +39,12 @@ public interface IConnector<S extends EObject, T extends EObject> extends
* in case of a reconnect.
*/
boolean canConnect(S source, T destination, EObject connection,
IConnectionContext context);
IConnectionCompositionContext context);
/**
* Actually connects the given source and destination. This will only be
* called if
* {@link #canConnect(EObject, EObject, EObject, IConnectionContext)}
* {@link #canConnect(EObject, EObject, EObject, IConnectionCompositionContext)}
* returned true.
*
* @param source
......@@ -60,5 +60,5 @@ public interface IConnector<S extends EObject, T extends EObject> extends
* context information for the connection. May be null.
*/
void connect(S source, T destination, EObject connection,
IConnectionContext context);
IConnectionCompositionContext context);
}
......@@ -21,58 +21,59 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.base.EObjectAware2ServiceBase;
import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
import org.fortiss.tooling.kernel.interfaces.IConnector;
import org.fortiss.tooling.kernel.services.IConnectorService;
import org.fortiss.tooling.kernel.interfaces.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.interfaces.IConnectionCompositor;
import org.fortiss.tooling.kernel.services.IConnectionCompositorService;
/**
* This class implements the {@link IConnectorService} interface.
* This class implements the {@link IConnectionCompositorService} interface.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: E4E7A3B42928271F17D36BABCB6BEF58
*/
public class ConnectorService extends
EObjectAware2ServiceBase<IConnector<EObject, EObject>> implements
IConnectorService {
public class ConnectionCompositorService extends
EObjectAware2ServiceBase<IConnectionCompositor<EObject, EObject>>
implements IConnectionCompositorService {
/** The connector extension point ID. */
private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementConnector";
private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementConnectionCompositor";
/** The connector configuration element name. */
private static final String CONFIGURATION_ELEMENT_NAME = "modelElementConnector";
private static final String CONFIGURATION_ELEMENT_NAME = "modelElementConnectionCompositor";
/** The connector attribute name. */
private static final String ATTRIBUTE_NAME = "connector";
private static final String ATTRIBUTE_NAME = "modelElementConnectionCompositor";
/** {@inheritDoc} */
@Override
public boolean canConnect(EObject source, EObject destination,
EObject connection, IConnectionContext context) {
EObject connection, IConnectionCompositionContext context) {
return findWorkingConnector(source, destination, connection, context) != null;
}
/** {@inheritDoc} */
@Override
public void connect(EObject source, EObject destination,
EObject connection, IConnectionContext context) {
EObject connection, IConnectionCompositionContext context) {
findWorkingConnector(source, destination, connection, context).connect(
source, destination, connection, context);
}
/**
* Returns the first {@link IConnector} which can connect the given elements
* (or <code>null</code>n if no such connector exists).
* Returns the first {@link IConnectionCompositor} which can connect the
* given elements (or <code>null</code>n if no such connector exists).
*/
private IConnector<EObject, EObject> findWorkingConnector(EObject source,
EObject target, EObject connection, IConnectionContext context) {
List<IConnector<EObject, EObject>> list = getRegisteredHandlers(
private IConnectionCompositor<EObject, EObject> findWorkingConnector(
EObject source, EObject target, EObject connection,
IConnectionCompositionContext context) {
List<IConnectionCompositor<EObject, EObject>> list = getRegisteredHandlers(
source.getClass(), target.getClass());
if (list == null) {
return null;
}
for (IConnector<EObject, EObject> connector : list) {
for (IConnectionCompositor<EObject, EObject> connector : list) {
if (connector.canConnect(source, target, connection, context)) {
return connector;
}
......
......@@ -18,8 +18,8 @@ $Id$
package org.fortiss.tooling.kernel.services;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.interfaces.IConnectionContext;
import org.fortiss.tooling.kernel.internal.ConnectorService;
import org.fortiss.tooling.kernel.interfaces.IConnectionCompositionContext;
import org.fortiss.tooling.kernel.internal.ConnectionCompositorService;
/**
* The connector service provides registration and access to model element
......@@ -30,10 +30,10 @@ import org.fortiss.tooling.kernel.internal.ConnectorService;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 0D2545C48EFB0383922CBB05BB469585
*/
public interface IConnectorService {
public interface IConnectionCompositorService {
/** Returns the singleton instance of the service. */
public static final IConnectorService INSTANCE = new ConnectorService();
public static final IConnectionCompositorService INSTANCE = new ConnectionCompositorService();
/**
* Returns whether a connection between the source and the destination is
......@@ -41,12 +41,12 @@ public interface IConnectorService {
* also may be null.
*/
public boolean canConnect(EObject source, EObject destination,
EObject connection, IConnectionContext context);
EObject connection, IConnectionCompositionContext context);
/**
* Actually connects the given source and destination. This will only be
* called if
* {@link #canConnect(EObject, EObject, EObject, IConnectionContext)}
* {@link #canConnect(EObject, EObject, EObject, IConnectionCompositionContext)}
* returned true.
*
* @param source
......@@ -62,5 +62,5 @@ public interface IConnectorService {
* context information for the connection. May be null.
*/
public void connect(EObject source, EObject destination,
EObject connection, IConnectionContext context);
EObject connection, IConnectionCompositionContext context);
}
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