1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.jface.dialogs.IDialogConstants; 14 import org.eclipse.jface.preference.IPreferenceNode; 15 import org.eclipse.jface.preference.IPreferencePageContainer; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.resource.JFaceResources; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.custom.ScrolledComposite; 20 import org.eclipse.swt.events.MouseAdapter; 21 import org.eclipse.swt.events.MouseEvent; 22 import org.eclipse.swt.graphics.Color; 23 import org.eclipse.swt.graphics.Font; 24 import org.eclipse.swt.graphics.Point; 25 import org.eclipse.swt.graphics.Rectangle; 26 import org.eclipse.swt.layout.FormAttachment; 27 import org.eclipse.swt.layout.FormData; 28 import org.eclipse.swt.layout.FormLayout; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Control; 33 import org.eclipse.swt.widgets.Label; 34 35 39 public class PreferencesPageContainer implements IPreferencePageContainer { 40 41 private Composite control; 42 43 private ScrolledComposite scrolled; 44 45 private class PreferenceEntry { 46 47 Composite composite; 48 49 IPreferenceNode node; 50 51 String title; 52 53 int offset; 54 55 Label expandImage; 56 57 Label titleLabel; 58 59 Composite pageContainer; 60 61 67 PreferenceEntry(IPreferenceNode displayedNode, String pageTitle) { 68 node = displayedNode; 69 title = pageTitle; 70 } 71 72 75 private void addSubNodes() { 76 IPreferenceNode[] subnodes = node.getSubNodes(); 77 PreferenceEntry previous = null; 78 for (int i = 0; i < subnodes.length; i++) { 79 PreferenceEntry entry = createEntry(subnodes[i], subnodes[i] 80 .getLabelText(), offset + 1); 81 if (previous == null) { 82 entry.composite.moveBelow(this.composite); 83 } else { 84 entry.composite.moveBelow(previous.composite); 85 } 86 previous = entry; 87 } 88 } 89 90 96 void createContents(int indent) { 97 98 composite = new Composite(control, SWT.NULL); 99 100 103 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); 104 gridData.horizontalIndent = IDialogConstants.SMALL_INDENT * indent; 105 composite.setLayoutData(gridData); 106 107 FormLayout layout = new FormLayout(); 108 layout.marginHeight = 0; 109 layout.marginWidth = 0; 110 composite.setLayout(layout); 111 112 Font titleFont = JFaceResources.getBannerFont(); 113 114 expandImage = new Label(composite, SWT.RIGHT); 115 expandImage.setText("+"); expandImage.setFont(titleFont); 117 118 FormData imageData = new FormData(); 119 imageData.top = new FormAttachment(0); 120 imageData.left = new FormAttachment(0, 121 IDialogConstants.HORIZONTAL_SPACING); 122 expandImage.setLayoutData(imageData); 123 124 titleLabel = new Label(composite, SWT.LEFT); 126 titleLabel.setText(title); 127 titleLabel.setFont(titleFont); 128 129 FormData titleData = new FormData(); 130 titleData.right = new FormAttachment(100); 131 titleData.top = new FormAttachment(0); 132 titleData.left = new FormAttachment(expandImage, 133 IDialogConstants.HORIZONTAL_SPACING); 134 titleLabel.setLayoutData(titleData); 135 136 titleLabel.addMouseListener(new MouseAdapter() { 137 142 public void mouseDown(MouseEvent e) { 143 144 if (pageContainer == null) { 145 boolean adjustScrollbars = false; 146 147 pageContainer = new Composite(composite, SWT.BORDER); 148 149 FormData containerData = new FormData(); 150 containerData.top = new FormAttachment(titleLabel, 0); 151 containerData.left = new FormAttachment(0); 152 containerData.right = new FormAttachment(100); 153 pageContainer.setLayoutData(containerData); 154 155 pageContainer.setLayout(new GridLayout()); 156 157 node.createPage(); 158 node.getPage().createControl(pageContainer); 159 node.getPage().setContainer( 160 PreferencesPageContainer.this); 161 node.getPage().getControl().setLayoutData( 162 new GridData(GridData.FILL_BOTH)); 163 adjustScrollbars = true; 164 165 Point contentSize = node.getPage().computeSize(); 166 Rectangle totalArea = composite.getClientArea(); 167 168 if (contentSize.x < totalArea.width) { 169 contentSize.x = totalArea.width; 170 } 171 172 node.getPage().setSize(contentSize); 173 if (adjustScrollbars) { 174 adjustScrollbars(contentSize); 175 } 176 177 expandImage.setText("-"); 179 addSubNodes(); 180 181 setSelectionColors(composite.getDisplay() 182 .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); 183 } else { 184 setSelectionColors(null); 185 pageContainer.dispose(); 186 pageContainer = null; 187 expandImage.setText("+"); } 189 190 control.layout(true); 191 } 192 }); 193 offset = indent; 194 } 195 196 202 private void setSelectionColors(Color highlight) { 203 composite.setBackground(highlight); 204 titleLabel.setBackground(highlight); 205 expandImage.setBackground(highlight); 206 } 207 208 } 209 210 213 public PreferencesPageContainer() { 214 super(); 215 } 216 217 223 void createContents(Composite parent, int style) { 224 scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); 225 226 GridData newPageData = new GridData(GridData.FILL_BOTH); 227 scrolled.setLayoutData(newPageData); 228 229 control = new Composite(scrolled, style); 230 231 scrolled.setContent(control); 232 scrolled.setExpandVertical(true); 233 scrolled.setExpandHorizontal(true); 234 GridData controlData = new GridData(GridData.FILL_BOTH); 235 control.setLayoutData(controlData); 236 237 GridLayout layout = new GridLayout(); 238 layout.marginHeight = 0; 239 layout.marginWidth = 0; 240 layout.verticalSpacing = 1; 241 control.setLayout(layout); 242 243 } 244 245 250 Control getControl() { 251 return control; 252 } 253 254 261 boolean show(IPreferenceNode node) { 262 createGeneralEntry(node); 263 control.layout(true); 264 return true; 265 } 266 267 273 private void createGeneralEntry(IPreferenceNode node) { 274 PreferenceEntry entry = createEntry(node, "General", 0); entry.addSubNodes(); 276 277 } 278 279 288 private PreferenceEntry createEntry(IPreferenceNode node, String name, 289 int indent) { 290 PreferenceEntry entry = new PreferenceEntry(node, name); 291 entry.createContents(indent); 292 return entry; 293 } 294 295 300 public IPreferenceStore getPreferenceStore() { 301 return null; 303 } 304 305 310 public void updateButtons() { 311 313 } 314 315 320 public void updateMessage() { 321 323 } 324 325 330 public void updateTitle() { 331 333 } 334 335 340 private void adjustScrollbars(Point contentSize) { 341 342 Point size = control.getSize(); 343 scrolled.setMinHeight(size.y + contentSize.y); 344 scrolled.setMinWidth(Math.max(size.x, contentSize.x)); 345 } 346 347 } 348 | Popular Tags |