How to add listeners to ProjectManager

Hello,

How could I know about new projects opened or created by user?
What I get from ApplicationManager.instance().getProjectManager().getProject() if there are no opened projects.

Regards,
Aleksei

Hi Aleksei,

Thanks for your post. As you know, IProjectListener should be added into IProject. ProjectManager.getProject() will not return null.
Here is a simple test by our engineers:

public void loaded(VPPluginInfo aArg0);
add project listener by the following code:

    public void loaded(VPPluginInfo aArg0) {
        IProject lProject = ApplicationManager.instance().getProjectManager().getProject();
        System.out.println(">>> here: " + lProject);

        lProject.addProjectListener(new IProjectListener() {
            public void projectAfterOpened(IProject aArg0) {
                System.out.println(">>> project after opened: " + aArg0.getName());
            }
            public void projectNewed(IProject aArg0) {
                System.out.println(">>> project newed: " + aArg0.getName());
            }
            public void projectOpened(IProject aArg0) {
                System.out.println(">>> project opened: " + aArg0.getName());
            }
            public void projectPreSave(IProject aArg0) {
                System.out.println(">>> project pre save: " + aArg0.getName());
            }
            public void projectRenamed(IProject aArg0) {
                System.out.println(">>> project renamed: " + aArg0.getName());
            }
            public void projectSaved(IProject aArg0) {
                System.out.println(">>> project saved: " + aArg0.getName());
            }
        });
    }

Our engineers only added listener once, the listener can listen all project new/open/etc…
Therefore, if you want to listen the project(s), you simply need to add the listener in VPPlugin’s implemenation class.

Hope this helps. Please let me know if there is any further inquiry.

Best regards,
Lilian Wong

Hello Lilian,

Thanks for your suggestions. I planning to make plugin with options user could edit. Are there ways to store plugin parameters using openAPI or I need simply save and load to/from selfcreated file.

Regards,
Aleksei

Hi Aleksei,

Thanks for replying. IProject supports IProjectProperties that can save/load string values:

            IProject lProject = ApplicationManager.instance().getProjectManager().getProject();
            IProjectProperties lProjectProperties = lProject.getProjectProperties();
            // set
            lProjectProperties.setProperty("CustomizedVariable", new SimpleDateFormat("MMM dd, yyyy hh:mm:ss").format(new Date()));
            // get
            lProjectProperties.getProperty("CustomizedVariable");

Those properties will be saved in project file (.vpp).
By the way, the variable name must contains letter, digit or _ only. It cannot contain any space or other character, or saving project will fail and make the project corrupted (all models will lose).

If you need to save/load in other file, you may want to know location of current project file. You can get from IProject.getProjectFile().

If you want to save in you plugin’s folder (VPSuite/plugins/{your_plugin_folder}, you can get it from VPPlugin.loaded(VPPluginInfo), VPPluginInfo.getPluginDir()

Hope these help. Please let me know if there is any further question.

Best regards,
Lilian Wong

Hello Lilian,
Please review my code below


if (modelElement.getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS))  {    
                IClass lClass = (IClass)modelElement;
		IOperation lCopyConstructor = lClass.createOperation();
		lCopyConstructor.setName(lClass.getName());
		lDetail = IModelElementFactory.instance().createDotNetOperationCodeDetail();
		lDetail.setMethodKind(IDotNetOperationCodeDetail.METHOD_KIND_CONSTRUCTOR);
		lCopyConstructor.setDotnetCodeDetail(lDetail);
		lCopyConstructor.setVisibility(IClass.VISIBILITY_PRIVATE);
		IParameter lParameter = lCopyConstructor.createParameter();
		lParameter.setType(lClass);
		lParameter.setTypeModifier(IParameter.TYPE_MODIFIER_AMP);
		lParameter.setName("test");
//		IDotNetParameterCodeDetail lParameterCodeDetail = lParameter.getDotnetCodeDetail();
//		lParameterCodeDetail.setConst(true);
}

When code was executed I get class with copy constructor like private ClassName(ClassName & test). If I uncomment two lines I get the same code but I want to get private ClassName(const ClassName & test). How to set const to parameters?

Regards,
Aleksei

Hi Aleksei,

Thanks for your inquiry. I’ve passed the details to our engineers to check. If there is any feedback, I’ll come back you immediately.

Best regards,
Lilian Wong

Hi Aleksei,

I would like to let you know that your code is correct, just because our application does not support showing code details on parameters. We enhanced the application to support showing code details on application, please update your product to latest patch (20100127a or later) by “VP Suite Update”. For details about updating to latest patch, please visit:

Please let me know it there is any inquiry.

Best regards,
Lilian Wong

Hi Lilian,

I’ve just updated to (Build 20100127a) but do not see any differences. Can’t set const to parameter using openAPI.

Hi Aleksei,

Sorry for my late response. I checked with our engineers that you can edit your code as shown as image for setting Parameter Code Details as “const”. Hope this solves your problem.

Best regards,
Lilian Wong


set_const_to_parameter.png