GrxServerManagerPanel.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.util;
18 
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.events.SelectionListener;
23 import org.eclipse.swt.events.ModifyEvent;
24 import org.eclipse.swt.events.ModifyListener;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.FileDialog;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Text;
32 import org.eclipse.swt.widgets.TabFolder;
33 import org.eclipse.osgi.util.NLS;
34 
39 
40 public class GrxServerManagerPanel extends Composite {
41 
42  static private final int HORIZON_INDENT_ = 4;
43  static private final int LABEL_LENGTH_ = 40;
44  static private final int LOCAL_REF_BUTTON_LENGTH_ = 18;
45  static private final int BUTTON_LENGTH_ = 64;
46  static private final int TEXT_LENGTH_ = 256;
47  static private final String START_ = MessageBundle.get("GrxServerManagerPanel.button.start"); //$NON-NLS-1$
48  static private final String STOP_ = MessageBundle.get("GrxServerManagerPanel.button.stop"); //$NON-NLS-1$
49  static private final String RESTART_ = MessageBundle.get("GrxServerManagerPanel.button.restart"); //$NON-NLS-1$
50 
51  private Button toggleButton_ = null; // Start <-> Stop Button
52  private Button restartButton_= null; // Restart Button
53  private Button autoChkBox_ = null; // Automatic start process flag
54  private Button useORBChkBox_ = null;
55  private Text pathText_ = null;
56  private Text argsText_ = null;
58 
59  private String pathStr_ = null;
60  private String argsStr_ = null;
61  private boolean bUseORB_;
62  private boolean bAuto_;
63 
65  private boolean restartFlag_ = false;
67 
68  public GrxServerManagerPanel(GrxServerManager manager, TabFolder parent, int style, int index, GrxPluginManager pluginManager) {
69  super(parent, style);
70  pluginManager_ = pluginManager;
71  serverManager_ = manager;
72  processInfo_ = manager.getServerInfo().elementAt(index);
73  Composite localPanel = this;
74  localPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
75  GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
76 
77  GridLayout localGridLayout = new GridLayout(4, false);
78 
79  localGridLayout.marginLeft = 0;
80  localGridLayout.horizontalSpacing = 0;
81  localPanel.setLayout(localGridLayout);
82 
83  Label localLabelPath = new Label(localPanel, SWT.RIGHT);
84  localLabelPath.setText(MessageBundle.get("GrxServerManagerPanel.label.path")); //$NON-NLS-1$
85  GridData labelPathGridData = new GridData();
86  labelPathGridData.widthHint = LABEL_LENGTH_;
87 
88  pathText_ = new Text(localPanel, SWT.BORDER);
89  GridData pathGridData = new GridData(GridData.FILL_HORIZONTAL);
90  pathGridData.widthHint = TEXT_LENGTH_;
91  pathText_.setText(processInfo_.com.get(processInfo_.editComIndex));
92  pathStr_ = processInfo_.com.get(processInfo_.editComIndex);
93  pathText_.addModifyListener( new ModifyListener() {
94  public void modifyText(ModifyEvent e){
95  pathStr_ = new String( pathText_.getText().trim());
96  }
97  });
98 
99  Button localRefButton = new Button(localPanel, SWT.PUSH);
100  localRefButton.setText("..."); //$NON-NLS-1$
101  GridData refbtnGridData = new GridData();
102  refbtnGridData.horizontalIndent = HORIZON_INDENT_;
103  refbtnGridData.widthHint = LOCAL_REF_BUTTON_LENGTH_;
104 
105  restartButton_ = new Button(localPanel, SWT.PUSH);
106  restartButton_.setText(RESTART_);
107  GridData rstbtnGridData = new GridData();
108  rstbtnGridData.horizontalIndent = HORIZON_INDENT_;
109  rstbtnGridData.widthHint = BUTTON_LENGTH_;
110 
111  Label localLabelArgs = new Label(localPanel, SWT.RIGHT);
112  localLabelArgs.setText(MessageBundle.get("GrxServerManagerPanel.label.args")); //$NON-NLS-1$
113  GridData labelArgsGridData = new GridData();
114  labelArgsGridData.widthHint = LABEL_LENGTH_;
115 
116  argsText_ = new Text(localPanel, SWT.BORDER);
117  GridData argsGridData = new GridData(GridData.FILL_HORIZONTAL);
118  argsGridData.widthHint = TEXT_LENGTH_;
119  argsText_.setText(processInfo_.args);
120  argsStr_ = processInfo_.args;
121  argsText_.addModifyListener( new ModifyListener() {
122  public void modifyText(ModifyEvent e){
123  argsStr_ = new String(argsText_.getText().trim());
124  }
125  });
126 
127  toggleButton_ = new Button(localPanel, SWT.PUSH);
128  GrxProcessManager pm = (GrxProcessManager) pluginManager_.getItem("processManager");
129  AProcess process = pm.get(processInfo_.id);
130  if ( process!=null && process.isRunning() ) {
131  toggleButton_.setText(STOP_);
132  restartButton_.setVisible(true);
133  } else {
134  toggleButton_.setText(START_);
135  restartButton_.setVisible(false);
136  }
137 
138  localRefButton.addSelectionListener(new SelectionListener() {
139  public void widgetDefaultSelected(SelectionEvent e) {}
140 
141  public void widgetSelected(SelectionEvent e) {
142  updateRefBtn();
143  }
144  });
145 
146  toggleButton_.addSelectionListener(new SelectionListener() {
147  public void widgetDefaultSelected(SelectionEvent e) {}
148 
149  public void widgetSelected(SelectionEvent e) {
150  updateBtn();
151  }
152  });
153 
154  restartButton_.addSelectionListener(new SelectionListener() {
155  public void widgetDefaultSelected(SelectionEvent e) {}
156 
157  public void widgetSelected(SelectionEvent e) {
159  }
160  });
161 
162  GridData btnGridData = new GridData();
163  btnGridData.horizontalIndent = HORIZON_INDENT_;
164  btnGridData.widthHint = BUTTON_LENGTH_;
165  btnGridData.horizontalAlignment = SWT.END;
166  btnGridData.horizontalSpan = 2;
167 
168  Label localLabelAuto = new Label(localPanel, SWT.RIGHT | SWT.FILL);
169  localLabelAuto.setText(MessageBundle.get("GrxServerManagerPanel.label.start")); //$NON-NLS-1$
170  GridData labelAutoGridData = new GridData(GridData.FILL_HORIZONTAL);
171  labelAutoGridData.horizontalSpan = 2;
172  labelAutoGridData.widthHint = LABEL_LENGTH_ + TEXT_LENGTH_;
173 
174  autoChkBox_ = new Button(localPanel, SWT.CHECK);
175  GridData chkbtnGridData = new GridData();
176  chkbtnGridData.horizontalIndent = HORIZON_INDENT_;
177  autoChkBox_.setSelection(processInfo_.autoStart);
178  bAuto_ = processInfo_.autoStart;
179  autoChkBox_.addSelectionListener( new SelectionListener() {
180  public void widgetDefaultSelected(SelectionEvent e){}
181 
182  public void widgetSelected(SelectionEvent e){
183  bAuto_ = autoChkBox_.getSelection();
184  }
185 
186  });
187  Label localLabelUseORB = new Label(localPanel, SWT.RIGHT | SWT.FILL);
188  localLabelUseORB.setText(MessageBundle.get("GrxServerManagerPanel.label.useeRef")); //$NON-NLS-1$
189  GridData labelUseORBGridData = new GridData(GridData.FILL_HORIZONTAL);
190  labelUseORBGridData.horizontalSpan = 2;
191  labelUseORBGridData.widthHint = LABEL_LENGTH_ + TEXT_LENGTH_;
192 
193  useORBChkBox_ = new Button(localPanel, SWT.CHECK);
194  GridData UseORBchkbtnGridData = new GridData();
195  UseORBchkbtnGridData.horizontalIndent = HORIZON_INDENT_;
196  useORBChkBox_.setSelection(processInfo_.useORB);
197  bUseORB_ = processInfo_.useORB;
198  useORBChkBox_.addSelectionListener( new SelectionListener() {
199  public void widgetDefaultSelected(SelectionEvent e){}
200 
201  public void widgetSelected(SelectionEvent e){
202  bUseORB_ = useORBChkBox_.getSelection();
203  }
204 
205  });
206  localLabelPath.setLayoutData(labelPathGridData);
207  pathText_.setLayoutData(pathGridData);
208  localRefButton.setLayoutData(refbtnGridData);
209  restartButton_.setLayoutData(rstbtnGridData);
210  localLabelArgs.setLayoutData(labelArgsGridData);
211  argsText_.setLayoutData(argsGridData);
212  toggleButton_.setLayoutData(btnGridData);
213  localLabelAuto.setLayoutData(labelAutoGridData);
214  autoChkBox_.setLayoutData(chkbtnGridData);
215  localLabelUseORB.setLayoutData(labelUseORBGridData);
216  useORBChkBox_.setLayoutData(UseORBchkbtnGridData);
217  }
218 
219  //パネルの情報を元にProcessInfoを更新する
220  public void updateProcessInfo(){
221  processInfo_.autoStart = bAuto_;
222  processInfo_.useORB = bUseORB_;
223  processInfo_.args = argsStr_;
224 
225  // comに関してはupdateBtn(int localDim)を参照
226  processInfo_.com.remove(processInfo_.editComIndex);
227  processInfo_.com.add( processInfo_.editComIndex, pathStr_ );
228  }
229 
230  //ファイル参照用のモーダルダイアログを開く
231  private void updateRefBtn() {
232  //ファイル名の取得
233  String[] filterNames = new String[] { MessageBundle.get("GrxServerManagerPanel.filedialog.filterName") }; //$NON-NLS-1$
234  String[] filterExtensions = new String[] { "*" }; //$NON-NLS-1$
235  FileDialog fileDlg = new FileDialog(GrxUIPerspectiveFactory.getCurrentShell(), SWT.OPEN);
236 
237  fileDlg.setText(""); //$NON-NLS-1$
238  fileDlg.setFilterNames(filterNames);
239  fileDlg.setFilterExtensions(filterExtensions);
240 
241  String strServerName = processInfo_.id;
242  fileDlg.setText(MessageBundle.get("GrxServerManagerPanel.filedialog.title") + strServerName); //$NON-NLS-1$
243  pathText_.setText(fileDlg.open());
244  }
245 
246  //プロセス停止と開始
247  private void updateBtn() {
248  String mes = MessageBundle.get("GrxServerManagerPanel.dialog.message.update"); //$NON-NLS-1$
249  mes = NLS.bind(mes, new String[]{toggleButton_.getText()});
250 
251  // 確認ダイアログ表示後 当該 タブを削除
252  if ( MessageDialog.openConfirm(
253  this.getShell(),
254  MessageBundle.get("GrxServerManagerPanel.dialog.title.update") + toggleButton_.getText(), //$NON-NLS-1$
255  mes)) //$NON-NLS-1$ //$NON-NLS-2$
256  {
258  if( serverManager_.toggleProcess(processInfo_) )
259  {
260  toggleButton_.setText(STOP_);
261  restartButton_.setVisible(true);
262  }else{
263  toggleButton_.setText(START_);
264  restartButton_.setVisible(false);
265  }
266  }
267  }
268 
269  //プロセス再起動
270  private void updateRestartBtn() {
271  String mes = MessageBundle.get("GrxServerManagerPanel.dialog.message.restart"); //$NON-NLS-1$
272  String title = MessageBundle.get("GrxServerManagerPanel.dialog.title.update") + restartButton_.getText(); //$NON-NLS-1$
273  // 確認ダイアログ表示後 再起動
274  if ( MessageDialog.openConfirm(
275  this.getShell(),
276  title,
277  mes)) //$NON-NLS-1$ //$NON-NLS-2$
278  {
280 
281  GrxProcessManager pm = (GrxProcessManager) pluginManager_.getItem("processManager");
282  AProcess process = pm.get(processInfo_.id);
283 
284  //プロセス停止時は起動のみ行う
285  //(停止時は非表示のためイレギュラーケース)
286  if(process==null || !process.isRunning()){
287  if( serverManager_.toggleProcess(processInfo_) )
288  {
289  toggleButton_.setText(STOP_);
290  restartButton_.setVisible(true);
291  }else{
292  toggleButton_.setText(START_);
293  restartButton_.setVisible(false);
294  MessageDialog.openError(
295  this.getShell(),title,
296  MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
297  }
298  return;
299  }
300 
301  // サーバの停止
302  if(serverManager_.toggleProcess(processInfo_))
303  {
304  toggleButton_.setText(STOP_);
305  restartButton_.setVisible(true);
306  MessageDialog.openError(
307  this.getShell(),title,
308  MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
309  return;
310  }
311  // サーバの起動
312  if(!serverManager_.toggleProcess(processInfo_))
313  {
314  toggleButton_.setText(START_);
315  restartButton_.setVisible(false);
316  MessageDialog.openError(
317  this.getShell(),title,
318  MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
319  return;
320  }
321 
322  toggleButton_.setText(STOP_);
323  restartButton_.setVisible(true);
324  restartFlag_ = true;
325  }
326  }
327 
328  public void setStartText(){
329  // 再起動時はプロセス停止notifyを一回無視する
330  if(restartFlag_)
331  {
332  restartFlag_ = false;
333  return;
334  }
335 
336  toggleButton_.setText(START_);
337  restartButton_.setVisible(false);
338  }
339 }
static final String get(String key)
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxBaseItem getItem(Class<?extends GrxBaseItem > cls, String name)
boolean toggleProcess(ProcessInfo pInfo)
サーバプログラムの起動トグル
GrxServerManagerPanel(GrxServerManager manager, TabFolder parent, int style, int index, GrxPluginManager pluginManager)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Vector< ProcessInfo > getServerInfo()
vecServerInfoの取得
org


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22