11 package com.generalrobotix.ui.view;
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.Vector;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.TabItem;
22 import org.eclipse.swt.widgets.Text;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
25 import org.eclipse.jface.operation.IRunnableWithProgress;
41 import org.eclipse.swt.events.SelectionEvent;
42 import org.eclipse.swt.events.SelectionListener;
43 import org.eclipse.swt.events.ModifyEvent;
44 import org.eclipse.swt.events.ModifyListener;
45 import org.eclipse.swt.graphics.Point;
46 import org.eclipse.swt.layout.GridData;
47 import org.eclipse.swt.layout.GridLayout;
48 import org.eclipse.swt.widgets.*;
50 import org.eclipse.swt.events.DisposeEvent;
51 import org.eclipse.swt.events.DisposeListener;
52 import org.eclipse.osgi.util.NLS;
54 @SuppressWarnings(
"serial")
56 implements DisposeListener {
57 public static final String TITLE =
"Server Manager";
58 static private final int HORIZONTAL_INDENT = 8;
59 static private final int COLLUMN_NUM = 4;
60 static private final int NAME_SERVER_GROUP_COLLUMN_NUM = 3;
64 private Vector<TabItem> vecTabItem_ =
new Vector<TabItem>();
66 private Text textNsPort_ =
null;
67 private Text textNsHost_ =
null;
68 private Button updateNameServerBtn_ =
null;
72 super(name, manager_, vp, parent);
75 if(serverManager_ !=
null){
96 Composite top =
new Composite(composite_,SWT.NONE);
97 top.setLayoutData(
new GridData(GridData.FILL_BOTH));
98 GridLayout localGridLayout =
new GridLayout( COLLUMN_NUM,
false);
99 localGridLayout.marginWidth = 0;
100 localGridLayout.horizontalSpacing = 0;
101 top.setLayout( localGridLayout );
103 Button insertBtn =
new Button(top , SWT.PUSH);
105 GridData insertBtnGridData =
new GridData();
106 insertBtnGridData.horizontalIndent = HORIZONTAL_INDENT;
107 insertBtn.setLayoutData(insertBtnGridData);
109 Button addBtn =
new Button(top , SWT.PUSH);
111 GridData addBtnGridData =
new GridData();
112 addBtnGridData.horizontalIndent = HORIZONTAL_INDENT;
113 addBtn.setLayoutData(addBtnGridData);
115 Button delBtn =
new Button(top , SWT.PUSH);
117 GridData delBtnGridData =
new GridData();
118 delBtnGridData.horizontalIndent = HORIZONTAL_INDENT;
119 delBtn.setLayoutData(delBtnGridData);
121 Button defBtn =
new Button(top , SWT.PUSH);
123 GridData defBtnGridData =
new GridData();
124 defBtnGridData.horizontalIndent = HORIZONTAL_INDENT;
125 defBtn.setLayoutData(defBtnGridData);
127 folder_ =
new TabFolder(top,SWT.FILL);
129 GridData folderGridData =
new GridData();
130 folderGridData.horizontalSpan = COLLUMN_NUM;
131 folderGridData.horizontalAlignment = SWT.FILL;
132 folderGridData.grabExcessHorizontalSpace =
true;
133 folder_.setLayoutData(folderGridData);
135 insertBtn.addSelectionListener(
new SelectionListener(){
136 public void widgetDefaultSelected(SelectionEvent e) {}
137 public void widgetSelected(SelectionEvent e) {
138 insertServerBtn( folder_ );
142 addBtn.addSelectionListener(
new SelectionListener(){
143 public void widgetDefaultSelected(SelectionEvent e) {}
144 public void widgetSelected(SelectionEvent e) {
145 addServerBtn( folder_ );
149 delBtn.addSelectionListener(
new SelectionListener(){
150 public void widgetDefaultSelected(SelectionEvent e) {}
152 public void widgetSelected(SelectionEvent e) {
153 removeServerBtn( folder_ );
158 defBtn.addSelectionListener(
new SelectionListener(){
159 public void widgetDefaultSelected(SelectionEvent e) {}
161 public void widgetSelected(SelectionEvent e) {
168 Vector<ProcessInfo> vecServerInfo = serverManager_.
getServerInfo();
170 for (
int i = 0;
i < vecServerInfo.size() ; ++
i ){
171 vecTabItem_.add(
new TabItem(folder_,SWT.NONE)) ;
172 vecTabItem_.elementAt(
i).setText(vecServerInfo.elementAt(
i).id);
174 folder_.setSelection(
i);
176 vecTabItem_.elementAt(
i).setControl(panel);
178 folder_.addDisposeListener(
this);
179 folder_.setSelection(0);
182 Group localGroup =
new Group(top, SWT.FILL);
183 localGroup.setText(
"Name Service");
184 GridData groupGridData =
new GridData();
185 groupGridData.heightHint = 60;
186 groupGridData.horizontalAlignment = SWT.FILL;
187 groupGridData.horizontalSpan = NAME_SERVER_GROUP_COLLUMN_NUM;
189 localGroup.setLayoutData(
new GridData(GridData.HORIZONTAL_ALIGN_FILL |
190 GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
192 GridLayout groupGridLayout =
new GridLayout(NAME_SERVER_GROUP_COLLUMN_NUM,
false);
193 groupGridLayout.marginWidth = 2;
194 groupGridLayout.marginHeight = 2;
196 localGroup.setLayout(groupGridLayout);
197 localGroup.setLayoutData(groupGridData);
199 Label localHostLabel =
new Label(localGroup, SWT.RIGHT);
200 GridData hostLabelGridData =
new GridData();
201 hostLabelGridData.widthHint = 100;
203 localHostLabel.setLayoutData(hostLabelGridData);
205 textNsHost_ =
new Text(localGroup, SWT.SINGLE | SWT.BORDER);
206 GridData textNsHostGridData =
new GridData();
207 textNsHostGridData.widthHint = 100;
208 textNsHost_.setText( String.valueOf( serverManager_.
getNewHost()) );
209 textNsHost_.setLayoutData(textNsHostGridData);
210 textNsHost_.addModifyListener(
new ModifyListener(){
211 public void modifyText(ModifyEvent e){
212 updateNameServerBtn_.setEnabled(!equalsHostPort());
216 updateNameServerBtn_ =
new Button(localGroup , SWT.PUSH);
217 GridData btnGridData =
new GridData();
218 btnGridData.widthHint = 64;
219 btnGridData.verticalSpan = 2;
221 updateNameServerBtn_.setText(
MessageBundle.
get(
"GrxServerManagerView.NameServer.button"));
223 updateNameServerBtn_.addSelectionListener(
new SelectionListener() {
224 public void widgetDefaultSelected(SelectionEvent e) {}
226 public void widgetSelected(SelectionEvent e) {
227 updateNameServerBtn();
231 updateNameServerBtn_.setEnabled(
false);
232 updateNameServerBtn_.setLayoutData(btnGridData);
234 Label localPortLabel =
new Label(localGroup, SWT.RIGHT);
235 GridData portLabelGridData =
new GridData();
236 portLabelGridData.widthHint = 100;
238 localPortLabel.setLayoutData(portLabelGridData);
240 textNsPort_ =
new Text(localGroup, SWT.SINGLE | SWT.BORDER);
241 GridData textNsPortGridData =
new GridData();
242 textNsPortGridData.widthHint = 100;
243 textNsPort_.setText( String.valueOf( serverManager_.
getNewPort()) );
244 textNsPort_.setLayoutData(textNsPortGridData);
246 textNsPort_.addModifyListener(
new ModifyListener(){
247 public void modifyText(ModifyEvent e){
248 updateNameServerBtn_.setEnabled(!equalsHostPort());
255 textNsHost_.setText( String.valueOf( serverManager_.
getNewHost()) );
256 textNsPort_.setText( String.valueOf( serverManager_.
getNewPort()) );
257 for (
int i = 0;
i < vecTabItem_.size() ; ++
i ){
258 vecTabItem_.elementAt(
i).getControl().dispose();
259 vecTabItem_.elementAt(
i).dispose();
262 Vector<ProcessInfo> vecServerInfo = serverManager_.
getServerInfo();
263 for (
int i = 0;
i < vecServerInfo.size() ; ++
i ){
264 vecTabItem_.add(
new TabItem(folder_,SWT.NONE)) ;
265 vecTabItem_.elementAt(
i).setText(vecServerInfo.elementAt(
i).id);
267 vecTabItem_.elementAt(
i).setControl(panel);
269 folder_.setSelection(0);
273 Display display = Display.getCurrent();
274 final Shell shell =
new Shell(display , SWT.TITLE | SWT.OK);
275 shell.setLayout(
new GridLayout(2,
false));
277 Label idLabel =
new Label( shell , SWT.RIGHT);
278 idLabel.setText(
"id:");
279 final Text
id =
new Text( shell , SWT.BORDER);
280 GridData idGridData =
new GridData();
281 idGridData.horizontalAlignment = SWT.FILL;
282 idGridData.grabExcessHorizontalSpace =
true;
283 id.setLayoutData(idGridData);
284 Button okBtn =
new Button( shell , SWT.PUSH);
286 Point point = display.getCursorLocation();
287 shell.setLocation(point.x , point.y );
288 shell.setSize(200, 100);
291 okBtn.addSelectionListener(
new SelectionListener(){
292 public void widgetDefaultSelected(SelectionEvent e) {}
294 public void widgetSelected(SelectionEvent e) {
296 int index = folder.getSelectionIndex();
299 localInfo.
id =
id.getText();
300 localInfo.
com.clear();
301 localInfo.
com.add(
"");
307 Vector<ProcessInfo> vecServerInfo = serverManager_.
getServerInfo();
308 vecServerInfo.add(index,localInfo);
309 vecTabItem_.add(index ,
new TabItem(folder,SWT.NONE , index)) ;
310 vecTabItem_.elementAt(index).setText(vecServerInfo.elementAt(index).id);
311 folder.setSelection(index);
313 vecTabItem_.elementAt(index).setControl(panel);
323 Display display = Display.getCurrent();
324 final Shell shell =
new Shell(display , SWT.TITLE | SWT.OK);
325 shell.setLayout(
new GridLayout(2,
false));
327 Label idLabel =
new Label( shell , SWT.RIGHT);
328 idLabel.setText(
"id:");
329 final Text
id =
new Text( shell , SWT.BORDER);
330 GridData idGridData =
new GridData();
331 idGridData.horizontalAlignment = SWT.FILL;
332 idGridData.grabExcessHorizontalSpace =
true;
333 id.setLayoutData(idGridData);
334 Button okBtn =
new Button( shell , SWT.PUSH);
336 Point point = display.getCursorLocation();
337 shell.setLocation(point.x , point.y );
338 shell.setSize(200, 100);
340 okBtn.addSelectionListener(
new SelectionListener(){
341 public void widgetDefaultSelected(SelectionEvent e) {}
343 public void widgetSelected(SelectionEvent e) {
345 int index = folder.getSelectionIndex() + 1;
347 localInfo.
id =
id.getText();
348 localInfo.
com.clear();
349 localInfo.
com.add(
"");
355 Vector<ProcessInfo> vecServerInfo = serverManager_.
getServerInfo();
356 vecServerInfo.add(index,localInfo);
357 vecTabItem_.add(index ,
new TabItem(folder,SWT.NONE , index)) ;
358 vecTabItem_.elementAt(index).setText(vecServerInfo.elementAt(index).id);
359 folder.setSelection(index);
361 vecTabItem_.elementAt(index).setControl(panel);
371 int index = folder.getSelectionIndex();
372 Vector<ProcessInfo> vecServerInfo = serverManager_.
getServerInfo();
374 String mes =
MessageBundle.
get(
"GrxServerManagerView.dialog.message.remove");
375 mes = NLS.bind(mes,
new String[]{vecTabItem_.elementAt(index).getText()});
378 if ( MessageDialog.openConfirm(
379 composite_.getShell(),
383 vecTabItem_.elementAt(index).getControl().dispose();
384 folder.getItem(index).dispose();
385 vecTabItem_.remove(index);
386 vecServerInfo.remove(index);
392 MessageDialog.openWarning(
393 composite_.getShell(),
399 String localID =
id.toUpperCase();
400 for (TabItem
i:vecTabItem_){
401 String srcStr =
i.getText().toUpperCase();
402 if( srcStr.equals(localID) ){
404 MessageDialog.openWarning(
405 composite_.getShell(),
416 String port = textNsPort_.getText();
417 String host = textNsHost_.getText();
419 if( !host.equals(serverManager_.
getNewHost()) ){
424 if( serverManager_.
getNewPort() != Integer.valueOf(port) ){
427 }
catch (NumberFormatException ex){
429 }
catch (Exception ex){
430 ex.printStackTrace();
439 for (
int i = 0;
i < vecTabItem_.size(); ++
i){
446 StringBuffer refHost =
new StringBuffer(
"");
447 StringBuffer refPort =
new StringBuffer(
"");
449 boolean ret = MessageDialog.openQuestion(composite_.getShell(),
450 MessageBundle.
get(
"GrxServerManagerView.dialog.infomation.tittle.updateNameServer"),
451 MessageBundle.
get(
"GrxServerManagerView.dialog.infomation.message.updateNameServer"));
454 String
message = serverManager_.
setNewHostPort(textNsHost_.getText(), textNsPort_.getText(), refHost, refPort );
456 if(message.isEmpty()){
457 updateNameServerBtn_.setEnabled(
false);
460 MessageDialog.openError(composite_.getShell(),
461 MessageBundle.
get(
"GrxServerManagerView.dialog.error.tittle.updateNameServer"),
463 if( refHost.length() != 0){
464 textNsHost_.setText(refHost.toString());
466 if( refPort.length() != 0 ){
467 textNsPort_.setText(refPort.toString());
475 IRunnableWithProgress iProgress =
new IRunnableWithProgress() {
476 public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
477 monitor.beginTask(
MessageBundle.
get(
"GrxServerManagerView.dialog.title.progress"),
479 restartServers(monitor);
484 }
catch (InvocationTargetException e) {
486 }
catch (InterruptedException e) {
492 private void restartServers(IProgressMonitor monitor)
throws InterruptedException{
497 if(simItem_ !=
null){
501 serverManager_.
restart(monitor);
503 if(simItem_ !=
null){
518 GrxServerManager serverManager = (GrxServerManager) item;
521 if(serverManager_ ==
null){
522 serverManager_ = serverManager;
531 GrxSimulationItem simItem = (GrxSimulationItem) item;
534 if(simItem_!=simItem){
541 if(simItem_==simItem){
554 storevecServerInfo();
558 if(serverManager_==plugin){
559 if((String)
arg[0]==
"ProcessEnd"){
560 for (TabItem
i: vecTabItem_){
561 if(
i.getText().equals((String)
arg[1])){
566 }
else if(simItem_==plugin){
567 if((String)
arg[0]==
"StartSimulation"){
568 setEditableHostPortText(
false);
569 }
else if((String)
arg[0]==
"StopSimulation"){
570 setEditableHostPortText(
true);
577 if(serverManager_!=
null)
586 textNsHost_.setEditable(bEnable);
587 textNsPort_.setEditable(bEnable);
static final String get(String key)
void setEditableHostPortText(boolean bEnable)
void addObserver(GrxObserver v)
#define null
our own NULL pointer
GrxBaseItem getItem(Class<?extends GrxBaseItem > cls, String name)
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void deleteObserver(GrxObserver v)
static final int ADD_ITEM
static final int SELECTED_ITEM
static Shell getCurrentShell()
void restart(IProgressMonitor monitor)
String serverInfoDefaultDir_
static final int REMOVE_ITEM
void removeServerBtn(TabFolder folder)
void storevecServerInfo()
void widgetDisposed(DisposeEvent e)
void addServerBtn(final TabFolder folder)
boolean checkID(String id)
void update(GrxBasePlugin plugin, Object...arg)
String setNewHostPort(String host, String port, StringBuffer refHost, StringBuffer refPort)
void restartServers(IProgressMonitor monitor)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Vector< ProcessInfo > getServerInfo()
vecServerInfoの取得
def getText(self, nodes=None)
synchronized void SaveServerInfo()
static final int NOTSELECTED_ITEM
int serverInfoDefaultWaitCount_
void updateNameServerBtn()
void registerItemChange(GrxBaseItem item, int event)
GrxServerManagerView(String name, GrxPluginManager manager_, GrxBaseViewPart vp, Composite parent)
void registerItemChangeListener(GrxItemChangeListener view, Class<?extends GrxBaseItem > cls)
void insertServerBtn(final TabFolder folder)