Need Help how to change color of the shape programatically [message #6584] |
Fri, 04 August 2006 09:01  |
Eclipse User |
|
|
|
Originally posted by: senthil.periasamy.flextronicssoftware.com
Hi , I have gone through the "Diagram Services Layer -
How-to-guide" for GMF and in that guide there are sample code related to
1.How to open multiple read-only views on a diagram.
2.How to change the color of a shape dynamically.
i have tried used the code and failed in that Following are the steps
which i have done
1.I have gone through the cheat sheet help and created the mind map gmf
example 2.I have created a mind map gmf diagram 3.I am able to drag and
drop the palatte elements now i wanted to change the color of the shape.
4. Inside my "org.eclipse.gmf.examples.mindmap.diagram" plugin project i
have updated plugin.xml with the following lines <extension
id="TraceEditPolicyProvider"
name="TraceEditPolicyProvider"
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders ">
<editpolicyProvider
class=" org.eclipse.gmf.examples.mindmap.diagram.edit.policies.Trace DiagramEditPolicyProvider ">
<Priority
name="Low">
</Priority>
<object
class=" org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art "
id="TraceEditPart">
<method name="getViewer()">
<value
class=" org.eclipse.gmf.examples.mindmap.diagram.edit.policies.Trace DiagramGraphicalViewer "/>
</method> </object>
<context
editparts="TraceEditPart">
</context>
</editpolicyProvider>
</extension>
5.Inside the "org.eclipse.gmf.examples.mindmap.diagram" plugin project and
under the package "org.eclipse.gmf.examples.mindmap.diagram.edit.policies"
i have included the a class TraceDiagramEditPolicy which extends fronm
the GraphicalEditPolicy the code which i copied from the guide.
6.Now i tried to run mindmap sample and then noticed the color of shape is
not getting changed
Please let me know how to use the sample codes given in the help guide for
1.How to open multiple read-only views on a diagram.
2.How to change the color of a shape dynamically.
Regards
Senthil
|
|
|
|
|
Re: Need Help how to change color of the shape programatically [message #20782 is a reply to message #17347] |
Wed, 16 August 2006 10:13   |
Eclipse User |
|
|
|
Originally posted by: senthil.periasamy.flextronicssoftware.com
My goal is to have read only view of the diagram and to chnage shape of
the color in the diagram which was shown in a read only viewer
I refered to Cheet Sheet Help for the GMF Frame Work and i have created
MindMap GMF example which has the follwing plugins
1. org.eclipse.gmf.examples.mindmap
2. org.eclipse.gmf.examples.mindmap.diagram
3. org.eclipse.gmf.examples.mindmap.edit
4. org.eclipse.gmf.examples.mindmap.editor
I am able to run mindmap project and i am able to draw the diagram for the
MindMap
I refered to Diagram Services Layer - How to Guide according to this
document i have done the following steps.
Step 1
under the " org.eclipse.gmf.examples.mindmap.diagram" plugin i have
inserted following lines inside the plugin.xml
<extension point="org.eclipse.ui.views">
<category
id="org.eclipse.gmf.examples.mindmap.diagram.part"
name="Article">
</category>
<view id="org.eclipse.gmf.examples.mindmap.diagram.part.labelview "
name="Label View"
icon="icons\view.gif"
class="org.eclipse.gmf.examples.mindmap.diagram.part.LabelView "/>
</extension>
Step 2
Under the package "org.eclipse.gmf.examples.mindmap.diagram.part" i have a
class called LabelView.java
package org.eclipse.gmf.examples.mindmap.diagram.part;
import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gmf.examples.mindmap.diagram.edit.parts.MapEditP art;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart ;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEdit Part;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack ;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalVie wer;
import
org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPar tService;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
class MDiagramGraphicalViewer extends DiagramGraphicalViewer
{
// no implementation. This class is extended from
// DiagramGraphicalViewer for type information only.
}
public class LabelView extends ViewPart {
//private Label label;
/*public LabelView() {
super();
}*/
/*public void setFocus() {
label.setFocus();
}
public void createPartControl(Composite parent) {
label = new Label(parent, 0);
label.setText("Hello World");
}*/
private GraphicalViewer viewer;
public void createPartControl(Composite comp) {
viewer = new MDiagramGraphicalViewer();
viewer.createControl(comp);
viewer.getControl().setBackground(ColorConstants.listBackgro und);
DiagramEditDomain editDomain = new DiagramEditDomain(null);
editDomain.setCommandStack(new DiagramCommandStack(editDomain));
viewer.setEditDomain(editDomain);
viewer.setRootEditPart(new DiagramRootEditPart());
viewer.setEditPartFactory(EditPartService.getInstance());
// viewer.
// setContents(ViewService.getInstance().incarnateView(MapEditP art.getView()));
//View myView = MapEditPart.getView();
//myView.setVisible(true);
viewer.setContents(MapEditPart.getView());
// viewer.setContents(new MapCanonicalEditPolicy().showDiagram());
viewer.flush();
// now disable editing
Assert.isTrue(viewer.getContents() instanceof DiagramEditPart);
DiagramEditPart diagEP = (DiagramEditPart) viewer.getContents();
diagEP.disableEditMode();
// TODO Auto-generated method stub
return;
}
//@Override;
public void setFocus() {
// TODO Auto-generated method stub
viewer.getControl().setFocus();
}
}
Step 4
Under the package "org.eclipse.gmf.examples.mindmap.diagram.edit.parts" i
have a class called MapEditPart , included a static variable of type View
to get the instance of the View and exposed to the outside using static
method which i am using to set in my Read only Viewer
Step 3
I ran the MindMap Project i am able to see the diagram in the view in read
only mode but the diagram is very very tiny when compared to original
diagram - This is problem i am facing related to the read only view of the
diagram
Coming back to changing the color of the shape in the run time
Step 1
under the " org.eclipse.gmf.examples.mindmap.diagram" plugin i have
inserted following lines inside the plugin.xml
<extension
id="MindmapEditPolicyProvider"
name="MindmapEditPolicyProvider"
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders ">
<editpolicyProvider
class=" org.eclipse.gmf.examples.mindmap.diagram.edit.policies.Mindm apEditPolicyProvider ">
<Priority
name="Low">
</Priority>
<object
class=" org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art "
id="MapEditPart">
<method name="getViewer()">
<value
class=" org.eclipse.gmf.examples.mindmap.diagram.part.MDiagramGraphi calViewer "/>
</method>
</object>
<context
editparts="MapEditPart">
</context>
</editpolicyProvider>
</extension>
step 2
Under the package "org.eclipse.gmf.examples.mindmap.diagram.edit.policies"
i have the following class
package org.eclipse.gmf.examples.mindmap.diagram.edit.policies;
import java.awt.event.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.draw2d.MouseMotionListener;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.swt.graphics.RGB;
public class MindmapEditPolicy extends GraphicalEditPolicy {
private class TraceMouseMotionListener extends MouseMotionListener.Stub {
private Color color;
/**
* @see
com.ibm.etools.draw2d.MouseMotionListener#mouseEntered(Mouse Event)
*/
public void mouseEntered(MouseEvent me) {
color = getHostFigure().getForegroundColor();
getHostFigure().setForegroundColor(new Color(null, new RGB(255, 0, 0)));
getHostFigure().invalidate();
}
/**
* @see com.ibm.etools.draw2d.MouseMotionListener#mouseExited(MouseE vent)
*/
public void mouseExited(MouseEvent me) {
getHostFigure().setForegroundColor(color);
getHostFigure().invalidate();
}
}
/** mouse motion listener for the owner shape and handles */
private TraceMouseMotionListener myMouseListener = new
TraceMouseMotionListener();
/**
*
* @see org.eclipse.gef.EditPolicy#activate()
*/
public void activate() {
super.activate();
getHostFigure().addMouseMotionListener(myMouseListener);
}
/**
*
* @see org.eclipse.gef.EditPolicy#deactivate()
*/
public void deactivate() {
getHostFigure().removeMouseMotionListener(myMouseListener);
super.deactivate();
}
}
Step 3
As per your suggestion i have the following class under the
package "org.eclipse.gmf.examples.mindmap.diagram.edit.policies"
package org.eclipse.gmf.examples.mindmap.diagram.edit.policies;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeL istener;
import
org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEdit PolicyProvider;
public class MindmapEditPolicyProvider implements IEditPolicyProvider {
public void createEditPolicies(EditPart editPart) {
// TODO Auto-generated method stub
editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new
MindmapEditPolicy());
}
public void addProviderChangeListener(IProviderChangeListener listener) {
// TODO Auto-generated method stub
}
public boolean provides(IOperation operation) {
// TODO Auto-generated method stub
return false;
}
public void removeProviderChangeListener(IProviderChangeListener
listener) {
// TODO Auto-generated method stub
}
}
Step 4
I ran the mindmap project for debugging i put a break point in
createeditpolices the break point is hitting and i put another break
point inside my logic
public void mouseEntered(MouseEvent me) {
color = getHostFigure().getForegroundColor();
getHostFigure().setForegroundColor(new Color(null, new RGB(255, 0, 0)));
getHostFigure().invalidate();
}
the break point is not hitting and one more thing i want to make note
here in the plugin.xml i have a line called
<method name="getViewer()">
<value
class=" org.eclipse.gmf.examples.mindmap.diagram.part.MDiagramGraphi calViewer "/>
MindmapEditPolicyProvider but i dnt have an method "getViewer" in my
MDiagramGraphicalViewer class.
and my shape is not getting highlighted
please help in resloving the above issues
I want to know where i can found the help for the above problems other
eclipse.org and default help guide which comes with the GMF Framework is
there any docs avaliable related to GMF Programming please let me know.
Regards
Senthil.
|
|
|
Re: Need Help how to change color of the shape programatically [message #20890 is a reply to message #20782] |
Wed, 16 August 2006 12:27  |
Eclipse User |
|
|
|
Hello senthil,
> I ran the MindMap Project i am able to see the diagram in the view in
> read
> only mode but the diagram is very very tiny when compared to original
Just an idea – try to set Units to Himetric ( http://wiki.eclipse.org/index.php/GMF_GenModel_Hints#Diagram _group)
and regenerate the code.
> public void activate() {
> super.activate();
> getHostFigure().addMouseMotionListener(myMouseListener);
> }
Can you check that this method was called, myMouseListener was successfully
installed and your edit-policy was not de-activated? If yes, myMouseListener
should be called by hostFgirure.
> the break point is not hitting and one more thing i want to make note
> here in the plugin.xml i have a line called
>
> <method name="getViewer()">
> <value
> class=" org.eclipse.gmf.examples.mindmap.diagram.part.MDiagramGraphi cal
> Viewer"/>
> MindmapEditPolicyProvider but i dnt have an method "getViewer" in my
> MDiagramGraphicalViewer class.
I think this is a method from IGraphicalEditPart, but it’s better to check
it with the runtime team.
BTW, do you have any exceptions logged into eclipse log?
-----------------
Alex Shatalin
|
|
|
Powered by
FUDForum. Page generated in 0.03458 seconds