GrxServerManagerPanel.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  */
00017 package com.generalrobotix.ui.util;
00018 
00019 import org.eclipse.jface.dialogs.MessageDialog;
00020 import org.eclipse.swt.SWT;
00021 import org.eclipse.swt.events.SelectionEvent;
00022 import org.eclipse.swt.events.SelectionListener;
00023 import org.eclipse.swt.events.ModifyEvent;
00024 import org.eclipse.swt.events.ModifyListener;
00025 import org.eclipse.swt.layout.GridData;
00026 import org.eclipse.swt.layout.GridLayout;
00027 import org.eclipse.swt.widgets.Button;
00028 import org.eclipse.swt.widgets.Composite;
00029 import org.eclipse.swt.widgets.FileDialog;
00030 import org.eclipse.swt.widgets.Label;
00031 import org.eclipse.swt.widgets.Text;
00032 import org.eclipse.swt.widgets.TabFolder;
00033 import org.eclipse.osgi.util.NLS;
00034 
00035 import com.generalrobotix.ui.GrxPluginManager;
00036 import com.generalrobotix.ui.grxui.GrxUIPerspectiveFactory;
00037 import com.generalrobotix.ui.util.GrxProcessManager.AProcess;
00038 import com.generalrobotix.ui.util.GrxProcessManager.ProcessInfo;
00039 
00040 public class GrxServerManagerPanel extends Composite {
00041 
00042     static private final int    HORIZON_INDENT_ = 4;
00043     static private final int    LABEL_LENGTH_   = 40;
00044     static private final int    LOCAL_REF_BUTTON_LENGTH_ = 18;
00045     static private final int    BUTTON_LENGTH_   = 64;
00046     static private final int    TEXT_LENGTH_    = 256;
00047     static private final String START_          = MessageBundle.get("GrxServerManagerPanel.button.start"); //$NON-NLS-1$
00048     static private final String STOP_           = MessageBundle.get("GrxServerManagerPanel.button.stop"); //$NON-NLS-1$
00049     static private final String RESTART_        = MessageBundle.get("GrxServerManagerPanel.button.restart"); //$NON-NLS-1$
00050     
00051     private Button  toggleButton_ = null; // Start <-> Stop Button
00052     private Button  restartButton_= null; // Restart Button
00053     private Button  autoChkBox_   = null; // Automatic start process flag
00054     private Button  useORBChkBox_ = null;
00055     private Text    pathText_     = null;
00056     private Text    argsText_     = null;
00057     private GrxServerManager serverManager_ = null;
00058     
00059     private String  pathStr_ = null;
00060     private String  argsStr_ = null;
00061     private boolean bUseORB_;
00062     private boolean bAuto_;
00063     
00064     private ProcessInfo processInfo_=null;
00065     private boolean restartFlag_ = false;
00066     private GrxPluginManager pluginManager_ = null;
00067     
00068     public GrxServerManagerPanel(GrxServerManager manager, TabFolder parent, int style, int index, GrxPluginManager pluginManager) {
00069         super(parent, style);
00070         pluginManager_ = pluginManager;
00071         serverManager_ = manager;
00072         processInfo_ = manager.getServerInfo().elementAt(index);
00073         Composite localPanel = this;
00074         localPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL |
00075                 GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
00076 
00077         GridLayout localGridLayout = new GridLayout(4, false);
00078 
00079         localGridLayout.marginLeft = 0;
00080         localGridLayout.horizontalSpacing = 0;
00081         localPanel.setLayout(localGridLayout);
00082 
00083         Label localLabelPath = new Label(localPanel, SWT.RIGHT);
00084         localLabelPath.setText(MessageBundle.get("GrxServerManagerPanel.label.path")); //$NON-NLS-1$
00085         GridData labelPathGridData = new GridData();
00086         labelPathGridData.widthHint = LABEL_LENGTH_;
00087 
00088         pathText_ = new Text(localPanel, SWT.BORDER);
00089         GridData pathGridData = new GridData(GridData.FILL_HORIZONTAL);
00090         pathGridData.widthHint = TEXT_LENGTH_;
00091         pathText_.setText(processInfo_.com.get(processInfo_.editComIndex));
00092         pathStr_ = processInfo_.com.get(processInfo_.editComIndex);
00093         pathText_.addModifyListener( new ModifyListener() {
00094             public void modifyText(ModifyEvent e){
00095                 pathStr_ = new String( pathText_.getText().trim());
00096             }
00097         });
00098         
00099         Button localRefButton = new Button(localPanel, SWT.PUSH);
00100         localRefButton.setText("..."); //$NON-NLS-1$
00101         GridData refbtnGridData = new GridData();
00102         refbtnGridData.horizontalIndent = HORIZON_INDENT_;
00103         refbtnGridData.widthHint = LOCAL_REF_BUTTON_LENGTH_;
00104         
00105         restartButton_ = new Button(localPanel, SWT.PUSH);
00106         restartButton_.setText(RESTART_);
00107         GridData rstbtnGridData = new GridData();
00108         rstbtnGridData.horizontalIndent = HORIZON_INDENT_;
00109         rstbtnGridData.widthHint = BUTTON_LENGTH_;
00110 
00111         Label localLabelArgs = new Label(localPanel, SWT.RIGHT);
00112         localLabelArgs.setText(MessageBundle.get("GrxServerManagerPanel.label.args")); //$NON-NLS-1$
00113         GridData labelArgsGridData = new GridData();
00114         labelArgsGridData.widthHint = LABEL_LENGTH_;
00115 
00116         argsText_ = new Text(localPanel, SWT.BORDER);
00117         GridData argsGridData = new GridData(GridData.FILL_HORIZONTAL);
00118         argsGridData.widthHint = TEXT_LENGTH_;
00119         argsText_.setText(processInfo_.args);
00120         argsStr_ = processInfo_.args;
00121         argsText_.addModifyListener( new ModifyListener() {
00122             public void modifyText(ModifyEvent e){
00123                 argsStr_ = new String(argsText_.getText().trim()); 
00124             }
00125         });
00126 
00127         toggleButton_ = new Button(localPanel, SWT.PUSH);
00128         GrxProcessManager pm = (GrxProcessManager) pluginManager_.getItem("processManager");
00129         AProcess process = pm.get(processInfo_.id);
00130         if ( process!=null && process.isRunning() ) {
00131             toggleButton_.setText(STOP_);
00132             restartButton_.setVisible(true);
00133         } else {
00134             toggleButton_.setText(START_);
00135             restartButton_.setVisible(false);
00136         }
00137         
00138         localRefButton.addSelectionListener(new SelectionListener() {
00139             public void widgetDefaultSelected(SelectionEvent e) {}
00140             
00141             public void widgetSelected(SelectionEvent e) {
00142                 updateRefBtn();
00143             }
00144         });
00145 
00146         toggleButton_.addSelectionListener(new SelectionListener() {
00147             public void widgetDefaultSelected(SelectionEvent e) {}
00148 
00149             public void widgetSelected(SelectionEvent e) {
00150                 updateBtn();
00151             }
00152         });
00153 
00154         restartButton_.addSelectionListener(new SelectionListener() {
00155             public void widgetDefaultSelected(SelectionEvent e) {}
00156 
00157             public void widgetSelected(SelectionEvent e) {
00158                 updateRestartBtn();
00159             }
00160         });
00161         
00162         GridData btnGridData = new GridData();
00163         btnGridData.horizontalIndent = HORIZON_INDENT_;
00164         btnGridData.widthHint = BUTTON_LENGTH_;
00165         btnGridData.horizontalAlignment = SWT.END;
00166         btnGridData.horizontalSpan = 2;
00167 
00168         Label localLabelAuto = new Label(localPanel, SWT.RIGHT | SWT.FILL);
00169         localLabelAuto.setText(MessageBundle.get("GrxServerManagerPanel.label.start")); //$NON-NLS-1$
00170         GridData labelAutoGridData = new GridData(GridData.FILL_HORIZONTAL);
00171         labelAutoGridData.horizontalSpan = 2;
00172         labelAutoGridData.widthHint = LABEL_LENGTH_ + TEXT_LENGTH_;
00173 
00174         autoChkBox_ = new Button(localPanel, SWT.CHECK);
00175         GridData chkbtnGridData = new GridData();
00176         chkbtnGridData.horizontalIndent = HORIZON_INDENT_;
00177         autoChkBox_.setSelection(processInfo_.autoStart);
00178         bAuto_ = processInfo_.autoStart;
00179         autoChkBox_.addSelectionListener( new SelectionListener() {
00180             public void widgetDefaultSelected(SelectionEvent e){}
00181             
00182             public void widgetSelected(SelectionEvent e){
00183                 bAuto_ = autoChkBox_.getSelection();
00184             }
00185             
00186         });
00187         Label localLabelUseORB = new Label(localPanel, SWT.RIGHT | SWT.FILL);
00188         localLabelUseORB.setText(MessageBundle.get("GrxServerManagerPanel.label.useeRef")); //$NON-NLS-1$
00189         GridData labelUseORBGridData = new GridData(GridData.FILL_HORIZONTAL);
00190         labelUseORBGridData.horizontalSpan = 2;
00191         labelUseORBGridData.widthHint = LABEL_LENGTH_ + TEXT_LENGTH_;
00192 
00193         useORBChkBox_ = new Button(localPanel, SWT.CHECK);
00194         GridData UseORBchkbtnGridData = new GridData();
00195         UseORBchkbtnGridData.horizontalIndent = HORIZON_INDENT_;
00196         useORBChkBox_.setSelection(processInfo_.useORB);
00197         bUseORB_ = processInfo_.useORB;
00198         useORBChkBox_.addSelectionListener( new SelectionListener() {
00199             public void widgetDefaultSelected(SelectionEvent e){}
00200             
00201             public void widgetSelected(SelectionEvent e){
00202                 bUseORB_ = useORBChkBox_.getSelection();
00203             }
00204             
00205         });
00206         localLabelPath.setLayoutData(labelPathGridData);
00207         pathText_.setLayoutData(pathGridData);
00208         localRefButton.setLayoutData(refbtnGridData);
00209         restartButton_.setLayoutData(rstbtnGridData);
00210         localLabelArgs.setLayoutData(labelArgsGridData);
00211         argsText_.setLayoutData(argsGridData);
00212         toggleButton_.setLayoutData(btnGridData);
00213         localLabelAuto.setLayoutData(labelAutoGridData);
00214         autoChkBox_.setLayoutData(chkbtnGridData);
00215         localLabelUseORB.setLayoutData(labelUseORBGridData);
00216         useORBChkBox_.setLayoutData(UseORBchkbtnGridData);
00217     }
00218 
00219     //パネルの情報を元にProcessInfoを更新する
00220     public void updateProcessInfo(){
00221         processInfo_.autoStart = bAuto_;
00222         processInfo_.useORB = bUseORB_;
00223         processInfo_.args = argsStr_;
00224         
00225         // comに関してはupdateBtn(int localDim)を参照
00226         processInfo_.com.remove(processInfo_.editComIndex);
00227         processInfo_.com.add( processInfo_.editComIndex, pathStr_ );
00228     }
00229     
00230     //ファイル参照用のモーダルダイアログを開く
00231     private void updateRefBtn() {
00232         //ファイル名の取得
00233         String[] filterNames = new String[] { MessageBundle.get("GrxServerManagerPanel.filedialog.filterName") }; //$NON-NLS-1$
00234         String[] filterExtensions = new String[] { "*" }; //$NON-NLS-1$
00235         FileDialog fileDlg = new FileDialog(GrxUIPerspectiveFactory.getCurrentShell(), SWT.OPEN);
00236 
00237         fileDlg.setText(""); //$NON-NLS-1$
00238         fileDlg.setFilterNames(filterNames);
00239         fileDlg.setFilterExtensions(filterExtensions);
00240 
00241         String strServerName = processInfo_.id;
00242         fileDlg.setText(MessageBundle.get("GrxServerManagerPanel.filedialog.title") + strServerName); //$NON-NLS-1$
00243         pathText_.setText(fileDlg.open());
00244     }
00245 
00246     //プロセス停止と開始
00247     private void updateBtn() {
00248         String mes = MessageBundle.get("GrxServerManagerPanel.dialog.message.update"); //$NON-NLS-1$
00249         mes = NLS.bind(mes, new String[]{toggleButton_.getText()});
00250 
00251         // 確認ダイアログ表示後 当該 タブを削除
00252         if ( MessageDialog.openConfirm(
00253                 this.getShell(),
00254                 MessageBundle.get("GrxServerManagerPanel.dialog.title.update") + toggleButton_.getText(), //$NON-NLS-1$
00255                 mes)) //$NON-NLS-1$ //$NON-NLS-2$
00256         {
00257             updateProcessInfo();
00258             if( serverManager_.toggleProcess(processInfo_) )
00259             {
00260                 toggleButton_.setText(STOP_);
00261                 restartButton_.setVisible(true);
00262             }else{
00263                 toggleButton_.setText(START_);
00264                 restartButton_.setVisible(false);
00265             }
00266         }
00267     }
00268 
00269     //プロセス再起動
00270     private void updateRestartBtn() {
00271         String mes = MessageBundle.get("GrxServerManagerPanel.dialog.message.restart"); //$NON-NLS-1$
00272         String title = MessageBundle.get("GrxServerManagerPanel.dialog.title.update") + restartButton_.getText(); //$NON-NLS-1$
00273         // 確認ダイアログ表示後 再起動
00274         if ( MessageDialog.openConfirm(
00275                 this.getShell(),
00276                 title,
00277                 mes)) //$NON-NLS-1$ //$NON-NLS-2$
00278         {
00279             updateProcessInfo();
00280 
00281             GrxProcessManager pm = (GrxProcessManager) pluginManager_.getItem("processManager");
00282             AProcess process = pm.get(processInfo_.id);
00283             
00284             //プロセス停止時は起動のみ行う
00285             //(停止時は非表示のためイレギュラーケース)
00286             if(process==null || !process.isRunning()){
00287                 if( serverManager_.toggleProcess(processInfo_) )
00288                 {
00289                     toggleButton_.setText(STOP_);
00290                     restartButton_.setVisible(true);
00291                 }else{
00292                     toggleButton_.setText(START_);
00293                     restartButton_.setVisible(false);
00294                     MessageDialog.openError(
00295                             this.getShell(),title,
00296                             MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
00297                 }
00298                 return;
00299             }
00300 
00301             // サーバの停止
00302             if(serverManager_.toggleProcess(processInfo_))
00303             {
00304                 toggleButton_.setText(STOP_);
00305                 restartButton_.setVisible(true);
00306                 MessageDialog.openError(
00307                         this.getShell(),title,
00308                         MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
00309                 return;
00310             }
00311             // サーバの起動
00312             if(!serverManager_.toggleProcess(processInfo_))
00313             {
00314                 toggleButton_.setText(START_);
00315                 restartButton_.setVisible(false);
00316                 MessageDialog.openError(
00317                         this.getShell(),title,
00318                         MessageBundle.get("GrxServerManagerPanel.dialog.message.errorRestart"));
00319                 return;
00320             }
00321 
00322             toggleButton_.setText(STOP_);
00323             restartButton_.setVisible(true);
00324             restartFlag_ = true;
00325         }
00326     }
00327     
00328     public void setStartText(){
00329         // 再起動時はプロセス停止notifyを一回無視する
00330         if(restartFlag_)
00331         {
00332             restartFlag_ = false;
00333             return;
00334         }
00335 
00336         toggleButton_.setText(START_);
00337         restartButton_.setVisible(false);
00338     }
00339 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:54