Main Menu
Login
SSL SecureMode
Username:
Password:  
Lost Password?
Register now!
ChangeVision Members Map
Search
Forum Index   -   Topic Index
   How to use of Astah (Pro/SysML/GSN/Com)
     rapidly create operations/attributes part2

Flat Previous Topic | Next Topic
Poster Thread
Joba
Posted on: 2012/10/16 15:58
Developer
Joined: 2006/6/6
From:
Posts: 969
Re: rapidly create operations/attributes part2
Hi, thank you for your additional post.

Unfortunately there is no way to customize to do so, but I'd suggest you to use "Script Plug-in" which is the easiest way to access Astah via scripting languages. For details and download, please visit Astah Script Plug-in page. We've created java script for you, so here's the step to use.

1. Install Astah Script Plug-in
2. In the structure tree (Top left pane of Astah) select Attributes you want to change the setter/getter names of
3. Go to [Tool] - [Script], copy and paste the java script below (Customize the scripts in red below) and run it

importPackage(com.change_vision.jude.api.inf.editor);
importPackage(com.change_vision.jude.api.inf.model);

run();

function run() {
     var attributes = getSelectedAttributesInProjectView();
     
     if (attributes.length === 0) {
         println('Please select attributes you want to add setter/getter in StructureTree');
         return;
     }
     
     TransactionManager.beginTransaction();
     for (var i in attributes) {
         addSetterGetter(attributes[i]);
     }
     TransactionManager.endTransaction();
 }

function getSelectedAttributesInProjectView() {
     var attributes = [];
     var projectViewManager = astah.getViewManager().getProjectViewManager();
     var selectedEntities = projectViewManager.getSelectedEntities();
     for (var i in selectedEntities) {
         var entity = selectedEntities[i];
         if (entity instanceof IAttribute) {
             attributes.push(entity);
             println('HIT: ' + entity.getName());
         }
     }
      
     return attributes;
}

function addSetterGetter(attribute) {
     createSetter(attribute.getOwner(), attribute);
     createGetter(attribute.getOwner(), attribute);
}

function createSetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     var name =  convertToSetterName(iAtt.getName());
     println('createSetter: ' + name);
     var iOperation = bme.createOperation(iClass, name, 'void');
     bme.createParameter(iOperation, "parameter1", iAtt.getType());
}

function convertToSetterName(attName) {
     //do something
     return "set_"+ attName;
}

function createGetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     bme.createOperation(iClass, convertToGetterName(iAtt.getName()), iAtt.getType().getName());
}

function convertToGetterName(attName) {
     //do something
     return "get_"+ attName;
}


Hope this helps. If you have any further questions, let us know.

Cheers,
SJ
Flat Previous Topic | Next Topic

Subject Poster Date
   rapidly create operations/attributes part2 xenocide 2012/10/15 15:46
   » Re: rapidly create operations/attributes part2 Joba 2012/10/16 15:58