1 11 package org.eclipse.ui.internal.views.properties.tabbed.view; 12 13 import org.eclipse.core.runtime.ISafeRunnable; 14 import org.eclipse.core.runtime.Platform; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.layout.FillLayout; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.ui.IWorkbenchPart; 22 import org.eclipse.ui.views.properties.tabbed.ISection; 23 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; 24 25 31 public class Tab { 32 33 private ISection[] sections; 34 35 private boolean controlsCreated; 36 37 Tab() { 38 controlsCreated = false; 39 } 40 41 46 public int getSectionIndex(ISection section) { 47 for (int i = 0; i < sections.length; i++) { 48 if (section == sections[i]) { 49 return i; 50 } 51 } 52 return -1; 53 } 54 55 60 public ISection getSectionAtIndex(int i) { 61 if (i >= 0 && i < sections.length) { 62 return sections[i]; 63 } 64 return null; 65 } 66 67 72 public ISection[] getSections() { 73 return sections; 74 } 75 76 82 public void createControls(Composite parent, 83 final TabbedPropertySheetPage page) { 84 Composite pageComposite = page.getWidgetFactory().createComposite( 85 parent, SWT.NO_FOCUS); 86 GridLayout layout = new GridLayout(); 87 layout.marginWidth = 0; 88 layout.marginHeight = 0; 89 layout.verticalSpacing = 0; 90 pageComposite.setLayout(layout); 91 92 for (int i = 0; i < sections.length; i++) { 93 final ISection section = sections[i]; 94 final Composite sectionComposite = page.getWidgetFactory() 95 .createComposite(pageComposite, SWT.NO_FOCUS); 96 sectionComposite.setLayout(new FillLayout()); 97 int style = (section.shouldUseExtraSpace()) ? GridData.FILL_BOTH 98 : GridData.FILL_HORIZONTAL; 99 GridData data = new GridData(style); 100 data.heightHint = section.getMinimumHeight(); 101 sectionComposite.setLayoutData(data); 102 103 ISafeRunnable runnable = new ISafeRunnable() { 104 105 public void run() 106 throws Exception { 107 section.createControls(sectionComposite, page); 108 } 109 110 public void handleException(Throwable exception) { 111 112 } 113 }; 114 Platform.run(runnable); 115 } 116 controlsCreated = true; 117 } 118 119 122 public void dispose() { 123 for (int i = 0; i < sections.length; i++) { 124 final ISection section = sections[i]; 125 ISafeRunnable runnable = new ISafeRunnable() { 126 127 public void run() 128 throws Exception { 129 section.dispose(); 130 } 131 132 public void handleException(Throwable exception) { 133 134 } 135 }; 136 Platform.run(runnable); 137 } 138 } 139 140 143 public void aboutToBeShown() { 144 for (int i = 0; i < sections.length; i++) { 145 final ISection section = sections[i]; 146 ISafeRunnable runnable = new ISafeRunnable() { 147 148 public void run() 149 throws Exception { 150 section.aboutToBeShown(); 151 } 152 153 public void handleException(Throwable exception) { 154 155 } 156 }; 157 Platform.run(runnable); 158 } 159 } 160 161 164 public void aboutToBeHidden() { 165 for (int i = 0; i < sections.length; i++) { 166 final ISection section = sections[i]; 167 ISafeRunnable runnable = new ISafeRunnable() { 168 169 public void run() 170 throws Exception { 171 section.aboutToBeHidden(); 172 } 173 174 public void handleException(Throwable exception) { 175 176 } 177 }; 178 Platform.run(runnable); 179 } 180 } 181 182 188 public void setInput(final IWorkbenchPart part, final ISelection selection) { 189 for (int i = 0; i < sections.length; i++) { 190 final ISection section = sections[i]; 191 ISafeRunnable runnable = new ISafeRunnable() { 192 193 public void run() 194 throws Exception { 195 section.setInput(part, selection); 196 } 197 198 public void handleException(Throwable throwable) { 199 throwable.printStackTrace(); 200 } 201 }; 202 Platform.run(runnable); 203 } 204 } 205 206 void setSections(ISection[] sections) { 207 this.sections = sections; 208 } 209 210 214 public boolean controlsHaveBeenCreated() { 215 return controlsCreated; 216 } 217 218 221 public void refresh() { 222 if (controlsCreated) { 223 for (int i = 0; i < sections.length; i++) { 224 final ISection section = sections[i]; 225 ISafeRunnable runnable = new ISafeRunnable() { 226 227 public void run() 228 throws Exception { 229 section.refresh(); 230 } 231 232 public void handleException(Throwable throwable) { 233 throwable.printStackTrace(); 234 } 235 }; 236 Platform.run(runnable); 237 } 238 } 239 } 240 } 241 | Popular Tags |