Marama Code 125 ~ Detect shape updated info

November 23, 2011 Leave a comment

Did you know that you capture or be aware of the changes made in the diagram? For instance when user change a shape name or delete a shape? Yes you can. You just need this codes:

EventPropertyUpdateInfo info = this.propertyUpdated(notification); // get the update info

if (info == null) { return; } // ignore if no update

then,

MaramaDiagram diagram = info.getMaramaDiagram(); // get the diagram

if (diagram == null) { return; } // ignore if diagram doesn’t exist

or

MaramaShape shape = info.getMaramaShape(); // get the shape

if (shape == null) { return; } // ignore if shape doesn’t exist

Once you have captured the diagram/shape, you retrieve the new value that would like to minitor:

String testCategories = mu.getShapeString(sh, “testCategories”); // get the shape value

or, you can filter the shape to make sure you obtain the right shape

if (!sh.getShapeType().equals(“TestInfoShape”)) { return; } // ignore if not info shape

Categories: Java, Life on Marama

Marama Code 124 ~ Hide Your Custome Event Handler

November 21, 2011 Leave a comment

While reading marama WriteEventHandler codes, I found this method that helps to hide the event handlers until a specific icon is selected. Just beware that this method is only applicable for event handlers that were created in working workspace.

public boolean isRunnable() {
  final MaramaShape s = this.getSelectedShape();
    if (s == null) { return false; }

    if (isEventHandlerShapeType(s.getShapeType())) { return true; }
   else { return false; }
}

Categories: Uncategorized

Marama Code 123 ~ Set Custom Properties for Marama Shape

November 15, 2011 Leave a comment

Did you know that you can set the custom properties for each shape in marama, instead using the default properties. The advantages of using this method is you can load a pre-properties attribute rather than having empty space or pre-specified text.

To do this, you need to set a custom method in the event handler to load as soon as the method is invoke. Here is the code that need to be include in the event handler:

@Override
    public void setDiagram(final MaramaDiagram diagram) {
        super.setDiagram(diagram);

        for (final MaramaShapeType st : diagram.getViewType().getShapeTypes()) {
            st.setCustomProperties(new NewCustomProperties());
        }
    }

You need to create a custom properties class, for instance in this example, the NewCustomProperties class.

Categories: Uncategorized

Cross Compiling ~ Compile java code written in Mac in Windows

October 11, 2011 Leave a comment

I have a problem of compiling student assignment where a few of them have written it in Mac OS. Obviously, I’m using Windows.

The solution, delete the hidden file that come along with the programme, .classFile.java. If you can’t see it, just toggle the folder option to show hidden file.

Here is the link to my question.

Categories: Java

Marama Code 122 ~ How to create entity and its attributes in Marama tool model automatically

October 3, 2011 Leave a comment

Marama tool model is the diagram used to define tool project tool meta-model. To help user define the test tool (to be used with Marama model project), user need to specify the test tool shape properties. From there, a number of test entity (based on level of test) will be create automatically.

Due to the fact that when Marama tool model there is no underlying model created for it, the normal code to create shape cannot be applied to Marama tool model, shape definer and view definer. Here is the code to create and set the entity shape for Marama tool model:

MaramaShape testShape = this.createNewShape(MaramaConstants.ENTITY_METAMODEL_SHAPE, x, y, shapeWidth, shapeHeight); // create the entity shape
testShape.setPropertyValue(“name”, “TestSuite”); // set the attribute

MaramaShape testAttribute = this.createNewShape(MaramaConstants.ATTRIBUTE_SHAPE, x + 5, y + 5, shapeWidth, shapeHeight); // create the entity attribute shape
testAttribute.setPropertyValue(“iskey”, “key”); // set the attribute
testAttribute.setPropertyValue(“name”, “tid”);
testAttribute.setPropertyValue(“type”, “String”);

        processSubshapeAdded(testAttribute);

Hope you will understand it. Cheers.

p/s: credit to Jun for showing it to me

Categories: Java, Life on Marama

Marama Code 121 ~ How to get or set shape size

October 3, 2011 Leave a comment

Today I’ll explain how to get or set shape’s size. This can be done using this code:

Dimension maramaShape_size = maramaShape.getSize();

It will return the shape’s size in Dimension. You can set the shape’s size with this code:

Dimension newSize = new Dimension(int width, int height);

maramaShape.setSize(newSize);

Categories: Java, Life on Marama

Marama Code 120 ~ Creating XSLT Java Template

September 29, 2011 Leave a comment

I’m creating an XSLT file that create a customise properties view for a list of test in a diagram. The trouble that I faced during my template creation is the ‘<’ tag for ArrayList <String> alString = new ArrayList<String>();. XSLT would read the ‘<’ as one of the processing syntax instead. How to go around this problem?

After reading a couple post on the net and scrolling up and down w3school, I end up using HTML Number to deceive the XSLT processor. Take that XSLT. So, the next time you want to create XSLT template and the processor keep disturbing you, just replace it as HTML code.

Here is my syntax:

ArrayList &#60String&#62 alString = new ArrayList&#60String&#62();

for

ArrayList <String> alString = new ArrayList<String>();

Categories: Java, Life on Marama, XSLT

Marama Code 119 ~ Exported Properties

August 24, 2011 Leave a comment

As you may know by now, there are two types of entities in Marama. Yes, the first is Model Entity and the second is Shape Entity. This example is concern about retrieving and updating  exported properties in Shape Entity.

In Shape Definer (where you define what shape you like to represent your model), you can set the attribute display as Exported Properties. Exported Properties is different from Label, TextField n TextArea Shape. Exported Properties will not display the input in it. It will only appear in the Properties View.

Enough for the intro. The trouble with Exported Properties is that you can’t retrieve or update the value using normal shape command:

shape.setPropertyValue(“AttributeName”, “NewName”); or

shape.getPropertyValue(“AttributeName”).toString();

You need to use this command instead:

shape.getModelEntity.setPropertyValue(“AttributeName”, “NewName”); or

shape.getModelEntity.getPropertyValue(“AttributeName”).toString();

You need to add .getModelEntity to the shape because it’s referring directly to the Model Entity. The usual method access the Model Entity through Shape Entity.

Did you get it? Ya, it’s a bit confusing. Welcome to Marama!

Categories: Life on Marama

Marama Code 118 ~ Get multiple input from entity attribute

August 15, 2011 Leave a comment

Sometimes you will create an entity with a multiline attribute values. In my case an entity name Input with attribute name var (short for variable). The var can be more than one depending on the Input. So how do I retrieve this multipleline attribute values? Here is the code:

ArrayList<String> alVarInput = (ArrayList) inputShape.getPropertyValue(“var”);

All the var value will be stored in the alVarInput variable. You can now access the value.

Cheers.

Categories: Java, Life on Marama

Marama Code 117 ~ How to automatically create a shape

August 15, 2011 Leave a comment

Hi again. Do you need to create a shape after a certain action? I do. So I used this code to create a new shape automatically:

MaramaShape myNewShape = createNewShape(shapeType, shapeXPossition, shapeYPossition, shapeWidth, shapeHeight);

The code above will automatically create a new shape. If you want to add the shape information, such as name, you can use this code:

myNewShape.setPropertyValue(“name”, “New Shape Name”);

 

Categories: Java, Life on Marama
Follow

Get every new post delivered to your Inbox.