Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/dynamicview/figure/OperationPropertyFigure.java

Go to the documentation of this file.
00001 
00015 package m2m.frontend.dynamicview.figure;
00016 
00017 import java.util.ArrayList;
00018 
00019 import m2m.backend.structure.Operation;
00020 import m2m.frontend.dynamicview.model.*;
00021 
00022 import org.eclipse.draw2d.ActionEvent;
00023 import org.eclipse.draw2d.ActionListener;
00024 import org.eclipse.draw2d.CheckBox;
00025 import org.eclipse.draw2d.ColorConstants;
00026 import org.eclipse.draw2d.Figure;
00027 import org.eclipse.draw2d.Label;
00028 import org.eclipse.draw2d.ToolbarLayout;
00029 import org.eclipse.draw2d.XYLayout;
00030 import org.eclipse.draw2d.geometry.Rectangle;
00031 
00032 
00033 import m2m.backend.buildingblocks.BuildingBlock;
00034 import m2m.backend.buildingblocks.BuildingBlocksManager;
00035 
00036 public class OperationPropertyFigure extends Figure implements ActionListener
00037 {
00041         private Schema schema;
00045     private XYLayout layout;
00049     private Label labelName = new Label();
00053     private Label labelDescriptionBlock = new Label();
00057     private ArrayList<BuildingBlock> blockList = new ArrayList<BuildingBlock>();
00061     private ArrayList<CheckBox> checkBoxesBlockList = new ArrayList<CheckBox>();
00065     private CheckBox checkBoxSelectAll = new CheckBox("Select for all same operation");
00069         private GraphicOperation graphicOperation;
00070     
00071         
00075     public OperationPropertyFigure(Schema schema) 
00076     {
00077         this.schema = schema;
00078         
00079         /* Set the type of layout */
00080         layout = new XYLayout();
00081         setLayoutManager(layout);
00082         
00083         /* Initialisation of the labelName */
00084         labelName.setForegroundColor(ColorConstants.black);
00085         add(labelName, ToolbarLayout.VERTICAL); 
00086         setConstraint(labelName, new Rectangle(0, 0, -1, -1));
00087         labelName.setText("Unknown");
00088 
00089         /* Initialisation of the labelDescriptionBlock */
00090         labelDescriptionBlock.setForegroundColor(ColorConstants.black);
00091         add(labelDescriptionBlock, ToolbarLayout.VERTICAL); 
00092         setConstraint(labelDescriptionBlock, new Rectangle(0, 150, -1, -1));
00093         labelDescriptionBlock.setText("Unknown");
00094         
00095         /* Initialisation of the checkBoxSelectAll */
00096         add(checkBoxSelectAll);
00097         setConstraint(checkBoxSelectAll, new Rectangle(0, 30, -1, -1));
00098         checkBoxSelectAll.addActionListener(this);
00099         
00100         /* Initialisation of the figure */
00101         setOpaque(true);     
00102         setBackgroundColor(ColorConstants.menuBackground);
00103         setForegroundColor(ColorConstants.menuForeground);
00104     }
00105     
00106     
00111     public void setProperty(GraphicOperation graphicOperation)
00112     {
00113         
00114         int space = 30;
00115         this.graphicOperation = graphicOperation;
00116         labelName.setText("Name : " + graphicOperation.getName());
00117 
00118                 if(((Operation)(graphicOperation.getElement())).getBlock() == null) {
00119                 if(getChildren().contains(checkBoxSelectAll))
00120                         remove(checkBoxSelectAll); 
00121                 if(getChildren().contains(labelDescriptionBlock))
00122                         remove(labelDescriptionBlock); 
00123                 for(CheckBox cb : checkBoxesBlockList)
00124                         if(getChildren().contains(cb))
00125                                 remove(cb);     
00126                         System.out.println("There is no bloc for this operation. Please check the lib path.");
00127                 }       
00128                 else {
00129                         add(labelDescriptionBlock, ToolbarLayout.VERTICAL); 
00130                 for(CheckBox cb : checkBoxesBlockList)
00131                         if(getChildren().contains(cb))
00132                                 remove(cb);
00133                         checkBoxesBlockList.removeAll(checkBoxesBlockList); 
00134                         /* Get all possible BuildingBlocks for this operation */
00135                 blockList.removeAll(blockList);
00136                 Operation opElement = (Operation)(graphicOperation.getElement());               
00137                 for(BuildingBlock block : BuildingBlocksManager.getInstance().blockNamed(opElement.getOpName()))
00138                         if(block.numType() == schema.getDataType())
00139                                 blockList.add(block);                                           
00140                 
00141                 if(blockList.size() != 0)
00142                 {
00143                         /* Add and initialize the checkBoxSelectAll */
00144                         add(checkBoxSelectAll); 
00145                         setConstraint(checkBoxSelectAll, new Rectangle(0, space, -1, -1));
00146                         checkBoxSelectAll.setSelected(graphicOperation.getSelectAll());
00147                         space += 15;
00148                 }               
00149                 
00150                 /* Create CheckBoxes for the blockList */
00151                 for(BuildingBlock block : blockList)
00152                 {               
00153                         checkBoxesBlockList.add(new CheckBox(block.entityName()));
00154                         add(checkBoxesBlockList.get(blockList.indexOf(block)));
00155                         setConstraint(checkBoxesBlockList.get(blockList.indexOf(block)), new Rectangle(20, space, -1, -1));
00156                         checkBoxesBlockList.get(blockList.indexOf(block)).addActionListener(this);
00157                         if(opElement.getBlock() == block)
00158                                 checkBoxesBlockList.get(blockList.indexOf(block)).setSelected(true);
00159                         space += 15;
00160                 }
00161                         
00162                 if(!blockList.contains(opElement.getBlock()))
00163                         {
00164                                 /* Set the default buildingBlock */
00165                                 checkBoxesBlockList.get(0).setSelected(true);
00166                                 opElement.setBlock(blockList.get(0));
00167                         }
00168                         
00169                         setConstraint(labelDescriptionBlock, new Rectangle(0, space+15, -1, -1));
00170                         labelDescriptionBlock.setText("--------------------------------------\n" +
00171                                                                                   "Function name\t : " + opElement.getBlock().functionName() + "\n" +
00172                                                                                   "Entity name\t : " + opElement.getBlock().entityName() + "\n" +
00173                                                                                   "Author\t\t : " + opElement.getBlock().author() + "\n" +
00174                                                                                   "Description\t : " + opElement.getBlock().description()+ "\n" +
00175                                                                                   "--------------------------------------\n");
00176                 }
00177     }
00178 
00179 
00184         @Override
00185         public void actionPerformed(ActionEvent arg) 
00186         {
00187                 /* Update the state of all checkBoxesBlockList */
00188                 if(checkBoxesBlockList.contains(arg.getSource()))
00189                         for(int i = 0; i < blockList.size(); i++)
00190                                 if(checkBoxesBlockList.get(i) == arg.getSource())
00191                                 {
00192                                         checkBoxesBlockList.get(i).setSelected(true);
00193                                         ((Operation)(graphicOperation.getElement())).setBlock(blockList.get(i));
00194                                         labelDescriptionBlock.setText("--------------------------------------\n" +
00195                                                           "Function name\t : " + ((Operation)(graphicOperation.getElement())).getBlock().functionName() + "\n" +
00196                                                           "Entity name\t : " + ((Operation)(graphicOperation.getElement())).getBlock().entityName() + "\n" +
00197                                                           "Author\t\t : " + ((Operation)(graphicOperation.getElement())).getBlock().author() + "\n" +
00198                                                           "Description\t : " + ((Operation)(graphicOperation.getElement())).getBlock().description()+ "\n" +
00199                                                           "--------------------------------------\n");
00200                                 }
00201                                 else
00202                                         checkBoxesBlockList.get(i).setSelected(false);          
00203                 
00204                 /* Get the selected building block */
00205                 BuildingBlock block = null;
00206         for(CheckBox cb : checkBoxesBlockList)  
00207                 if(cb.isSelected())
00208                         block = blockList.get(checkBoxesBlockList.indexOf(cb));
00209         
00210         /* Set the building block for all same operations if the is checkBoxSelectAll selected */
00211                 if(checkBoxSelectAll.isSelected())
00212                 {
00213                 for(Node node : schema.getAllNodes())
00214                 {
00215                                 if(node instanceof GraphicOperation && ((Operation)(node.getElement())).getOpName() == block.functionName())
00216                                 {
00217                                         ((Operation)(node.getElement())).setBlock(block);
00218                                         ((GraphicOperation)node).setSelectAll(true);
00219                                 }
00220                                 else if(node instanceof GraphicLoopIterator && ((GraphicLoopIterator)node).getIterOperation().getOpName() == block.functionName())
00221                                 {
00222                                         ((GraphicLoopIterator)node).getIterOperation().setBlock(block);
00223                                         ((GraphicLoopIterator)node).setSelectAll(true);
00224                                 }
00225                 }
00226                 }
00227                 else
00228                 for(Node node : schema.getAllNodes())
00229                 {
00230                                 if(node instanceof GraphicOperation && ((Operation)(node.getElement())).getOpName() == block.functionName())
00231                                         ((GraphicOperation)node).setSelectAll(false);
00232                                 else if(node instanceof GraphicLoopIterator && ((GraphicLoopIterator)node).getIterOperation().getOpName() == block.functionName())
00233                                         ((GraphicLoopIterator)node).setSelectAll(false);
00234                 }
00235         }
00236 }
 All Classes Namespaces Files Functions Variables Enumerations