StartSimulate.java
Go to the documentation of this file.
1 package com.generalrobotix.ui.actions;
2 
3 import org.eclipse.jface.action.ActionContributionItem;
4 import org.eclipse.jface.action.IAction;
5 import org.eclipse.jface.action.IContributionItem;
6 import org.eclipse.jface.action.ICoolBarManager;
7 import org.eclipse.jface.action.IToolBarManager;
8 import org.eclipse.jface.action.ToolBarContributionItem;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.jface.window.ApplicationWindow;
11 import org.eclipse.ui.IWorkbenchWindow;
12 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
13 import org.eclipse.ui.PlatformUI;
14 
24 
25 public class StartSimulate implements IWorkbenchWindowActionDelegate, GrxItemChangeListener, GrxObserver {
26  private IAction action_ = null;
28 
29  public StartSimulate() {
30  setUp();
32  manager_.registerItemChangeListener(this, GrxSimulationItem.class);
33  }
34 
35  public void setUp(){
36  if(simItem_ != null)
37  simItem_.deleteObserver(this);
39  simItem_ = manager_.<GrxSimulationItem>getSelectedItem(GrxSimulationItem.class, null);
40  if(simItem_!=null){
41  simItem_.addObserver(this);
42  }
43  }
44 
45  public void run(IAction action) {
46  action_ = action;
48  if(simItem_==null){
49  simItem_ = (GrxSimulationItem)manager_.createItem(GrxSimulationItem.class, null);
50  simItem_.addObserver(this);
51  manager_.itemChange(simItem_, GrxPluginManager.ADD_ITEM);
52  manager_.setSelectedItem(simItem_, true);
53  }
54  if(simItem_.isSimulating()){
55  action_.setEnabled(false);
56  simItem_.stopSimulation();
57  }else {
58  action_.setEnabled(false);
59  if(!simItem_.startSimulation(true))
60  action_.setEnabled(true);
61  }
62  }
63 
64  public void selectionChanged(IAction action, ISelection selection) {}
65  public void dispose() {
66  }
67  public void init(IWorkbenchWindow window) {}
68 
69  public void setActionImage(boolean start){
70  if(action_==null)
71  action_ = getStartSimulationAction();
72  if(start){
73  action_.setToolTipText(MessageBundle.get("GrxOpenHRPView.text.stop")); //$NON-NLS-1$
74  action_.setText(MessageBundle.get("GrxOpenHRPView.menu.stop")); //$NON-NLS-1$
75  action_.setImageDescriptor(Activator.getDefault().getDescriptor("sim_stop.png")); //$NON-NLS-1$
76  }else{
77  action_.setToolTipText(MessageBundle.get("GrxOpenHRPView.text.start")); //$NON-NLS-1$
78  action_.setText(MessageBundle.get("GrxOpenHRPView.menu.start")); //$NON-NLS-1$
79  action_.setImageDescriptor(Activator.getDefault().getDescriptor("sim_start.png")); //$NON-NLS-1$
80  }
81  }
82 
83  private IAction getStartSimulationAction()
84  {
85  IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
86  for(IWorkbenchWindow w : windows){
87  if(!(w instanceof ApplicationWindow))
88  continue;
89  ApplicationWindow window = (ApplicationWindow)w;
90  ICoolBarManager coolbar = window.getCoolBarManager2();
91  if(coolbar == null)
92  continue;
93  IContributionItem setitem = coolbar.find("com.generalrobotix.ui.actionSet");
94  if(setitem != null && setitem instanceof ToolBarContributionItem)
95  {
96  IToolBarManager toolbar = ((ToolBarContributionItem)setitem).getToolBarManager();
97  if(toolbar == null)
98  continue;
99  IContributionItem actitem = toolbar.find("com.generalrobotix.ui.actions.StartSimulate");
100  if(actitem != null && actitem instanceof ActionContributionItem)
101  return ((ActionContributionItem)actitem).getAction();
102  }
103  }
104  return null;
105  }
106 
107  public void registerItemChange(GrxBaseItem item, int event) {
108  if(item instanceof GrxSimulationItem){
109  GrxSimulationItem simItem = (GrxSimulationItem) item;
110  switch(event){
112  if(simItem_!=simItem){
113  simItem_ = simItem;
114  simItem_.addObserver(this);
115  }
116  break;
119  if(simItem_==simItem){
120  simItem_.deleteObserver(this);
121  simItem_ = null;
122  }
123  break;
124  default:
125  break;
126  }
127  }
128 
129  }
130 
131  public void update(GrxBasePlugin plugin, Object... arg) {
132  if(simItem_==plugin){
133  if(arg[0].equals("StartSimulation")){
134  setActionImage(true);
135  action_.setEnabled(true);
136  }else if(arg[0].equals("StopSimulation")){
137  setActionImage(false);
138  action_.setEnabled(true);
139  }
140  }
141  }
142 
143 }
static final String get(String key)
void selectionChanged(IAction action, ISelection selection)
void itemChange(GrxBaseItem item, int event)
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxBaseItem createItem(Class<?extends GrxBaseItem > cls, String name)
アイテムの作成. 指定したアイテムプラグインに、指定したアイテム名で新しいアイテムを作る。 ...
void registerItemChange(GrxBaseItem item, int event)
w
void setSelectedItem(GrxBaseItem item, boolean select)
select/unselect item
boolean startSimulation(boolean isInteractive)
png_size_t start
Definition: png.h:1496
void update(GrxBasePlugin plugin, Object...arg)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void init(IWorkbenchWindow window)
org
char * arg
Definition: cdjpeg.h:136
void registerItemChangeListener(GrxItemChangeListener view, Class<?extends GrxBaseItem > cls)


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:25