19 package com.generalrobotix.ui.view;
21 import java.util.ArrayList;
22 import java.util.List;
24 import java.util.Vector;
25 import java.util.Iterator;
27 import org.eclipse.jface.action.Action;
28 import org.eclipse.jface.action.MenuManager;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.ISelectionChangedListener;
31 import org.eclipse.jface.viewers.IStructuredSelection;
32 import org.eclipse.jface.viewers.ITreeContentProvider;
33 import org.eclipse.jface.viewers.IViewerLabelProvider;
34 import org.eclipse.jface.viewers.LabelProvider;
35 import org.eclipse.jface.viewers.SelectionChangedEvent;
36 import org.eclipse.jface.viewers.StructuredSelection;
37 import org.eclipse.jface.viewers.TreeViewer;
38 import org.eclipse.jface.viewers.Viewer;
39 import org.eclipse.jface.viewers.ViewerLabel;
41 import org.eclipse.swt.SWT;
42 import org.eclipse.swt.graphics.Image;
43 import org.eclipse.swt.widgets.Composite;
44 import org.eclipse.swt.widgets.Event;
45 import org.eclipse.swt.widgets.Listener;
46 import org.eclipse.swt.widgets.Tree;
47 import org.eclipse.ui.ISharedImages;
48 import org.eclipse.ui.PlatformUI;
67 @SuppressWarnings(
"serial")
76 MenuManager menuMgr=
new MenuManager();
78 private List<GrxBasePlugin> baseItems_ =
new ArrayList<GrxBasePlugin>();
86 @SuppressWarnings(
"unchecked")
88 super(name, manager, vp, parent);
90 tv =
new TreeViewer(composite_);
91 tv.setContentProvider(
new TreeContentProvider() );
92 tv.setLabelProvider(
new TreeLabelProvider() );
94 Tree
t = tv.getTree();
97 tv.addSelectionChangedListener(
new ISelectionChangedListener() {
98 public void selectionChanged(SelectionChangedEvent event) {
99 ISelection selection =
event.getSelection();
100 for (Object o : ((IStructuredSelection) selection).toArray() ){
101 if (
GrxBaseItem.class.isAssignableFrom(o.getClass()) ){
103 }
else if(o instanceof String){
104 manager_.focusedItem(manager_.getProject());
110 t.addListener ( SWT.DefaultSelection,
new Listener () {
111 public void handleEvent (Event event) {
112 ISelection selection = tv.getSelection();
113 for (Object o : ((IStructuredSelection) selection).toArray() ){
114 if (
GrxBaseItem.class.isAssignableFrom(o.getClass()) ){
122 t.setMenu(menuMgr.createContextMenu( t ));
123 t.addListener ( SWT.MenuDetect,
new Listener () {
124 public void handleEvent (Event event) {
125 ISelection selection = tv.getSelection();
126 Object o = ((IStructuredSelection) selection).getFirstElement();
130 if (o instanceof String){
131 Vector<Action> menus = manager_.getProject().getMenu();
132 for( Action
a: menus){
138 if( Class.class.isAssignableFrom( o.getClass() ) ){
139 if(
GrxBaseItem.class.isAssignableFrom( (Class<?>)o ) ) {
140 Vector<Action> menus = manager_.getItemMenu( (Class<? extends GrxBaseItem>) o );
141 for( Action
a: menus){
149 for( Action
a: menus){
152 Vector<MenuManager> subMenus = ((
GrxBasePlugin)o).getSubMenu();
153 for( MenuManager m: subMenus){
161 tv.setInput( manager_ );
163 manager_.registerItemChangeListener(
this,
GrxBaseItem.class);
168 Iterator<GrxBasePlugin> it0 = baseItems_.iterator();
170 it0.next().deleteObserver(
this);
174 while (it.hasNext()){
175 Class<? extends GrxBaseItem>
local = (Class<? extends GrxBaseItem>)it.next();
176 if ( manager_.isItemVisible( local ) ){
177 Map<String, ?> map = (Map<String, ?>) manager_.getItemMap(local);
178 Iterator itI = map.values().iterator();
179 while(itI.hasNext()){
181 baseItems_.add(baseItem);
184 GrxModelItem model = (GrxModelItem)baseItem;
187 addchildrenObserver(root);
200 baseItems_.add(item);
203 for(
int i=0;
i<children.size();
i++){
204 addchildrenObserver(children.get(
i));
211 class TreeContentProvider
implements ITreeContentProvider {
213 Object[] gets( Object o ) {
216 Object[] os = { ((GrxPluginManager)o).getProjectName() };
221 if( o instanceof String ) {
224 ArrayList<Class<? extends GrxBaseItem>> localList =
new ArrayList<Class<? extends GrxBaseItem>>();
227 while (it.hasNext()){
228 Class<? extends GrxBaseItem>
local = (Class<? extends GrxBaseItem>)it.next();
229 if ( manager_.isItemVisible( local ) ){
230 localList.add( local );
233 return localList.toArray();
237 if( o instanceof Class ) {
238 if(
GrxBaseItem.class.isAssignableFrom( (Class<?>)o ) ) {
240 return oMap.
values().toArray();
245 GrxModelItem model = (GrxModelItem)o;
248 Vector<GrxExtraJointItem> extraJointList = ((GrxModelItem)o).extraJoints_;
249 Object[] os =
new Object[extraJointList.size() + 1];
250 os[0] = ((GrxModelItem)o).rootLink();
251 for(
int i=0;
i<extraJointList.size();
i++)
252 os[
i+1] = extraJointList.get(
i);
260 GrxLinkItem link = (GrxLinkItem)o;
266 GrxSegmentItem link = (GrxSegmentItem)o;
272 GrxSensorItem sensor = (GrxSensorItem)o;
278 GrxHwcItem hwc = (GrxHwcItem)o;
285 public Object[] getChildren(Object parentElement) {
return gets(parentElement); }
286 public Object getParent(Object element) {
return null; }
287 public boolean hasChildren(Object element) {
288 Object[] os = gets(element);
289 return os !=
null && os.length > 0;
291 public Object[] getElements(Object inputElement) {
return gets(inputElement); }
292 public void dispose() {}
293 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
299 class TreeLabelProvider
extends LabelProvider implements IViewerLabelProvider{
301 public String
getText(Object
object) {
303 if(
object instanceof Class ) {
304 if(
GrxBaseItem.class.isAssignableFrom( (Class<?>)
object ) ) {
305 return manager_.getItemTitle( (Class<? extends GrxBaseItem>)
object );
309 if(
GrxBaseItem.class.isAssignableFrom(
object.getClass() ) ) {
314 return object.toString();
317 public Image getImage( Object o ){
318 if(
GrxBaseItem.class.isAssignableFrom( o.getClass() ) ) {
320 return PlatformUI.getWorkbench().getSharedImages().getImage(
321 ISharedImages.IMG_OBJ_FILE);
324 return PlatformUI.getWorkbench().getSharedImages().getImage(
325 ISharedImages.IMG_OBJ_FOLDER);
328 public void updateLabel(ViewerLabel label, Object element) {
329 label.setText(
getText(element) );
330 label.setImage( getImage(element) );
331 if(
GrxBaseItem.class.isAssignableFrom( element.getClass() ) ) {
338 label.setText(
"("+
getText(element)+
")" );
353 if((String)
arg[0]!=
"PropertyChange")
361 if(!baseItems_.contains(item)){
363 baseItems_.add(item);
367 if(baseItems_.contains(item)){
369 baseItems_.remove(item);
377 List<GrxBasePlugin> l =
new ArrayList<GrxBasePlugin>();
379 tv.setSelection(
new StructuredSelection(l),
true);
384 manager_.removeItemChangeListener(
this,
GrxBaseItem.class);
385 Iterator<GrxBasePlugin> it = baseItems_.iterator();
387 it.next().deleteObserver(
this);
389 manager_.getProject().deleteObserver(
this);
void registerItemChange(GrxBaseItem item, int event)
ArrayList< GrxObserver > getObserver()
void addchildrenObserver(GrxBaseItem item)
void addObserver(GrxObserver v)
#define null
our own NULL pointer
png_infop png_charpp name
item corresponds to a robot model
void deleteObserver(GrxObserver v)
static final int ADD_ITEM
static Activator getDefault()
static final int FOCUSED_ITEM
GrxLinkItem rootLink()
get root link
static final int REMOVE_ITEM
This view shows tree of various items.
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void update(GrxBasePlugin plugin, Object...arg)
def getText(self, nodes=None)
ArrayList< Class<?extends GrxBaseItem > > activeItemClassList_