SeriesDialog.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 package com.generalrobotix.ui.view.graph;
00011 
00012 //import java.awt.*;
00013 import java.net.URL;
00014 import java.util.*;
00015 
00016 
00017 import org.eclipse.jface.dialogs.Dialog;
00018 import org.eclipse.jface.dialogs.IDialogConstants;
00019 import org.eclipse.jface.viewers.ArrayContentProvider;
00020 import org.eclipse.jface.viewers.CellEditor;
00021 import org.eclipse.jface.viewers.ColorCellEditor;
00022 import org.eclipse.jface.viewers.ICellModifier;
00023 import org.eclipse.jface.viewers.ITableColorProvider;
00024 import org.eclipse.jface.viewers.ITableLabelProvider;
00025 import org.eclipse.jface.viewers.LabelProvider;
00026 import org.eclipse.jface.viewers.TableViewer;
00027 import org.eclipse.jface.viewers.TextCellEditor;
00028 import org.eclipse.swt.SWT;
00029 import org.eclipse.swt.events.SelectionEvent;
00030 import org.eclipse.swt.events.SelectionListener;
00031 import org.eclipse.swt.graphics.Color;
00032 import org.eclipse.swt.graphics.Image;
00033 import org.eclipse.swt.graphics.RGB;
00034 import org.eclipse.swt.layout.FillLayout;
00035 import org.eclipse.swt.layout.RowData;
00036 import org.eclipse.swt.layout.RowLayout;
00037 import org.eclipse.swt.widgets.Button;
00038 import org.eclipse.swt.widgets.Combo;
00039 import org.eclipse.swt.widgets.Composite;
00040 import org.eclipse.swt.widgets.Control;
00041 import org.eclipse.swt.widgets.Group;
00042 import org.eclipse.swt.widgets.Item;
00043 import org.eclipse.swt.widgets.Label;
00044 import org.eclipse.swt.widgets.Shell;
00045 import org.eclipse.swt.widgets.Table;
00046 import org.eclipse.swt.widgets.TableColumn;
00047 
00048 import com.generalrobotix.ui.grxui.Activator;
00049 import com.generalrobotix.ui.item.GrxLinkItem;
00050 import com.generalrobotix.ui.item.GrxModelItem;
00051 import com.generalrobotix.ui.util.MessageBundle;
00052 
00053 
00059 @SuppressWarnings("serial") //$NON-NLS-1$
00060 public class SeriesDialog extends Dialog {
00061         private boolean updated_;
00062     private ArrayList<DataItemInfo> dataItemInfoList_; 
00063     private ArrayList<DataItemInfo> removedList_;
00064     private DataItemInfo[] dataItemInfoArray_;
00065     private DataItemInfo[] removedArray_;
00066     
00067     private ArrayList<DataItemInfo> addedList_;
00068     private DataItemInfo[] addedArray_;
00069     
00070    // private JTable seriesTable_ = new JTable();
00071     private TableViewer tableviewer_;
00072     private static final String ROBOT_MODEL = "ROBOT MODEL"; //$NON-NLS-1$
00073     private static final String DATA_TYPE   = "DATA TYPE"; //$NON-NLS-1$
00074     private static final String LINK_NAME   = "LINK NAME"; //$NON-NLS-1$
00075     private static final String ATTRIBUTE   = "ATTRIBUTE"; //$NON-NLS-1$
00076     private static final String colNode = MessageBundle.get("dialog.graph.series.table.node"); //$NON-NLS-1$
00077     private static final String colAttribute = MessageBundle.get("dialog.graph.series.table.attribute"); //$NON-NLS-1$
00078     private static final String colIndex = MessageBundle.get("dialog.graph.series.table.index"); //$NON-NLS-1$
00079     private static final String colColor = MessageBundle.get("dialog.graph.series.table.color"); //$NON-NLS-1$
00080     private static final String colLegend = MessageBundle.get("dialog.graph.series.table.legend"); //$NON-NLS-1$
00081     private Combo comboModel_ ;
00082     private Combo comboType_ ;
00083     private Combo comboLink_ ;
00084     private Combo comboAttr_ ;
00085     private Button setButton_;
00086         private Button removeButton_;
00087                 
00088     private static final String GRAPH_PROPERTIES = "/resources/graph.properties"; //$NON-NLS-1$
00089     private URL url = this.getClass().getResource(GRAPH_PROPERTIES);
00090     private Properties prop = new Properties();
00091     private GraphElement currentGraph_;
00092     
00093     private MyTable tableModel_;
00094         private final Map<String, ArrayList<String>> nodeMap =  new HashMap<String, ArrayList<String>>();
00095         private int graphIndex = 0;
00096     private List<GrxModelItem> currentModels_ = null;
00097     // -----------------------------------------------------------------
00098     public SeriesDialog(GraphElement initialGraph, Shell shell) {
00099         super(shell);
00100         currentGraph_ = initialGraph;
00101         
00102         tableModel_ = new MyTable();
00103         
00104         try {
00105                 prop.load(url.openStream());
00106         } catch (java.io.IOException e) {
00107                 e.printStackTrace();
00108         }
00109         
00110 //       this is temporary limit for data type
00111         List<String> typeList = new ArrayList<String>();
00112         typeList.add("Joint"); //$NON-NLS-1$
00113         typeList.add("ForceSensor"); //$NON-NLS-1$
00114         typeList.add("Gyro"); //$NON-NLS-1$
00115         typeList.add("AccelerationSensor"); //$NON-NLS-1$
00116         
00117         Iterator<Object> it = prop.keySet().iterator();
00118         while (it.hasNext()) {
00119                 String key = (String) it.next();
00120                 String[] property = key.split("[.]"); //$NON-NLS-1$
00121                 if (property.length > 2 && property[2].equals("dataKind") && typeList.contains(property[0])) { //$NON-NLS-1$
00122                         if (!nodeMap.containsKey(property[0]))
00123                                 nodeMap.put(property[0], new ArrayList<String>());
00124                         nodeMap.get(property[0]).add(property[1]);
00125                 }
00126         }      
00127     }
00128     
00129     protected void configureShell(Shell newShell) {   
00130         super.configureShell(newShell);
00131         newShell.setText(MessageBundle.get("dialog.graph.series.title")); //$NON-NLS-1$
00132     }
00133     
00134     protected Control createDialogArea(Composite parent) {
00135         Composite composite = (Composite)super.createDialogArea(parent);
00136         composite.setLayout(new RowLayout(SWT.VERTICAL));
00137         RowData rowdata = new RowData();
00138         rowdata.height = 100;
00139         rowdata.width = 600;
00140         
00141         Label label = new Label(composite, SWT.LEFT);
00142         label.setText(MessageBundle.get("dialog.graph.series.dataseries")); //$NON-NLS-1$
00143         tableviewer_ = new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER);
00144         tableviewer_.getControl().setLayoutData(rowdata);
00145         Table table = tableviewer_.getTable();
00146         table.setFont(Activator.getDefault().getFont("preference_table"));
00147         table.setLinesVisible(true);
00148         table.setHeaderVisible(true);
00149         TableColumn column = new TableColumn(table,SWT.NONE);
00150         column.setText(colNode);
00151         column.setWidth(100);
00152         column = new TableColumn(table,SWT.NONE);
00153         column.setText(colAttribute);
00154         column.setWidth(100);
00155         column = new TableColumn(table,SWT.NONE);
00156         column.setText(colIndex);
00157         column.setWidth(60);
00158         column = new TableColumn(table,SWT.NONE);
00159         column.setText(colColor);
00160         column.setWidth(60);
00161         column = new TableColumn(table,SWT.NONE);
00162         column.setText(colLegend);
00163         column.setWidth(280);
00164         
00165         String[] properties = new String[]{ null, null, null, "color", "legend"}; //$NON-NLS-1$ //$NON-NLS-2$
00166         tableviewer_.setColumnProperties(properties); 
00167         CellEditor[] editors = new CellEditor[]{ null, null, null, 
00168                 new ColorCellEditor(table),
00169                 new TextCellEditor(table)  };
00170         tableviewer_.setCellEditors(editors);
00171         tableviewer_.setContentProvider(new ArrayContentProvider());
00172         tableviewer_.setLabelProvider(new MyLabelProvider());
00173         tableviewer_.setCellModifier(new MyCellModifier(tableviewer_));
00174         
00175         tableviewer_.setInput(tableModel_.getList());
00176        
00177         Composite line3 = new Composite(composite, SWT.NONE);
00178         line3.setLayout(new RowLayout());
00179         Group group0 = new Group(line3, SWT.NONE);
00180         group0.setText(ROBOT_MODEL);
00181         group0.setLayout(new FillLayout());
00182         comboModel_ = new Combo(group0,SWT.READ_ONLY);
00183         comboModel_.addSelectionListener(new SelectionListener() {
00184                         public void widgetDefaultSelected(SelectionEvent e) {                           
00185                         }
00186                         public void widgetSelected(SelectionEvent e) {
00187                                 comboType_.removeAll();
00188                                 comboLink_.removeAll();
00189                                 comboAttr_.removeAll();
00190                                 
00191                                 Iterator<String> it = nodeMap.keySet().iterator();
00192                                 if (tableModel_.getRowCount() > 0) {
00193                                         String curAttr = currentGraph_.getTrendGraph().getDataItemInfoList()[0].dataItem.attribute;
00194                                         while (it.hasNext()) {
00195                                                 String key = it.next();
00196                                                 if (nodeMap.get(key).contains(curAttr))
00197                                                         comboType_.add(key);
00198                                         }
00199                                 } else {
00200                                         while (it.hasNext()) {
00201                                                 comboType_.add(it.next());
00202                         }
00203                                 }
00204                                 comboType_.setEnabled(true);
00205                                 comboLink_.setEnabled(false);
00206                                 comboAttr_.setEnabled(false);
00207                                 setButton_.setEnabled(false);
00208                                 
00209                                 
00210                                 
00211                                 if(comboType_.getItemCount()>0){
00212                                         comboType_.select(0);
00213                                         comboType_.notifyListeners(SWT.Selection, null);
00214                                 }
00215                                 
00216                         }
00217                 });     
00218         Group group1 = new Group(line3, SWT.NONE);
00219         group1.setText(DATA_TYPE);
00220         group1.setLayout(new FillLayout());
00221         comboType_ = new Combo(group1,SWT.READ_ONLY);
00222         comboType_.addSelectionListener(new SelectionListener() {
00223                         public void widgetDefaultSelected(SelectionEvent e) {                   
00224                         }
00225                         public void widgetSelected(SelectionEvent e) {
00226                                 
00227                                 comboLink_.removeAll();
00228                                 comboAttr_.removeAll();
00229                                 
00230                                 String type = comboType_.getItem(comboType_.getSelectionIndex());
00231                                 String modelName = comboModel_.getItem(comboModel_.getSelectionIndex());
00232                                 Iterator<GrxModelItem> it = currentModels_.iterator();
00233                                 GrxModelItem model=null;
00234                                 while (it.hasNext()) {
00235                                         model = it.next();
00236                                         if(model.getName().equals(modelName))
00237                                                 break;
00238                                 }
00239                                 if (type.equals("Joint")) { //$NON-NLS-1$
00240                                         Vector<GrxLinkItem> li = model.links_;
00241                                         for (int i = 0; i < li.size(); i++) 
00242                                                 comboLink_.add(li.get(i).getName());
00243                                 } else {
00244                                         String t = null;
00245                                         if (type.equals("ForceSensor")) //$NON-NLS-1$
00246                                                 t = "Force"; //$NON-NLS-1$
00247                                         else if (type.equals("Gyro")) //$NON-NLS-1$
00248                                                 t = "RateGyro"; //$NON-NLS-1$
00249                                         else if (type.equals("AccelerationSensor")) //$NON-NLS-1$
00250                                                 t = "Acceleration"; //$NON-NLS-1$
00251                                         String[] snames = model.getSensorNames(t);
00252 
00253                                         if (snames != null) {
00254                                                 for (int i=0; i<snames.length; i++) {
00255                                                         comboLink_.add(snames[i]);
00256                                                 }
00257                                         }
00258                                 }
00259                                 comboLink_.setEnabled(true);
00260                                 comboAttr_.setEnabled(false);
00261                                 setButton_.setEnabled(false);
00262                                 
00263                                                         
00264                                 if(comboLink_.getItemCount()>0){
00265                                         comboLink_.select(0);
00266                                         comboLink_.notifyListeners(SWT.Selection, null);
00267                                 }
00268                         }
00269                 });
00270         Group group2 = new Group(line3, SWT.NONE);
00271         group2.setText(LINK_NAME);
00272         group2.setLayout(new FillLayout());
00273         comboLink_ = new Combo(group2,SWT.READ_ONLY);
00274         comboLink_.addSelectionListener(new SelectionListener() {
00275 
00276                         public void widgetDefaultSelected(SelectionEvent e) {                   
00277                         }
00278 
00279                         public void widgetSelected(SelectionEvent e) {
00280                                 
00281                                 comboAttr_.removeAll();
00282                                 
00283                                 String type = comboType_.getItem(comboType_.getSelectionIndex());
00284                                 List<String> l = nodeMap.get(type);
00285                                 if(type.equals("Joint")){
00286                                         String modelName = comboModel_.getItem(comboModel_.getSelectionIndex());
00287                                         Iterator<GrxModelItem> it = currentModels_.iterator();
00288                                         GrxModelItem model=null;
00289                                         while (it.hasNext()) {
00290                                                 model = it.next();
00291                                                 if(model.getName().equals(modelName))
00292                                                         break;
00293                                         }
00294                                         String linkName = comboLink_.getItem(comboLink_.getSelectionIndex());
00295                                         boolean isControlJoint = false;
00296                                         if(model!=null){
00297                                                 GrxLinkItem link = model.getLink(linkName);
00298                                                 if(link!=null)
00299                                                         if(link.jointType_.equals("rotate") || link.jointType_.equals("slide") )
00300                                                         isControlJoint = true;
00301                                         }
00302                                         if (tableModel_.getRowCount() > 0) {
00303                                                 String curAttr = (String)tableModel_.getValueAt(0, 1);
00304                                                 if(!isControlJoint)
00305                                                         if(curAttr.equals("translation") || curAttr.equals("attitude"))
00306                                                                 comboAttr_.add(curAttr);
00307                                                         else
00308                                                                 ;
00309                                                 else
00310                                                         if (l.contains(curAttr))
00311                                                                 comboAttr_.add(curAttr);
00312                                                         else
00313                                                                 ;
00314                                         } else {
00315                                                 if(!isControlJoint){
00316                                                         comboAttr_.add("translation");
00317                                                         comboAttr_.add("attitude");
00318                                                 }else {
00319                                                         Iterator<String> it0 = l.iterator();
00320                                                         while (it0.hasNext()) {
00321                                                                 comboAttr_.add(it0.next());
00322                                         }
00323                                                 }
00324                                         }
00325                                 }else{
00326                                         if (tableModel_.getRowCount() > 0) {
00327                                                 String curAttr = (String)tableModel_.getValueAt(0, 1);
00328                                                 if (l.contains(curAttr))
00329                                                         comboAttr_.add(curAttr);
00330                                         }else {
00331                                                 Iterator<String> it0 = l.iterator();
00332                                                 while (it0.hasNext()) 
00333                                                         comboAttr_.add(it0.next());
00334                                         }
00335                                 }
00336                                 comboAttr_.setEnabled(true);
00337                                 
00338                                 setButton_.setEnabled(comboAttr_.getItemCount() > 0);
00339                                 
00340                                                         
00341                                 if(comboAttr_.getItemCount()>0)
00342                                         comboAttr_.select(0);
00343                         } 
00344                 });
00345         Group group3 = new Group(line3, SWT.NONE);
00346         group3.setText(ATTRIBUTE);
00347         group3.setLayout(new FillLayout());
00348         comboAttr_ = new Combo(group3,SWT.READ_ONLY);
00349         removeButton_ = new Button(line3,SWT.PUSH);
00350         removeButton_.setText(MessageBundle.get("dialog.graph.series.remove")); //$NON-NLS-1$
00351         removeButton_.addSelectionListener(new SelectionListener(){
00352                 public void widgetDefaultSelected(SelectionEvent e) {
00353                 }
00354                 
00355                 public void widgetSelected(SelectionEvent e) {
00356                         int ind = tableviewer_.getTable().getSelectionIndex();
00357                         if (ind < 0) 
00358                                 return;
00359                         
00360                         tableModel_.removeRow(ind);
00361                         tableviewer_.refresh();
00362                         int cnt = tableModel_.getRowCount();
00363                         if (cnt < 1) {
00364                                 _resetSelection();
00365                                 return;
00366                         }
00367                         if (ind >= cnt) {
00368                                 ind -= 1;
00369                         }
00370                         tableviewer_.getTable().select(ind);
00371                 }
00372         });
00373         removeButton_.setEnabled(true); 
00374         setButton_ = new Button(line3,SWT.PUSH);
00375         setButton_.setText(MessageBundle.get("dialog.graph.series.set")); //$NON-NLS-1$
00376         setButton_.addSelectionListener(new SelectionListener(){
00377 
00378                         public void widgetDefaultSelected(SelectionEvent e) {
00379                         }
00380 
00381                         public void widgetSelected(SelectionEvent e) {
00382                                 int length = 1;
00383                                 String combo1 = (String)comboType_.getItem(comboType_.getSelectionIndex());
00384                                 if (combo1.equals("ForceSensor") || //$NON-NLS-1$
00385                                         combo1.equals("AccelerationSensor") || //$NON-NLS-1$
00386                                         combo1.equals("Gyro"))  //$NON-NLS-1$
00387                                         length = 3;
00388                                 String model = comboModel_.getItem(comboModel_.getSelectionIndex());
00389                                 String link = comboLink_.getItem(comboLink_.getSelectionIndex());
00390                                 String attr = comboAttr_.getItem(comboAttr_.getSelectionIndex());
00391                                 if(combo1.equals("Joint") && (attr.equals("translation") || attr.equals("attitude")))
00392                                         length = 3;
00393                                 for (int i=0; i<length; i++) {  
00394                                         String legend = model + "." + link + "." + attr + (length > 1 ? "." + i : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
00395                                         if(!tableModel_.contains(legend)){
00396                                                 DataItemInfo newDataItemInfo = new DataItemInfo(new DataItem(model,link,attr,
00397                                                         length > 1 ? i : -1,
00398                                                 comboType_.getItem(comboType_.getSelectionIndex())),
00399                                                 currentGraph_.getTrendGraph().getGraphColor(graphIndex),
00400                                                 legend);
00401                                                 tableModel_.addRow(newDataItemInfo, legend);
00402                                                 tableviewer_.refresh();
00403                                                 graphIndex++;
00404                                         }
00405                                 }
00406                                 removeButton_.setEnabled(true);
00407                         comboLink_.notifyListeners(SWT.Selection, null);
00408                         }
00409         });
00410         _resetSelection();
00411         return composite;
00412     }
00413 
00414     protected void buttonPressed(int buttonId) {
00415         if (buttonId == IDialogConstants.OK_ID) {
00416             ArrayList<DataItemInfo> newDataItemInfoList = new ArrayList<DataItemInfo>();
00417             for(int i=0; i<tableModel_.getRowCount(); i++){
00418                 String fullName = tableModel_.getString(i);
00419                 Iterator<DataItemInfo> it = dataItemInfoList_.iterator();
00420                 boolean contain = false;
00421                 while(it.hasNext()){
00422                         DataItemInfo info = it.next();
00423                         if(fullName.equals(info.dataItem.toString())){
00424                                 info.color = (RGB)tableModel_.getValueAt(i, 3);
00425                                 info.legend = (String)tableModel_.getValueAt(i, 4);
00426                                 newDataItemInfoList.add(info);
00427                                 dataItemInfoList_.remove(info);
00428                                 contain = true;
00429                                 break;
00430                         }
00431                 }
00432                 if(!contain){
00433                         addedList_.add(tableModel_.getItem(i));
00434                 }
00435             }
00436             Iterator<DataItemInfo> it = dataItemInfoList_.iterator();
00437             while(it.hasNext()){
00438                 removedList_.add(it.next());
00439             }
00440             dataItemInfoArray_ =
00441                 newDataItemInfoList.toArray(new DataItemInfo[0]);
00442                 removedArray_ = removedList_.toArray(new DataItemInfo[0]);
00443                 removeAllRows();
00444             addedArray_ = addedList_.toArray(new DataItemInfo[0]);
00445                 updated_ = true;
00446         }else if(buttonId == IDialogConstants.CANCEL_ID){
00447             removeAllRows();
00448         }
00449         setReturnCode(buttonId);
00450         close();
00451         super.buttonPressed(buttonId);
00452     }
00453     
00454     private void _resetSelection() {
00455                 graphIndex = 0;
00456         
00457                 
00458                 comboModel_.removeAll();
00459                 Iterator<GrxModelItem> it = currentModels_.iterator();
00460                 while (it.hasNext()) {
00461                         GrxModelItem model = it.next();
00462                         if (model.isRobot())
00463                                 comboModel_.add(model.getName());
00464                 }
00465                 comboType_.removeAll();
00466                 comboLink_.removeAll();
00467                 comboAttr_.removeAll();
00468                 
00469                 comboModel_.setEnabled(true);
00470                 comboType_.setEnabled(false);
00471                 comboLink_.setEnabled(false);
00472                 comboAttr_.setEnabled(false);
00473                 setButton_.setEnabled(false);
00474                 
00475                 
00476                 if(comboModel_.getItemCount()>0){
00477                         comboModel_.select(0);
00478                         comboModel_.notifyListeners(SWT.Selection, null);
00479                 }
00480     }
00481 
00482     public void setCurrentGraph(GraphElement currentGraph) {
00483         currentGraph_ = currentGraph;
00484     }
00485 
00486     
00492         public int open( ) {
00493                 removedList_ = new ArrayList<DataItemInfo>(); 
00494                 addedList_ = new ArrayList<DataItemInfo>();
00495                 updated_ = false;     
00496             return super.open(); 
00497         }
00498 
00499 
00503     public void setDataItemInfoList( DataItemInfo[] dii) {
00504         dataItemInfoList_ = new ArrayList<DataItemInfo>();
00505         for (int i = 0; i < dii.length; i++) {
00506             dataItemInfoList_.add(dii[i]);
00507             tableModel_.addRow(dii[i],dii[i].dataItem.toString());
00508         }
00509     }
00510 
00514     public DataItemInfo[] getDataItemInfoList() {
00515         return dataItemInfoArray_;
00516     }
00517 
00521     public DataItemInfo[] getRemovedList() {
00522         return removedArray_;
00523     }
00524     public DataItemInfo[] getAddedList() {
00525         return addedArray_;
00526     }
00530     public boolean isUpdated() {
00531         return updated_;
00532     }
00533 
00537     private void removeAllRows() {
00538         int cnt = tableModel_.getRowCount();
00539         for (int i = 0; i < cnt; i++) {
00540             tableModel_.removeRow(0);
00541         }
00542     }
00543 
00544     private class MyTable {
00545         private ArrayList<String> nameList = new ArrayList<String>();
00546         private ArrayList<DataItemInfo> itemList = new ArrayList<DataItemInfo>(); 
00547         
00548         public void addRow(DataItemInfo item, String name){
00549                 itemList.add(item);
00550                 nameList.add(name);
00551         }
00552         
00553         public void removeRow(int i){
00554                 itemList.remove(i);
00555                 nameList.remove(i);
00556         }
00557         
00558         public DataItemInfo getItem(int i){
00559                 return itemList.get(i);
00560         }
00561         
00562         public int getRowCount(){
00563                 return itemList.size();
00564         }
00565         
00566         public String getString(int i){
00567                 return nameList.get(i);
00568         }
00569         
00570         public ArrayList getList(){
00571                 return itemList;
00572         }
00573     
00574         public boolean contains(String name){
00575             return nameList.contains(name);
00576         }
00577         
00578         public Object getValueAt(int i, int j){
00579                 DataItemInfo dii = itemList.get(i);
00580                 DataItem di = dii.dataItem;
00581                 switch (j) {
00582                     case 0:
00583                          if (di.object == null) {
00584                                  return di.node;
00585                          }else{
00586                                  return di.object + "." + di.node; //$NON-NLS-1$
00587                          }
00588                     case 1:
00589                         return di.attribute;
00590                     case 2:
00591                         return new Integer(di.index);
00592                     case 3:
00593                         return dii.color;
00594                     case 4:
00595                         return dii.legend;
00596                     default:
00597                         break;
00598                 }
00599                 return null;
00600         }
00601     }
00602     
00603     public void setModelList(List<GrxModelItem> list){
00604         currentModels_ = list;
00605     }
00606     
00607     public class MyLabelProvider extends LabelProvider 
00608     implements ITableLabelProvider, ITableColorProvider { 
00609 
00610         public Image getColumnImage(Object element, int columnIndex) {
00611                 return null;
00612         }
00613 
00614         public String getColumnText(Object element, int columnIndex) {
00615                 DataItemInfo item = (DataItemInfo) element;
00616                 String result = ""; //$NON-NLS-1$
00617                 DataItem di = item.dataItem;
00618                 switch (columnIndex) {
00619                     case 0:
00620                          if (di.object == null) {
00621                                  result = di.node;
00622                          }else{
00623                                  result = di.object + "." + di.node; //$NON-NLS-1$
00624                          }
00625                          break;
00626                     case 1:
00627                         result = di.attribute;
00628                         break;
00629                     case 2:
00630                         if(di.index < 0)
00631                                 result = ""; //$NON-NLS-1$
00632                         else
00633                                 result = (new Integer(di.index)).toString();
00634                         break;
00635                     case 3:
00636                         result = ""; //$NON-NLS-1$
00637                         break;
00638                     case 4:
00639                         result = item.legend;
00640                         break;
00641                     default:
00642                         break;
00643                 }
00644                 return result;
00645         }
00646 
00647                 public Color getBackground(Object element, int columnIndex) {
00648                         DataItemInfo item = (DataItemInfo) element;
00649                 if(columnIndex == 3)
00650                         return Activator.getDefault().getColor(item.color);
00651                 else
00652                         return null;
00653                 }
00654 
00655                 public Color getForeground(Object element, int columnIndex) {
00656                         return null;
00657                 }
00658     }
00659     
00660     public class MyCellModifier implements ICellModifier {
00661           private TableViewer viewer_;
00662 
00663           public MyCellModifier(TableViewer viewer) {
00664             this.viewer_ = viewer;
00665           }
00666 
00667                 public boolean canModify(Object element, String property) {
00668                         if(property == "color" || property == "legend") //$NON-NLS-1$ //$NON-NLS-2$
00669                                 return true;
00670                         else
00671                                 return false;
00672                 }
00673 
00674                 public Object getValue(Object element, String property) {
00675                         DataItemInfo item = (DataItemInfo) element;
00676                         if(property == "color") //$NON-NLS-1$
00677                                 return item.color;
00678                         else if(property == "legend") //$NON-NLS-1$
00679                                 return item.legend;
00680                         return null;
00681                 }
00682 
00683                 public void modify(Object element, String property, Object value) {
00684                         if (element instanceof Item) {
00685                               element = ((Item) element).getData();
00686                         }
00687                         DataItemInfo item = (DataItemInfo) element;
00688                         if(property == "color"){ //$NON-NLS-1$
00689                                 item.color =(RGB)value;
00690                         }else if(property == "legend") //$NON-NLS-1$
00691                                 item.legend = (String)value;
00692                                 
00693                          viewer_.update(element, null);
00694                 }
00695     }
00696 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:19