17 package com.generalrobotix.ui.view.simulation;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Vector;
24 import org.eclipse.jface.dialogs.MessageDialog;
25 import org.eclipse.jface.viewers.ArrayContentProvider;
26 import org.eclipse.jface.viewers.ColumnWeightData;
27 import org.eclipse.jface.viewers.ILabelProviderListener;
28 import org.eclipse.jface.viewers.ITableLabelProvider;
29 import org.eclipse.jface.viewers.TableLayout;
30 import org.eclipse.jface.viewers.TableViewer;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.events.SelectionListener;
34 import org.eclipse.swt.graphics.Image;
35 import org.eclipse.swt.layout.FillLayout;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Button;
39 import org.eclipse.swt.widgets.Combo;
40 import org.eclipse.swt.widgets.Composite;
41 import org.eclipse.swt.widgets.Control;
42 import org.eclipse.swt.widgets.FileDialog;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.TableColumn;
45 import org.eclipse.swt.widgets.Text;
57 @SuppressWarnings(
"serial")
70 private static final String ATTRIBUTE_CONTROLLER =
"controller";
71 private static final String ATTRIBUTE_CONTROL_TIME =
"controlTime";
72 private static final String ATTRIBUTE_SETUP_DIRECTORY =
"setupDirectory";
73 private static final String ATTRIBUTE_SETUP_COMMAND =
"setupCommand";
75 private static final int BUTTONS_HEIGHT = 26;
77 private final String[] clmName_ ={
84 private final String[] attrName_ = {
87 ATTRIBUTE_CONTROL_TIME,
88 ATTRIBUTE_SETUP_DIRECTORY,
89 ATTRIBUTE_SETUP_COMMAND
96 vecRobot_ =
new Vector<GrxModelItem>();
97 setLayout(
new GridLayout(1,
false));
99 viewer_ =
new TableViewer(
this, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
100 viewer_.setContentProvider(
new ArrayContentProvider());
102 TableLayout tableLayout =
new TableLayout();
103 for(
int i=0;
i<clmName_.length;
i++){
104 new TableColumn(viewer_.getTable(),
i).setText(clmName_[
i]);
105 tableLayout.addColumnData(
new ColumnWeightData(1,
true));
107 viewer_.getTable().setLayout(tableLayout);
108 viewer_.getTable().setHeaderVisible(
true);
110 viewer_.getTable().addSelectionListener(
new SelectionListener(){
112 public void widgetDefaultSelected(SelectionEvent e) {
115 public void widgetSelected(SelectionEvent e) {
116 int row = viewer_.getTable().getSelectionIndex();
117 if(row>=0 && row<vecRobot_.size()){
118 editorPanel_.
setNode(vecRobot_.get(row));
122 viewer_.getTable().setLinesVisible(
true);
123 viewer_.getTable().setLayoutData(
new GridData(GridData.FILL_BOTH));
124 viewer_.setInput(vecRobot_);
125 Composite pnlBttn =
new Composite(
this,SWT.NONE);
126 GridData gridData =
new GridData(GridData.FILL_HORIZONTAL);
127 gridData.heightHint = BUTTONS_HEIGHT;
128 pnlBttn.setLayoutData(gridData);
129 pnlBttn.setLayout(
new FillLayout(SWT.HORIZONTAL));
131 btnRemove_ =
new Button(pnlBttn,SWT.PUSH);
133 btnRemove_.addSelectionListener(
new SelectionListener(){
135 public void widgetDefaultSelected(SelectionEvent e) {
138 public void widgetSelected(SelectionEvent e) {
139 int row = viewer_.getTable().getSelectionIndex();
140 if (row >= 0 && row < vecRobot_.size()) {
149 }
catch (Exception ex) {
150 ex.printStackTrace();
159 btnEdit_ =
new Button(pnlBttn,SWT.PUSH);
161 btnEdit_.addSelectionListener(
new SelectionListener(){
163 public void widgetDefaultSelected(SelectionEvent e) {
166 public void widgetSelected(SelectionEvent e) {
167 int row = viewer_.getTable().getSelectionIndex();
168 if(row>=0 && row<vecRobot_.size()){
169 _setButtonEnabled(
false);
178 names =
new String[0];
181 Composite editorPanelComposite =
new Composite(
this,SWT.NONE);
182 GridData editorPanelGridData =
new GridData(GridData.FILL_HORIZONTAL);
183 editorPanelComposite.setLayoutData(editorPanelGridData);
184 editorPanelComposite.setLayout(
new FillLayout(SWT.HORIZONTAL));
194 boolean overwrite = MessageDialog.openQuestion(getShell(),
MessageBundle.
get(
"dialog.overwrite"), msg);
199 btnRemove_.setEnabled(flag);
200 btnEdit_.setEnabled(flag);
201 viewer_.getTable().setEnabled(flag);
206 viewer_.setInput(vecRobot_);
207 viewer_.getTable().update();
213 super.setEnabled(flag);
215 _setButtonEnabled(flag);
220 boolean flag =
false;
222 while (it.hasNext()) {
225 String controllName = node.getProperty(ATTRIBUTE_CONTROLLER);
226 if (controllName !=
null) {
227 double t = node.
getDbl(ATTRIBUTE_CONTROL_TIME, 0.001);
239 return Double.MAX_VALUE;
246 private static final int MODE_EDIT = 1 ;
248 private static final int COMBO_WIDTH = 200;
249 private static final int BUTTON_WIDTH = 50;
262 setLayout(
new GridLayout(5,
true));
264 Label lbl =
new Label(
this,SWT.SHADOW_NONE);
266 lbl.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
268 boxController_ =
new Combo(
this,SWT.DROP_DOWN);
269 boxController_.setItems(initialNames);
270 boxController_.select(0);
271 GridData gridData =
new GridData();
272 gridData.widthHint = COMBO_WIDTH;
273 gridData.horizontalSpan = 2;
274 boxController_.setLayoutData(gridData);
275 boxController_.setItems(
new String[0]);
278 lbl =
new Label(
this,SWT.SHADOW_NONE);
280 lbl.setLayoutData(
new GridData(GridData.VERTICAL_ALIGN_CENTER|GridData.HORIZONTAL_ALIGN_END));
283 gridData =
new GridData(GridData.FILL_HORIZONTAL);
284 spinControlTime_.setLayoutData(gridData);
287 lbl =
new Label(
this,SWT.SHADOW_NONE);
289 lbl.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
291 tfSetupDirectory_ =
new Text(
this,SWT.DROP_DOWN);
293 gridData =
new GridData(GridData.FILL_HORIZONTAL);
294 gridData.horizontalSpan = 2;
295 tfSetupDirectory_.setLayoutData(gridData);
297 Button btnCmdRef =
new Button(
this, SWT.PUSH);
298 GridData btnGridData =
new GridData(GridData.VERTICAL_ALIGN_END);
299 btnGridData.verticalSpan = 2;
300 btnCmdRef.setLayoutData(btnGridData);
303 Button btnCreate =
new Button(
this, SWT.PUSH);
306 btnCreate.addSelectionListener(
new SelectionListener(){
307 public void widgetDefaultSelected(SelectionEvent e) {
309 public void widgetSelected(SelectionEvent e) {
311 int row = viewer_.getTable().getSelectionIndex();
314 String controllerName = boxController_.getText();
315 if(controllerName==
""){
316 MessageDialog.openError(getShell(),
MessageBundle.
get(
"dialog.error.title"),
323 controllerBridge_.open();
328 lbl =
new Label(
this,SWT.SHADOW_NONE);
330 lbl.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_END));
332 tfSetupCommand_ =
new Text(
this, SWT.DROP_DOWN);
333 tfSetupCommand_.setLayoutData(gridData);
335 btnCmdRef.addSelectionListener(
new SelectionListener(){
336 public void widgetDefaultSelected(SelectionEvent e) {
339 public void widgetSelected(SelectionEvent e) {
341 fdlg.setFilterPath(tfSetupDirectory_.getText());
342 String fPath = fdlg.open();
343 if( fPath !=
null ) {
345 tfSetupDirectory_.setText(selFile.getParent());
346 tfSetupCommand_.setText(selFile.getName());
351 Button btnEdit_ =
new Button(
this, SWT.PUSH);
353 btnEdit_.addSelectionListener(
new SelectionListener(){
354 public void widgetDefaultSelected(SelectionEvent e) {
356 public void widgetSelected(SelectionEvent e) {
358 if(!controllerBridge_.
load(tfSetupDirectory_.getText()+
File.separator+tfSetupCommand_.getText())){
359 MessageDialog.openError(getShell(),
MessageBundle.
get(
"dialog.error.title"),
363 int row = viewer_.getTable().getSelectionIndex();
366 String controllerName = boxController_.getText();
367 if(controllerName==
""){
368 MessageDialog.openError(getShell(),
MessageBundle.
get(
"dialog.error.title"),
373 if(MessageDialog.openQuestion(getShell(),
MessageBundle.
get(
"dialog.error.title"),
378 if(MessageDialog.openQuestion(getShell(),
MessageBundle.
get(
"dialog.error.title"),
383 controllerBridge_.open();
388 btnOk_ =
new Button(
this,SWT.PUSH);
390 btnOk_.addSelectionListener(
new SelectionListener(){
392 public void widgetDefaultSelected(SelectionEvent e) {
395 public void widgetSelected(SelectionEvent e) {
398 _setAttribute(node_);
408 ATTRIBUTE_CONTROLLER,
409 boxController_.getText()
412 ATTRIBUTE_CONTROL_TIME,
416 ATTRIBUTE_SETUP_DIRECTORY,
417 tfSetupDirectory_.getText()
420 ATTRIBUTE_SETUP_COMMAND,
421 tfSetupCommand_.getText()
423 }
catch (Exception ex) {
424 MessageDialog.openWarning(getShell(),
"",
MessageBundle.
get(
"message.attributeerror"));
432 gridData =
new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
433 gridData.widthHint = BUTTON_WIDTH;
434 btnOk_.setLayoutData(gridData);
436 btnCancel_ =
new Button(
this,SWT.PUSH);
438 btnCancel_.addSelectionListener(
new SelectionListener() {
439 public void widgetDefaultSelected(SelectionEvent e) {
442 public void widgetSelected(SelectionEvent e) {
447 gridData =
new GridData();
449 btnCancel_.setLayoutData(gridData);
457 names =
new String[0];
459 boxController_.removeAll();
460 boxController_.setItems(names);
471 boolean is_set_boxctrl =
false;
472 String attr = node.getProperty(ATTRIBUTE_CONTROLLER,
"");
473 for (
int i = 0;
i < boxController_.getItemCount();
i ++) {
474 if (attr.equals(boxController_.getItem(
i).toString())) {
475 is_set_boxctrl =
true;
476 boxController_.select(
i);
480 if(is_set_boxctrl ==
false)
481 boxController_.setText(attr);
483 spinControlTime_.
setValue(node.getProperty(ATTRIBUTE_CONTROL_TIME,
"0.001"));
486 attr = node.
getStr(ATTRIBUTE_SETUP_COMMAND,
"");
487 tfSetupCommand_.setText(attr);
488 }
catch (Exception ex) {
489 ex.printStackTrace();
495 super.setEnabled(flag);
496 Control[] cmps = this.getChildren();
497 for(
int i = 0;
i < cmps.length;
i ++) {
498 cmps[
i].setEnabled(flag);
500 _setButtonEnabled(!flag);
507 for (i = 0; i < vecRobot_.size(); i ++) {
509 if ((vecRobot_.get(i)).getName().compareTo(node.
getName()) > 0)
514 vecRobot_.add(i, node);
528 if (columnIndex ==0){
532 str = node.
getStr(attrName_[columnIndex]);
533 }
catch(Exception ex){
534 ex.printStackTrace();
561 vecRobot_.remove(node);
570 vecRobot_ =
new Vector<GrxModelItem>();
571 for (
int i=0;
i<list.size();
i++) {
574 vecRobot_.add(list.get(
i));
576 setEnabled(vecRobot_.size() > 0);
577 viewer_.setInput(vecRobot_);
582 return vecRobot_.size();
SEDoubleTextWithSpinForSWT spinControlTime_
static final String get(String key)
void _setButtonEnabled(boolean flag)
void removeListener(ILabelProviderListener listener)
void setRobot(GrxModelItem robot)
void childAdded(GrxModelItem node)
ControllerEditorPanel(Composite parent, int style, String[] initialNames)
#define null
our own NULL pointer
void setEnabled(boolean flag)
boolean _checkDialog(String msg)
void setNode(GrxModelItem node)
item corresponds to a robot model
ControllerBridgePanel controllerBridge_
GrxPluginManager manager_
static Shell getCurrentShell()
static Activator getDefault()
void childRemoved(GrxModelItem node)
Map<?, ?> getItemMap(Class<? extends GrxBaseItem > cls)
void setControlTime(double time)
double getMaxControllTime()
static String expandEnvVal(String str)
Object setProperty(String key, String value)
set property value associated with a keyword
Font getFont(String fontName)
final Double getDbl(String key, Double defaultVal)
get double value associated to key
ControllerEditorPanel editorPanel_
String getColumnText(Object element, int columnIndex)
final String getStr(String key)
get value associated to keyword
Vector< GrxModelItem > vecRobot_
void updateRobots(List< GrxModelItem > list)
ControllerPanel(Composite parent, int style, GrxPluginManager manager)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Image getColumnImage(Object element, int columnIndex)
void setControllerName(String _controllerName)
boolean load(String fileName)
void addListener(ILabelProviderListener listener)
final String getName()
get name
static String [] getObjectNameList()
void startEditMode(GrxModelItem node)
png_infop png_uint_32 flag
boolean checkNameServer()
boolean setProjectControllerName(String _controllerName)
void setEnabled(boolean flag)
boolean isLabelProperty(Object element, String property)