Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » NullPointException
NullPointException [message #815727] Thu, 08 March 2012 01:18 Go to next message
bjyjtdj znjhmyy is currently offline bjyjtdj znjhmyyFriend
Messages: 5
Registered: February 2012
Junior Member
Hi guys:
There is a problem with the generated code of GMF.
When I select a component in the Palette and then double-click on the Drawer, that means I do not click on the diagram editor. It throws the NullPointException.
at com.oncedq.model.process.diagram.edit.parts.ComponentEditPart$ComponentFigure.createContents(ComponentEditPart.java:445)
[i]Image image = ImageFactory.getImage(def.getIcon(), def.getBundleid());[/i]

How can I solve it?

Regards
Re: NullPointException [message #815937 is a reply to message #815727] Thu, 08 March 2012 08:23 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi,

did you check with the debugger where the NPE comes from?
Is def null or the icon or the bundleid?

Andreas
Re: NullPointException [message #815965 is a reply to message #815937] Thu, 08 March 2012 09:13 Go to previous messageGo to next message
bjyjtdj znjhmyy is currently offline bjyjtdj znjhmyyFriend
Messages: 5
Registered: February 2012
Junior Member
Hi:
It is the def==null. But if I check it with
if(def != null)

gmf will not add the figure on diagram editor, instead a rectangle with no content appear .
Re: NullPointException [message #816031 is a reply to message #815965] Thu, 08 March 2012 10:39 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Can you attach the ComponentEditPart code?
Re: NullPointException [message #816534 is a reply to message #816031] Fri, 09 March 2012 00:35 Go to previous messageGo to next message
bjyjtdj znjhmyy is currently offline bjyjtdj znjhmyyFriend
Messages: 5
Registered: February 2012
Junior Member
public class ComponentEditPart extends ShapeNodeEditPart {

/**
* @generated
*/
public static final int VISUAL_ID = 2001;

/**
* @generated
*/
protected IFigure contentPane;

/**
* @generated
*/
protected IFigure primaryShape;

// **** add

private Component component;

private ComponentStatus status;

public ComponentStatus getStatus() {
return status;
}

public void setStatus(ComponentStatus status) {
this.status = status;
}

public String getComponentId() {
return component.getId();
}

public Component getComponent() {
return component;
}

/**
* @generated
*/
public ComponentEditPart(View view) {
super(view);
component = (Component) this.getNotationView().getElement();
}

/**
* @generated
*/
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,new ComponentItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
}

/**
* @generated
*/
protected LayoutEditPolicy createLayoutEditPolicy() {

FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {

protected Command createAddCommand(EditPart child, EditPart after) {
return null;
}

protected Command createMoveChildCommand(EditPart child,
EditPart after) {
return null;
}

protected Command getCreateCommand(CreateRequest request) {
return null;
}
};
return lep;
}

protected IFigure createNodeShape() {
ComponentFigure figure = new ComponentFigure();
return primaryShape = figure;
}

/**
* @generated
*/
public ComponentFigure getPrimaryShape() {
return (ComponentFigure) primaryShape;
}

/**
* @generated
*/
protected boolean addFixedChild(EditPart childEditPart) {
if (childEditPart instanceof ComponentNameEditPart) {
((ComponentNameEditPart) childEditPart).setLabel(getPrimaryShape()
.getFigureComponentNameFigure());
return true;
}
return false;
}

/**
* @generated
*/
protected boolean removeFixedChild(EditPart childEditPart) {
if (childEditPart instanceof ComponentNameEditPart) {
return true;
}
return false;
}

/**
* @generated
*/
protected void addChildVisual(EditPart childEditPart, int index) {
if (addFixedChild(childEditPart)) {
return;
}
super.addChildVisual(childEditPart, -1);
}

/**
* @generated
*/
protected void removeChildVisual(EditPart childEditPart) {
if (removeFixedChild(childEditPart)) {
return;
}
super.removeChildVisual(childEditPart);
}

/**
* @generated
*/
protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
return getContentPane();
}

/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40);
return result;
}

/**
* Creates figure for this edit part.
*
* Body of this method does not depend on settings in generation model so
* you may safely remove <i>generated</i> tag and modify it.
*
* @generated
*/
protected NodeFigure createNodeFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new StackLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}

/**
* Default implementation treats passed figure as content pane. Respects
* layout one may have set for generated figure.
*
* @param nodeShape
* instance of generated figure class
* @generated
*/
protected IFigure setupContentPane(IFigure nodeShape) {
if (nodeShape.getLayoutManager() == null) {
ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
layout.setSpacing(5);
nodeShape.setLayoutManager(layout);
}
return nodeShape;
}

/**
* @generated
*/
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}

/**
* @generated
*/
protected void setForegroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setForegroundColor(color);
}
}

/**
* @generated
*/
protected void setBackgroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setBackgroundColor(color);
}
}

/**
* @generated
*/
protected void setLineWidth(int width) {
if (primaryShape instanceof Shape) {
((Shape) primaryShape).setLineWidth(width);
}
}

/**
* @generated
*/
protected void setLineType(int style) {
if (primaryShape instanceof Shape) {
((Shape) primaryShape).setLineStyle(style);
}
}

/**
* @generated
*/
public EditPart getPrimaryChildEditPart() {
return getChildBySemanticHint(ProcessVisualIDRegistry
.getType(ComponentNameEditPart.VISUAL_ID));
}

/**
* @generated
*/

public List getMARelTypesOnSource() {
List types = new ArrayList();
types.add(ProcessElementTypes.Connection_4001);
return types;
}

/**
* @generated
*/
public List getMARelTypesOnSourceAndTarget(
IGraphicalEditPart targetEditPart) {
List types = new ArrayList();
if (targetEditPart instanceof com.oncedq.model.process.diagram.edit.parts.ComponentEditPart) {
types.add(ProcessElementTypes.Connection_4001);
}
return types;
}

/**
* @generated
*/
public List getMATypesForTarget(
IElementType relationshipType) {
List types = new ArrayList();
if (relationshipType == ProcessElementTypes.Connection_4001) {
types.add(ProcessElementTypes.Component_2001);
}
return types;
}

/**
* @generated
*/
public List getMARelTypesOnTarget() {
List types = new ArrayList();
types.add(ProcessElementTypes.Connection_4001);
return types;
}

/**
* @generated
*/
public List getMATypesForSource(
IElementType relationshipType) {
List types = new ArrayList();
if (relationshipType == ProcessElementTypes.Connection_4001) {
types.add(ProcessElementTypes.Component_2001);
}
return types;
}

private int timeStamp = 0;
private int lastStatus;
/**
* 刷新流程界面
*/
//LUOHOUQI
@Override
protected void refreshVisuals() {

ComponentFigure figure = this.getPrimaryShape();
if (status != null) {
if(lastStatus!=status.getStatus()&&status.getStatus() == ComponentStatus.STOP){
figure.createContents(ComponentFigure.NO_LABEL);
figure.removeBorder();
super.refreshVisuals();
}
else if (status.getStatus() == ComponentStatus.RUNNING) {
timeStamp++;
figure.setBackgroundColor(ColorConstants.white);
if (timeStamp % 8 < 4)
figure.setBorderColor(ColorConstants.red);
else
figure.setBorderColor(ColorConstants.blue);
if(lastStatus!=status.getStatus())
figure.createContents(ComponentFigure.NO_LABEL);
super.refreshVisuals();

} else if (lastStatus!=status.getStatus()&&status.getStatus() == ComponentStatus.FINISHED) {
figure.setBorderColor(ColorConstants.green);
figure.createContents(ComponentFigure.SUCCESS_LABEL);
super.refreshVisuals();
} else if (lastStatus!=status.getStatus()&& status.getStatus() == ComponentStatus.ERROR) {
figure.removeBorder();
figure.setBackgroundColor(ColorConstants.red);
figure.createContents(ComponentFigure.FAIL_LABEL);
super.refreshVisuals();
}
lastStatus = status.getStatus();
}
else
super.refreshVisuals();
}

/**
* @generated
*/
public class ComponentFigure extends RectangleFigure {
public static final int NO_LABEL = 0;
public static final int SUCCESS_LABEL = 2;
public static final int FAIL_LABEL = 3;

private static final String SUCCESS_IMAGE_PATH = "icons/imagesCAGJMN7G.jpg";
private static final String FAILED_IMAGE_PATH = "icons/imagesCAJI64PE.jpg";
ImageFigure imageFigure;
LineBorder border = new LineBorder();
/**
* @generated
*/
private WrappingLabel fFigureComponentNameFigure;

/**
* @generated
*/
public ComponentFigure() {
GridLayout layoutThis = new GridLayout();
this.setLayoutManager(layoutThis);
this.setLineWidth(1);
createContents(NO_LABEL);
this.setBorder(this.border);
}

public void setBorderColor(Color color) {
this.border.setWidth(4);
this.border.setColor(color);
}

public void removeBorder() {
this.border.setWidth(1);
this.border.setColor(ColorConstants.darkGray);
}

/**
* Add image
*
* @param label
*
*/
private void createContents(int label) {
this.removeAll();

Image image2 = null;
switch (label) {
case SUCCESS_LABEL:
image2 = ImageFactory.getImage(SUCCESS_IMAGE_PATH,ProcessDiagramEditorPlugin.ID);
break;
case FAIL_LABEL:
image2 = ImageFactory.getImage(FAILED_IMAGE_PATH,ProcessDiagramEditorPlugin.ID);
break;
}
if (image2 != null) {
ImageFigure imageF = new ImageFigure(image2);
imageF.setSize(20, 20);
add(imageF, new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
}
ComponentDefinition def = ComponentManager.getComponentRegistry().get(component.getType());
if(def!=null){
Image image = ImageFactory.getImage(def.getIcon(), def.getBundleid());
imageFigure = new ImageFigure(image);
add(imageFigure, new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
fFigureComponentNameFigure = this.getFigureComponentNameFigure();
add(fFigureComponentNameFigure, new GridData(SWT.CENTER, SWT.BOTTOM, false, false, 1, 1));
}

}

/**
* @generated
*/
private boolean myUseLocalCoordinates = false;

/**
* @generated
*/
protected boolean useLocalCoordinates() {
return myUseLocalCoordinates;
}

/**
* @generated
*/
protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
myUseLocalCoordinates = useLocalCoordinates;
}

/**
* @generated
*/
public WrappingLabel getFigureComponentNameFigure() {
if (this.fFigureComponentNameFigure == null) {
fFigureComponentNameFigure = new WrappingLabel();
fFigureComponentNameFigure.setText("");
}
return fFigureComponentNameFigure;
}

}

}

[Updated on: Fri, 09 March 2012 00:36]

Report message to a moderator

Re: NullPointException [message #816853 is a reply to message #816534] Fri, 09 March 2012 10:41 Go to previous message
Michael Golubev is currently offline Michael GolubevFriend
Messages: 383
Registered: July 2009
Senior Member
Hello,

It is clearly not a GMF-T problem because the whole contents of the createContents(int) method is not generated, and NPE occurs from the results of the invocation of the non-generated ComponentManager.

Regards,
Michael
Previous Topic:org.eclipse.gmf.runtime.lite.svg
Next Topic:runtime extension of a GMF editor with additional elements
Goto Forum:
  


Current Time: Fri Apr 26 03:53:52 GMT 2024

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

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

Back to the top