1 11 package org.eclipse.ui.internal.views.properties.tabbed.view; 12 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.StructuredViewer; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.swt.widgets.Widget; 22 import org.eclipse.ui.IWorkbenchPart; 23 24 31 public class TabbedPropertyViewer extends StructuredViewer { 32 33 protected TabbedPropertyList list; 34 protected List elements; 35 protected IWorkbenchPart part; 36 37 43 public TabbedPropertyViewer(TabbedPropertyList list) { 44 this.list = list; 45 hookControl(list); 46 elements = new ArrayList (); 47 } 48 49 57 public Object getElementAt(int index) { 58 if (index >= 0 && index < elements.size()) { 59 return elements.get(index); 60 } 61 return null; 62 } 63 64 70 public int getSelectionIndex() { 71 return list.getSelectionIndex(); 72 } 73 74 protected Widget doFindInputItem(Object element) { 75 76 return null; 77 } 78 79 protected Widget doFindItem(Object element) { 80 81 return null; 82 } 83 84 protected void doUpdateItem(Widget item, Object element, boolean fullMap) { 85 86 } 87 88 protected List getSelectionFromWidget() { 89 int index = list.getSelectionIndex(); 90 if (index == TabbedPropertyList.NONE) { 91 return Collections.EMPTY_LIST; 92 } 93 List result = new ArrayList (1); 94 result.add(getElementAt(index)); 95 return result; 96 } 97 98 protected void internalRefresh(Object element) { 99 100 } 101 102 public void reveal(Object element) { 103 104 } 105 106 110 protected void setSelectionToWidget(List l, boolean reveal) { 111 if (l == null || l.size() == 0) { list.deselectAll(); 113 } else { 114 Object object = l.get(0); 115 int index = -1; 116 for (int i = 0; i < elements.size(); i++) { 117 if (elements.get(i) == object) { 118 index = i; 119 } 120 } 121 Assert.isTrue(index != -1, "Could not set the selected tab in the tabbed property viewer"); list.select(index); 123 } 124 } 125 126 public Control getControl() { 127 return list; 128 } 129 130 protected void inputChanged(Object input, Object oldInput) { 131 elements.clear(); 132 Object [] children = getSortedChildren(getRoot()); 133 list.removeAll(); 134 for (int i = 0; i < children.length; i++) { 135 elements.add(children[i]); 136 mapElement(children[i], list); 137 } 138 list.setElements(children); 139 } 140 141 149 public void setInput(IWorkbenchPart part, ISelection selection) { 150 this.part = part; 151 setInput(selection); 152 } 153 154 159 public IWorkbenchPart getWorkbenchPart() { 160 return part; 161 } 162 } 163 | Popular Tags |