Home » Modeling » Graphiti » How to resize Polygon shapes and How to have a multiline text
How to resize Polygon shapes and How to have a multiline text [message #554070] |
Fri, 20 August 2010 02:59 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi there,
I am using Graphiti to develop an editor for a model in which business objects are associated with different shapes. I have two questions and I really hope that you guys will be able to help me:
Q1) For some of these shapes I am using Polygons. Therefore, is the resize functionality already provided by the framework for Polygons(in a way similar to Rectangle, Ellipse, etc.)?
I am not an expert of eclipse or java but it seems that the answer is NO. Am I wrong?
If I am not, should I implement the resizeShape method to resize Ploygon shapes? if YES can you provide me with an example
Q2) For all these shapes I need a multiline text similar to the notes shape in the UML editor. Should I use something such as:
"MultiText text = gaService.createDefaultMultiText(shape, addedClass.getName());"
?
Do you have an example for the EClass Shape in which instead of having a line for the name of the class I can have a multiline description?
Thank you in advance for any suggestions or help.
Daniele
[Updated on: Fri, 20 August 2010 03:01] Report message to a moderator
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #554130 is a reply to message #554070] |
Fri, 20 August 2010 09:28 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
I'll try...
to Q1)
Yes, you are right. The framework does not support it out-of the-box. What
you would need to do is scale the points of your Polygon according to the
size change. This can be done in the Resize feature of course, but for a
more general usage it would be good to place it inside the layout feature
(if you have other operations that affect the size of a shape but do not
trigger a resize).
You could do something like this in the resize feature (quite into the
blue - there's probable better implementations...):
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
// Get new sizes
int width = context.getWidth();
int height = context.getHeight();
// Get old sizes. They are defined by the max values for x and y on all
// points
PictogramElement pictogramElement = context.getPictogramElement();
Polygon polygon = (Polygon) pictogramElement.getGraphicsAlgorithm();
EList<Point> points = polygon.getPoints();
int maxX = 0;
int maxY = 0;
for (Iterator<Point> iterator = points.iterator(); iterator.hasNext();) {
Point point = iterator.next();
if (point.getX() > maxX) {
maxX = point.getX();
}
if (point.getY() > maxY) {
maxY = point.getY();
}
}
// Compute scale factor
float scaleX = width / maxX;
float scaleY = height / maxY;
if (scaleX != 1 || scaleY != 1) {
for (Iterator<Point> iterator = points.iterator(); iterator.hasNext();) {
Point point = iterator.next();
int newX = Math.round(point.getX() * scaleX);
point.setX(newX);
int newY = Math.round(point.getY() * scaleY);
point.setY(newY);
}
}
}
to Q2)
The line to create the MultiText looks ok. Basically the MultiText is quite
similar to the Text, the main difference is that it allows setting the
number of lines to show and it supports line breaks. I changed the the
TutorialAddEClassFeature to come up with a MultiText instead of a text.
Here's the part of the add method I applied changes:
// SHAPE WITH LINE
{
// create shape for line
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set graphics algorithm
final Polyline polyline = gaService.createPolyline(shape, new int[] { 0, 40,
width, 40 });
polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram())) ;
}
// SHAPE WITH TEXT
{
// create shape for text
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
final MultiText text = gaService.createMultiText(shape, addedClass.getName()
+ "\n" + addedClass.getOperationCount());
text.setStyle(StyleUtil.getStyleForEClassText(getDiagram())) ;
gaService.createFont(text, "Arial", 8);
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.getFont().setBold(true);
text.setHeight(2);
gaService.setLocationAndSize(text, 0, 0, width, 40);
Of course you would also need to adapt the layout, direct editing and others
features dealing with the Text object.
I hope this helps...
-Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i4kr2u$vq$1@build.eclipse.org...
> Hi there,
> I am using Graphiti to develop an editor for a model in which business
> objects are associated with different shapes. I have two questions and I
> really hope that you guys will be able to help me:
>
> Q1) For some of these shapes I am using Polygons. Therefore, is the
> resize functionality already provided by the framework for Polygons(in a
> way similar to Rectangle, Ellipse, etc.)?
> I am not an expert of eclipse or java but it seems that the answer is NO.
> Am I wrong?
>
> If I am not should I implement the resizeShape method to resize Ploygon
> shapes? if YES can you provide me with an example :)
>
>
> Q2) For all the shapes I need a multiline text similar to the notes shape
> in the UML editor. Should I use something such as:
>
> "MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());"
>
> ?
> Do you have an example for the EClass Shape in which instead of having a
> line for the name of the class I can have a multiline description?
>
> Thank you in advance for any suggestions or help.
> Daniele
>
|
|
| |
Re: How to resize Polygon shapes and How to have a multiline text [message #554326 is a reply to message #554130] |
Sat, 21 August 2010 16:22 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi Micheal,
This is what I did:
Q1) it works perfectly!! The only change I made is:
int maxX = 0; ---> float maxX = 0;
int maxY = 0; ---> float maxY = 0;
since in the calculation of (float) scaleX and (float) scaleY, the results were rounded to intengers number creating weird behaviours.
Q2) I adapted the layout, direct editing and others features dealing with the Text object changing:
Text variables ---> MultiText variables
Now, If I use the method createMultiText:
MultiText text = gaService.createMultiText(shape, addedClass.getName());
when in the diagram I add a new object (in my case the BusinessObecjt (BO) is called Intention), the feature direct editing does not work and, also, if I use the rename feature to set the name of such BO, the name is not visualized in the shape altough it correctly appears in the properties panel. This probably the reason why the direct editing does not work since there is no label to edit.
Moreover, I have such an error:
java.lang.NullPointerException
at org.eclipse.graphiti.bim.features.Intention.AddIntentionFeat ure.add(AddIntentionFeature.java:136)
at org.eclipse.graphiti.internal.command.AddFeatureCommandWithC ontext.execute(AddFeatureCommandWithContext.java:76)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.do Execute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.internal.command.CommandExec.executeCom mand(CommandExec.java:75)
at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.a ddIfPossible(AbstractFeatureProvider.java:313)
at org.eclipse.graphiti.features.impl.AbstractFeature.addGraphi calRepresentation(AbstractFeature.java:108)
at org.eclipse.graphiti.bim.features.Intention.CreateIntentionF eature.create(CreateIntentionFeature.java:65)
at org.eclipse.graphiti.features.impl.AbstractCreateFeature.exe cute(AbstractCreateFeature.java:100)
at org.eclipse.graphiti.internal.command.GenericFeatureCommandW ithContext.execute(GenericFeatureCommandWithContext.java:64)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.do Execute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.internal.command.CommandExec.executeCom mand(CommandExec.java:75)
at org.eclipse.graphiti.ui.internal.command.CreateModelObjectCo mmand.execute(CreateModelObjectCommand.java:52)
at org.eclipse.graphiti.ui.internal.editor.EmfOnGefCommand.exec ute(EmfOnGefCommand.java:58)
at org.eclipse.graphiti.internal.command.GFPreparableCommand2.d oExecute(GFPreparableCommand2.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFC ommandOperation.java:119)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:150)
at org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doE xecute(WorkspaceCommandStackImpl.java:208)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:47)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.ui.internal.editor.GFCommandStack.execu te(GFCommandStack.java:106)
at org.eclipse.gef.tools.AbstractTool.executeCommand(AbstractTo ol.java:426)
at org.eclipse.gef.tools.AbstractTool.executeCurrentCommand(Abs tractTool.java:443)
at org.eclipse.gef.tools.CreationTool.performCreation(CreationT ool.java:266)
at org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTo ol.java:186)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1206)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:301)
at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainEventDispatcher.java:380)
at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.java:548)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:213)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3552)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3171)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
BUT, if I use the method createDefaultMultiText:
MultiText text = gaService.createDefaultMultiText(shape, addedClass.getName());
the label is there and the direct editing feature works.
So my first question Q1) is which is the difference among these two methods? They both return a MultiText variable but I had two different beahviours.
Therefore, I am actually trying to use the createDefaultMultiText method but:
A) altough now I have a multiline text field, the height of the field is fixed (I am unable to resize it) and also no sidebar appears to scroll the text
B) to solve the fixed height I tried to set to TRUE instead of to FALSE the value in the createShape method for the shape of the Text, in fact I am using:
Shape shape = peCreateService.createShape(containerShape, true);
Now, in the diagram, I can move the "shape text" and resize as I desire but:
- the direct editing is not opened automatically after object creation (but I can do that manually)
- I have two decorator images, one attached to the pictogram element and one on the text shape. The latter is located at the bottom-center of the figure and if I resize the text shape after a while it disappears (maybe due to something in the layout class). Probably I will need to use the "ILocation, which provides the decorator location relative to the pictogram element." but I don't know how to use that or maybe I can eliminate this second decorator on the text shape (obviously, if I will use such approach for resizing.)
My question Q2) is: How Can I properly create the (Default?)MultiText field? Am I doing something wrong? and how the shape containing the multitext can adapt when more lines are inputed?
Q3) (The last ), when I am editing the multitext, the editing field is a line. Can I have instead a multiline field? Should I change in the -- public int getEditingType():
return TYPE_TEXT; ---> return TYPE_MULTILINETEXT;
but in this case the direct edit stops to work
I am sorry for all these questions but as I said I am not an expert, this is why I will greatly appreciate for any suggestions or help you may have
Thank you also for all your works.
Daniele
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #554463 is a reply to message #554326] |
Mon, 23 August 2010 09:27 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Hi Daniele,
please see my answers inline.
-Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i4ouge$p0$1@build.eclipse.org...
> Hi Micheal,
>
> This is what I did:
>
>
> Q1) it works perfectly!! The only change I made is:
>
> int maxX = 0; ---> float maxX = 0;
> int maxY = 0; ---> float maxY = 0;
>
> since in the calculation of (float) scaleX and (float) scaleY, the results
> were rounded to intengers number creating weird behaviours.
>
>
> Q2) I adapted the layout, direct editing and others features dealing with
> the Text object changing:
>
> Text variables ---> MultiText variables
>
> Now, If I use the method createMultiText:
>
> MultiText text = gaService.createMultiText(shape, addedClass.getName());
>
> when in the diagram I add a new object (in my case the BusinessObecjt (BO)
> is called Intention), the feature direct editing does not
> work and, also, if I use the rename feature to set the name of such BO,
> the name is not visualized in the shape altough it correctly appears in
> the properties panel. This probably the reason why the direct editing does
> not work since there is no label to edit.
Probably the font is not set for the MultiText. See below.
>
> Moreover, I have such an error:
>
> java.lang.NullPointerException
> at org.eclipse.graphiti.bim.features.Intention.AddIntentionFeat
> ure.add(AddIntentionFeature.java:136)
> at org.eclipse.graphiti.internal.command.AddFeatureCommandWithC
> ontext.execute(AddFeatureCommandWithContext.java:76)
> at org.eclipse.graphiti.internal.command.GFPreparableCommand.do
> Execute(GFPreparableCommand.java:37)
> at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi
> ngCommand.java:135)
> at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt
> ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
.....
Here, I cannot help since I don't know what your coding does in that line
>
> BUT, if I use the method createDefaultMultiText:
>
> MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());
>
> the label is there and the direct editing feature works.
>
> So my first question Q1) is which is the difference among these two
> methods? They both return a MultiText variable but I had two different
> beahviours.
The basic difference is that createDefaultMultiText also add a font to the
multi text (the default one) which is not done in createMultiText.
>
> Therefore, I am actually trying to use the createDefaultMultiText method
> but:
>
> A) altough now I have a multiline text field, the height of the field is
> fixed (I am unable to resize it) and also no sidebar appears to scroll the
> text
There is a setHeight() method on the MultiText object. You can use it to set
the number of lines to display. It is not possible to have that dynamically
by framework means instead you would change the height inside your resize
feature and adapt it to the size of your shape.
>
> B) to solve the fixed height I tried to set to TRUE instead of to FALSE
> the value in the createShape method for the shape of the Text, in fact I
> am using:
>
> Shape shape = peCreateService.createShape(containerShape, true);
>
> Now, in the diagram, I can move the "shape text" and resize as I desire
> but:
>
> - the direct editing is not opened automatically after object creation
> (but I can do that manually)
You can tell the framework to do so in the add feature. There is a section
on that in the tutorial in the Eclipse Help: Graphiti Developer Guide -->
Tutorial --> Features --> Direct Editing Feature --> Direct Editing
Activation
> - I have two decorator images, one attached to the pictogram element and
> one on the text shape. The latter is located at the bottom-center of the
> figure and if I resize the text shape after a while it disappears (maybe
> due to something in the layout class). Probably I will need to use the
> "ILocation, which provides the decorator location relative to the
> pictogram element." but I don't know how to use that :) or maybe I can
> eliminate this second decorator on the text shape (obviously, if I will
> use such approach for resizing.)
>
> My question Q2) is: How Can I properly create the (Default?)MultiText
> field? Am I doing something wrong? and how the shape containing the
> multitext can adapt when more lines are inputed?
See answers above
>
> Q3) (The last :) ), when I am editing the multitext, the editing field is
> a line. Can I have instead a multiline field? Should I change in the --
> public int getEditingType():
>
> return TYPE_TEXT; ---> return TYPE_MULTILINETEXT;
>
> but in this case the direct edit stops to work :(
As soon as you have multiple lines, you can also use them for direct
editing.
>
>
> I am sorry for all these questions but as I said I am not an expert, this
> is why I will greatly appreciate for any suggestions or help you may have
> :)
>
> Thank you also for all your works.
> Daniele
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #555141 is a reply to message #554463] |
Wed, 25 August 2010 14:50 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi Michael,
thank you again for your useful suggestions !!!
Now, I have a multiline text which resizes with the shape. This is what I did as you described:
Add...Feature.java
...
{
// create shape for text
Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
MultiText text = gaService.createDefaultMultiText(shape, addedClass.getName());
text.setStyle(StyleUtil.getStyleForIntentionText(getDiagram( )));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.getFont().setBold(true);
//text.setHeight(2);
// changed the line below, added height
gaService.setLocationAndSize(text, 0, 0, width, height);
// create link and wire it
link(shape, addedClass);
// provide information to support direct-editing directly
// after object creation (must be activated additionally)
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// set container shape for direct editing after object creation
directEditingInfo.setMainPictogramElement(containerShape);
// set shape and graphics algorithm where the editor for
// direct editing shall be opened after object creation
directEditingInfo.setPictogramElement(shape);
directEditingInfo.setGraphicsAlgorithm(text);
}
...
and in the:
Layout...Feature.java
...
if ((rectangleWidth != size.getWidth()) || (rectangleHeight != size.getHeight())) {
if (graphicsAlgorithm instanceof Polyline) {
...
} else if (graphicsAlgorithm instanceof MultiText){
// I changed this line
gaService.setLocationAndSize(graphicsAlgorithm, 0, 0,rectangleWidth,rectangleHeight);
anythingChanged = true;
}
...
Now everything works fine, the only problem is that if I make this change:
public int getEditingType() {
// there are several possible editor-types supported:
// text-field, checkbox, color-chooser, combobox, ...
// changed this line to have a multilinetext editor
return TYPE_MULTILINETEXT;
//return TYPE_TEXT;
}
the directEditing is not opened automatically when I create a new element, although it works correctly in the other case (since the direct editing is actived in the code)
Anyway, it is not a big deal, indeed I can use a single line editor.
Thank you again for all your great suggestions!!!!
Daniele
[Updated on: Wed, 25 August 2010 14:58] Report message to a moderator
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #555394 is a reply to message #555141] |
Thu, 26 August 2010 13:36 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Thanks for this update. Could you please open a Bugzilla regarding this last
issue? This seems to be a bug.
Thanks,
Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i53aka$u65$1@build.eclipse.org...
> Hi Micheal,
> thank you again for your useful suggestions :) !!!
>
> Now, I have a multiline text which resizes with the shape. This is what I
> did as you described:
>
> Add...Feature.java
>
> ..
> {
> // create shape for text
> Shape shape = peCreateService.createShape(containerShape, false);
>
> // create and set text graphics algorithm
>
> MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());
>
> text.setStyle(StyleUtil.getStyleForIntentionText(getDiagram( )));
> text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
> text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
> text.getFont().setBold(true);
> //text.setHeight(2);
> // changed the line below, added height
> gaService.setLocationAndSize(text, 0, 0, width, height);
>
> // create link and wire it
> link(shape, addedClass);
>
> // provide information to support direct-editing directly
> // after object creation (must be activated additionally)
> final IDirectEditingInfo directEditingInfo =
> getFeatureProvider().getDirectEditingInfo();
> // set container shape for direct editing after object creation
> directEditingInfo.setMainPictogramElement(containerShape);
> // set shape and graphics algorithm where the editor for
> // direct editing shall be opened after object creation
> directEditingInfo.setPictogramElement(shape);
> directEditingInfo.setGraphicsAlgorithm(text);
>
> }
> ..
>
> and in the:
>
> Layout...Feature.java
>
> ..
>
> if ((rectangleWidth != size.getWidth()) || (rectangleHeight !=
> size.getHeight())) {
> if (graphicsAlgorithm instanceof Polyline) {
> ..
> } else if (graphicsAlgorithm instanceof MultiText){
>
> // I changed this line
> gaService.setLocationAndSize(graphicsAlgorithm, 0,
> 0,rectangleWidth,rectangleHeight);
>
> anythingChanged = true;
> }
>
> ..
>
>
> Now everything works fine, the only problem is that if I make this
> change:
>
> public int getEditingType() {
> // there are several possible editor-types supported:
> // text-field, checkbox, color-chooser, combobox, ...
>
> // changed this line to have a multilinetext editor
> return TYPE_MULTILINETEXT;
> //return TYPE_TEXT;
> }
>
> the directEditing is not opened automatically when I create a new element,
> although it works correctly in the other case (since the direct editing is
> actived in the code)
>
> Anyway, it is not a big deal, indeed I can use a single line editor.
>
> Thank you again for all your great suggestions!!!!
> Daniele
>
>
|
|
| | | | |
Re: How to resize Polygon shapes and How to have a multiline text [message #563756 is a reply to message #554130] |
Sat, 21 August 2010 16:22 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi Micheal,
This is what I did:
Q1) it works perfectly!! The only change I made is:
int maxX = 0; ---> float maxX = 0;
int maxY = 0; ---> float maxY = 0;
since in the calculation of (float) scaleX and (float) scaleY, the results were rounded to intengers number creating weird behaviours.
Q2) I adapted the layout, direct editing and others features dealing with the Text object changing:
Text variables ---> MultiText variables
Now, If I use the method createMultiText:
MultiText text = gaService.createMultiText(shape, addedClass.getName());
when in the diagram I add a new object (in my case the BusinessObecjt (BO) is called Intention), the feature direct editing does not work and, also, if I use the rename feature to set the name of such BO, the name is not visualized in the shape altough it correctly appears in the properties panel. This probably the reason why the direct editing does not work since there is no label to edit.
Moreover, I have such an error:
java.lang.NullPointerException
at org.eclipse.graphiti.bim.features.Intention.AddIntentionFeat ure.add(AddIntentionFeature.java:136)
at org.eclipse.graphiti.internal.command.AddFeatureCommandWithC ontext.execute(AddFeatureCommandWithContext.java:76)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.do Execute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.internal.command.CommandExec.executeCom mand(CommandExec.java:75)
at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.a ddIfPossible(AbstractFeatureProvider.java:313)
at org.eclipse.graphiti.features.impl.AbstractFeature.addGraphi calRepresentation(AbstractFeature.java:108)
at org.eclipse.graphiti.bim.features.Intention.CreateIntentionF eature.create(CreateIntentionFeature.java:65)
at org.eclipse.graphiti.features.impl.AbstractCreateFeature.exe cute(AbstractCreateFeature.java:100)
at org.eclipse.graphiti.internal.command.GenericFeatureCommandW ithContext.execute(GenericFeatureCommandWithContext.java:64)
at org.eclipse.graphiti.internal.command.GFPreparableCommand.do Execute(GFPreparableCommand.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.internal.command.CommandExec.executeCom mand(CommandExec.java:75)
at org.eclipse.graphiti.ui.internal.command.CreateModelObjectCo mmand.execute(CreateModelObjectCommand.java:52)
at org.eclipse.graphiti.ui.internal.editor.EmfOnGefCommand.exec ute(EmfOnGefCommand.java:58)
at org.eclipse.graphiti.internal.command.GFPreparableCommand2.d oExecute(GFPreparableCommand2.java:37)
at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi ngCommand.java:135)
at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFC ommandOperation.java:119)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:150)
at org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doE xecute(WorkspaceCommandStackImpl.java:208)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:47)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt ackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
at org.eclipse.graphiti.ui.internal.editor.GFCommandStack.execu te(GFCommandStack.java:106)
at org.eclipse.gef.tools.AbstractTool.executeCommand(AbstractTo ol.java:426)
at org.eclipse.gef.tools.AbstractTool.executeCurrentCommand(Abs tractTool.java:443)
at org.eclipse.gef.tools.CreationTool.performCreation(CreationT ool.java:266)
at org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTo ol.java:186)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1206)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:301)
at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainEventDispatcher.java:380)
at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.java:548)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:213)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3552)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3171)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
BUT, if I use the method createDefaultMultiText:
MultiText text = gaService.createDefaultMultiText(shape, addedClass.getName());
the label is there and the direct editing feature works.
So my first question Q1) is which is the difference among these two methods? They both return a MultiText variable but I had two different beahviours.
Therefore, I am actually trying to use the createDefaultMultiText method but:
A) altough now I have a multiline text field, the height of the field is fixed (I am unable to resize it) and also no sidebar appears to scroll the text
B) to solve the fixed height I tried to set to TRUE instead of to FALSE the value in the createShape method for the shape of the Text, in fact I am using:
Shape shape = peCreateService.createShape(containerShape, true);
Now, in the diagram, I can move the "shape text" and resize as I desire but:
- the direct editing is not opened automatically after object creation (but I can do that manually)
- I have two decorator images, one attached to the pictogram element and one on the text shape. The latter is located at the bottom-center of the figure and if I resize the text shape after a while it disappears (maybe due to something in the layout class). Probably I will need to use the "ILocation, which provides the decorator location relative to the pictogram element." but I don't know how to use that :) or maybe I can eliminate this second decorator on the text shape (obviously, if I will use such approach for resizing.)
My question Q2) is: How Can I properly create the (Default?)MultiText field? Am I doing something wrong? and how the shape containing the multitext can adapt when more lines are inputed?
Q3) (The last :) ), when I am editing the multitext, the editing field is a line. Can I have instead a multiline field? Should I change in the -- public int getEditingType():
return TYPE_TEXT; ---> return TYPE_MULTILINETEXT;
but in this case the direct edit stops to work :(
I am sorry for all these questions but as I said I am not an expert, this is why I will greatly appreciate for any suggestions or help you may have :)
Thank you also for all your works.
Daniele
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #563777 is a reply to message #563756] |
Mon, 23 August 2010 09:27 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Hi Daniele,
please see my answers inline.
-Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i4ouge$p0$1@build.eclipse.org...
> Hi Micheal,
>
> This is what I did:
>
>
> Q1) it works perfectly!! The only change I made is:
>
> int maxX = 0; ---> float maxX = 0;
> int maxY = 0; ---> float maxY = 0;
>
> since in the calculation of (float) scaleX and (float) scaleY, the results
> were rounded to intengers number creating weird behaviours.
>
>
> Q2) I adapted the layout, direct editing and others features dealing with
> the Text object changing:
>
> Text variables ---> MultiText variables
>
> Now, If I use the method createMultiText:
>
> MultiText text = gaService.createMultiText(shape, addedClass.getName());
>
> when in the diagram I add a new object (in my case the BusinessObecjt (BO)
> is called Intention), the feature direct editing does not
> work and, also, if I use the rename feature to set the name of such BO,
> the name is not visualized in the shape altough it correctly appears in
> the properties panel. This probably the reason why the direct editing does
> not work since there is no label to edit.
Probably the font is not set for the MultiText. See below.
>
> Moreover, I have such an error:
>
> java.lang.NullPointerException
> at org.eclipse.graphiti.bim.features.Intention.AddIntentionFeat
> ure.add(AddIntentionFeature.java:136)
> at org.eclipse.graphiti.internal.command.AddFeatureCommandWithC
> ontext.execute(AddFeatureCommandWithContext.java:76)
> at org.eclipse.graphiti.internal.command.GFPreparableCommand.do
> Execute(GFPreparableCommand.java:37)
> at org.eclipse.emf.transaction.RecordingCommand.execute(Recordi
> ngCommand.java:135)
> at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandSt
> ackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
.....
Here, I cannot help since I don't know what your coding does in that line
>
> BUT, if I use the method createDefaultMultiText:
>
> MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());
>
> the label is there and the direct editing feature works.
>
> So my first question Q1) is which is the difference among these two
> methods? They both return a MultiText variable but I had two different
> beahviours.
The basic difference is that createDefaultMultiText also add a font to the
multi text (the default one) which is not done in createMultiText.
>
> Therefore, I am actually trying to use the createDefaultMultiText method
> but:
>
> A) altough now I have a multiline text field, the height of the field is
> fixed (I am unable to resize it) and also no sidebar appears to scroll the
> text
There is a setHeight() method on the MultiText object. You can use it to set
the number of lines to display. It is not possible to have that dynamically
by framework means instead you would change the height inside your resize
feature and adapt it to the size of your shape.
>
> B) to solve the fixed height I tried to set to TRUE instead of to FALSE
> the value in the createShape method for the shape of the Text, in fact I
> am using:
>
> Shape shape = peCreateService.createShape(containerShape, true);
>
> Now, in the diagram, I can move the "shape text" and resize as I desire
> but:
>
> - the direct editing is not opened automatically after object creation
> (but I can do that manually)
You can tell the framework to do so in the add feature. There is a section
on that in the tutorial in the Eclipse Help: Graphiti Developer Guide -->
Tutorial --> Features --> Direct Editing Feature --> Direct Editing
Activation
> - I have two decorator images, one attached to the pictogram element and
> one on the text shape. The latter is located at the bottom-center of the
> figure and if I resize the text shape after a while it disappears (maybe
> due to something in the layout class). Probably I will need to use the
> "ILocation, which provides the decorator location relative to the
> pictogram element." but I don't know how to use that :) or maybe I can
> eliminate this second decorator on the text shape (obviously, if I will
> use such approach for resizing.)
>
> My question Q2) is: How Can I properly create the (Default?)MultiText
> field? Am I doing something wrong? and how the shape containing the
> multitext can adapt when more lines are inputed?
See answers above
>
> Q3) (The last :) ), when I am editing the multitext, the editing field is
> a line. Can I have instead a multiline field? Should I change in the --
> public int getEditingType():
>
> return TYPE_TEXT; ---> return TYPE_MULTILINETEXT;
>
> but in this case the direct edit stops to work :(
As soon as you have multiple lines, you can also use them for direct
editing.
>
>
> I am sorry for all these questions but as I said I am not an expert, this
> is why I will greatly appreciate for any suggestions or help you may have
> :)
>
> Thank you also for all your works.
> Daniele
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #565597 is a reply to message #554463] |
Wed, 25 August 2010 14:50 |
Daniele Messages: 45 Registered: August 2010 |
Member |
|
|
Hi Micheal,
thank you again for your useful suggestions :) !!!
Now, I have a multiline text which resizes with the shape. This is what I did as you described:
Add...Feature.java
...
{
// create shape for text
Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
MultiText text = gaService.createDefaultMultiText(shape, addedClass.getName());
text.setStyle(StyleUtil.getStyleForIntentionText(getDiagram( )));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.getFont().setBold(true);
//text.setHeight(2);
// changed the line below, added height
gaService.setLocationAndSize(text, 0, 0, width, height);
// create link and wire it
link(shape, addedClass);
// provide information to support direct-editing directly
// after object creation (must be activated additionally)
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// set container shape for direct editing after object creation
directEditingInfo.setMainPictogramElement(containerShape);
// set shape and graphics algorithm where the editor for
// direct editing shall be opened after object creation
directEditingInfo.setPictogramElement(shape);
directEditingInfo.setGraphicsAlgorithm(text);
}
...
and in the:
Layout...Feature.java
...
if ((rectangleWidth != size.getWidth()) || (rectangleHeight != size.getHeight())) {
if (graphicsAlgorithm instanceof Polyline) {
...
} else if (graphicsAlgorithm instanceof MultiText){
// I changed this line
gaService.setLocationAndSize(graphicsAlgorithm, 0, 0,rectangleWidth,rectangleHeight);
anythingChanged = true;
}
...
Now everything works fine, the only problem is that if I make this change:
public int getEditingType() {
// there are several possible editor-types supported:
// text-field, checkbox, color-chooser, combobox, ...
// changed this line to have a multilinetext editor
return TYPE_MULTILINETEXT;
//return TYPE_TEXT;
}
the directEditing is not opened automatically when I create a new element, although it works correctly in the other case (since the direct editing is actived in the code)
Anyway, it is not a big deal, indeed I can use a single line editor.
Thank you again for all your great suggestions!!!!
Daniele
|
|
|
Re: How to resize Polygon shapes and How to have a multiline text [message #565626 is a reply to message #565597] |
Thu, 26 August 2010 13:36 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Thanks for this update. Could you please open a Bugzilla regarding this last
issue? This seems to be a bug.
Thanks,
Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i53aka$u65$1@build.eclipse.org...
> Hi Micheal,
> thank you again for your useful suggestions :) !!!
>
> Now, I have a multiline text which resizes with the shape. This is what I
> did as you described:
>
> Add...Feature.java
>
> ..
> {
> // create shape for text
> Shape shape = peCreateService.createShape(containerShape, false);
>
> // create and set text graphics algorithm
>
> MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());
>
> text.setStyle(StyleUtil.getStyleForIntentionText(getDiagram( )));
> text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
> text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
> text.getFont().setBold(true);
> //text.setHeight(2);
> // changed the line below, added height
> gaService.setLocationAndSize(text, 0, 0, width, height);
>
> // create link and wire it
> link(shape, addedClass);
>
> // provide information to support direct-editing directly
> // after object creation (must be activated additionally)
> final IDirectEditingInfo directEditingInfo =
> getFeatureProvider().getDirectEditingInfo();
> // set container shape for direct editing after object creation
> directEditingInfo.setMainPictogramElement(containerShape);
> // set shape and graphics algorithm where the editor for
> // direct editing shall be opened after object creation
> directEditingInfo.setPictogramElement(shape);
> directEditingInfo.setGraphicsAlgorithm(text);
>
> }
> ..
>
> and in the:
>
> Layout...Feature.java
>
> ..
>
> if ((rectangleWidth != size.getWidth()) || (rectangleHeight !=
> size.getHeight())) {
> if (graphicsAlgorithm instanceof Polyline) {
> ..
> } else if (graphicsAlgorithm instanceof MultiText){
>
> // I changed this line
> gaService.setLocationAndSize(graphicsAlgorithm, 0,
> 0,rectangleWidth,rectangleHeight);
>
> anythingChanged = true;
> }
>
> ..
>
>
> Now everything works fine, the only problem is that if I make this
> change:
>
> public int getEditingType() {
> // there are several possible editor-types supported:
> // text-field, checkbox, color-chooser, combobox, ...
>
> // changed this line to have a multilinetext editor
> return TYPE_MULTILINETEXT;
> //return TYPE_TEXT;
> }
>
> the directEditing is not opened automatically when I create a new element,
> although it works correctly in the other case (since the direct editing is
> actived in the code)
>
> Anyway, it is not a big deal, indeed I can use a single line editor.
>
> Thank you again for all your great suggestions!!!!
> Daniele
>
>
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 13:59:33 GMT 2024
Powered by FUDForum. Page generated in 0.04421 seconds
|