Adding comment to ModelElement via IComment

Hi all,

I am struggling a bit understanding how to add a comment to an element;

	public IctElementComment(IModelElement element, String comment, Date date){
	
			
			if(element==null||comment.equals(null)){
				eCheck.sendMessage(MessageType.ERROR,
						"IctElementComment() - specify element and comment please");
			}
			
			factory = IModelElementFactory.instance();
			IComment newComment = factory.createComment();
			
			newComment.setAuthor("ictengineer");
			newComment.setDateTime(date.toString());
			newComment.setName(element.getName()+" - "+comment);
			newComment.setDocumentation("Documentation");
			
			try{
			((IComment)element).addComment(newComment);
			
		} catch (Exception ex) {
			eCheck.sendMessage(MessageType.ERROR,
					"IctElementComment() - " + ex.getMessage() + "" + ex.getLocalizedMessage());
		}
	}

I cannot find any info other that the API detail.

Any help or pointers will be appreciated.

George

Hi all again,

I am starting to get a result. However:

  1. The comment does seem to be persistent, BUT it is NOT attached to the elements and NOT visible in the GUI
  2. I cannot seen to change the Author (needs to be special one)
  3. I cannot seem to change the date ( I need a run date, not the system datetime of the instant)

The following code is what I currently have:

 
public IctComment(IModelElement element, String comment,
			String body, Date date) {
	
		try {

			if (element == null || comment.equals(null) || body.equals(null)) {
				eCheck.sendMessage(MessageType.ERROR,
						"IctComment() - specify element and comment please");
			}
			
			IModelElement c = element
					.createChild(IModelElementFactory.MODEL_TYPE_COMMENT);
		
			((IComment) c).setName(comment);
			((IComment) c).setDocumentation(body);

		} catch (Exception ex) {
			eCheck.sendMessage(
					MessageType.ERROR,
					"IctComment() - " + ex.getMessage() + " "
							+ ex.getCause());
		}
	}		

Any help will be appreciated,

Thanks,

George.

Hi all,

Need to bump this, I still have issues!