Home » Eclipse Projects » GEF » EDiagram changes on 10-May-2005
| |
Re: EDiagram changes on 10-May-2005 [message #182735 is a reply to message #182701] |
Thu, 26 May 2005 19:52 |
Ed Willink Messages: 7680 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------030307030402090302050600
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi Pratik
I found that it took only a very little change to EDiagramEditor to make the
pre 10-May-2005 code work with M6; mostly just losing the ...properties.emf
variants that seem to have made into GEF core. This holds up under M7.
If I do the Providers, I will want to keep them extensible, so I would seek
to eliminate the PropertySourceFactory so that instanceof polling is replaced
by something like
public Object getAdapter(Class key) {
if (IPropertySource.class == key) {
IRegime regime = Regimen.getRegime(getDiagram().getClass(), getModel().getClass());
return regime.getPropertySource(getModel());
}
return super.getAdapter(key);
}
to get the diagram-class-dependent policy for the model-class.
It is then possible to extend by registering another IRegime derivation
with Regimen via an extension point. (Mostly-working example sources attached
demnonstrating how Palette, EditPart, Command and Link/Node creation are
all localised; TreeEditPart still to be done.).
- UmlcDiagram is not intentionally different from EDiagram, just a more
consistent name when needing distinct 'UML' Class/Package/Transformation diagrams
- DiagramElement is a common base for Diagram, Link, Node
Regards
Ed Willink
Pratik Shah wrote:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=84910
>
> We intend to move away from using the EMF providers as property sources.
> That release was the first step towards that. I still need to write the
> property sources for ECore classes. That'll be updated soon. (If you want
> to help out with these, that would be great!) I released the changes w/o
> having completed the new property sources because the code in the repository
> was not compiling against the latest GEF builds. Until all the new code is
> in, you can still use the old properties by checking out the "oldProperties"
> version of the ediagram example. I think the latest milestone build that
> that compiled against was M5.
>
> "Ed Willink" <ed@willink.me.uk> wrote in message
> news:d73puj$unm$1@news.eclipse.org...
>
>>Hi Pratik
>>
>>You committed a number of updates to EDiagram on 10-May,
>>which seem to remove previously useful functionality.
>>
>>The introduction of the ...properties.emf classes and elimination
>>of the use of the EMF Providers seem to be part of a more
>>consistent OutlinePage integration and to eliminate the clutter
>>from derived properties. But, only graphical properties are
>>now shown so useful properties such as names, or reference
>>attributes cannot be edited (Editing names by direct editing
>>is awkward since the direct editor doesn't often activate and
>>when it does it hits an unpleasant off-by-one bug showing one
>>too few characters).
>>
>>Editing reference attributes is not always possible now because
>>as noted in other threads there must be a router constraint to
>>avoid a null bendpoints. Examining the properties of a bendpoint-less
>>reference now gets an NPE. I tracked a similar problem to an
>
> initialisation
>
>>order issue that crept in with a change to ScrollingGraphicalViewer
>>in 3.1M6.
>>
>>What is the intent of these changes?
>>
>>Regards
>>
>>Ed Willink
>
>
>
--------------030307030402090302050600
Content-Type: text/plain;
name="Regimen.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Regimen.java"
/**
*
*/
package org.eclipse.gmt.umlx.editor.regime;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.gmt.umlx.UmlxPlugin;
import org.eclipse.gmt.umlx.ediagram.Diagram;
import org.eclipse.gmt.umlx.ediagram.DiagramElement;
public class Regimen<M extends Object> {
private static class DiagramMap extends HashMap<Class<? extends Diagram>, IRegime> {
private static final long serialVersionUID = 1L;
}
/**
* Return the diagram that is or that contains diagramElement
* @param diagramElement for which diagram required
* @return the diagram
*/
public static Diagram getDiagram(DiagramElement diagramElement) {
while ((diagramElement != null) && !(diagramElement instanceof Diagram))
diagramElement = (DiagramElement) diagramElement.eContainer();
return (Diagram) diagramElement;
}
private static boolean initialised = false;
public static void init() {
if (initialised)
return;
initialised = true;
IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = pluginRegistry.getExtensionPoint(UmlxPlugin.DIAGRAM_CONTENT_ ID);
if (extensionPoint == null) {
UmlxPlugin.logException(UmlxPlugin.newError("No '" + UmlxPlugin.DIAGRAM_CONTENT_ID + "' extension point", null), true);
return;
}
for (IExtension extension : extensionPoint.getExtensions()) {
for (IConfigurationElement diagramElement : extension.getConfigurationElements()) {
try {
String diagramName = diagramElement.getAttribute("name");
if (diagramName == null)
throw UmlxPlugin.newError("Missing \"name=\" attribute for <diagram> element", null);
String diagramClassName = diagramElement.getAttribute("class");
if (diagramClassName == null)
throw UmlxPlugin.newError("Missing \"class=\" attribute for <diagram> element", null);
Class<?> diagramClass = Class.forName(diagramClassName);
for (IConfigurationElement regimeElement : diagramElement.getChildren("regime")) {
try {
String regimeClassName = regimeElement.getAttribute("class");
if (regimeClassName == null)
throw UmlxPlugin.newError("Missing \"class=\" attribute for <diagram name='" + diagramName + "' <regime>> element", null);
Class<?> regimeClass = Class.forName(regimeClassName);
} catch (Exception e) {
UmlxPlugin.logException(e, true);
}
}
} catch (Exception e) {
UmlxPlugin.logException(e, true);
}
}
}
}
private Map<Class<? extends M>, DiagramMap> map = null;
public void addRegime(Class<? extends Diagram> diagramClass, Class<? extends M> objectClass, IRegime regime) {
if (diagramClass != null) {
if (map == null)
createMap();
DiagramMap diagramMap = map.get(objectClass);
if (diagramMap == null) {
diagramMap = new DiagramMap();
map.put(objectClass, diagramMap);
}
diagramMap.put(diagramClass, regime);
}
}
public void createMap() {
if (map == null) {
map = new HashMap<Class<? extends M>, DiagramMap>();
init();
}
}
/**
* Return the AbstractCreationFactory appropriate for an instance of modelClass below a parent.
* @param modelClass class of model element that needs creating
* @param objectClass of model element in graphical view
* @return the AbstractCreationFactory
*/
public IRegime getRegime(DiagramElement parent, Class<? extends M> objectClass) {
Diagram diagram = Regimen.getDiagram(parent);
if (diagram == null)
return null;
Class<? extends Diagram> diagramClass = diagram.getClass();
return getRegime(diagramClass, objectClass);
}
public IRegime getRegime(Class<? extends Diagram> diagramClass, Class<? extends M> objectClass) {
if ((diagramClass == null) || (objectClass == null))
return null;
if (map == null)
createMap();
DiagramMap diagramMap = map.get(objectClass);
if (diagramMap == null) { // Initial registration is of an interface, add derivation map entries lazily
for (Class<? extends Object> searchModelClass : map.keySet()) {
if (!searchModelClass.isAssignableFrom(objectClass))
;
else if (diagramMap != null) {
UmlxPlugin.openError("Multiple Regimen for " + objectClass.getName(), null);
}
else {
diagramMap = map.get(searchModelClass);
map.put(objectClass, diagramMap);
break;
}
}
}
if (diagramMap == null)
return null;
IRegime regime = diagramMap.get(diagramClass);
if (regime == null) { // Initial registration is of an interface, add derivation map entries lazily
for (Class<? extends Diagram> searchDiagramClass : diagramMap.keySet()) {
if (!searchDiagramClass.isAssignableFrom(diagramClass))
;
else if (regime != null) {
UmlxPlugin.openError("Multiple AbstractCreationFactory for " + objectClass.getName() + " in " + diagramClass.getName(), null);
}
else {
regime = diagramMap.get(searchDiagramClass);
diagramMap.put(diagramClass, regime);
break;
}
}
}
return regime;
}
}
--------------030307030402090302050600
Content-Type: text/plain;
name="IRegime.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="IRegime.java"
package org.eclipse.gmt.umlx.editor.regime;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmt.umlx.ediagram.DiagramElement;
import org.eclipse.gmt.umlx.ediagram.Link;
import org.eclipse.gmt.umlx.ediagram.Node;
import org.eclipse.gmt.umlx.editor.commands.links.CreateLinkCommand ;
public interface IRegime {
public static Regimen<Object> MODEL = new Regimen<Object>();
public static Regimen<DiagramElement> VIEW = new Regimen<DiagramElement>();
public Command completeLinkCommand(CreateLinkCommand command, Node source, DiagramElement view, Node target);
// public Command createCreateCommand(DiagramElement parent);
/**
* Create a command to create model and/or child optionally at loc in a parent.
* @param model object to be created if null and not obtainable via child, used if non-null
* @param view object to be created if null, used if non-null
* @param parent view object that is the parent of the child view object
* @param loc location of child view object if non-null
* @return the creation command
*/
public Command createCreateCommand(Object model, Object view, DiagramElement parent, Point loc);
public EditPart createEditPart(Object modelOrView, DiagramElement parent);
public Object createModelObject(DiagramElement parent);
// public Object getNewModelObject(DiagramElement parent);
public DiagramElement createViewObject(Object newModelObject, DiagramElement parent);
public Command createLinkCommand(CreateLinkCommand command, Node source, DiagramElement view, Node target);
public Command createReconnectSourceCommand(Link link, Node node);
public Command createReconnectTargetCommand(Link link, Node node);
public Object getNewObject();
}
--------------030307030402090302050600
Content-Type: text/plain;
name="Regime.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Regime.java"
/**
*
*/
package org.eclipse.gmt.umlx.editor.regime;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmt.umlx.TypeSafeUtils;
import org.eclipse.gmt.umlx.ediagram.Diagram;
import org.eclipse.gmt.umlx.ediagram.DiagramElement;
import org.eclipse.gmt.umlx.ediagram.Link;
import org.eclipse.gmt.umlx.ediagram.Node;
import org.eclipse.gmt.umlx.editor.commands.links.CreateLinkCommand ;
public abstract class Regime<T extends Object, V extends DiagramElement/*, PV extends DiagramElement*/> implements IRegime {
protected final Class<? extends Diagram> diagramClass;
protected final Class<T> modelClass;
protected final Class<V> viewClass;
// protected final Class<PV> parentViewClass;
protected Regime(Class<? extends Diagram> diagramClass, Class<T> modelClass, Class<V> viewClass/*, Class<PV> parentViewClass*/) {
if (diagramClass == null)
throw new NullPointerException("Null diagramClass for " + getClass().getName());
// if (modelClass == null)
// throw new NullPointerException("Null modelClass for " + getClass().getName());
if (viewClass == null)
throw new NullPointerException("Null viewClass for " + getClass().getName());
this.diagramClass = diagramClass;
this.modelClass = modelClass;
this.viewClass = viewClass;
// this.parentViewClass = parentViewClass;
if (modelClass != null)
IRegime.MODEL.addRegime(diagramClass, modelClass, this);
IRegime.VIEW.addRegime(diagramClass, viewClass, this);
}
/**
* Create a command to create model and/or child optionally at loc in a parent.
* @param model object to be created if null and not obtainable via child, used if non-null
* @param child view object to be created if null, used if non-null
* @param parent view object that is the parenmt of the child view object
* @param loc location of child view object if non-null
* @return the creation command
*/
public final Command completeLinkCommand(CreateLinkCommand command, Node source, DiagramElement view, Node target) {
// T validModel = TypeSafeUtils.castTo(model, modelClass);
V validView = TypeSafeUtils.castTo(view, viewClass);
return completeLinkCommand0(command, source, validView, target);
}
public Command completeLinkCommand0(CreateLinkCommand command, Node source, V view, Node target) {
/*
* The disallow cursor will be shown IFF you return null. If you return
* UnexecutableCommand.INSTANCE, the disallow cursor will not appear. This is
* because since this is the first step of the Command it doesn't check to
* see if it's executable or not (which it most likely isn't).
*/
return UnexecutableCommand.INSTANCE;
}
/**
* Create a command to create model and/or child optionally at loc in a parent.
* @param model object to be created if null and not obtainable via child, used if non-null
* @param child view object to be created if null, used if non-null
* @param parent view object that is the parenmt of the child view object
* @param loc location of child view object if non-null
* @return the creation command
*/
public final Command createCreateCommand(Object model, Object view, DiagramElement parent, Point loc) {
T validModel = TypeSafeUtils.castTo(model, modelClass);
V validView = TypeSafeUtils.castTo(view, viewClass);
return createCreateCommand0(validModel, validView, parent, loc);
}
public Command createCreateCommand0(T model, V view, DiagramElement parent, Point loc) {
/*
* The disallow cursor will be shown IFF you return null. If you return
* UnexecutableCommand.INSTANCE, the disallow cursor will not appear. This is
* because since this is the first step of the Command it doesn't check to
* see if it's executable or not (which it most likely isn't).
*/
return UnexecutableCommand.INSTANCE;
}
public EditPart createEditPart(Object modelOrViewObject, DiagramElement parent) {
DiagramElement view = null;
if (modelOrViewObject instanceof DiagramElement)
view = (DiagramElement) modelOrViewObject;
else
view = createViewObject(modelOrViewObject, parent);
V validView = TypeSafeUtils.castTo(view, viewClass);
return createEditPart0(validView);
}
public abstract EditPart createEditPart0(V view);
/**
* Create a command to create model and/or child optionally at loc in a parent.
* @param model object to be created if null and not obtainable via child, used if non-null
* @param child view object to be created if null, used if non-null
* @param parent view object that is the parenmt of the child view object
* @param loc location of child view object if non-null
* @return the creation command
*/
public final Command createLinkCommand(CreateLinkCommand command, Node source, DiagramElement view, Node target) {
// T validModel = TypeSafeUtils.castTo(model, modelClass);
V validView = TypeSafeUtils.castTo(view, viewClass);
return createLinkCommand0(command, source, validView, target);
}
public Command createLinkCommand0(CreateLinkCommand command, Node source, V view, Node target) {
/*
* The disallow cursor will be shown IFF you return null. If you return
* UnexecutableCommand.INSTANCE, the disallow cursor will not appear. This is
* because since this is the first step of the Command it doesn't check to
* see if it's executable or not (which it most likely isn't).
*/
return UnexecutableCommand.INSTANCE;
}
/**
* Create a new modelObject that does not have a view.
* @param parent TODO
* @return the new model object.
*/
public T createModelObject(DiagramElement parent) { return null; }
public Command createReconnectSourceCommand(Link link, Node node) {
V validLink = TypeSafeUtils.castTo(link, viewClass);
return createReconnectCommand0(node, validLink, (Node) link.getTarget());
}
public Command createReconnectCommand0(Node newSource, V link, Node newTarget) {
return UnexecutableCommand.INSTANCE;
}
public Command createReconnectTargetCommand(Link link, Node node) {
V validLink = TypeSafeUtils.castTo(link, viewClass);
return createReconnectCommand0((Node) link.getSource(), validLink, node);
}
/**
* Create a new view object for modelObject if non-null, or for a new model object
* as well
* @param modelObject optional model object to be viewed.
* @param parent TODO
* @return the new view object.
*/
public final V createViewObject(Object model, DiagramElement parent) {
T validModel = TypeSafeUtils.castTo(model, modelClass);
return createViewObject0(validModel, parent);
}
public abstract V createViewObject0(T modelObject, DiagramElement parent);
}
--------------030307030402090302050600
Content-Type: text/plain;
name="ClassRegime.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ClassRegime.java"
/**
*
*/
package org.eclipse.gmt.umlx.editor.regimes;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gmt.umlx.ediagram.DiagramElement;
import org.eclipse.gmt.umlx.editor.commands.nodes.CreateClassComman d;
import org.eclipse.gmt.umlx.editor.edit.parts.ClassEditPart;
import org.eclipse.gmt.umlx.editor.palette.RegimenCreationFactory;
import org.eclipse.gmt.umlx.editor.palette.UmlxDiagramImages;
import org.eclipse.gmt.umlx.editor.regime.Regime;
import org.eclipse.gmt.umlx.udiagram.ClassView;
import org.eclipse.gmt.umlx.udiagram.UDiagramFactory;
import org.eclipse.gmt.umlx.udiagram.UmlcDiagram;
import org.eclipse.jface.resource.ImageDescriptor;
public class ClassRegime extends Regime<EClass, ClassView> {
private static EClass undefinedClass = null;
public static final ClassRegime INSTANCE = new ClassRegime();
public static PaletteEntry createPaletteEntry() {
RegimenCreationFactory factory = new RegimenCreationFactory(INSTANCE);
ImageDescriptor img = UmlxDiagramImages.getImageDescriptor(UmlxDiagramImages.CLASS );
return new CombinedTemplateCreationEntry("Class",
"Create a new class or interface", factory, factory, img, img);
}
private ClassRegime() {
super(UmlcDiagram.class, EClass.class, ClassView.class);
}
public Command createCreateCommand0(EClass model, ClassView child, DiagramElement parent, Point loc) {
if (parent instanceof UmlcDiagram)
return new CreateClassCommand(model, child, (UmlcDiagram)parent, loc);
else
return UnexecutableCommand.INSTANCE;
}
public ClassEditPart createEditPart0(ClassView view) {
return new ClassEditPart(view);
}
public ClassView createViewObject0(EClass model, DiagramElement parent) {
if (parent instanceof UmlcDiagram) {
if (model == null)
model = EcoreFactory.eINSTANCE.createEClass();
ClassView classView = UDiagramFactory.eINSTANCE.createClassView();
classView.setENamedElement(model);
return classView;
}
else
return null;
}
public ClassView getNewObject() {
return UDiagramFactory.eINSTANCE.createClassView();
}
}
--------------030307030402090302050600--
|
|
| |
Goto Forum:
Current Time: Tue Dec 03 06:20:57 GMT 2024
Powered by FUDForum. Page generated in 0.03287 seconds
|