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); |