From Optflux
Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 92: Line 92:
 
##:[[Image:release8.png]]
 
##:[[Image:release8.png]]
 
# To understand the structure and contents of the plugin.xml file, please refer to the [[The_Plugin.xml_File]] section.
 
# To understand the structure and contents of the plugin.xml file, please refer to the [[The_Plugin.xml_File]] section.
#: [[Image:release9.png]]
+
## We Provide an almost empty sample here just for reference [[File:plugin.xml]]
 +
##: [[Image:release9.png]]
 
# Filling the sub-directory structure with rational packages is the next step. Since AIBench/OptFlux development is based on 3 main artifacts we usually sub-divide our java classes by those 3 artifacts.
 
# Filling the sub-directory structure with rational packages is the next step. Since AIBench/OptFlux development is based on 3 main artifacts we usually sub-divide our java classes by those 3 artifacts.
 
## This means that '''we should create 3 sub-packages''', one for the OPERATIONS, one for the VIEWS and one for our DATATYPES.
 
## This means that '''we should create 3 sub-packages''', one for the OPERATIONS, one for the VIEWS and one for our DATATYPES.
Line 114: Line 115:
 
# Create your own @Datatype (s)  
 
# Create your own @Datatype (s)  
 
# Create your own Views for the desired Datatypes
 
# Create your own Views for the desired Datatypes
# Create your own GUIs for your Operations (Advanced - out of scope)
+
# Create your own GUIs for your Operations (Advanced)
  
 
== Create your first operation ==
 
== Create your first operation ==
Line 143: Line 144:
 
  }
 
  }
 
 
 
 
  '''@Port(direction=Direction.OUTPUT,order=3)'''                ''// use the port annotation with Direction = OUTPUT to note that this is an output of the operation''
+
  '''@Port(direction=Direction.OUTPUT,order=3)'''                "''// use the port annotation with Direction = OUTPUT to note that this is an output of the operation''"
 
  public int result(){
 
  public int result(){
 
  return this.x + this.y;
 
  return this.x + this.y;
Line 183: Line 184:
 
For a more clear understanding of AIBench explicit Datatypes, please refer [[Developers#AIBench_Datatypes | here]]
 
For a more clear understanding of AIBench explicit Datatypes, please refer [[Developers#AIBench_Datatypes | here]]
  
'''NOTE: ''' All this datatypes will be created inside the datatypes sub-package.
 
  
 
=== Creating a Simple Datatype ===
 
=== Creating a Simple Datatype ===
Line 207: Line 207:
 
  }
 
  }
  
* You can see that the datatype does not declare a STRUCTURE, this happens because, by default, all types are interpreted as SIMPLE.  
+
* You can see that the datatype does not declare a STRUCTURE, this happens because, by default all types are interpreted as SIMPLE.  
 
* This would be the same as adding the annotation:
 
* This would be the same as adding the annotation:
  
Line 217: Line 217:
 
=== Creating a List Datatype ===
 
=== Creating a List Datatype ===
  
In this step we will create a List Datatype. This will be a wrapper to a List of MySimpleDatatype:
+
In this step we will create a List Datatype. This will be a wrapper to a List of SimpleDatatype:
  
 
  @Datatype(structure=Structure.LIST)
 
  @Datatype(structure=Structure.LIST)
Line 241: Line 241:
 
* '''Notice that:'''
 
* '''Notice that:'''
 
** We have the ''@Datatype(structure=Structure.LIST)'' annotation, declaring this as a List Datatype;
 
** We have the ''@Datatype(structure=Structure.LIST)'' annotation, declaring this as a List Datatype;
** The method ''getMyList'' is annotated with '''@ListElements'''. This is mandatory for List datatypes, and tells AIBench how to access our list;
+
** The method ''getMyList'' is annotated with '''@ListElements'''. This is mandatory for List datatypes, and tells AIBench where to access our list;
  
 
=== Creating a Complex Datatype ===
 
=== Creating a Complex Datatype ===
Line 281: Line 281:
 
*** The '''name''' property will be used as a name to display in the Clipboard.
 
*** The '''name''' property will be used as a name to display in the Clipboard.
 
*** The '''order''' property is the relative order by which each element will be displayed.
 
*** The '''order''' property is the relative order by which each element will be displayed.
 
The OperationEnumeration was declared as follows:
 
 
public enum OperationEnumeration {
 
 
SUM,
 
SUBRACTION,
 
MULTIPLICATION,
 
DIVISION;
 
}
 
 
You should have your project looking like this:
 
 
[[Image:datatype1.png]]
 
  
 
=== Final Remarks Regarding datatypes ===
 
=== Final Remarks Regarding datatypes ===
  
 
* The ''@Datatype'' annotation contains several properties that can be specified. Please refer [[Developers#AIBench_Datatypes | here]] for that.
 
* The ''@Datatype'' annotation contains several properties that can be specified. Please refer [[Developers#AIBench_Datatypes | here]] for that.
* You don't need to declare the Datatypes in the '''plugin.xml''' file. These will be captured automatically by AIBench/OptFlux when used in Operations or placed in the Clipboard.
+
* You don't need to declare the Datatypes in the '''plugin.xml''' file. This will be capture automatically by AIBench/OptFlux when used in Operations or placed in the Clipboard.
  
 
== Creating your first View ==
 
== Creating your first View ==
 
Let us create our first simple view for you to understand the basics.
 
 
Some initial remarks:
 
 
* A view will have to be declared in the '''plugin.xml''' file;
 
* A view is usually a simple Java class extending the JPanel class;
 
* It is mandatory to have a unary constructor (with a unique argument), where that argument is an instance of the Datatype which the view will display.
 
 
We will create a view for our MySimpleDatatype, simply to display the value of the integer stored in each instance of this datatype:
 
 
public class MyViewForSimpleDatatype extends JPanel{
 
 
private static final long serialVersionUID = 1L;
 
 
MySimpleDatatype instanceToVisualize;
 
 
public MyViewForSimpleDatatype(MySimpleDatatype toView){
 
this.instanceToVisualize = toView;
 
initGUI();
 
}
 
 
public void initGUI(){
 
 
this.setLayout(new BorderLayout());
 
 
JTextArea textArea = new JTextArea();
 
textArea.setText(Integer.toString(instanceToVisualize.getNumber()));
 
textArea.setEditable(false);
 
 
this.add(textArea,BorderLayout.CENTER);
 
 
this.setVisible(true);
 
 
}
 
 
}
 
 
* '''Notice that:'''
 
** This view is a simple JTextArea containing the value of the integer stored in each instance of the MySimpleDatatype class;
 
** Notice the unary constructor  ''public MyViewForSimpleDatatype(MySimpleDatatype toView)'';
 
** The GUI initialization method (initGUI) should be called from the constructor. AIBench will invoke this constructor by default.
 
 
=== Declaring the view in the plugin.xml file ===
 
 
Declaring a view in the '''plugin.xml''' is a mandatory step. It is an easy process:
 
 
<extension
 
    uid="aibench.workbench"
 
    name="aibench.workbench.view" >
 
    <view
 
            name="SimpleDatatype View"
 
            datatype="myplugin4optflux.datatypes.MySimpleDatatype"
 
            class="myplugin4optflux.views.MyViewForSimpleDatatype"
 
    />
 
</extension>
 
 
This entry should be added to the original plugin.xml file that should now look like this:
 
 
[[Image:view1.png]]
 
 
== Creating a more complex operation and gluing things together ==
 
 
Now we will create a more complex operation to interact with the recently created Datatypes and View:
 
 
We will name it ''MyMapOperation'' and place it inside the operations sub-package.
 
 
The code for the operation goes as follows:
 
 
@Operation(description="This operation creates a complex datatype containing an operator, a list and the result of applying the operator to each element of the list sequentially")
 
public class MyMapOperation {
 
 
OperationEnumeration operation;
 
int[] elements;
 
 
@Port(name="Operation",direction=Direction.INPUT,order=1)        '' // deciding on the operator to use - INPUT''
 
public void setOperator(OperationEnumeration operation){
 
this.operation = operation;
 
}
 
 
@Port(name="Elements",direction=Direction.INPUT,order=2)            ''// defining the list of elements on which to apply the operator - INPUT''
 
public void setList(int[] elements){
 
this.elements = elements;
 
}
 
 
@Port(direction=Direction.OUTPUT,order=3)                                        ''// the output port''
 
public MyComplexDatatype getResult(){
 
int res = elements[0];
 
 
for(int i=1;i<elements.length;i++){
 
if(operation.equals(OperationEnumeration.SUM))
 
res += elements[i];
 
else if(operation.equals(OperationEnumeration.SUBRACTION))
 
res -= elements[i];
 
else if(operation.equals(OperationEnumeration.MULTIPLICATION))
 
res *= elements[i];
 
else res /= elements[i];
 
}
 
 
List<MySimpleDatatype> listOfSimples = new ArrayList<MySimpleDatatype>();
 
for(int elem: elements)
 
listOfSimples.add(new MySimpleDatatype(elem));                    ''// create a list of MySimpleDatatype, one for each integer''
 
 
MyListDatatype list = new MyListDatatype(listOfSimples);              ''// create an instance of MyListDatatype. A wrapper for the list created above''
 
 
MySimpleDatatype result = new MySimpleDatatype(res);                ''// create an instance of MySimpleDatatype to store the result''
 
 
MyComplexDatatype toReturn = new MyComplexDatatype(list, operation, result); ''// create an instance of MyComplexDatatype to hold all the the information above''
 
 
return toReturn;  ''// return the instance of MyComplexDatatype to the Clipboard''
 
}
 
 
}
 
 
The above example should be self-explanatory to any Java developer. We are applying the selected operation sequentially from the first element of the list to the next one, until the list of elements end.
 
 
=== Declaring the new operation in the plugin.xml file ===
 
 
We can not forget to declare the new operation in the '''plugin.xml''' file:
 
 
<extension
 
        uid="aibench.core"
 
        name="aibench.core.operation-definition"
 
        class="myplugin4optflux.operations.MyMapOperation">
 
        <operation-description
 
                  name="My Map Operation"
 
                  uid= "myplugin_mymapoperation"
 
                  path="20@Plugins/2@MyOperations"
 
          />
 
</extension>
 
 
If everything went well, we should now be able to run OptFlux using the [[Developers_First_Plugin#Creating_a_Run_Configuration_to_run_OptFlux_from_within_Eclipse | previously defined Run Configuration]] and test our new Operation:
 
 
=== Testing the new operation ===
 
 
* After running OptFlux, we should now be able to see a new operation in the menu:
 
*: [[Image:complex1.png]]
 
* The Input dialog for the new operation is generated and we will use it with the options depicted bellow:
 
*: [[Image:complex2.png]]
 
* We can now observe the Clipboard containing an instance of our '''MyComplexDatatype''':
 
*: [[Image:complex3.png]]
 
** Notice the structure of the complex datatype being reflected in the Clipboard. The instance contains three levels at the root:
 
*** An ''Operation'' of the type: OperationEnumeration;
 
*** A ''List of Elements'' of the type: MyListDatatype;
 
**** The list of elements list all the instances of ''MySimpleDatatype'' therein contained;
 
*** A ''Result'' of the type: MySimpleDatatype;
 
** This structure perfectly reflects the one that we defined in the Java code. This structure can be as complex as the programmer wishes.
 
* Finally by pressing one of the instances of ''MySimpleDatatype'' in the Clipboard, the new View will be launched in the right panel. You can see that the default view is also there. The programmer can add as many different views as desired to a given Datatype
 
*: [[Image:complex4.png]]
 

Please note that all contributions to Optflux may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Optflux:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)