View | Details | Raw Unified | Return to bug 91965
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java (+1 lines)
Lines 387-392 Link Here
387
	public static String FileEditorPreference_existsMessage;
387
	public static String FileEditorPreference_existsMessage;
388
	public static String FileEditorPreference_defaultLabel;
388
	public static String FileEditorPreference_defaultLabel;
389
    public static String FileEditorPreference_contentTypesRelatedLink;
389
    public static String FileEditorPreference_contentTypesRelatedLink;
390
    public static String FileEditorPreference_isLocked;
390
391
391
	public static String FileExtension_extensionEmptyMessage;
392
	public static String FileExtension_extensionEmptyMessage;
392
	public static String FileExtension_fileNameInvalidMessage;
393
	public static String FileExtension_fileNameInvalidMessage;
(-)Eclipse UI/org/eclipse/ui/internal/messages.properties (+1 lines)
Lines 374-379 Link Here
374
FileEditorPreference_existsMessage = An entry already exists for that file type
374
FileEditorPreference_existsMessage = An entry already exists for that file type
375
FileEditorPreference_defaultLabel = (default)
375
FileEditorPreference_defaultLabel = (default)
376
FileEditorPreference_contentTypesRelatedLink = See <a>''{0}''</a> for content-type based file associations.
376
FileEditorPreference_contentTypesRelatedLink = See <a>''{0}''</a> for content-type based file associations.
377
FileEditorPreference_isLocked = (locked)
377
378
378
FileExtension_extensionEmptyMessage = The file extension cannot be empty
379
FileExtension_extensionEmptyMessage = The file extension cannot be empty
379
FileExtension_fileNameInvalidMessage = The file name cannot include the wild card character (*) in the current location
380
FileExtension_fileNameInvalidMessage = The file name cannot include the wild card character (*) in the current location
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java (-17 / +105 lines)
Lines 16-21 Link Here
16
import java.util.List;
16
import java.util.List;
17
import java.util.Map;
17
import java.util.Map;
18
18
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.jface.preference.IPreferenceStore;
21
import org.eclipse.jface.preference.PreferencePage;
23
import org.eclipse.jface.preference.PreferencePage;
Lines 61-67 Link Here
61
 */
63
 */
62
public class FileEditorsPreferencePage extends PreferencePage implements
64
public class FileEditorsPreferencePage extends PreferencePage implements
63
        IWorkbenchPreferencePage, Listener {
65
        IWorkbenchPreferencePage, Listener {
64
    protected Table resourceTypeTable;
66
	
67
    private static final String DATA_EDITOR = "editor"; //$NON-NLS-1$
68
69
    private static final String DATA_FROM_CONTENT_TYPE = "type"; //$NON-NLS-1$
70
    
71
	protected Table resourceTypeTable;
65
72
66
    protected Button addResourceTypeButton;
73
    protected Button addResourceTypeButton;
67
74
Lines 320-326 Link Here
320
            for (int i = 0; i < array.length; i++) {
327
            for (int i = 0; i < array.length; i++) {
321
                IEditorDescriptor editor = array[i];
328
                IEditorDescriptor editor = array[i];
322
                TableItem item = new TableItem(editorTable, SWT.NULL);
329
                TableItem item = new TableItem(editorTable, SWT.NULL);
323
                item.setData(editor);
330
                item.setData(DATA_EDITOR, editor);
324
                // Check if it is the default editor
331
                // Check if it is the default editor
325
                String defaultString = null;
332
                String defaultString = null;
326
                FileEditorMapping ext = getSelectedResourceType();
333
                FileEditorMapping ext = getSelectedResourceType();
Lines 337-348 Link Here
337
                }
344
                }
338
                item.setImage(getImage(editor));
345
                item.setImage(getImage(editor));
339
            }
346
            }
347
            
348
            // now add any content type editors
349
			EditorRegistry registry = (EditorRegistry) WorkbenchPlugin
350
					.getDefault().getEditorRegistry();
351
			IContentType[] contentTypes = Platform.getContentTypeManager()
352
					.findContentTypesFor(resourceType.getLabel());
353
			for (int i = 0; i < contentTypes.length; i++) {
354
				array = registry.getEditorsForContentType(contentTypes[i]);
355
				for (int j = 0; j < array.length; j++) {
356
					IEditorDescriptor editor = array[i];
357
					// don't add duplicates
358
					TableItem[] items = editorTable.getItems();
359
					TableItem foundItem = null;
360
					for (int k = 0; k < items.length; k++) {
361
						if (items[k].getData(DATA_EDITOR).equals(editor)) {
362
							foundItem = items[k];
363
							break;
364
						}
365
					}
366
					if (foundItem == null) {
367
						TableItem item = new TableItem(editorTable, SWT.NULL);
368
						item.setData(DATA_EDITOR, editor);
369
						item.setData(DATA_FROM_CONTENT_TYPE, Boolean.TRUE);
370
						item
371
								.setText(editor.getLabel()
372
										+ " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$
373
						item.setImage(getImage(editor));
374
					} else { // update the item to reflect its origin
375
						foundItem.setData(DATA_FROM_CONTENT_TYPE, Boolean.TRUE);
376
						foundItem
377
								.setText(foundItem.getText()
378
										+ " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$
379
					}
380
				}
381
			}
382
            
340
        }
383
        }
341
    }
384
    }
342
385
343
    /**
386
    /**
344
     * Place the existing resource types in the table
387
	 * Place the existing resource types in the table
345
     */
388
	 */
346
    protected void fillResourceTypeTable() {
389
    protected void fillResourceTypeTable() {
347
        // Populate the table with the items
390
        // Populate the table with the items
348
        IFileEditorMapping[] array = WorkbenchPlugin.getDefault()
391
        IFileEditorMapping[] array = WorkbenchPlugin.getDefault()
Lines 380-386 Link Here
380
        if (editorTable.getItemCount() > 0) {
423
        if (editorTable.getItemCount() > 0) {
381
            ArrayList editorList = new ArrayList();
424
            ArrayList editorList = new ArrayList();
382
            for (int i = 0; i < editorTable.getItemCount(); i++)
425
            for (int i = 0; i < editorTable.getItemCount(); i++)
383
                editorList.add(editorTable.getItem(i).getData());
426
                editorList.add(editorTable.getItem(i).getData(DATA_EDITOR));
384
427
385
            return (IEditorDescriptor[]) editorList
428
            return (IEditorDescriptor[]) editorList
386
                    .toArray(new IEditorDescriptor[editorList.size()]);
429
                    .toArray(new IEditorDescriptor[editorList.size()]);
Lines 473-479 Link Here
473
                int i = editorTable.getItemCount();
516
                int i = editorTable.getItemCount();
474
                boolean isEmpty = i < 1;
517
                boolean isEmpty = i < 1;
475
                TableItem item = new TableItem(editorTable, SWT.NULL, i);
518
                TableItem item = new TableItem(editorTable, SWT.NULL, i);
476
                item.setData(editor);
519
                item.setData(DATA_EDITOR, editor);
477
                if (isEmpty)
520
                if (isEmpty)
478
                    item
521
                    item
479
                            .setText(editor.getLabel()
522
                            .setText(editor.getLabel()
Lines 510-525 Link Here
510
        boolean defaultEditor = editorTable.getSelectionIndex() == 0;
553
        boolean defaultEditor = editorTable.getSelectionIndex() == 0;
511
        if (items.length > 0) {
554
        if (items.length > 0) {
512
            getSelectedResourceType().removeEditor(
555
            getSelectedResourceType().removeEditor(
513
                    (EditorDescriptor) items[0].getData());
556
                    (EditorDescriptor) items[0].getData(DATA_EDITOR));
514
            items[0].dispose(); //Table is single selection
557
            items[0].dispose(); //Table is single selection
515
        }
558
        }
516
        if (defaultEditor && editorTable.getItemCount() > 0) {
559
        if (defaultEditor && editorTable.getItemCount() > 0) {
517
            TableItem item = editorTable.getItem(0);
560
            TableItem item = editorTable.getItem(0);
518
            if (item != null)
561
            if (item != null)
519
                item
562
                item
520
                        .setText(((EditorDescriptor) (item.getData()))
563
                        .setText(((EditorDescriptor) (item.getData(DATA_EDITOR)))
521
                                .getLabel()
564
                                .getLabel()
522
                                + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$
565
                                + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$
566
			if (!isEditorRemovable(item))
567
				item
568
						.setText(item.getText()
569
								+ " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$
523
        }
570
        }
524
571
525
    }
572
    }
Lines 545-563 Link Here
545
            // First change the label of the old default
592
            // First change the label of the old default
546
            TableItem oldDefaultItem = editorTable.getItem(0);
593
            TableItem oldDefaultItem = editorTable.getItem(0);
547
            oldDefaultItem
594
            oldDefaultItem
548
                    .setText(((EditorDescriptor) oldDefaultItem.getData())
595
                    .setText(((EditorDescriptor) oldDefaultItem.getData(DATA_EDITOR))
549
                            .getLabel());
596
                            .getLabel());
597
            // update the label to reflect the locked state
598
            if (!isEditorRemovable(oldDefaultItem)) 
599
            	oldDefaultItem
600
						.setText(oldDefaultItem.getText()
601
								+ " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$
550
            // Now set the new default
602
            // Now set the new default
551
            EditorDescriptor editor = (EditorDescriptor) items[0].getData();
603
            EditorDescriptor editor = (EditorDescriptor) items[0].getData(DATA_EDITOR);
552
            getSelectedResourceType().setDefaultEditor(editor);
604
            getSelectedResourceType().setDefaultEditor(editor);
605
            Boolean fromContentType = (Boolean) items[0].getData(DATA_FROM_CONTENT_TYPE);
553
            items[0].dispose(); //Table is single selection
606
            items[0].dispose(); //Table is single selection
554
            TableItem item = new TableItem(editorTable, SWT.NULL, 0);
607
            TableItem item = new TableItem(editorTable, SWT.NULL, 0);
555
            item.setData(editor);
608
            item.setData(DATA_EDITOR, editor);
609
            if (fromContentType != null)
610
            		item.setData(DATA_FROM_CONTENT_TYPE, fromContentType);
556
            item
611
            item
557
                    .setText(editor.getLabel()
612
                    .setText(editor.getLabel()
558
                            + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$
613
                            + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$
559
            item.setImage(getImage(editor));
614
            item.setImage(getImage(editor));
560
            editorTable.setSelection(new TableItem[] { item });
615
            if (!isEditorRemovable(item))
616
				item
617
						.setText(item.getText()
618
								+ " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$
619
			editorTable.setSelection(new TableItem[] { item });
561
        }
620
        }
562
    }
621
    }
563
622
Lines 572-586 Link Here
572
        removeResourceTypeButton.setEnabled(resourceTypeSelected);
631
        removeResourceTypeButton.setEnabled(resourceTypeSelected);
573
        editorLabel.setEnabled(resourceTypeSelected);
632
        editorLabel.setEnabled(resourceTypeSelected);
574
        addEditorButton.setEnabled(resourceTypeSelected);
633
        addEditorButton.setEnabled(resourceTypeSelected);
575
        removeEditorButton.setEnabled(editorSelected);
634
        removeEditorButton.setEnabled(editorSelected && isEditorRemovable());
576
        defaultEditorButton.setEnabled(editorSelected);
635
        defaultEditorButton.setEnabled(editorSelected);
577
    }
636
    }
578
637
    
579
    /**
638
    /**
580
     * Update the selected type.
639
	 * Return whether the selected editor is removable. An editor is removable
581
     */
640
	 * if it is not submitted via a content-type binding.
641
	 * 
642
	 * @return whether the selected editor is removable
643
	 * @since 3.1
644
	 */
645
    private boolean isEditorRemovable() {
646
		TableItem[] items = editorTable.getSelection();
647
		if (items.length > 0) 
648
			return isEditorRemovable(items[0]);
649
		return false;
650
	}
651
    
652
    /**
653
	 * Return whether the given editor is removable. An editor is removable
654
	 * if it is not submitted via a content-type binding.
655
	 * 
656
	 * @param item the item to test
657
	 * @return whether the selected editor is removable
658
	 * @since 3.1
659
	 */
660
    private boolean isEditorRemovable(TableItem item) {
661
		Boolean fromContentType = (Boolean) item.getData(DATA_FROM_CONTENT_TYPE);
662
		if (fromContentType == null)
663
			return true;
664
		return !fromContentType.booleanValue();
665
	}
666
667
	/**
668
	 * Update the selected type.
669
	 */
582
    public void updateSelectedResourceType() {
670
    public void updateSelectedResourceType() {
583
        //  TableItem item = resourceTypeTable.getSelection()[0]; //Single select
671
        // TableItem item = resourceTypeTable.getSelection()[0]; //Single select
584
        //  Image image = ((IFileEditorMapping)item.getData()).getImageDescriptor().getImage();
672
        //  Image image = ((IFileEditorMapping)item.getData()).getImageDescriptor().getImage();
585
        //  imagesToDispose.addElement(image);
673
        //  imagesToDispose.addElement(image);
586
        //  item.setImage(image);
674
        //  item.setImage(image);
(-)Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java (+41 lines)
Lines 1428-1431 Link Here
1428
		}
1428
		}
1429
		return allRelated.toArray();
1429
		return allRelated.toArray();
1430
	}
1430
	}
1431
1432
	/**
1433
	 * Return the editors bound to this content type, either directly or indirectly.
1434
	 * 
1435
	 * @param type the content type to check
1436
	 * @return the editors
1437
	 * @since 3.1
1438
     *
1439
     * TODO: this should be rolled in with the above findRelatedObjects code
1440
	 */
1441
	public IEditorDescriptor [] getEditorsForContentType(IContentType type) {
1442
		ArrayList allRelated = new ArrayList();
1443
		if (type == null) 
1444
			return new IEditorDescriptor [0];
1445
		
1446
		Object [] related = relatedRegistry.getRelatedObjects(type);
1447
		for (int i = 0; i < related.length; i++) {	
1448
			// we don't want to return duplicates
1449
			if (!allRelated.contains(related[i])) {
1450
				// if it's not filtered, add it to the list
1451
				if (!WorkbenchActivityHelper.filterItem(related[i]))
1452
					allRelated.add(related[i]);
1453
				
1454
			}
1455
		}
1456
		
1457
		// now add any indirectly related objects, walking up the content type hierarchy 
1458
		while ((type = type.getBaseType()) != null) {
1459
			related = relatedRegistry.getRelatedObjects(type);
1460
			for (int i = 0; i < related.length; i++) {
1461
				// we don't want to return duplicates
1462
				if (!allRelated.contains(related[i])) {
1463
					// if it's not filtered, add it to the list
1464
					if (!WorkbenchActivityHelper.filterItem(related[i]))
1465
						allRelated.add(related[i]);
1466
				}
1467
			}
1468
		}
1469
		
1470
		return (IEditorDescriptor[]) allRelated.toArray(new IEditorDescriptor[allRelated.size()]);
1471
	}
1431
}
1472
}

Return to bug 91965