Home » Modeling » GMF (Graphical Modeling Framework) » graphdef.editor -> Problems when generating diagram code
| | | | |
Re: graphdef.editor -> Problems when generating diagram code [message #199541 is a reply to message #195298] |
Wed, 30 July 2008 13:49 |
Nikolay Georgiev Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Thank You Alex for the tips!
For those who are interested I solved the synchronization in the following
way:
==================================================
1) I copied the AbstractFigureEditPart class from the graphdef editor
(version 25. Nov. 2007) in my .diagram project.
2) The following things are added in the AbstractFigureEditPart:
===== AbstractFigureEditPart.java BEGIN =====
private final TransactionalEditingDomain editingDomain;
public AbstractFigureEditPart(View view) {
super(view);
editingDomain =
TransactionalEditingDomain.Factory.INSTANCE.createEditingDom ain();
}
public TransactionalEditingDomain getTransactionalEditingDomain()
{
return editingDomain;
}
/**
* @generated NOT
*/
@Override
public void activate() {
if (isActive()) {
return;
}
View view = (View) getModel();
if (view.getElement() == null) {
super.activate();
return;
}
final EObject modelElement = view.getElement();
final EClass eClass = modelElement.eClass();
final EStructuralFeature eFX = eClass.getEStructuralFeature("x");
final EStructuralFeature eFY = eClass.getEStructuralFeature("y");
final EStructuralFeature eFWidth = eClass.getEStructuralFeature("width");
final EStructuralFeature eFHeight =
eClass.getEStructuralFeature("height");
if (eFWidth != null)
{
addListenerFilter("Model_Width_Listener",
new NotificationListener() {
public void notifyChanged(Notification notification) {
// width from model
final EStructuralFeature eFWidth =
eClass.getEStructuralFeature("width");
String modelWidthStr = (String)modelElement.eGet(eFWidth);
if(!isInteger(modelWidthStr))
{
refreshBounds();
}
else
{
final Integer modelWidthInt = Integer.decode(modelWidthStr);
setStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_ Width(),
modelWidthInt);
}
}
}, modelElement, eFWidth);
}
if (eFHeight != null)
{
addListenerFilter("Model_Height_Listener",
new NotificationListener() {
public void notifyChanged(Notification notification) {
// height from model
final EStructuralFeature eFHeight =
eClass.getEStructuralFeature("height");
String modelHeightStr = (String)modelElement.eGet(eFHeight);
if(!isInteger(modelHeightStr))
{
refreshBounds();
}
else
{
final Integer modelHeightInt = Integer.decode(modelHeightStr);
setStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_ Height(),
modelHeightInt);
}
}
}, modelElement, eFHeight);
}
if (eFX != null)
{
addListenerFilter("Model_X_Listener",
new NotificationListener() {
public void notifyChanged(Notification notification) {
final EStructuralFeature eFX = eClass.getEStructuralFeature("x");
String modelXStr = (String)modelElement.eGet(eFX);
if(!isInteger(modelXStr))
{
refreshBounds();
}
else
{
final Integer modelXInt = Integer.decode(modelXStr);
setStructuralFeatureValue(NotationPackage.eINSTANCE.getLocat ion_X(),
modelXInt);
}
}
}, modelElement, eFX);
}
if (eFY != null)
{
addListenerFilter("Model_Y_Listener",
new NotificationListener() {
public void notifyChanged(Notification notification) {
// height from model
final EStructuralFeature eFY = eClass.getEStructuralFeature("y");
String modelYStr = (String)modelElement.eGet(eFY);
if(!isInteger(modelYStr))
{
refreshBounds();
}
else
{
final Integer modelYInt = Integer.decode(modelYStr);
setStructuralFeatureValue(NotationPackage.eINSTANCE.getLocat ion_Y(),
modelYInt);
}
}
}, modelElement, eFY);
}
final Bounds bounds = (Bounds) ((Node) view).getLayoutConstraint();
addListenerFilter("BoundsListener", new NotificationListener() {
public void notifyChanged(final Notification notification) {
try {
new AbstractEMFOperation(
getEditingDomain(),
"Synchronizing model size with the view",
Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE)) {
//$NON-NLS-1$
protected IStatus doExecute(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
refreshBounds();
return Status.OK_STATUS;
}
}.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
// GMFGraphDiagramEditorPlugin
// .getInstance()
// .logError(
// "Unable to synchronize model size with the view", e);
//$NON-NLS-1$
System.err.println("Unable to synchronize model size with the view");
}
if (getRoot() != null) {
handleMajorSemanticChange();
}
}
}, bounds);
super.activate();
}
/**
* Checks whether the given string is an integer
*
* @param string a string
* @return true or false
*/
private static boolean isInteger(String string)
{
boolean res = true;
try
{
Integer.parseInt(string);
}
catch(NumberFormatException e)
{
res = false;
}
return res;
}
===== AbstractFigureEditPart.java END =====
3) All *EditPart.java extend the AbstractFigureEditPart and the following
things are added:
===== *EditPart.java BEGIN =====
/**
* @generated NOT
*/
private Figure myNodeFigure;
/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode()
.DPtoLP(40), getMapMode().DPtoLP(40));
myNodeFigure = result;
return result;
}
/**
* @generated NOT
*/
protected void refreshBounds() {
super.refreshBounds();
View view = getNotationView();
final EObject element = view.getElement();
EClass eClass = element.eClass();
final EStructuralFeature eFX = eClass.getEStructuralFeature("x");
final EStructuralFeature eFY = eClass.getEStructuralFeature("y");
final int x = ((Integer)
getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_X())).intValue();
final int y = ((Integer)
getStructuralFeatureValue(NotationPackage.eINSTANCE
.getLocation_Y())).intValue();
// update x,y,w,h of the model
TransactionalEditingDomain editingDomain =
getTransactionalEditingDomain();
RecordingCommand updateModelCmd = new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
element.eSet(eFX, String.valueOf(x));
element.eSet(eFY, String.valueOf(y));
}
};
TransactionalCommandStack tstack = (TransactionalCommandStack)
editingDomain.getCommandStack();
tstack.execute(updateModelCmd);
}
/**
* @generated NOT
*/
protected LayoutManager getFigureLayoutManager() {
return contentPane.getLayoutManager();
}
/**
* @generated NOT
*/
protected void setFigureLayoutManager(LayoutManager layoutManager) {
contentPane.setLayoutManager(layoutManager);
}
===== *EditPart.java END =====
==================================================
Greetings,
Nikolay
|
|
| | |
Goto Forum:
Current Time: Thu Sep 19 10:41:58 GMT 2024
Powered by FUDForum. Page generated in 0.04519 seconds
|