1 12 package org.eclipse.team.internal.ccvs.ui; 13 14 import java.util.*; 15 16 import org.eclipse.compare.internal.TabFolderLayout; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.jface.dialogs.Dialog; 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.preference.PreferencePage; 22 import org.eclipse.jface.resource.*; 23 import org.eclipse.jface.util.IPropertyChangeListener; 24 import org.eclipse.jface.util.PropertyChangeEvent; 25 import org.eclipse.jface.viewers.*; 26 import org.eclipse.jface.window.Window; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.*; 29 import org.eclipse.swt.graphics.*; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.*; 32 import org.eclipse.team.internal.ccvs.core.CVSException; 33 import org.eclipse.team.internal.ccvs.core.client.Command; 34 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 35 import org.eclipse.team.internal.ui.SWTUtils; 36 import org.eclipse.ui.*; 37 import org.eclipse.ui.dialogs.ListSelectionDialog; 38 import org.eclipse.ui.ide.IDE.SharedImages; 39 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 40 41 public class CVSDecoratorPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { 42 43 private static class PreviewFile { 44 45 public final String name, tag, mode; 46 public final int type; 47 public final boolean added, dirty, hasRemote, ignored, newResource; 48 public Collection children; 49 50 public PreviewFile(String name, int type, boolean added, boolean newResource, boolean dirty, boolean ignored, boolean hasRemote, String mode, String tag) { 51 this.name= name; 52 this.type= type; 53 this.added= added; 54 this.ignored= ignored; 55 this.dirty= dirty; 56 this.hasRemote= hasRemote; 57 this.newResource= newResource; 58 this.mode= mode != null ? mode : Command.KSUBST_TEXT.getShortDisplayText(); 59 this.tag= tag != null ? tag : ""; this.children= Collections.EMPTY_LIST; 61 } 62 63 public void configureDecoration(CVSDecoration decoration) { 64 decoration.setResourceType(type); 65 decoration.setAdded(added); 66 decoration.setDirty(dirty); 67 decoration.setNewResource(newResource); 68 decoration.setIgnored(ignored); 69 decoration.setHasRemote(hasRemote); 70 decoration.setTag(tag); 71 decoration.setKeywordSubstitution(mode); 72 } 73 } 74 75 private static class FormatEditor extends SelectionAdapter { 76 private final Text fText; 77 private final Map fBindings; 78 private final String fKey; 79 80 public FormatEditor(Composite composite, String title, String buttonText, Map bindings, String key) { 81 82 fKey= key; 83 fBindings= bindings; 84 85 final Label label= SWTUtils.createLabel(composite, title); 86 label.setLayoutData(SWTUtils.createGridData(SWT.DEFAULT, SWT.DEFAULT, false, false)); 87 88 fText= SWTUtils.createText(composite); 89 90 final Button button = new Button(composite, SWT.NONE); 91 button.setText(buttonText); 92 button.setLayoutData(new GridData()); 93 94 button.addSelectionListener(this); 95 } 96 97 public void addModifyListener(ModifyListener listener) { 98 fText.addModifyListener(listener); 99 } 100 101 public String getText() { 102 return fText.getText(); 103 } 104 105 public void widgetSelected(SelectionEvent e) { 106 107 final ILabelProvider labelProvider = new LabelProvider() { 108 public String getText(Object element) { 109 return ((Map.Entry)element).getKey() + " - " + ((Map.Entry)element).getValue(); } 111 }; 112 113 final IStructuredContentProvider contentsProvider = new IStructuredContentProvider() { 114 public Object [] getElements(Object inputElement) { 115 return ((Collection)inputElement).toArray(); 116 } 117 public void dispose() {} 118 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 119 }; 120 121 final ListSelectionDialog dialog= new ListSelectionDialog( 122 fText.getShell(), 123 fBindings.entrySet(), 124 contentsProvider, 125 labelProvider, 126 CVSUIMessages.CVSDecoratorPreferencesPage_0); 127 dialog.setHelpAvailable(false); 128 dialog.setTitle(CVSUIMessages.CVSDecoratorPreferencesPage_1); 129 if (dialog.open() != Window.OK) 130 return; 131 132 Object [] result = dialog.getResult(); 133 134 for (int i = 0; i < result.length; i++) { 135 fText.insert("{"+((Map.Entry)result[i]).getKey() +"}"); } 137 } 138 139 public void performOk(IPreferenceStore store) { 140 store.setValue(fKey, fText.getText()); 141 } 142 143 public void performDefaults(IPreferenceStore store) { 144 store.setToDefault(fKey); 145 fText.setText(store.getDefaultString(fKey)); 146 } 147 148 public void initializeValue(IPreferenceStore store) { 149 fText.setText( 150 CVSDecoration.updateOldDirtyFlag(store.getString(fKey))); 151 } 152 } 153 154 private abstract class Tab extends Observable { 155 156 public abstract void initializeValues(IPreferenceStore store); 157 public abstract void performDefaults(IPreferenceStore store); 158 public abstract void performOk(IPreferenceStore store); 159 public abstract void setPreferences(Preferences preferences); 160 161 } 162 163 private class IconDecoratorTab extends Tab implements SelectionListener { 164 165 private final Button fDirty, fHasRemote, fAdded, fNewResource; 166 167 public IconDecoratorTab(TabFolder parent) { 168 169 final Composite composite= SWTUtils.createHFillComposite(parent, SWTUtils.MARGINS_DEFAULT); 170 171 fDirty= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_2); 172 fDirty.addSelectionListener(this); 173 174 fHasRemote= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_3); 175 fHasRemote.addSelectionListener(this); 176 177 fAdded= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_4); 178 fAdded.addSelectionListener(this); 179 180 fNewResource= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_5); 181 fNewResource.addSelectionListener(this); 182 183 final TabItem item= new TabItem(parent, SWT.NONE); 184 item.setText(CVSUIMessages.CVSDecoratorPreferencesPage_6); 185 item.setControl(composite); 186 } 187 188 public void widgetSelected(SelectionEvent e) { 189 setChanged(); 190 notifyObservers(); 191 } 192 193 public void initializeValues(IPreferenceStore store) { 194 fDirty.setSelection(store.getBoolean(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION)); 195 fAdded.setSelection(store.getBoolean(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION)); 196 fHasRemote.setSelection(store.getBoolean(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION)); 197 fNewResource.setSelection(store.getBoolean(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION)); 198 } 199 200 public void performOk(IPreferenceStore store) { 201 store.setValue(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION, fDirty.getSelection()); 202 store.setValue(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION, fAdded.getSelection()); 203 store.setValue(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION, fHasRemote.getSelection()); 204 store.setValue(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION, fNewResource.getSelection()); 205 } 206 207 public void performDefaults(IPreferenceStore store) { 208 fDirty.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION)); 209 fAdded.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION)); 210 fHasRemote.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION)); 211 fNewResource.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION)); 212 } 213 214 public void setPreferences(Preferences prefs) { 215 prefs.setDefault(ICVSUIConstants.PREF_SHOW_DIRTY_DECORATION, fDirty.getSelection()); 216 prefs.setDefault(ICVSUIConstants.PREF_SHOW_ADDED_DECORATION, fAdded.getSelection()); 217 prefs.setDefault(ICVSUIConstants.PREF_SHOW_HASREMOTE_DECORATION, fHasRemote.getSelection()); 218 prefs.setDefault(ICVSUIConstants.PREF_SHOW_NEWRESOURCE_DECORATION, fNewResource.getSelection()); 219 } 220 221 public void widgetDefaultSelected(SelectionEvent e) { 222 } 223 } 224 225 private class TextDecoratorTab extends Tab implements ModifyListener { 226 227 private final FormatEditor fFileDecoration; 228 private final FormatEditor fFolderDecoration; 229 private final FormatEditor fProjectDecoration; 230 231 private final Text dirtyFlag; 232 private final Text addedFlag; 233 234 public TextDecoratorTab(TabFolder parent) { 235 236 final Composite composite= SWTUtils.createHFillComposite(parent, SWTUtils.MARGINS_DEFAULT, 3); 237 Dialog.applyDialogFont(composite); 238 239 fFileDecoration= new FormatEditor(composite, CVSUIMessages.CVSDecoratorPreferencesPage_7, CVSUIMessages.CVSDecoratorPreferencesPage_8, BINDINGS, ICVSUIConstants.PREF_FILETEXT_DECORATION); fFolderDecoration= new FormatEditor(composite, CVSUIMessages.CVSDecoratorPreferencesPage_9, CVSUIMessages.CVSDecoratorPreferencesPage_10, FOLDER_BINDINGS, ICVSUIConstants.PREF_FOLDERTEXT_DECORATION); fProjectDecoration= new FormatEditor(composite, CVSUIMessages.CVSDecoratorPreferencesPage_11, CVSUIMessages.CVSDecoratorPreferencesPage_12, FOLDER_BINDINGS, ICVSUIConstants.PREF_PROJECTTEXT_DECORATION); 243 fFileDecoration.addModifyListener(this); 244 fFolderDecoration.addModifyListener(this); 245 fProjectDecoration.addModifyListener(this); 246 247 SWTUtils.createPlaceholder(composite, 1, 3); 248 final Label dirtyLabel= SWTUtils.createLabel(composite, CVSUIMessages.CVSDecoratorPreferencesPage_13, 1); 249 dirtyLabel.setLayoutData(new GridData()); 250 251 dirtyFlag = new Text(composite, SWT.BORDER); 252 dirtyFlag.setLayoutData(SWTUtils.createHFillGridData(1)); 253 dirtyFlag.addModifyListener(this); 254 SWTUtils.createPlaceholder(composite, 1, 1); 255 256 257 final Label addedLabel= SWTUtils.createLabel(composite, CVSUIMessages.CVSDecoratorPreferencesPage_14, 1); 258 addedLabel.setLayoutData(new GridData()); 259 260 addedFlag = new Text(composite, SWT.BORDER); 261 addedFlag.setLayoutData(SWTUtils.createHFillGridData(1)); 262 addedFlag.addModifyListener(this); 263 SWTUtils.createPlaceholder(composite, 1, 1); 264 265 SWTUtils.createPlaceholder(composite, 1, 3); 266 267 final TabItem item= new TabItem(parent, SWT.NONE); 268 item.setText(CVSUIMessages.CVSDecoratorPreferencesPage_15); 269 item.setControl(composite); 270 } 271 272 public void initializeValues(IPreferenceStore store) { 273 fFileDecoration.initializeValue(store); 274 fFolderDecoration.initializeValue(store); 275 fProjectDecoration.initializeValue(store); 276 addedFlag.setText(store.getString(ICVSUIConstants.PREF_ADDED_FLAG)); 277 dirtyFlag.setText(store.getString(ICVSUIConstants.PREF_DIRTY_FLAG)); 278 } 279 280 public void performOk(IPreferenceStore store) { 281 fFileDecoration.performOk(store); 282 fFolderDecoration.performOk(store); 283 fProjectDecoration.performOk(store); 284 store.setValue(ICVSUIConstants.PREF_ADDED_FLAG, addedFlag.getText()); 285 store.setValue(ICVSUIConstants.PREF_DIRTY_FLAG, dirtyFlag.getText()); 286 } 287 288 public void performDefaults(IPreferenceStore store) { 289 fFileDecoration.performDefaults(store); 290 fFolderDecoration.performDefaults(store); 291 fProjectDecoration.performDefaults(store); 292 293 addedFlag.setText(store.getDefaultString(ICVSUIConstants.PREF_ADDED_FLAG)); 294 dirtyFlag.setText(store.getDefaultString(ICVSUIConstants.PREF_DIRTY_FLAG)); 295 } 296 297 public String getFileTextFormat() { 298 return fFileDecoration.getText(); 299 } 300 301 public String getFolderTextFormat() { 302 return fFolderDecoration.getText(); 303 } 304 305 public String getProjectTextFormat() { 306 return fProjectDecoration.getText(); 307 } 308 309 public void modifyText(ModifyEvent e) { 310 setChanged(); 311 notifyObservers(); 312 } 313 314 public void setPreferences(Preferences prefs) { 315 prefs.setDefault(ICVSUIConstants.PREF_CALCULATE_DIRTY, true); 316 prefs.setDefault(ICVSUIConstants.PREF_DIRTY_FLAG, dirtyFlag.getText()); 317 prefs.setDefault(ICVSUIConstants.PREF_ADDED_FLAG, addedFlag.getText()); 318 } 319 } 320 321 private class GeneralTab extends Tab implements SelectionListener { 322 private final Button fShowDirty; 323 private final Button fUseFontDecorations; 324 325 public GeneralTab(TabFolder parent) { 326 final Composite composite= SWTUtils.createHFillComposite(parent, SWTUtils.MARGINS_DEFAULT); 327 Dialog.applyDialogFont(composite); 328 329 SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSDecoratorPreferencesPage_36, CVSUIMessages.CVSDecoratorPreferencesPage_37); 330 331 fShowDirty= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_16); 332 SWTUtils.createLabel(composite, CVSUIMessages.CVSDecoratorPreferencesPage_17); 333 334 fUseFontDecorations= SWTUtils.createCheckBox(composite, CVSUIMessages.CVSDecoratorPreferencesPage_18); 335 336 SWTUtils.createPreferenceLink((IWorkbenchPreferenceContainer) getContainer(), composite, CVSUIMessages.CVSDecoratorPreferencesPage_19, CVSUIMessages.CVSDecoratorPreferencesPage_20); 337 338 fShowDirty.addSelectionListener(this); 339 fUseFontDecorations.addSelectionListener(this); 340 341 final TabItem item= new TabItem(parent, SWT.NONE); 342 item.setText(CVSUIMessages.CVSDecoratorPreferencesPage_21); 343 item.setControl(composite); 344 } 345 346 public void widgetSelected(SelectionEvent e) { 347 setChanged(); 348 notifyObservers(); 349 } 350 351 public void widgetDefaultSelected(SelectionEvent e) { 352 } 353 354 public void initializeValues(IPreferenceStore store) { 355 fShowDirty.setSelection(store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY)); 356 fUseFontDecorations.setSelection(store.getBoolean(ICVSUIConstants.PREF_USE_FONT_DECORATORS)); 357 } 358 359 public void performDefaults(IPreferenceStore store) { 360 fShowDirty.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY)); 361 fUseFontDecorations.setSelection(store.getDefaultBoolean(ICVSUIConstants.PREF_USE_FONT_DECORATORS)); 362 } 363 364 public void performOk(IPreferenceStore store) { 365 store.setValue(ICVSUIConstants.PREF_CALCULATE_DIRTY, fShowDirty.getSelection()); 366 store.setValue(ICVSUIConstants.PREF_USE_FONT_DECORATORS, fUseFontDecorations.getSelection()); 367 } 368 369 public void setPreferences(Preferences preferences) { 370 preferences.setValue(ICVSUIConstants.PREF_CALCULATE_DIRTY, fShowDirty.getSelection()); 371 preferences.setValue(ICVSUIConstants.PREF_USE_FONT_DECORATORS, fUseFontDecorations.getSelection()); 372 } 373 374 public boolean isFontDecorationEnabled() { 375 return this.fUseFontDecorations.getEnabled(); 376 } 377 378 } 379 380 public class Preview extends LabelProvider implements Observer, ITreeContentProvider { 381 382 private final ResourceManager fImageCache; 383 private final TreeViewer fViewer; 384 385 public Preview(Composite composite) { 386 SWTUtils.createLabel(composite, CVSUIMessages.CVSDecoratorPreferencesPage_39); 387 fImageCache= new LocalResourceManager(JFaceResources.getResources()); 388 fViewer = new TreeViewer(composite); 389 fViewer.getControl().setLayoutData(SWTUtils.createHVFillGridData()); 390 fViewer.setContentProvider(this); 391 fViewer.setLabelProvider(this); 392 fViewer.setInput(ROOT); 393 fViewer.expandAll(); 394 } 395 396 public void refresh() { 397 fViewer.refresh(true); 398 setColorsAndFonts(); 399 } 400 401 private void setColorsAndFonts() { 402 TreeItem[] items = fViewer.getTree().getItems(); 403 setColorsAndFonts(items); 404 } 405 406 private void setColorsAndFonts(TreeItem[] items) { 407 for (int i = 0; i < items.length; i++) { 408 if (fGeneralTab.isFontDecorationEnabled()) { 409 Color backGroundColor = getBackground(items[i].getData()); 410 items[i].setBackground(backGroundColor); 411 Color foreGroundColor = getForeground(items[i].getData()); 412 items[i].setForeground(foreGroundColor); 413 Font font = getFont(items[i].getData()); 414 items[i].setFont(font); 415 } else { 416 items[i].setBackground(null); 417 items[i].setForeground(null); 418 items[i].setFont(null); 419 } 420 setColorsAndFonts(items[i].getItems()); 421 } 422 } 423 424 public void update(Observable o, Object arg) { 425 refresh(); 426 } 427 428 public Object [] getChildren(Object parentElement) { 429 return ((PreviewFile)parentElement).children.toArray(); 430 } 431 432 public Object getParent(Object element) { 433 return null; 434 } 435 436 public boolean hasChildren(Object element) { 437 return !((PreviewFile)element).children.isEmpty(); 438 } 439 440 public Object [] getElements(Object inputElement) { 441 return ((Collection)inputElement).toArray(); 442 } 443 444 public void dispose() { 445 fImageCache.dispose(); 446 } 447 448 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 449 } 450 451 public Color getBackground(Object element) { 452 return getDecoration(element).getBackgroundColor(); 453 } 454 455 public Color getForeground(Object element) { 456 return getDecoration(element).getForegroundColor(); 457 } 458 459 public Font getFont(Object element) { 460 return getDecoration(element).getFont(); 461 } 462 463 public String getText(Object element) { 464 final CVSDecoration decoration = getDecoration(element); 465 final StringBuffer buffer = new StringBuffer (); 466 final String prefix = decoration.getPrefix(); 467 if (prefix != null) 468 buffer.append(prefix); 469 buffer.append(((PreviewFile)element).name); 470 final String suffix = decoration.getSuffix(); 471 if (suffix != null) 472 buffer.append(suffix); 473 return buffer.toString(); 474 } 475 476 public CVSDecoration getDecoration(Object element) { 477 final CVSDecoration decoration = buildDecoration((PreviewFile)element); 478 ((PreviewFile)element).configureDecoration(decoration); 479 decoration.compute(); 480 return decoration; 481 } 482 483 public Image getImage(Object element) { 484 final String s; 485 switch (((PreviewFile)element).type) { 486 case IResource.PROJECT: 487 s= SharedImages.IMG_OBJ_PROJECT; break; 488 case IResource.FOLDER: 489 s= ISharedImages.IMG_OBJ_FOLDER; break; 490 default: 491 s= ISharedImages.IMG_OBJ_FILE; break; 492 } 493 final Image baseImage= PlatformUI.getWorkbench().getSharedImages().getImage(s); 494 final ImageDescriptor overlay = getDecoration(element).getOverlay(); 495 if (overlay == null) 496 return baseImage; 497 try { 498 return fImageCache.createImage(new DecorationOverlayIcon(baseImage, overlay, IDecoration.BOTTOM_RIGHT)); 499 } catch (DeviceResourceException e) { 500 CVSUIPlugin.log(new Status(IStatus.ERROR, CVSUIPlugin.ID, 0, "Error creating decorator image", e)); } 502 return null; 503 } 504 } 505 506 private static class ThemeListener implements IPropertyChangeListener { 507 508 private final Preview fPreview; 509 510 ThemeListener(Preview preview) { 511 fPreview= preview; 512 } 513 public void propertyChange(PropertyChangeEvent event) { 514 fPreview.refresh(); 515 } 516 } 517 518 protected static final Collection ROOT; 519 protected static final Map BINDINGS; 520 protected static final Map FOLDER_BINDINGS; 521 522 static { 523 BINDINGS= new HashMap(); 524 BINDINGS.put(CVSDecoratorConfiguration.RESOURCE_NAME, CVSUIMessages.CVSDecoratorPreferencesPage_22); 525 BINDINGS.put(CVSDecoratorConfiguration.RESOURCE_TAG, CVSUIMessages.CVSDecoratorPreferencesPage_23); 526 BINDINGS.put(CVSDecoratorConfiguration.FILE_KEYWORD, CVSUIMessages.CVSDecoratorPreferencesPage_24); 527 BINDINGS.put(CVSDecoratorConfiguration.FILE_REVISION, CVSUIMessages.CVSDecoratorPreferencesPage_25); 528 BINDINGS.put(CVSDecoratorConfiguration.NEW_DIRTY_FLAG, CVSUIMessages.CVSDecoratorPreferencesPage_26); 529 BINDINGS.put(CVSDecoratorConfiguration.ADDED_FLAG, CVSUIMessages.CVSDecoratorPreferencesPage_27); 530 531 FOLDER_BINDINGS= new HashMap(); 532 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.RESOURCE_NAME, CVSUIMessages.CVSDecoratorPreferencesPage_28); 533 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.RESOURCE_TAG, CVSUIMessages.CVSDecoratorPreferencesPage_29); 534 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_HOST, CVSUIMessages.CVSDecoratorPreferencesPage_30); 535 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_METHOD, CVSUIMessages.CVSDecoratorPreferencesPage_31); 536 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_USER, CVSUIMessages.CVSDecoratorPreferencesPage_32); 537 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_ROOT, CVSUIMessages.CVSDecoratorPreferencesPage_33); 538 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_REPOSITORY, CVSUIMessages.CVSDecoratorPreferencesPage_34); 539 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.REMOTELOCATION_LABEL, CVSUIMessages.CVSDecoratorPreferencesPage_38); 540 FOLDER_BINDINGS.put(CVSDecoratorConfiguration.NEW_DIRTY_FLAG, CVSUIMessages.CVSDecoratorPreferencesPage_35); 541 542 final PreviewFile project= new PreviewFile("Project", IResource.PROJECT, false, false, false, false, true, null, "v1_0"); final ArrayList children= new ArrayList(); 544 children.add(new PreviewFile("Folder", IResource.FOLDER, false, false, false, false, true, null, null)); children.add(new PreviewFile("ignored.txt", IResource.FILE, false, false, false, true, false, null, null)); children.add(new PreviewFile("dirty.cpp", IResource.FILE, false, false, true, false, true, null, null)); children.add(new PreviewFile("added.java", IResource.FILE, true, false, true, false, false, null, null)); children.add(new PreviewFile("todo.txt", IResource.FILE, false, true, true, false, false, null, null)); children.add(new PreviewFile("bugs.txt", IResource.FILE, false, false, true, false, true, null, null)); children.add(new PreviewFile("archive.zip", IResource.FILE, false, false, true, false, true, Command.KSUBST_BINARY.getShortDisplayText(), null)); project.children= children; 552 ROOT= Collections.singleton(project); 553 } 554 555 556 private TextDecoratorTab fTextTab; 557 private IconDecoratorTab fIconTab; 558 private GeneralTab fGeneralTab; 559 560 private Preview fPreview; 561 private ThemeListener fThemeListener; 562 563 protected Control createContents(Composite parent) { 564 565 final Composite composite= SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_NONE); 566 567 final Composite folderComposite= SWTUtils.createHFillComposite(composite, SWTUtils.MARGINS_NONE); 568 569 final TabFolder tabFolder = new TabFolder(folderComposite, SWT.NONE); 571 tabFolder.setLayout(new TabFolderLayout()); 572 tabFolder.setLayoutData(SWTUtils.createHFillGridData()); 573 574 fGeneralTab= new GeneralTab(tabFolder); 576 fTextTab= new TextDecoratorTab(tabFolder); 577 fIconTab= new IconDecoratorTab(tabFolder); 578 579 fPreview= new Preview(composite); 580 581 fTextTab.addObserver(fPreview); 582 fIconTab.addObserver(fPreview); 583 fGeneralTab.addObserver(fPreview); 584 585 initializeValues(); 586 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.DECORATORS_PREFERENCE_PAGE); 587 Dialog.applyDialogFont(parent); 588 589 PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(fThemeListener= new ThemeListener(fPreview)); 590 591 return tabFolder; 592 } 593 594 public void dispose() { 595 if (fThemeListener != null) 596 PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(fThemeListener); 597 if (fPreview != null) 598 fPreview.dispose(); 599 } 600 601 604 private void initializeValues() { 605 final IPreferenceStore store = getPreferenceStore(); 606 fTextTab.initializeValues(store); 607 fIconTab.initializeValues(store); 608 fGeneralTab.initializeValues(store); 609 fPreview.refresh(); 610 setValid(true); 611 } 612 613 616 public void init(IWorkbench workbench) { 617 } 618 619 624 public boolean performOk() { 625 final IPreferenceStore store = getPreferenceStore(); 626 fTextTab.performOk(store); 627 fIconTab.performOk(store); 628 fGeneralTab.performOk(store); 629 if (store.needsSaving()) { 630 CVSUIPlugin.broadcastPropertyChange(new PropertyChangeEvent(this, CVSUIPlugin.P_DECORATORS_CHANGED, null, null)); 631 CVSUIPlugin.getPlugin().savePluginPreferences(); 632 } 633 return true; 634 } 635 636 640 protected void performDefaults() { 641 final IPreferenceStore store = getPreferenceStore(); 642 643 fTextTab.performDefaults(store); 644 fIconTab.performDefaults(store); 645 fGeneralTab.performDefaults(store); 646 fPreview.refresh(); 647 super.performDefaults(); 648 } 649 650 657 protected IPreferenceStore doGetPreferenceStore() { 658 return CVSUIPlugin.getPlugin().getPreferenceStore(); 659 } 660 661 662 public CVSDecoration buildDecoration(PreviewFile file) { 663 final Preferences prefs = new Preferences(); 664 665 fIconTab.setPreferences(prefs); 666 fTextTab.setPreferences(prefs); 667 fGeneralTab.setPreferences(prefs); 668 669 final CVSDecoration decoration= new CVSDecoration(prefs, fTextTab.getFileTextFormat(), fTextTab.getFolderTextFormat(), fTextTab.getProjectTextFormat()); 670 671 decoration.setKeywordSubstitution(Command.KSUBST_TEXT.getShortDisplayText()); 672 decoration.setRevision("1.45"); try { 674 decoration.setLocation(CVSRepositoryLocation.fromString(":pserver:alize@cvs.site.org:/home/cvsroot")); } catch (CVSException e) { 676 } 678 return decoration; 679 } 680 } 681 | Popular Tags |