10 package com.generalrobotix.ui.view.graph;
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.jface.viewers.ArrayContentProvider;
20 import org.eclipse.jface.viewers.CellEditor;
21 import org.eclipse.jface.viewers.ColorCellEditor;
22 import org.eclipse.jface.viewers.ICellModifier;
23 import org.eclipse.jface.viewers.ITableColorProvider;
24 import org.eclipse.jface.viewers.ITableLabelProvider;
25 import org.eclipse.jface.viewers.LabelProvider;
26 import org.eclipse.jface.viewers.TableViewer;
27 import org.eclipse.jface.viewers.TextCellEditor;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.events.SelectionListener;
31 import org.eclipse.swt.graphics.Color;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.swt.graphics.RGB;
34 import org.eclipse.swt.layout.FillLayout;
35 import org.eclipse.swt.layout.RowData;
36 import org.eclipse.swt.layout.RowLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Combo;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.swt.widgets.Control;
41 import org.eclipse.swt.widgets.Group;
42 import org.eclipse.swt.widgets.Item;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.Shell;
45 import org.eclipse.swt.widgets.Table;
46 import org.eclipse.swt.widgets.TableColumn;
59 @SuppressWarnings(
"serial")
72 private static final String ROBOT_MODEL =
"ROBOT MODEL";
73 private static final String DATA_TYPE =
"DATA TYPE";
74 private static final String LINK_NAME =
"LINK NAME";
75 private static final String ATTRIBUTE =
"ATTRIBUTE";
76 private static final String colNode =
MessageBundle.
get(
"dialog.graph.series.table.node");
77 private static final String colAttribute =
MessageBundle.
get(
"dialog.graph.series.table.attribute");
78 private static final String colIndex =
MessageBundle.
get(
"dialog.graph.series.table.index");
79 private static final String colColor =
MessageBundle.
get(
"dialog.graph.series.table.color");
80 private static final String colLegend =
MessageBundle.
get(
"dialog.graph.series.table.legend");
88 private static final String GRAPH_PROPERTIES =
"/resources/graph.properties";
89 private URL url = this.getClass().getResource(GRAPH_PROPERTIES);
94 private final Map<String, ArrayList<String>> nodeMap =
new HashMap<String, ArrayList<String>>();
95 private int graphIndex = 0;
96 private List<GrxModelItem> currentModels_ =
null;
100 currentGraph_ = initialGraph;
105 prop.load(url.openStream());
106 }
catch (java.io.IOException e) {
111 List<String> typeList =
new ArrayList<String>();
112 typeList.add(
"Joint");
113 typeList.add(
"ForceSensor");
114 typeList.add(
"Gyro");
115 typeList.add(
"AccelerationSensor");
117 Iterator<Object> it = prop.keySet().iterator();
118 while (it.hasNext()) {
119 String key = (String) it.next();
120 String[]
property = key.split(
"[.]");
121 if (property.length > 2 && property[2].equals(
"dataKind") && typeList.contains(property[0])) {
122 if (!nodeMap.containsKey(property[0]))
123 nodeMap.put(property[0],
new ArrayList<String>());
124 nodeMap.get(property[0]).add(property[1]);
130 super.configureShell(newShell);
135 Composite composite = (Composite)super.createDialogArea(parent);
136 composite.setLayout(
new RowLayout(SWT.VERTICAL));
137 RowData rowdata =
new RowData();
138 rowdata.height = 100;
141 Label label =
new Label(composite, SWT.LEFT);
143 tableviewer_ =
new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER);
144 tableviewer_.getControl().setLayoutData(rowdata);
145 Table table = tableviewer_.getTable();
147 table.setLinesVisible(
true);
148 table.setHeaderVisible(
true);
149 TableColumn column =
new TableColumn(table,SWT.NONE);
150 column.setText(colNode);
151 column.setWidth(100);
152 column =
new TableColumn(table,SWT.NONE);
153 column.setText(colAttribute);
154 column.setWidth(100);
155 column =
new TableColumn(table,SWT.NONE);
156 column.setText(colIndex);
158 column =
new TableColumn(table,SWT.NONE);
159 column.setText(colColor);
161 column =
new TableColumn(table,SWT.NONE);
162 column.setText(colLegend);
163 column.setWidth(280);
165 String[] properties =
new String[]{
null,
null,
null,
"color",
"legend"};
166 tableviewer_.setColumnProperties(properties);
167 CellEditor[] editors =
new CellEditor[]{
null,
null,
null,
168 new ColorCellEditor(table),
169 new TextCellEditor(table) };
170 tableviewer_.setCellEditors(editors);
171 tableviewer_.setContentProvider(
new ArrayContentProvider());
175 tableviewer_.setInput(tableModel_.
getList());
177 Composite line3 =
new Composite(composite, SWT.NONE);
178 line3.setLayout(
new RowLayout());
179 Group group0 =
new Group(line3, SWT.NONE);
180 group0.setText(ROBOT_MODEL);
181 group0.setLayout(
new FillLayout());
182 comboModel_ =
new Combo(group0,SWT.READ_ONLY);
183 comboModel_.addSelectionListener(
new SelectionListener() {
184 public void widgetDefaultSelected(SelectionEvent e) {
186 public void widgetSelected(SelectionEvent e) {
187 comboType_.removeAll();
188 comboLink_.removeAll();
189 comboAttr_.removeAll();
191 Iterator<String> it = nodeMap.keySet().iterator();
194 while (it.hasNext()) {
195 String key = it.next();
196 if (nodeMap.get(key).contains(curAttr))
200 while (it.hasNext()) {
201 comboType_.add(it.next());
204 comboType_.setEnabled(
true);
205 comboLink_.setEnabled(
false);
206 comboAttr_.setEnabled(
false);
207 setButton_.setEnabled(
false);
211 if(comboType_.getItemCount()>0){
212 comboType_.select(0);
213 comboType_.notifyListeners(SWT.Selection,
null);
218 Group group1 =
new Group(line3, SWT.NONE);
219 group1.setText(DATA_TYPE);
220 group1.setLayout(
new FillLayout());
221 comboType_ =
new Combo(group1,SWT.READ_ONLY);
222 comboType_.addSelectionListener(
new SelectionListener() {
223 public void widgetDefaultSelected(SelectionEvent e) {
225 public void widgetSelected(SelectionEvent e) {
227 comboLink_.removeAll();
228 comboAttr_.removeAll();
230 String
type = comboType_.getItem(comboType_.getSelectionIndex());
231 String modelName = comboModel_.getItem(comboModel_.getSelectionIndex());
232 Iterator<GrxModelItem> it = currentModels_.iterator();
234 while (it.hasNext()) {
236 if(model.
getName().equals(modelName))
239 if (type.equals(
"Joint")) {
240 Vector<GrxLinkItem> li = model.
links_;
241 for (
int i = 0;
i < li.size();
i++)
242 comboLink_.add(li.get(
i).getName());
245 if (type.equals(
"ForceSensor"))
247 else if (type.equals(
"Gyro"))
249 else if (type.equals(
"AccelerationSensor"))
253 if (snames !=
null) {
254 for (
int i=0;
i<snames.length;
i++) {
255 comboLink_.add(snames[
i]);
259 comboLink_.setEnabled(
true);
260 comboAttr_.setEnabled(
false);
261 setButton_.setEnabled(
false);
264 if(comboLink_.getItemCount()>0){
265 comboLink_.select(0);
266 comboLink_.notifyListeners(SWT.Selection,
null);
270 Group group2 =
new Group(line3, SWT.NONE);
271 group2.setText(LINK_NAME);
272 group2.setLayout(
new FillLayout());
273 comboLink_ =
new Combo(group2,SWT.READ_ONLY);
274 comboLink_.addSelectionListener(
new SelectionListener() {
276 public void widgetDefaultSelected(SelectionEvent e) {
279 public void widgetSelected(SelectionEvent e) {
281 comboAttr_.removeAll();
283 String
type = comboType_.getItem(comboType_.getSelectionIndex());
284 List<String> l = nodeMap.get(type);
285 if(type.equals(
"Joint")){
286 String modelName = comboModel_.getItem(comboModel_.getSelectionIndex());
287 Iterator<GrxModelItem> it = currentModels_.iterator();
289 while (it.hasNext()) {
291 if(model.
getName().equals(modelName))
294 String linkName = comboLink_.getItem(comboLink_.getSelectionIndex());
295 boolean isControlJoint =
false;
300 isControlJoint =
true;
303 String curAttr = (String)tableModel_.
getValueAt(0, 1);
305 if(curAttr.equals(
"translation") || curAttr.equals(
"attitude"))
306 comboAttr_.add(curAttr);
310 if (l.contains(curAttr))
311 comboAttr_.add(curAttr);
316 comboAttr_.add(
"translation");
317 comboAttr_.add(
"attitude");
319 Iterator<String> it0 = l.iterator();
320 while (it0.hasNext()) {
321 comboAttr_.add(it0.next());
327 String curAttr = (String)tableModel_.
getValueAt(0, 1);
328 if (l.contains(curAttr))
329 comboAttr_.add(curAttr);
331 Iterator<String> it0 = l.iterator();
332 while (it0.hasNext())
333 comboAttr_.add(it0.next());
336 comboAttr_.setEnabled(
true);
338 setButton_.setEnabled(comboAttr_.getItemCount() > 0);
341 if(comboAttr_.getItemCount()>0)
342 comboAttr_.select(0);
345 Group group3 =
new Group(line3, SWT.NONE);
346 group3.setText(ATTRIBUTE);
347 group3.setLayout(
new FillLayout());
348 comboAttr_ =
new Combo(group3,SWT.READ_ONLY);
349 removeButton_ =
new Button(line3,SWT.PUSH);
351 removeButton_.addSelectionListener(
new SelectionListener(){
352 public void widgetDefaultSelected(SelectionEvent e) {
355 public void widgetSelected(SelectionEvent e) {
356 int ind = tableviewer_.getTable().getSelectionIndex();
361 tableviewer_.refresh();
370 tableviewer_.getTable().select(ind);
373 removeButton_.setEnabled(
true);
374 setButton_ =
new Button(line3,SWT.PUSH);
376 setButton_.addSelectionListener(
new SelectionListener(){
378 public void widgetDefaultSelected(SelectionEvent e) {
381 public void widgetSelected(SelectionEvent e) {
383 String combo1 = (String)comboType_.getItem(comboType_.getSelectionIndex());
384 if (combo1.equals(
"ForceSensor") ||
385 combo1.equals(
"AccelerationSensor") ||
386 combo1.equals(
"Gyro"))
388 String model = comboModel_.getItem(comboModel_.getSelectionIndex());
389 String link = comboLink_.getItem(comboLink_.getSelectionIndex());
390 String attr = comboAttr_.getItem(comboAttr_.getSelectionIndex());
391 if(combo1.equals(
"Joint") && (attr.equals(
"translation") || attr.equals(
"attitude")))
394 String legend = model +
"." + link +
"." + attr + (length > 1 ?
"." +
i :
"");
398 comboType_.getItem(comboType_.getSelectionIndex())),
401 tableModel_.
addRow(newDataItemInfo, legend);
402 tableviewer_.refresh();
406 removeButton_.setEnabled(
true);
407 comboLink_.notifyListeners(SWT.Selection,
null);
415 if (buttonId == IDialogConstants.OK_ID) {
416 ArrayList<DataItemInfo> newDataItemInfoList =
new ArrayList<DataItemInfo>();
419 Iterator<DataItemInfo> it = dataItemInfoList_.iterator();
420 boolean contain =
false;
426 newDataItemInfoList.add(info);
427 dataItemInfoList_.remove(info);
433 addedList_.add(tableModel_.
getItem(
i));
436 Iterator<DataItemInfo> it = dataItemInfoList_.iterator();
438 removedList_.add(it.next());
442 removedArray_ = removedList_.toArray(
new DataItemInfo[0]);
446 }
else if(buttonId == IDialogConstants.CANCEL_ID){
449 setReturnCode(buttonId);
451 super.buttonPressed(buttonId);
458 comboModel_.removeAll();
459 Iterator<GrxModelItem> it = currentModels_.iterator();
460 while (it.hasNext()) {
463 comboModel_.add(model.
getName());
465 comboType_.removeAll();
466 comboLink_.removeAll();
467 comboAttr_.removeAll();
469 comboModel_.setEnabled(
true);
470 comboType_.setEnabled(
false);
471 comboLink_.setEnabled(
false);
472 comboAttr_.setEnabled(
false);
473 setButton_.setEnabled(
false);
476 if(comboModel_.getItemCount()>0){
477 comboModel_.select(0);
478 comboModel_.notifyListeners(SWT.Selection,
null);
483 currentGraph_ = currentGraph;
493 removedList_ =
new ArrayList<DataItemInfo>();
494 addedList_ =
new ArrayList<DataItemInfo>();
504 dataItemInfoList_ =
new ArrayList<DataItemInfo>();
505 for (
int i = 0;
i < dii.length;
i++) {
506 dataItemInfoList_.add(dii[
i]);
507 tableModel_.
addRow(dii[i],dii[i].dataItem.toString());
515 return dataItemInfoArray_;
522 return removedArray_;
539 for (
int i = 0;
i < cnt;
i++) {
545 private ArrayList<String> nameList =
new ArrayList<String>();
546 private ArrayList<DataItemInfo> itemList =
new ArrayList<DataItemInfo>();
559 return itemList.get(i);
563 return itemList.size();
567 return nameList.get(i);
575 return nameList.contains(name);
591 return new Integer(di.
index);
604 currentModels_ = list;
608 implements ITableLabelProvider, ITableColorProvider {
618 switch (columnIndex) {
664 this.viewer_ = viewer;
667 public boolean canModify(Object element, String property) {
668 if(property ==
"color" || property ==
"legend")
674 public Object
getValue(Object element, String property) {
676 if(property ==
"color")
678 else if(property ==
"legend")
683 public void modify(Object element, String property, Object
value) {
684 if (element instanceof Item) {
685 element = ((Item) element).getData();
688 if(property ==
"color"){
689 item.
color =(RGB)value;
690 }
else if(property ==
"legend")
691 item.
legend = (String)value;
693 viewer_.update(element,
null);
static final String get(String key)
bool toString(IOP::IOR &ior, std::string &iorstr)
void configureShell(Shell newShell)
png_infop png_charp png_int_32 png_int_32 int * type
DataItemInfo[] dataItemInfoArray_
DataItemInfo[] getRemovedList()
Object getValueAt(int i, int j)
#define null
our own NULL pointer
String getColumnText(Object element, int columnIndex)
boolean contains(String name)
DataItemInfo getItem(int i)
void modify(Object element, String property, Object value)
SeriesDialog(GraphElement initialGraph, Shell shell)
DataItemInfo[] getAddedList()
GrxLinkItem getLink(String name)
get link from name
png_infop png_charpp name
item corresponds to a robot model
png_bytep png_bytep png_size_t length
ArrayList< DataItemInfo > addedList_
static Activator getDefault()
RGB getGraphColor(int index)
DataItemInfo[] removedArray_
Color getBackground(Object element, int columnIndex)
GraphElement currentGraph_
Image getColumnImage(Object element, int columnIndex)
void setDataItemInfoList(DataItemInfo[] dii)
Vector< GrxLinkItem > links_
Object getValue(Object element, String property)
ArrayList< DataItemInfo > removedList_
Color getForeground(Object element, int columnIndex)
MyCellModifier(TableViewer viewer)
String[] getSensorNames(String type)
void addRow(DataItemInfo item, String name)
TrendGraph getTrendGraph()
Font getFont(String fontName)
DataItemInfo[] addedArray_
ArrayList< DataItemInfo > dataItemInfoList_
boolean canModify(Object element, String property)
DataItemInfo[] getDataItemInfoList()
void setModelList(List< GrxModelItem > list)
DataItemInfo[] getDataItemInfoList()
final String getName()
get name
Control createDialogArea(Composite parent)
void buttonPressed(int buttonId)
void setCurrentGraph(GraphElement currentGraph)