Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to remove line above node compartment
How to remove line above node compartment [message #550151] Thu, 29 July 2010 10:15 Go to next message
Eclipse UserFriend
Originally posted by: jan.vandenbergh.uhasselt.be

Hi,

I am developing a GMF editor for a DSL. This DSL contains several nodes
that contain one compartment. Above this compartment there is a
horizontal line. Can I remove this horizontal line or change its
visualization? I would prefer a solution that only modifies the
..gmfgraph model, if possible.

Many thanks!

Kind regards,
Jan
Re: How to remove line above node compartment [message #550774 is a reply to message #550151] Wed, 04 August 2010 09:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 29.07.2010 12:15, wrote Jan Van den Bergh:
> Hi,
>
> I am developing a GMF editor for a DSL. This DSL contains several nodes
> that contain one compartment. Above this compartment there is a
> horizontal line. Can I remove this horizontal line or change its
> visualization? I would prefer a solution that only modifies the
> .gmfgraph model, if possible.

Late reply, for some reason I couldn't reach the news server for a
couple of days.

You can either modify the compartment's figure in the generated edit
part code, or use the following generic solution which uses a seperate
plugin:

plugin.xml:
<extension
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders ">
<editpolicyProvider class="XXX.policies.EditPolicyProvider">
<Priority
name="Medium">
</Priority>
</editpolicyProvider>
</extension>

XXX.policies.EditPolicyProvider:

private EditPartListener compartmentSilencer = new
EditPartListener.Stub() {
@Override
public void childAdded(EditPart child, int index) {
if (child instanceof CompartmentEditPart) {
// remove top border
((CompartmentEditPart)child).getFigure().setBorder(null);
}
}
}

public class EditPolicyProvider implements IEditPolicyProvider {
...
public void createEditPolicies(EditPart editPart) {
if (editPart instanceof ShapeNodeEditPart) {
editPart.addEditPartListener(compartmentSilencer);
}
}
}
public boolean provides(IOperation operation) {
boolean result = false;
if (operation instanceof CreateEditPoliciesOperation) {
EditPart editPart =
((CreateEditPoliciesOperation)operation).getEditPart();
result = editPart instanceof XXXEditPart;
}
return result;
}

I admit this is kind of complicated given the problem to solve, but for
me it's worth it. I prefer not modifying generated code because I want
to keep being able to complete wipe and regenerate it. Also, this method
allows other dynamic "fixes" or additions to be done to the EditParts.
In fact I called the listener "silencer" because in my code it also
registers an editpolicy to inhibit the selection handles and the "delete
from model" context menu entry.

HTH
Marius
Re: How to remove line above node compartment [message #550775 is a reply to message #550151] Wed, 04 August 2010 09:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 29.07.2010 12:15, wrote Jan Van den Bergh:
> Hi,
>
> I am developing a GMF editor for a DSL. This DSL contains several nodes
> that contain one compartment. Above this compartment there is a
> horizontal line. Can I remove this horizontal line or change its
> visualization? I would prefer a solution that only modifies the
> .gmfgraph model, if possible.

Late reply, for some reason I couldn't reach the news server for a
couple of days.

You can either modify the compartment's figure in the generated edit
part code, or use the following generic solution which uses a seperate
plugin:

plugin.xml:
<extension
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders ">
<editpolicyProvider class="XXX.policies.EditPolicyProvider">
<Priority
name="Medium">
</Priority>
</editpolicyProvider>
</extension>

XXX.policies.EditPolicyProvider:

private EditPartListener compartmentSilencer = new
EditPartListener.Stub() {
@Override
public void childAdded(EditPart child, int index) {
if (child instanceof CompartmentEditPart) {
// remove top border
((CompartmentEditPart)child).getFigure().setBorder(null);
}
}
}

public class EditPolicyProvider implements IEditPolicyProvider {
...
public void createEditPolicies(EditPart editPart) {
if (editPart instanceof ShapeNodeEditPart) {
editPart.addEditPartListener(compartmentSilencer);
}
}
}
public boolean provides(IOperation operation) {
boolean result = false;
if (operation instanceof CreateEditPoliciesOperation) {
EditPart editPart =
((CreateEditPoliciesOperation)operation).getEditPart();
result = editPart instanceof XXXEditPart;
}
return result;
}

I admit this is kind of complicated given the problem to solve, but for
me it's worth it. I prefer not modifying generated code because I want
to keep being able to complete wipe and regenerate it. Also, this method
allows other dynamic "fixes" or additions to be done to the EditParts.
In fact I called the listener "silencer" because in my code it also
registers an editpolicy to inhibit the selection handles and the "delete
from model" context menu entry.

HTH
Marius
Re: How to remove line above node compartment [message #553181 is a reply to message #550774] Mon, 16 August 2010 15:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.vandenbergh.uhasselt.be

On 4/08/2010 11:57, Marius Gröger wrote:
> Am 29.07.2010 12:15, wrote Jan Van den Bergh:
>> Hi,
>>
>> I am developing a GMF editor for a DSL. This DSL contains several nodes
>> that contain one compartment. Above this compartment there is a
>> horizontal line. Can I remove this horizontal line or change its
>> visualization? I would prefer a solution that only modifies the
>> .gmfgraph model, if possible.
>
> Late reply, for some reason I couldn't reach the news server for a
> couple of days.
>
> You can either modify the compartment's figure in the generated edit
> part code, or use the following generic solution which uses a seperate
> plugin:
>
> plugin.xml:
> <extension
> point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders ">
> <editpolicyProvider class="XXX.policies.EditPolicyProvider">
> <Priority
> name="Medium">
> </Priority>
> </editpolicyProvider>
> </extension>
>
> XXX.policies.EditPolicyProvider:
>
> private EditPartListener compartmentSilencer = new
> EditPartListener.Stub() {
> @Override
> public void childAdded(EditPart child, int index) {
> if (child instanceof CompartmentEditPart) {
> // remove top border
> ((CompartmentEditPart)child).getFigure().setBorder(null);
> }
> }
> }
>
> public class EditPolicyProvider implements IEditPolicyProvider {
> ...
> public void createEditPolicies(EditPart editPart) {
> if (editPart instanceof ShapeNodeEditPart) {
> editPart.addEditPartListener(compartmentSilencer);
> }
> }
> }
> public boolean provides(IOperation operation) {
> boolean result = false;
> if (operation instanceof CreateEditPoliciesOperation) {
> EditPart editPart = ((CreateEditPoliciesOperation)operation).getEditPart();
> result = editPart instanceof XXXEditPart;
> }
> return result;
> }
>
> I admit this is kind of complicated given the problem to solve, but for
> me it's worth it. I prefer not modifying generated code because I want
> to keep being able to complete wipe and regenerate it. Also, this method
> allows other dynamic "fixes" or additions to be done to the EditParts.
> In fact I called the listener "silencer" because in my code it also
> registers an editpolicy to inhibit the selection handles and the "delete
> from model" context menu entry.

Thank you very much!
This was exactly what I was looking for.

Kind regards,
Jan

>
> HTH
> Marius
Re: How to remove line above node compartment [message #676770 is a reply to message #553181] Mon, 06 June 2011 13:15 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hello, I have the same problem as you. But I would like to try this solution. It seems it works well. But I don't understand the code:

private EditPartListener compartmentSilencer = new
EditPartListener.Stub() {
@Override
public void childAdded(EditPart child, int index) {
if (child instanceof CompartmentEditPart) {
// remove top border
((CompartmentEditPart)child).getFigure().setBorder(null);
}
}
}


Where should I add them?

Thank you very much
Re: How to remove line above node compartment [message #676975 is a reply to message #676770] Tue, 07 June 2011 07:12 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

I have the following template for this in aspects/diagram/editparts/ComponentEditPart.xpt

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»

«AROUND createFigure FOR gmfgen::GenCompartment»
	«IF self.editPartClassName = 'xxxCompartmentEditPart'»
		«REM»By default titles are shown even if there are no TitleStyle, we need to switch it off«ENDREM»«-»
		«EXPAND xpt::Common::generatedMemberComment»
		public org.eclipse.draw2d.IFigure createFigure() {
			org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure result = (org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure) super.createFigure();
			result.setTitleVisibility(false);
			result.setBorder(null);
			return result;
		}
	«ELSE»
		«targetDef.proceed()»
	«ENDIF»
«ENDAROUND»


Replace xxxCompartmentEditPart with the editpart you want to hide the line. This should do the trick. I provided a way on how to do this in an Eclipse Wiki but I cannot find it anymore..

Ralph
Re: How to remove line above node compartment [message #677087 is a reply to message #676975] Tue, 07 June 2011 14:39 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hello, Thank you for you reply. But I don't understand your code. I have tried the first proposition. I have added the extension in the xml file and of cause implemented the class as you told us. I have attached my files as below. But I always have two annoying problems:
1.The service provider src.policies.EditPolicyProvider could not be activated.
2.Ignoring provider src.policies.EditPolicyProvider since it threw an exception or error in the provides() method.

In the java class, I replay your code "result = editPart instanceof XXXEditPart;" by "result = editPart instanceof PlaceEditPart;"
PlaceEditPart is the circle node which will have a small circle node (MarkEditPart) inside. Actually, I don't understand what this line of code is used for.

Do you have any idea?? Thank you very much.



import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartListener;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.PropertyHandlerEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;

import rdp.diagram.edit.parts.MarkEditPart;
import rdp.diagram.edit.parts.PlaceEditPart;

public class EditPolicyProvider implements IEditPolicyProvider {
	
	private EditPartListener compartmentSilence = new EditPartListener.Stub()
	{
		@Override
		public void childAdded(EditPart child, int index)
		{
			if(child instanceof CompartmentEditPart)
			{
				//remove top border
				((CompartmentEditPart)child).getFigure().setBorder(null);
			}
		}
	};

	@Override
	public void addProviderChangeListener(IProviderChangeListener arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean provides(IOperation operation) {
		// TODO Auto-generated method stub
		boolean result = false;
		if(operation instanceof CreateEditPoliciesOperation)
		{
			EditPart editPart = ((CreateEditPoliciesOperation)operation).getEditPart();
			result = true;
		}
		return result;
	}

	@Override
	public void removeProviderChangeListener(IProviderChangeListener arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void createEditPolicies(EditPart editPart) {
		// TODO Auto-generated method stub
		//editPart.installEditPolicy(EditPolicyRoles.PROPERTY_HANDLER_ROLE,
              //  new PropertyHandlerEditPolicy());
			if(editPart instanceof ShapeNodeEditPart)
			{
				editPart.addEditPartListener(compartmentSilence);
			}
		
		
	}
	

}

<extension
		point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
		<editpolicyProvider class="src.policies.EditPolicyProvider">
		<Priority
			name="Medium">
		</Priority>
		</editpolicyProvider>
	</extension>

Re: How to remove line above node compartment [message #677095 is a reply to message #677087] Tue, 07 June 2011 14:56 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you could do the following which is not the best but will help you without much effort.

1) Go to your generated plugin
2) Look for a package called xx.edit.parts
3) Open the code of the generated EditPart you want to modify
4) Search for the public org.eclipse.draw2d.IFigure createFigure() method

place the following inside this method:

result.setBorder(null);

5) Set the javadoc of this method to @generated no

This will mixup generated code with your handwritten one but is a quick and easy solution.

Ralph
Re: How to remove line above node compartment [message #677110 is a reply to message #677095] Tue, 07 June 2011 15:37 Go to previous message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
@Ralph, Could you please tell me what you mean by "generated plugin"? I have only find some Edit->Parts in XX.diagram. In fact, I have four dossier.
abc
abc.diagram
abc.edit
abc.editor
abc.tests

But I have no idea where the plugin->EditPart-createFigure() is ?

Thank you very much for your help.

Vincent
Previous Topic:Visual ID inconsistency after ecore namespace URI change
Next Topic:Diagram Model
Goto Forum:
  


Current Time: Fri Apr 19 21:11:15 GMT 2024

Powered by FUDForum. Page generated in 0.03775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top